Search code examples
javascriptbing-mapsbing-api

Bing Maps V8 JS API GroundOverlay beneathLabels mouse events


I use a transparent png as groundoverlay covering the whole map.I must set beneathLabels=false because the label-layer of the map makes some parts of my overlay unreadable. But with beneathLabels=false all the mouse/keyboard events goes to my groundoverlay not to the map anymore. I know thi sis documented but I don't want that, how can I route that events to the map? In the google-api I simple declare the groundoverlay as non-clickable. Or ist there any other way than groundoverly to put a transparent png above the whole map without capturing also all events ?


Solution

  • I believe to get the mouse events to go through the ground overlay the pointer-events CSS style needs to be set to none. I believe this isn't supported for images in IE10 (min supported browser by Bing Maps when this SDK was released, so likely why this isn't a built-in option). Doing some experimenting, the following seems to work:

    <!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>