使用 MarkerClusterer 在 Google 地图上折叠标记
我正在将 GMaps V3 与来自 http://code.google 的 MarkerClusterer 结合使用。 com/p/gmaps-utility-library-dev/
地图上显示的标记是用户定义的并且经常折叠,因此无论您放大多少,聚类器始终显示一个位置有多个项目。但用户应该能够单击每个标记来查看信息窗口。
我尝试在服务器上随机化位置,但随机性不够随机,标记不断崩溃,只是不那么频繁。
你知道有什么方法可以解决这个问题吗?
I'm using GMaps V3 with MarkerClusterer from http://code.google.com/p/gmaps-utility-library-dev/
Markers displayed on the map are user-defined and often collapse, so no matter how much you zoom-in, the clusterer always shows there are multiple items in one location. But the user should be able to click each single marker to see the info window.
I tried randomizing location a bit on the server, but the random is not random enough and markers keep collapsing, just not so often.
Do you know any way to deal with this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我遇到了这个问题,并通过定义“maxZoom”的构造函数属性来解决它,该属性低于 Google 地图的 maxZoom:
I had this problem and solved it by defining a constructor property of "maxZoom" that was lower than the maxZoom for the Google map:
回复OP在我之前的回答中的评论,因为它不适合评论框:
我认为这是 Google 地图的预期行为 - 如果标记具有完全相同的纬度/经度,那么您会得到彼此重叠的标记。
一种可能的解决方法是仅将第一个标记添加到地图,然后当您尝试将另一个标记添加到已定义的纬度/经度(使用 JS 地图跟踪它们)时,您可以添加一个计数(或建立一个标记信息数组)并使用该信息更新信息窗口文本。例如,单击标记将显示一个信息窗口,显示此位置有 15 个“事物”,然后在其下方的列表中列出它们的名称和属性...
另一种可能性是通过添加随机数来“抖动”后续标记小数点末尾的纬度/经度。这样,当用户完全放大时,标记将稍微偏移。不过这个选项感觉有点“肮脏”。
Reply to OP's comment in my previous answer as it didn't fit in the comment box:
I think that is the expected behaviour with Google maps - if markers have the exactly the same lat/lng then you get the markers on top of each other.
One possible workaround is to only add the first marker to the map and then when you attempt to add another marker to a lat/lng already defined (keep track of them with a JS map), you could add a count (or build up an array of marker info) and update the infowindow text with that information. E.g. clicking on the marker would then show an infowindow saying there are 15 "things" at this location and then list their names and attributes in a list under it...
Another possibility is to "dither" subsequent markers by adding a random number to the end of the decimal lat/lng. That way when the user zooms in all the way the markers will be slightly offset. This option feels a bit "dirty" though.
添加标记时,您可以检查同一位置是否有其他标记,并且在信息窗口中您可以注意到有多个标记。
When adding a marker you can check if there are other markers at that same location and in the infowindow you could note that there are multiple markers.