Geography
#Geography
LngLat and LngLatBounds represent point and polygon coordinates in the geographical world.
LngLat
The LngLat object represents a specified latitude and longitude coordinate in degrees.
To match the GeoJSON format, GL uses a coordinate order of longitude, latitude (instead of latitude, longitude).
Create the Marker component.
new LngLat(lng: number, lat: number)
Parameters
| Name | Type | Description |
|---|---|---|
| lat | Number | RequiredLatitude, unit is degree. |
| lng | Number | RequiredLongitude, unit is degree. |
Case
var ll = new mapmost.LngLat(-73.9749, 40.7736);
Static members
convert
Convert an array containing two numbers or an object with properties lng and lat or lon and lat to a LngLat object. If a LngLat object is passed, the function returns it unchanged.
Parameters
| Name | Type | Description |
|---|---|---|
| input | LngLatLike | RequiredAn array or object containing two numbers to be converted, or a LngLat object to be returned. |
Case
var arr = [-73.9749, 40.7736];
var ll = mapmost.LngLat.convert(arr);
ll; // = LngLat {Longitude: -73.9749, Latitude: 40.7736}
Instance members
toArray
Returns an array coordinate containing two numbers.
Case
var ll = new mapmost.LngLat(-73.9749, 40.7736);
ll.toArray(); // = [-73.9749, 40.7736]
toBounds
Returns a LngLatBounds from the coordinate position to the specified extension bounds.
Parameters
| name | type | default value | description |
|---|---|---|---|
| radius | Number | 0 | optionalThe distance (in meters) from the coordinate position to the extension boundary. |
Case
var ll = new mapmost.LngLat(-73.9749, 40.7736);
ll.toBounds(100).toArray(); // = [[-73.97501862141328, 40.77351016847229], [-73.97478137858673, 40.77368983152771]]
toString
Returns the coordinates as a string.
Case
var ll = new mapmost.LngLat(-73.9749, 40.7736);
ll.toString(); // = "LngLat(-73.9749, 40.7736)"
wrap
Returns a new LngLat object with longitude in the range (-180, 180).
Case
var ll = new mapmost.LngLat(286.0251, 40.7736);
var wrapped = ll.wrap();
wrapped.lng; // = -73.9749
LngLatBounds
The LngLatBounds object represents a geographic bounding box, defined by southwest and northeast points represented by latitude and longitude.
If no arguments are provided to the constructor, a null bounding box is created.
new LngLatBounds(sw: LngLatLike?, ne: LngLatLike?)
Parameters
| Name | Type | Description |
|---|---|---|
| sw | LngLatLike | RequiredThe southwest corner of the range box. |
| ne | LngLatLike | RequiredThe northeast corner of the range box. |
Case
var sw = new mapmost.LngLat(-73.9876, 40.7661);
var ne = new mapmost.LngLat(-73.9397, 40.8002);
var llb = new mapmost.LngLatBounds(sw, ne);
Static members
convert
Convert the array to a LngLatBounds object.If the passed argument is a LngLatBounds object, the function returns it unchanged.
This function internally calls the LngLat#convert function to convert the array into a LngLat value.
Parameters
| Name | Type | Description |
|---|---|---|
| input | LngLatBoundsLike | RequiredAn array containing two coordinates to be converted, or a LngLatBounds object to be returned. |
Case
var arr = [[-73.9876, 40.7661], [-73.9397, 40.8002]];
var llb = mapmost.LngLatBounds.convert(arr);
llb; // = LngLatBounds {_sw: LngLat {longitude: -73.9876, latitude: 40.7661}, _ne: LngLat {longitude: -73.9397, latitude: 40.8002}}
Instance members
extend
The extended bounds include the specified LngLat or LngLatBounds.
Parameters
| Name | Type | Description |
|---|---|---|
| obj | LngLat|LngLatBounds | RequiredObject that extends the boundaries. |
Case
const sw = new mapmost.LngLat(-73.9876, 40.7661);
const ne = new mapmost.LngLat(-73.9397, 40.8002);
const llb = new mapmost.LngLatBounds(sw, ne);
llb.extend([-72.9876, 42.2661]);
getCenter
Returns a geographic coordinate equidistant from the corners of the bounding box.
Case
var llb = new mapmost.LngLatBounds([-73.9876, 40.7661], [-73.9397, 40.8002]);
llb.getCenter(); // = LngLat {Longitude: -73.96365, Latitude: 40.78315}
getEast
Returns the eastern boundary of the range box.
Case
const llb = new mapmost.LngLatBounds([-73.9876, 40.7661], [-73.9397, 40.8002]);
llb.getEast(); // -73.9397
getNorth
Returns the northern boundary of the range box.
Case
const llb = new mapmost.LngLatBounds([-73.9876, 40.7661], [-73.9397, 40.8002]);
llb.getNorth(); // 40.8002
getNorthEast
Returns the northeast corner of the range box.
Case
const llb = new mapmost.LngLatBounds([-73.9876, 40.7661], [-73.9397, 40.8002]);
llb.getNorthEast(); // LngLat {Longitude: -73.9397, Latitude: 40.8002}
getNorthWest
Returns the northwest corner of the range box.
Case
const llb = new mapmost.LngLatBounds([-73.9876, 40.7661], [-73.9397, 40.8002]);
llb.getNorthWest(); // LngLat {Longitude: -73.9876, Latitude: 40.8002}
getSouth
Returns the southern boundary of the range box.
Case
const llb = new mapmost.LngLatBounds([-73.9876, 40.7661], [-73.9397, 40.8002]);
llb.getSouth(); // 40.7661
getSouthEast
Returns the southeast corner of the range box.
Case
const llb = new mapmost.LngLatBounds([-73.9876, 40.7661], [-73.9397, 40.8002]);
llb.getSouthEast(); // LngLat {Longitude: -73.9397, Latitude: 40.7661}
getSouthWest
Returns the southwest corner of the range box.
Case
const llb = new mapmost.LngLatBounds([-73.9876, 40.7661], [-73.9397, 40.8002]);
llb.getSouthWest(); // LngLat {Longitude: -73.9876, Latitude: 40.7661}
getWest
Returns the western boundary of the range box.
Case
const llb = new mapmost.LngLatBounds([-73.9876, 40.7661], [-73.9397, 40.8002]);
llb.getWest(); // -73.9876
isEmpty
Check if the range box is empty.
Case
const llb = new mapmost.LngLatBounds();
llb.isEmpty(); // true
llb.setNorthEast([-73.9876, 40.7661]);
llb.setSouthWest([-73.9397, 40.8002]);
llb.isEmpty(); // false
setNorthEast
Sets the northeast corner of the range box.
Parameters
| Name | Type | Description |
|---|---|---|
| ne | LngLatLike | RequiredThe northeast corner of the range box. |
Case
const sw = new mapmost.LngLat(-73.9876, 40.7661);
const ne = new mapmost.LngLat(-73.9397, 40.8002);
const llb = new mapmost.LngLatBounds(sw, ne);
llb.setNorthEast([-73.9397, 42.8002]);
setSouthWest
Sets the southwest corner of the range box.
Parameters
| Name | Type | Description |
|---|---|---|
| sw | LngLatLike | RequiredThe southwest corner of the range box. |
Case
const sw = new mapmost.LngLat(-73.9876, 40.7661);
const ne = new mapmost.LngLat(-73.9397, 40.8002);
const llb = new mapmost.LngLatBounds(sw, ne);
llb.setSouthWest([-73.9876, 40.2661]);
toArray
Returns the range box represented as an array.
Case
var llb = new mapmost.LngLatBounds([-73.9876, 40.7661], [-73.9397, 40.8002]);
llb.toArray(); // = [[-73.9876, 40.7661], [-73.9397, 40.8002]]
toString
Returns the range box as a string.
Case
var llb = new mapmost.LngLatBounds([-73.9876, 40.7661], [-73.9397, 40.8002]);
llb.toString(); // = "LngLatBounds(LngLat(-73.9876, 40.7661), LngLat(-73.9397, 40.8002))"
LngLatBoundsLike
A LngLatBounds object, or an array of LngLatLike objects in the order [Southwest, Northeast], or an array of numbers in the order [West, South, East, North].
Case
var v1 = new mapmost.LngLatBounds(
new mapmost.LngLat(-73.9876, 40.7661),
new mapmost.LngLat(-73.9397, 40.8002)
);
var v2 = new mapmost.LngLatBounds([-73.9876, 40.7661], [-73.9397, 40.8002])
var v3 = [[-73.9876, 40.7661], [-73.9397, 40.8002]];
LngLatLike
A LngLat object, either an array of two numbers representing longitude and latitude, or an object with lng and lat or lon and lat properties.
Case
var v1 = new mapmost.LngLat(-122.420679, 37.772537);
var v2 = [-122.420679, 37.772537];
var v3 = {lon: -122.420679, lat: 37.772537};
MercatorCoordinate
A MercatorCoordinate instance represents a three-dimensional projected coordinate.
MercatorCoordinate uses the Web Mercator projection (EPSG:3857), but has slightly different unit handling:
- Unit 1 represents the width of the projected world instead of meters in Mercator coordinates as originally defined
- The origin of the coordinate space is the northwest corner instead of the original center point
new MercatorCoordinate(x: number, y: number, z: number)
Parameters
| name | type | default value | description |
|---|---|---|---|
| x | Number | RequiredPosition on the x-axis. | |
| y | Number | RequiredPosition on the y-axis. | |
| z | Number | 0 | optionalPosition on the z-axis. |
Case
var nullIsland = new mapmost.MercatorCoordinate(0.5, 0.5, 0);
Static members
fromLngLat
Convert LngLat projection to MercatorCoordinate.
Parameters
| name | type | default value | description |
|---|---|---|---|
| lngLatLike | LngLatLike | RequiredLatitude and longitude to be converted. | |
| altitude | Number | 0 | optionalThe altitude of the location point, in meters. |
Case
var coord = mapmost.MercatorCoordinate.fromLngLat({ lng: 0, lat: 0}, 0);
coord; // MercatorCoordinate(0.5, 0.5, 0)
Instance members
toAltitude
Returns the altitude of this coordinate in meters.
Case
var coord = new mapmost.MercatorCoordinate(0, 0, 0.02);
coord.toAltitude(); // 6914.281956295339
toLngLat
Returns the latitude and longitude of this coordinate LngLat .
Case
var coord = new mapmost.MercatorCoordinate(0.5, 0.5, 0);
var latLng = coord.toLngLat(); // Latitude and longitude coordinates (0, 0)