[英]infoWindow on MarkerClusterer in google maps
I need infoWindow
to be opened instead of zooming in map, when clicking on the ClusterMarker. 单击ClusterMarker时,我需要打开
infoWindow
而不是放大地图。 I am using Gmaps util library MarkerClusterer
for creating cluster of markers. 我正在使用Gmaps实用程序库
MarkerClusterer
创建标记集群。 I tried changing following line in markerclusterer.js 我试图在markerclusterer.js中更改以下行
ClusterMarker_.prototype = new GOverlay();
with 与
ClusterMarker_.prototype = new GMarker();
so that I can get the openInfoWindow()
function in the clustermarker, but that didnt worked out. 这样我就可以在clustermarker中获得
openInfoWindow()
函数,但是没有解决。 Got some error. 有一些错误。 If possible, Please suggest solution so that this can be done with
MarkerClusterer
. 如果可能,请提出解决方案,以便可以使用
MarkerClusterer
来完成。 Or else any other library which will be able to do this. 否则,任何其他图书馆将能够做到这一点。 Any help will be appreciated.
任何帮助将不胜感激。
For MarkerCluster v3 there is a custom event named ' clusterclick ', which return the markerCluster object, then you can get its center and assign it to an infoWindow, something like this: 对于MarkerCluster v3,有一个名为' clusterclick '的自定义事件,该事件返回markerCluster对象,然后您可以获取其中心并将其分配给infoWindow,如下所示:
google.maps.event.addListener(mc, 'clusterclick', function (mCluster) {
//infowindow must be declared before in your code
infowindow.setContent("your info");
var myLatlng = new google.maps.LatLng(mCluster.getCenter().ya, mCluster.getCenter().za);
infowindow.setPosition(myLatlng);
infowindow.open(map);
});
Also you have to set the zoomOnClick option on false: 另外,您还必须将zoomOnClick选项设置为false:
var mcoptions = { zoomOnClick: false, showText: true, averageCenter: true}
var mc = new MarkerClusterer(map, markersArray, mcoptions);
You are probably better off modifying the click event for the marker in markerclusterer.js starting on line 672. 从672行开始,最好修改markerclusterer.js中标记的click事件。
Currently: 目前:
GEvent.addDomListener(div, "click", function () {
var pos = map.fromLatLngToDivPixel(latlng);
var sw = new GPoint(pos.x - padding, pos.y + padding);
sw = map.fromDivPixelToLatLng(sw);
var ne = new GPoint(pos.x + padding, pos.y - padding);
ne = map.fromDivPixelToLatLng(ne);
var zoom = map.getBoundsZoomLevel(new GLatLngBounds(sw, ne), map.getSize());
map.setCenter(latlng, zoom);
});
Change to something like: 更改为以下内容:
GEvent.addDomListener(div, "click", function () {
map.openInfoWindowHtml(latlng, "Put your infowindow content here");
});
Obviously, depending on how much you want to abstract things, you could do a couple of things: 显然,取决于要抽象多少东西,您可以做几件事:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.