【问题标题】:Bing Maps V8 JS API GroundOverlay beneathLabels mouse eventsBing Maps V8 JS API GroundOverlay underLabels 鼠标事件
【发布时间】:2022-01-07 11:22:54
【问题描述】:

我使用透明 png 作为覆盖整个地图的地面覆盖层。我必须设置 underLabels=false,因为地图的标签层使覆盖层的某些部分无法读取。但是使用 underLabels=false 时,所有鼠标/键盘事件都会转到我的 groundoverlay 而不是地图。我知道这个 sis 已记录,但我不希望这样,我怎样才能将这些事件路由到地图?在 google-api 中,我简单地将groundoverlay 声明为不可点击。或者除了彻底地在整个地图上方放置一个透明的png而不捕获所有事件之外还有其他方法吗?

【问题讨论】:

  • drawOrder 也不起作用。无论我的自定义叠加层是 drawOrder=100 还是 drawOrder -100,它始终位于标签下方。

标签: javascript bing-maps bing-api


【解决方案1】:

我相信要让鼠标事件通过地面覆盖,pointer-events CSS 样式需要设置为none。我相信 IE10 中的图像不支持此功能(此 SDK 发布时 Bing Maps 支持的浏览器最少,因此很可能为什么这不是内置选项)。做一些实验,以下似乎可行:

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title></title>
    <script>
    var map, overlay;

    function GetMap() {
        map = new Microsoft.Maps.Map('#myMap', {
            center: new Microsoft.Maps.Location(-16.366, -46.8945),
            zoom: 17
        });

        overlay = new Microsoft.Maps.GroundOverlay({
            bounds: Microsoft.Maps.LocationRect.fromEdges(-16.36523189120857, -46.89686679103114, -16.3674247514764, -46.89337059621697),
            imageUrl: 'https://upload.wikimedia.org/wikipedia/commons/e/e9/Foto_a%C3%A9rea_de_Una%C3%AD_detalhando_o_c%C3%B3rrego_Canabrava_3.jpg',
            rotation: 298,          
            beneathLabels: false
        });
        map.layers.insert(overlay);
        
        //Access the underlying image object and disable pointer events so that mouse events flow through to the map.
        overlay._img.style.pointerEvents = 'none';
    }
    </script>
    <script async defer src="https://bing.com/api/maps/mapcontrol?callback=GetMap&key=[Your Bing Maps Key]"></script>
</head>
<body>
    <div id="myMap" style="position:relative;width:800px;height:600px;"></div>
</body>
</html>

【讨论】:

  • 伟大的 rbrundritt,这适用于我的情况!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-03-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多