Google地图中的MarkerClusterer上的infoWindow [英] infoWindow on MarkerClusterer in google maps

查看:149
本文介绍了Google地图中的MarkerClusterer上的infoWindow的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当点击ClusterMarker时,我需要打开 infoWindow 而不是放大地图。
我使用Gmaps util库 MarkerClusterer 来创建标记集群。我尝试更改markerclusterer.js中的以下行

  ClusterMarker_.prototype = new GOverlay(); 

with

  ClusterMarker_.prototype = new GMarker(); 

这样我就可以得到 openInfoWindow()功能在集群标记,但没有解决。有一些错误。
如果可能,请建议解决方案,以便使用 MarkerClusterer 完成此操作。否则,任何其他图书馆将能够做到这一点。
任何帮助将被赞赏。

解决方案

您可能最好修改markerclusterer中marker的click事件。



目前:

  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);
});

更改为:

  GEvent.addDomListener(div,click,function(){
map.openInfoWindowHtml(latlng,将您的infowindow内容放在这里);
});

显然,取决于你想要抽象的东西的多少,你可以做几件事情: / p>


  • 向MarkerClusterer添加配置选项,以指定是否执行放大功能或infowindow功能
  • 定义回调函数设置,您可以指定在单击群集时MarkerClusterer将调用哪个函数。


I need infoWindow to be opened instead of zooming in map, when clicking on the ClusterMarker. I am using Gmaps util library MarkerClusterer for creating cluster of markers. I tried changing following line in 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. Got some error. If possible, Please suggest solution so that this can be done with MarkerClusterer. Or else any other library which will be able to do this. Any help will be appreciated.

解决方案

You are probably better off modifying the click event for the marker in markerclusterer.js starting on line 672.

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:

  • Add configuration options to MarkerClusterer to specify whether to do zoom in functionality or infowindow functionality
  • Define a callback function setup where you specify what function MarkerClusterer will call when a cluster is clicked.

这篇关于Google地图中的MarkerClusterer上的infoWindow的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆