Search code examples
coordinatescollision-detectionleafletpolygonturfjs

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?


Solution

  • 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.