简体   繁体   English

点击虚拟地球信息框而不是悬停?

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

Is it possible to make Virtual Earth pushpin infobox display respond from onclick instead of mouseover? 是否有可能使Virtual Earth图钉信息框显示响应来自onclick而不是鼠标悬停?

Currently I'm using something like this: 目前我正在使用这样的东西:

... ...

  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...
}

... ...

However, if I attempt to change the onmouseover to onclick, VE picks up onclick and disables the infobox entirely. 但是,如果我尝试将onmouseover更改为onclick,则VE会选择onclick并完全禁用信息框。

You can accomplish what describing through the use of events... note that I'm using Virtual Earth 6.2. 您可以通过使用事件来完成描述...请注意我正在使用Virtual Earth 6.2。

The trick is to suppress the onmouseover event and the subscribe to the onclick event. 诀窍是抑制onmouseover事件和订阅onclick事件。 When you have figured out if the user clicked on a shape or not you can call the ShowInfoBox method on the map control to force it to show the info box. 当您确定用户是否单击某个形状时,您可以在地图控件上调用ShowInfoBox方法以强制它显示信息框。

And here is teh codez =) 这是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);
    } 
});

Note that the infobox will show even if you right click on the shape; 请注意,即使您右键单击形状,信息框也会显示; to avoid this you would look at the leftMouseButton or rightMouseButton properties on the event object . 为避免这种情况,您将查看事件对象上的leftMouseButton或rightMouseButton属性。

References: 参考文献:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM