0

クラスタ化されたアイコンのクラスタ タイトル、ロールオーバー テキストを動的に設定しようとしています。クラスター数/合計をロールオーバー テキストで使用したい。

を通して、 が のセットに変更されているconsole.logことがわかります。にも対応しています。クラスターのデフォルトのタイトルは更新されていないようで、デフォルト値のままです。titlevar txtalert( txt )""

現在、タイトルを に設定していgoogle.maps.event.addListener( markerClusterer, 'mouseover', function( cluster ) {})ます。

私のコードは引き続き実行されていると考えています。それが変更が見られない理由かもしれませんが、それを絞り込むことはできませんでした。

var latlng = new google.maps.LatLng( lat, lng );

        var qs      = location.search;          
        var options = {
            zoom: 17,
            center: latlng,
            mapTypeId: google.maps.MapTypeId.ROADMAP,
            mapTypeControlOptions: { 
                style: google.maps.MapTypeControlStyle.DROPDOWN_MENU 
            }
        };

        map = new google.maps.Map( mapId[0], options );

        google.maps.event.addListener( map, 'idle', function() {

            var bounds = map.getBounds();

            downloadXML( ABSPATH + 'xml/maps/markers.php' + qs + '&bounds=' + bounds, function( data ) {

                var xml     = parseXml( data );
                var markers = xml.documentElement.getElementsByTagName( "marker" );
                var markerArray = [];

                for ( var i = 0; i < markers.length; i++ ) {

                    var attributes = getMarkerAttributes( markers[i] );
                    var marker     = createMarker( attributes );

                    // Add marker to marker array
                    markerArray.push(marker);

                }

                // Define the marker clusterer
                var clusterOptions = { 
                    zoomOnClick: false,
                    gridSize: 1
                }

                var markerClusterer = new MarkerClusterer( map, markerArray, clusterOptions );

                // Listen for a cluster to be clicked
                google.maps.event.addListener( markerClusterer, 'clusterclick', function( cluster ) {
                    combineInfoWindows( cluster );              
                });

                // Listen for a cluster to be hovered and set title
                google.maps.event.addListener( markerClusterer, 'mouseover', function( cluster ) {
                    var txt = 'There are ' + cluster.getSize() + ' properties at this location.';
                    //alert( txt );
                    console.log( cluster );
                    markerClusterer.setTitle( txt );
                });

            }); // downloadXML

        }); // google.maps.event.addListener( map, 'idle', ... )

どんな助けでも大歓迎です。ありがとう!

編集:1

Rickによって提案されたソリューションに基づくソリューションがあります。

onAdd メソッドを変更しました。

/**
 * Adds the icon to the DOM.
 */
ClusterIcon.prototype.onAdd = function () {
  var cClusterIcon = this;

// MY CHANGES - START
this.cluster_.markerClusterer_.title_ = 'There are ' + this.cluster_.getSize() + ' properties at this location.';
// MY CHANGES - END

  this.div_ = document.createElement("div");
  if (this.visible_) {
    this.show();
  }

...

};

編集: 2 - 最終的な解決策

リックが提案したように、show以前のonAdd方法に対して方法に変更を加えました。MarkerClustererPlus の元のソース ファイル以外のファイルに変更が加えられています。

/**
 * Positions and shows the icon.
 */
ClusterIcon.prototype.show = function () {
  if (this.div_) {
    var pos = this.getPosFromLatLng_(this.center_);
    this.div_.style.cssText = this.createCss(pos);
    if (this.cluster_.printable_) {
     // (Would like to use "width: inherit;" below, but doesn't work with MSIE)
     this.div_.innerHTML = "<img src='" + this.url_ + "'><div style='position: absolute; top: 0px; left: 0px; width: " + this.width_ + "px;'>" + this.sums_.text + "</div>";
    } else {
     this.div_.innerHTML = this.sums_.text;
    }
    //this.div_.title = this.cluster_.getMarkerClusterer().getTitle();
    // MY SOLUTION BELOW
    this.div_.title = 'There are ' + this.cluster_.getSize() + ' properties at this location.';
    this.div_.style.display = "";
  }
  this.visible_ = true;
};
4

3 に答える 3

2

これをマーカーのクラスタリングに使用していますか? 独自の setTitle 関数を作成するために拡張しましたか? そうでない場合は、独自のラベルを作成する必要があります。それ自体は実際にはマーカーではありません。

編集:これが存在することを知りませんでした。

クラスタ アイコンは、MCOptions からタイトルを取得するだけです。ClusterIcon または Cluster に setTitle 関数がある場所がわからないので、ClusterIcon ショー プロトタイプを自分でオーバーライドしてそこに設定するのが最善の策だと思います。

> ClusterIcon.prototype.show =
> function () {   if (this.div_) {
>     var pos = this.getPosFromLatLng_(this.center_);
>     this.div_.style.cssText = this.createCss(pos);
>     if (this.cluster_.printable_) {
>       // (Would like to use "width: inherit;" below, but doesn't work with MSIE)
>       this.div_.innerHTML = "<img src='" + this.url_ + "'><div style='position: absolute; top: 0px; left: 0px; width: " + this.width_
> + "px;'>" + this.sums_.text + "</div>";
>     } else {
>       this.div_.innerHTML = this.sums_.text;
>     }
>     this.div_.title = **** Your stuff here ***
>     this.div_.style.display = "";   }   this.visible_ = true; };
于 2012-05-04T16:45:29.817 に答える
1

あなたの問題は、mouseoverイベント リスナー (タイトルを設定した場所) をに割り当てようとしているMarkerClustererが、リスナーを定義するには、mouseoverを渡す必要があることClusterです。

インスタンスのMarkerClusterer.getClusters()を返す関数があります。それをループして、 のインスタンスをイベント リスナーに渡します。リファレンス ドキュメントを確認し、ドキュメントの [ Events ]セクションまでスクロールすると、 Argumentが次のように定義されている行が表示されます。ArrayClusterArrayClustermouseoverMarkerClusterer mouseover

c:Cluster

これは、 Argumentを次のように定義するclusteringbeginや などのイベントとは対照的です。clusteringend

mc:MarkerClusterer

そうは言っても、それぞれにタイトルを設定する簡単な方法があるかどうかはわかりませんCluster。そのクラスには機能がありませんsetTitlesetTitle上の は、すべてのインスタンスMarkerClustererにタイトルを適用するだけです。そして、JavaScript を再確認しました。クラスに機能はありません。現時点での最善の選択肢は、それぞれのハンドラ内に表示するコンテンツを動的に作成することです。InfoBoxを作成し、イベントで閉じることができます。これまでで最も簡単な解決策ではありませんが、あなたが望む場所にたどり着くことができます.ClustersetTitleClustermouseoverClusterCluster mouseoet

于 2012-05-04T17:02:30.460 に答える
1

これは古い質問だと思いますが、私の検索では Google で上位にランクされました。とにかく、このページのヒントのおかげで私がやったことは次のとおりです。

google.maps.event.addListener(markerCluster, 'mouseover', function (c) {
    if(c.clusterIcon_.div_){
        c.clusterIcon_.div_.title =  c.getSize() + ' businesses in this area';
    }
});

「プライベート」プロパティ clusterIcon_ および div_ を使用しているため、MarkerClusterer Plus の将来のバージョンとの互換性は保証できません。

于 2014-09-23T15:34:02.800 に答える