Google Maps API V3 & # 8594; Use MarkerCluster, but the clusters themselves are specific for the drawn polygon / region?

Well, let me preface this question with the fact that I created a lot of Google maps, but they were strictly markers and polylines denoting routes and a couple with some interaction with the handler.

Now I want to show mainly a map of the world, mainly in North America, and I want to divide this continent into my predefined regions with some lats / lng that I have. Using these areas, I want to draw something like a polygon with light opacity and a different color for each region.

Then I want to use marker clusters, but I want the clusters to be specific to these regions. I looked around, but I did not find such an example. I saw pages that say you can do this, and not how you do it. Again, I'm definitely a noob when it comes to drawing polygons and using a cluster of markers. I know this question is rather vague, but just looking for an example / idea to start with, and even more so I don’t want to write a bunch of code against this particular api and then find out that it is impossible.

Any ideas or suggestions are greatly appreciated .... Thanks.

0
source share
1 answer

This can be done, but you will need to rewrite MarkerClusterer (it may simplify it).

You will need to determine how you intend to represent and load the cluster boundary polygons (KML, GeoJSON, Google Maps API v3 custom polygons) and probably use google.maps.geometry.poly.containsLocation (point: LatLng, polygon: Polygon) instead LatLngBounds.contains to determine which cluster owns the token.

0
source

Source: https://habr.com/ru/post/1438369/


All Articles