Steve Bennett
Steve Bennett

Reputation: 126125

Find whether lat/long coordinate is inside any Leaflet polygon

I would like to check which polygon layer (if any) contains a given lat/long (provided by map.locate()).

I know you can do this using Turf's inside() function but is it possible with pure Leaflet?

Upvotes: 0

Views: 1578

Answers (1)

Mourner
Mourner

Reputation: 3301

There's no corresponding Leaflet core method, but you can use https://github.com/mapbox/leaflet-pip plugin.

BTW, the algorithm for checking a point in polygon (ray casting) is just a couple lines of code — you can also easily write it yourself.

Upvotes: 2

Related Questions