Skip to content

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

Name 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)

Adds a GeoJSON object to the layer.

Parameter Description Data type Default value
data GeoJSON
  • Return: this

setStyle(style)

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

Parameter Description Data type Default value
style Function
  • Return: this

resetStyle(layer)

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

Parameter Description Data type Default value
layer Path
  • Return: this

Static Methods

geometryToLayer(featureData, pointToLayer)

Creates a layer from a specific GeoJSON feature.

Parameter Description Data type Default value
featureData [required] GeoJSON
pointToLayer [optional] Function
  • Return: ILayer

coordsToLatLng(coords, reverse)

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).

Parameter Description Data type Default value
coords [required] Array
reverse [optional] bool
  • Return: LatLng

coordsToLatLngs(coords, levelsDeep, reverse)

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).

Parameter Description Data type Default value
coords [required] Array
levelsDeep [optional] int
reverse [optional] bool
  • Return: Array