Giter VIP home page Giter VIP logo

leaflet.snogylop's Introduction

Leaflet.snogylop

Leaflet.snogylop is a Leaflet plugin that inverts polygons.

Why? you ask. Sometimes you want to highlight a region of a map by de-emphasizing the rest of the map. Using this plugin you can set a relatively high opacity in order to de-emphasize everything outside of a polygon or multipolygon.

Demos

An inverted polygon.

An inverted multipolygon.

Custom worldLatLngs, eg for polygons near the antimeridian.

Usage

Include leaflet.snogylop.js on your page, set the options on your GeoJSON layer as specified below.

Leaflet.snogylop is only tested on Leaflet version 0.7 or greater with L.GeoJSON layers. It may work with older Leaflets and should work with other layers. Pull requests in this direction are welcome.

AMD compatible.

Available through bower: bower install --save leaflet.snogylop

Options

Define the following option in the vector options when creating a layer (eg, an L.GeoJSON):

  • invert: (boolean) True to invert. False by default.
  • worldLatLngs: (coordinate array) Optional, the coordinates of the outer ring of the inverted polygon that will be created.

Examples

Create a GeoJSON layer, set invert to true:

L.geoJson(data, {
    invert: true
}).addTo(map);

The default worldLatLngs can be overriden by using the worldLatLngs option:

L.geoJson(data, {
    invert: true,
    worldLatLngs: [
        L.latLng([90, 360]),
        L.latLng([90, -180]),
        L.latLng([-90, -180]),
        L.latLng([-90, 360])
    ]
}).addTo(map);

License

Leaflet.snogylop is free software, and may be redistributed under the MIT License.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.