7

Virtual Earth プッシュピン インフォボックスの表示を、マウスオーバーではなくオンクリックに応答させることはできますか?

現在、私は次のようなものを使用しています:

...

  var pin = new VEShape(
                  VEShapeType.Pushpin,
                  [location]
                );
  pin.SetCustomIcon(icon_url);
  pin.SetTitle(title);
  pin.SetDescription(info_window_template);
  map.AddShape(pin);

  document.getElementById(pin.GetPrimitive().iid).onmouseover = EventHandlerOnMouseOver;
}

var EventHandlerOnMouseOver = function(e) {
    // Handle content loading...
}

...

ただし、onmouseover を onclick に変更しようとすると、VE は onclick を選択し、infobox を完全に無効にします。

4

1 に答える 1

1

イベントを使用して説明することを達成できます...私はVirtual Earth 6.2を使用していることに注意してください。

秘訣は、onmouseover イベントを抑制し、onclick イベントにサブスクライブすることです。ユーザーが図形をクリックしたかどうかを判断したら、マップ コントロールで ShowInfoBox メソッドを呼び出して、強制的に情報ボックスを表示することができます。

そして、ここにコードがあります =)

// Begin by supressing the onmouseover event. Returning true 
// from an event handler disables the default Virtual Earth action
map.AttachEvent('onmouseover', function(e) { if(e.elementID) return true; });

// Subscribe to the onclick event and react whenever we get an element id
map.AttachEvent("onclick", function(e) {

    // elementID is null when someone clicks on the map and not on a shape
    if(e.elementID) {

        var shape = map.GetShapeByID(e.elementID); 
        if(shape) map.ShowInfoBox(shape);
    } 
});

形状を右クリックしても情報ボックスが表示されることに注意してください。これを回避するには、イベント オブジェクトの leftMouseButton または rightMouseButton プロパティを調べます。

参考文献:

于 2009-04-22T16:30:32.503 に答える