1

I want to the count of markers based on location using leaflet map ie, Say in india

Number of markers in bangalore number of makers in mysore so on...

only thing i would think of to do this is using contains( point ) which is in the doc

But how to use it to find the maker is in that region as i will not be aware of the coordinates of the region

Is there a way to check like

 region.contains(markerLatLang)
dhana lakshmi
  • 847
  • 1
  • 12
  • 29

1 Answers1

0

Leaflet .contains() works on L.LatLngBounds objects, which are actually a rectangular region. So it tells if your point / marker is within a rectangle or not.

You would need first to retrieve yourself the coordinates of your administrative areas of interest (India, etc.). See https://gis.stackexchange.com/questions/199765/where-to-get-world-wide-detailed-administrative-boundaries

BTW, a simple version of countries boundaries can be: https://github.com/johan/world.geo.json

Then you would probably want to use a more accurate detection method, for example leaflet-pip plugin or turf.js, which will actually check if your point is within arbitrarily shaped polygons, not just a rectangle.

See for instance Leaflet event: how to propagate to overlapping layers

ghybs
  • 47,565
  • 6
  • 74
  • 99