30

MarkerClusterer を Google マップに追加しました。それは完全にうまく機能します。

クラスターをクリックしたときのズームイン動作を調整する方法があるかどうか疑問に思っています。可能であればズームレベルを変更したいです。

これを達成する方法はありますか?

ありがとう

4

5 に答える 5

60

MarkerClusterer ソース コードが更新され、クリック イベントに簡単にアクセスできるようになりました。

google.maps.event.addListener(markerCluster, 'clusterclick', function(cluster) {
    // your code here
});

「markerCluster」は MarkerCluster オブジェクトです。関数内でアクセスすることもできます

cluster.getCenter();
cluster.getMarkers();
cluster.getSize();

これを使用して、別のマップ タイプに切り替えます。カスタム タイル セットを使用して、ズーム レベルが低い場合でも概要を簡単に確認できるようにします。

map.setCenter(cluster.getCenter()); // zoom to the cluster center
map.setMapTypeId(google.maps.MapTypeId.ROADMAP); // switch map type
map.setOptions(myMapOptions); // apply some other map options (optional)

よろしくジャック

于 2011-09-22T10:01:59.320 に答える
11

clusterclick markerClusterer イベントでリスナーを使用することにより、ソース コードを変更せずにこれを行うことができます。

var mcOptions = {gridSize: 40, maxZoom: 16, zoomOnClick: false, minimumClusterSize: 2};
markerClusterer = new MarkerClusterer(map, markers, mcOptions);

google.maps.event.addListener(markerClusterer, 'clusterclick', function(cluster){
    map.setCenter(markerClusterer.getCenter());
    map.setZoom(map.getZoom()+1);
});

すなわち。zoomOnClick=false を設定して、マップのズーム動作をより細かく制御し、クリックごとにトリガーされるズーム量とズーム位置を制御します。

于 2015-06-13T16:46:09.750 に答える
8

提案どおりに clusterclick イベントを変更しました。

/**
* Triggers the clusterclick event and zoom's if the option is set.
*/
ClusterIcon.prototype.triggerClusterClick = function() {
var markerClusterer = this.cluster_.getMarkerClusterer();

// Trigger the clusterclick event.
google.maps.event.trigger(markerClusterer, 'clusterclick', this.cluster_);

if (markerClusterer.isZoomOnClick()) {
// Zoom into the cluster.
// this.map_.fitBounds(this.cluster_.getBounds());

// modified zoom in function
this.map_.setZoom(markerClusterer.getMaxZoom()+1);

 }
};

それはうまくいきます!どうもありがとう

于 2011-04-19T15:21:04.283 に答える
3

APIではズーム機能のみを切り替えることができるようです

http://google-maps-utility-library-v3.googlecode.com/svn/trunk/markerclusterer/docs/reference.html

したがって、ソースを編集する必要があります。1055行目にあるようです。

/**
 * Triggers the clusterclick event and zoom's if the option is set.
 */
ClusterIcon.prototype.triggerClusterClick = function() {
  var markerClusterer = this.cluster_.getMarkerClusterer();

  // Trigger the clusterclick event.
  google.maps.event.trigger(markerClusterer, 'clusterclick', this.cluster_);

  if (markerClusterer.isZoomOnClick()) {
    // Zoom into the cluster.
    this.map_.fitBounds(this.cluster_.getBounds());
  }
};
于 2011-04-19T04:21:00.580 に答える