A small module for incorporating incorporating simple style on geojson layers in leafletjs
npm install leaflet-simplestyleL.geoJSON to support the simplestyle spec.
npm install leaflet-simplestyle
``$3
Step 1. Include the library after you've included leafletjs.`
require('leaflet-simplestyle')
// or
// or via CDN
`Step 2. Set the
useSimpleStyle option to true when adding your L.geoJSON layer. You can also chose whether to support the Maki Icon Library using the
useMakiMarkers property, this enables support for the marker-symbol property, however it does require calling the Mapbox API. If useMakiMarkers=false an inline SVG icon is still available which adjusts size and color.``
const rect = {
"type": "Feature",
"properties": {
"fill": "yellow"
},
"geometry": {
"type": "Polygon",
"coordinates": [
[
[
10.45007,
-10.359502
],
...
[
10.45007,
-10.359502
]
]
]
}
}, L.geoJSON(rect, {
useSimpleStyle: true,
useMakiMarkers: true
}).addTo(map);
``$3
- useSimpleStyle(), adds simple styling to a L.geoJSON object
- discardSimpleStyle(), Removes simple styling from a L.geoJSON object
- toggleMakiMarkers(), Toggles the maki marker styling on a L.geoJSON objectFor example
``
const myLayer = L.geoJSON(rect, {
useSimpleStyle: false
}).addTo(map); myLayer.useSimpleStyle()
```