-
Notifications
You must be signed in to change notification settings - Fork 152
Point, Location, and Coordinate
var point = new MM.Point(x, y)
// Get a point between two other points, biased by `t`.
var p3 = MM.Point.interpolate(p1, p2, t)
// Get the euclidean distance between two points
var d = MM.Point.distance(p1, p2);
Point is a simple data object with x and y properties. It's most often used to represent pixel positions on screen or within the map.
var p1 = new MM.Point(10, 20);
var p2 = new MM.Point(20, 20);
// d is 10
var d = MM.Point.distance(p1,p2);
// p3 is half way between p1 and p2: (15,20)
var amount = 0.5;
var p3 = MM.Point.interpolate(p1,p2,amount);
var loc = new MM.Location(latitude, longitude);
// Get the distance between two points, in
// meters, with a sphere of radius r meters (default 6378000)
var d = MM.Location.distance(l1, l2, r)
// Get the interpolation of two points, biased by f,
// along the great circle
var l3 = MM.Location.interpolate(l1, l2, f)
Location is similar to Point, but for geographic coordinates. It has lat and lon properties (and expects them in that order, unlike Point which works the other way around). It represents locations on the surface of the earth in degrees latitude and longitude. You can use a site like getlatlon.com to find the latitude and longitude of places by name.
// Create a new location at 30 latitude, 114 longitude (Xinjiezhen)
var loc = new MM.Location(30, 114);
var coord = new MM.Coordinate(row, column, zoom);
// Get a string key to refer to this coordinate
var key = coord.toKey();
// Get the whole-number coordinate that contains a potentially
// in-between coordinate
var container = coord.container();
// Get a copy of this coordinate
var copy = coord.copy();
// Navigation with coordinates
var zoomedTo = coord.zoomTo(5);
var zoomedIn = coord.zoomTo(1);
var pannedLeft = coord.left(1);
Coordinate is used internally to represent tiles, and the map state - so they have instance functions that let you do all of the navigation that you'd expect out of a map. It has row, column and zoom properties.
It also has several methods that help you navigate from one coordinate to
another: up
, right
, down
, left
, zoomTo
and zoomBy
. All return
a new Coordinate. Additionally, copy
can be used to clone a Coordinate
and container
can be used to obtain a Coordinate with floored row, column
and zoom for generating tile URLs.