mapbox / leaflet-pip

point in polygon intersections for leaflet
https://mapbox.github.io/leaflet-pip/
BSD 2-Clause "Simplified" License
199 stars 46 forks source link

point in polygon for Leaflet

build status

A Leaflet-friendly API for point in polygon operations, using substack's point in polygon library.

install

With browserify

npm install @mapbox/leaflet-pip

Resolve for a CDN/packaged version:

https://unpkg.com/@mapbox/leaflet-pip@latest/leaflet-pip.js

example

var gjLayer = L.geoJson(statesData);
var results = leafletPip.pointInLayer([-88, 38], gjLayer);
// results is an array of L.Polygon objects containing that point

api

leafletPip.pointInLayer(point, layer L.GeoJSON, [first])

Point can be:

Layer must be:

first can be:

Returns:

An array of polygons in which the given point resides, an empty array if there are none. The polygons are returned as direct sublayers, so they can include MultiPolygons. You can call pointInLayer again on those if you want the sub-polygon result.

leafletPip.bassackwards

Leaflet treats literate coordinate arrays as [lat, lon], unlike GeoJSON and any true scotsman. leaflet-pip treats literate coordinate arrays as [lon, lat], but if you set bassackwards to true, it'll do things the Leaflet/Google Maps API way.