ym.modules.provider.GeoJSON

Overview

Represents a GeoJSON object or an array of GeoJSON objects Allows GeoJSON data to be analyzed and displayed on the map. Advanced FeatureGroup.

ym.geoJson(data, {
    style: function (feature) {
        return {color: feature.properties.color};
    },
    onEachFeature: function (feature, layer) {
        layer.bindPopup(feature.properties.description);
    }
}).addTo(map);  

Each feature layer is given a feature property that refers to the GeoJSON property from which it was derived.

Initialization

Factory: ym.geoJson(geojson, options)

Parameter: geojson

[optional]

Parameter: options

[optional]
Option properties Description
pointToLayer(GeoJSON featureData, LatLng latlng) Function used to create layers for GeoJSON points (if not specified, simple markers are created).
style(GeoJSON featureData) Function used to obtain style options for vector layers created for GeoJSON features
onEachFeature(GeoJSON featureData, ILayer layer) function that is called on each created feature layer. Useful for attaching events and popups to features.
filter(GeoJSON featureData, ILayer layer) Function that is used to decide whether a feature should be displayed or not.
coordsToLatLng(Array coords) Function used to convert GeoJSON coordinates to LatLng points (if not specified, coordinates are assumed to be WGS84, meaning [Longitude, Latitude] in degrees).

Methods

Non-static methods

addData(data) ab v3

Adds a GeoJSON object to the layer.

Parameter

Name Description Data type Default value
data   GeoJSON  

Return

this

setStyle(style) ab v3

Changes the styles of GeoJSON vector layers using the specified style function.

Parameter

Name Description Data type Default value
style   Function  

Return

this

resetStyle(layer) ab v3

Resets the style of the specified vector layer (for example after a hover event) to the original GeoJSON style

Parameter

Name Description Data type Default value
layer   Path  

Return

this

Static methods

geometryToLayer(featureData, pointToLayer) ab v3

Creates a layer from a specific GeoJSON feature.

Parameters

Name Description Data type Default value
featureData [required] GeoJSON  
pointToLayer [optional] Function  

Return

ILayer

coordsToLatLng(coords, reverse) ab v3

Creates a LatLng object from an array of 2 numbers (latitude, longitude) used for points in GeoJSON. If reverse is set to true, the numbers are interpreted as (longitude, latitude).

Parameters

Name Description Data type Default value
coords [required] Array  
reverse [optional] bool  

Return

LatLng

coordsToLatLngs(coords, levelsDeep, reverse) ab v3

Creates a multidimensional array of LatLng objects from a GeoJSON coordinate array. levelsDeep specifies the nesting level (0 represents an array of points, 1 represents an array of points, etc.; 0 by default). If reverse is set to true, the numbers are interpreted as (longitude, latitude).

Parameters

Name Description Data type Default value
coords [required] Array  
levelsDeep [optional] int  
reverse [optional] bool  

Return

Array