point in polygon searches for leaflet
npm install leaflet-pip
var gjLayer = L.geoJson(statesData);var results = leafletPip.pointInLayer([-88, 38], gjLayer);// results is an array of L.Polygon objects containing that point
Point can be:
Layer must be:
first can be:
trueto accept the first match, or
falseto return all polygons containing this point. This can be useful if you know that your polygons are non-overlapping or don't care about more than one result, since it will be much faster. By default, this is false and all matches are returned.
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
Leaflet treats literate coordinate arrays as
[lat, lon], unlike GeoJSON
and any true scotsman.
treats literate coordinate arrays as
[lon, lat], but if you set
to true, it'll do things the Leaflet/Google Maps API way.