Constructor
new MapUtils()
Static Methods
Name | Description |
---|---|
bboxToPointArray | Converts a bounding box string of format POLYGON((lng1 lat1, lng2 lat2,...)) (POLYGON or LINESTRING) into an array of coordinates. The order of the latitude and longitude can be controlled by the latFirst parameter. |
calculateAreaKmSq | Calculate the area of a given GeoJSON object in square kilometers. The GeoJSON object can be a FeatureCollection or a Feature. For circle geometries, the Properties object must contain an attribute called Radius, with the radius in meters. |
createIcon | Utility function to create a new marker icon with sensible defaults |
createMarker | Convenience utility for creating a new marker with optional configuration parameters and popup. |
getGeometryWithCirclesFromGeoJSON |
Utility method to take a standard GeoJSON object and change the geometry of Point types to Circle types (not
supported by the GeoJSON standard). This function assumes that the properties object of the circle features has
a property of 'point_type' with a value of 'circle', and a property of 'radius'.
I.e. this function will convert
{
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"properties": {
"point_type": "circle",
"radius": 1027747.8506951465
},
"geometry": {
"type": "Point",
"coordinates": [
122.51953124999999,
-13.410994034321702
]
}
}
]
}
into
{
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"properties": {
"point_type": "circle",
"radius": 1027747.8506951465
},
"geometry": {
"type": "Circle",
"coordinates": [
122.51953124999999,
-13.410994034321702
],
"centre": [
122.51953124999999,
-13.410994034321702
],
"radius": 1027747.8506951465
}
}
]
}
|
getStandardGeoJSONForCircleGeometry | Performs the opposite of #getGeometryWithCirclesFromGeoJSON to produce valid standard GeoJSON. |
wrapGeometryInGeoJSONFeatureCol | Takes a bare geoJSON geometry object, and wraps it in a full GeoJSON structure with type=FeatureCollection |
-
bboxToPointArray(bboxString, latFirst) → {Array}static
-
Converts a bounding box string of format POLYGON((lng1 lat1, lng2 lat2,...)) (POLYGON or LINESTRING) into an array of coordinates. The order of the latitude and longitude can be controlled by the latFirst parameter.
Parameters
Name Type Description bboxString Bounding box string to convert latFirst True to produce LAT/LNG points, false to produce LNG/LAT points. Returns
Array array of points
-
calculateAreaKmSq(geoJson) → {number}static
-
Calculate the area of a given GeoJSON object in square kilometers. The GeoJSON object can be a FeatureCollection or a Feature.
For circle geometries, the Properties object must contain an attribute called Radius, with the radius in meters.
Parameters
Name Type Description geoJson Object GeoJSON object to calculate the area for Returns
number The calculated area in square kilometers
-
createIcon(iconUrl, iconOptions) → {Object}static
-
Utility function to create a new marker icon with sensible defaults
Parameters
Name Type Description iconUrl String The URL to the image for the marker. Mandatory. iconOptions Object Object containing leaflet Icon configuration options to override the defaults. Optional. Returns
Object Leaflet Icon object
-
createMarker(lat, lng, popup, markerOptions) → {Object}static
-
Convenience utility for creating a new marker with optional configuration parameters and popup.
Parameters
Name Type Description lat Number Latitude of the marker. Mandatory. lng Number Longitude of the marker. Mandatory. popup String Text or HTML to display in a popup when the marker is clicked. Optional. markerOptions Object Standard Leaflet L.Marker configuration options. Optional. Returns
Object Leaflet L.Marker object
-
getGeometryWithCirclesFromGeoJSON(geoJSON) → {*}static
-
Utility method to take a standard GeoJSON object and change the geometry of Point types to Circle types (not supported by the GeoJSON standard). This function assumes that the properties object of the circle features has a property of 'point_type' with a value of 'circle', and a property of 'radius'.
I.e. this function will convert
{ "type": "FeatureCollection", "features": [ { "type": "Feature", "properties": { "point_type": "circle", "radius": 1027747.8506951465 }, "geometry": { "type": "Point", "coordinates": [ 122.51953124999999, -13.410994034321702 ] } } ] }
into{ "type": "FeatureCollection", "features": [ { "type": "Feature", "properties": { "point_type": "circle", "radius": 1027747.8506951465 }, "geometry": { "type": "Circle", "coordinates": [ 122.51953124999999, -13.410994034321702 ], "centre": [ 122.51953124999999, -13.410994034321702 ], "radius": 1027747.8506951465 } } ] }
Parameters
Name Type Description geoJSON Returns
*
-
getStandardGeoJSONForCircleGeometry(geoJSON) → {GeoJSON}static
-
Performs the opposite of #getGeometryWithCirclesFromGeoJSON to produce valid standard GeoJSON.
Parameters
Name Type Description geoJSON The modified GeoJSON to be converted back to the standard format. Returns
GeoJSON
-
wrapGeometryInGeoJSONFeatureCol(geometry) → {Object}static
-
Takes a bare geoJSON geometry object, and wraps it in a full GeoJSON structure with type=FeatureCollection
Parameters
Name Type Description geometry The geoJSON geometry object to wrap Returns
Object Full GeoJSON structure with type=FeatureCollection