Converts imported GeoJSON data to MapKit JS items.
SDK
- MapKit JS 5.0+
Framework
- Map
Kit JS
Declaration
Item Collection|Error importGeoJSON(String|Object data, optional function|Geo JSONDelegate callback);
Parameters
data
The original GeoJSON data, which may be a URL to a GeoJSON file, or a GeoJSON object.
callback
A callback function that is required if you provide a URL for the
data
parameter, and optional otherwise.
Return Value
If the data argument is a GeoJSON object instead of a URL and you provide no callback
function, import
returns an Item
. If the data import fails, an error is returned.
Discussion
This function converts imported GeoJSON data to MapKit JS items, which are annotations
, overlays
, and/or Item
objects. Access the original GeoJSON data through the object's data
property.
You can customize the import by implementing a Geo
callback:
If you provide a GeoJSON object for the
data
parameter,import
returns the result directly. However, if you provide an optional callback, it is used.Geo JSON If you provide a URL to a GeoJSON file in the
data
parameter, you must provide a callback function.
The callback is invoked with two arguments, error
on failure and result
on success, as follows:
error
(Error)Contains an error code and descriptive message.
result
(Item)The resulting
Item
. The raw GeoJSON used to generate the object is tored in the object'sCollection data
property.
Note
GeoJSON is a format that encodes geographic data. See the GeoJSON standard specification RFC 7946 for more information.