JavaScript
GeoJsonLayer
The GeoJSON layer uses the GeoJSON data format to draw geometric objects over the map. See the GeoJSON Layer docs for details.
Creates a new instance of the layer.
Parameters
- def optional
-
object The layer definition object.
data
optionalInitial data to load into this layer. Data can be changed after instantiation via layer.data().
id
optional string A unique identifier for this layer. If omitted one will be generated automatically.
options
optionalInitial options to set on this layer. Options can be changed after instantiation via layer.options() or layer.resetOptions().
visible
optional boolean Initial visibility of this layer. Visibility can be changed after instantiation via layer.visible().
Returns
GeoJsonLayer
A unique id of the layer.
Gets or sets the current data for this layer.
Parameters
Returns
GeoJsonLayerData
A reference to the data object it was most recently passed.
Gets the bounds of the items in the layer with the specified ids, or all items if no ids are specified. Returns null if there are no items to compute bounds for.
Parameters
Returns
LngLatBounds
Gets or sets the layer options while preserving any previously set options.
Parameters
Returns
object
An object containing all layer options and their current values.
Overrides the style of the specified GeoJSON features.
Parameters
Returns
StyleReset
A reset function that removes the style override.
Sets the provided layer options while resetting any other previously set options to default values.
Parameters
Returns
void
Gets or sets the layer visibility.
Parameters
Returns
boolean
Specifies the styling for GeoJSON features. These styles can be overridden with overrideStyle.
const geoJsonData = {
type: 'Feature',
id: 'EiffelTower_linestring',
properties: {
color: 'rgba(0,0,255,0.7)', // custom color
width: 10, // custom line width
},
geometry: {
type: 'LineString',
coordinates: [
[2.2955, 48.8594],
[2.2935, 48.8594],
],
},
};border
optional object Defines the border styling for Polygon, MultiPolygon, Point and MultiPoint features.
color
optional string
default: '#808080' The fill color for the GeoJSON feature.
radius
optional number
default: 1 The radius for Point and MultiPoint features. Set the units in units.
width
optional number
default: 2 The width for LineString and MultiLineString features. Set the units in units.
GeoJsonLayerData GeoJSON | Feature[] The data describing the geometric object in GeoJSON format. Accepts a single GeoJSON object or an array of GeoJSON feature objects.
const geoJsonData = {
type: 'Feature',
id: 'EiffelTower_polygon',
properties: {
color: 'rgba(0,255,0,0.3)',
},
geometry: {
type: 'Polygon', // the polygon is a rectangle around the Eiffel Tower
coordinates: [
[
[2.2935, 48.8574], // bottom-left
[2.2955, 48.8574], // bottom-right
[2.2955, 48.8594], // top-right
[2.2935, 48.8594], // top-left
],
],
},
};The options to set on this layer.
const geoJsonOptions = {
filled: false,
units: 'pixels'
};
// ...
mapweave.addLayer(
new GeoJsonLayer({
data: geoJsonData,
options: geoJsonOptions
}),
);filled
optional boolean
default: true Set to true to fill the Polygon, MultiPolygon, Point and MultiPoint features with the color set in color.
units
optional "meters" | "pixels"
default: 'pixels' Sets the units used for border.width, width and radius.