簡體   English   中英

點擊虛擬地球信息框而不是懸停?

[英]Make virtual earth infobox appear on click instead of hover?

是否有可能使Virtual Earth圖釘信息框顯示響應來自onclick而不是鼠標懸停?

目前我正在使用這樣的東西:

...

  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並完全禁用信息框。

您可以通過使用事件來完成描述...請注意我正在使用Virtual Earth 6.2。

訣竅是抑制onmouseover事件和訂閱onclick事件。 當您確定用戶是否單擊某個形狀時,您可以在地圖控件上調用ShowInfoBox方法以強制它顯示信息框。

這是teh codez =)

// 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屬性。

參考文獻:

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM