Skip to content
Extends L.geoJSON to support the simplestyle spec with 1kb
JavaScript HTML
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
dist
example
src
.gitignore Initial commit Dec 16, 2019
.npmignore Update the packagejson and add demo link in readme Dec 17, 2019
LICENSE.md
README.md Update the packagejson and add demo link in readme Dec 17, 2019
package.json Update the packagejson and add demo link in readme Dec 17, 2019
rollup.config.js

README.md

leaflet-simplestyle

Extends L.geoJSON to support the simplestyle spec with less than 1kb of code.

Check out the demo

Installing

npm install leaflet-simplestyle

Usage

Step 1. Include the library after you've included leafletjs.

    require('leaflet-simplestyle')
    // or
    <script src="leaflet-simplestyle/dist/leaflet-simplestyle.min.js"></script>

Step 2. Set the useSimpleStyle option to true when adding your L.geoJSON layer

    const rect = {
      "type": "Feature",
      "properties": {
        "fill": "yellow"
      },
      "geometry": {
        "type": "Polygon",
        "coordinates": [
          [
            [
              10.45007,
              -10.359502
            ],
            ...
            [
              10.45007,
              -10.359502
            ]
          ]
        ]
      }
    },

    L.geoJSON(rect, {
        useSimpleStyle: true
    }).addTo(map);

Methods

  • useSimpleStyle(), adds simple styling to a L.geoJSON object
  • discardSimpleStyle(), Removes simple styling from a L.geoJSON object

For example

    const myLayer = L.geoJSON(rect, {
        useSimpleStyle: false
    }).addTo(map);

    myLayer.useSimpleStyle()

Acknowledgements

This borrows some of the code in the excellent mapbox.js library.

You can’t perform that action at this time.