none
Pushpin event not fire after execute function named "setPrimitives" of layer? RRS feed

  • Question

  • It works well before, but now it don't work. follow is my test code?

    <!DOCTYPE html>
    <html>
    <head>
        <title></title>
        <meta charset="utf-8" />
        <script type='text/javascript' src='https://www.bing.com/api/maps/mapcontrol?callback=GetMap' async defer></script>
        <script type='text/javascript' src='/BingMapsCredentials.js'></script>
        <script type='text/javascript'>
        var map;
    
        function GetMap() {
            map = new Microsoft.Maps.Map('#myMap', {
                credentials: YourBingMapsKey
            });
    
        	//Create a pushpin.
            var layer = new Microsoft.Maps.Layer();
            var pushpin = new Microsoft.Maps.Pushpin(map.getCenter());
            map.layers.insert(layer);
            layer.add(pushpin)
    
            //Add mouse events to the pushpin.
            Microsoft.Maps.Events.addHandler(pushpin, 'click', click);
            
            setTimeout(function ()
            {
            	var arrPushpin = layer.getPrimitives();
            	layer.setPrimitives(arrPushpin);
            }, 5000);
           
        }
    
        function click(e)
        {
        	alert(1);
        }
    
        </script>
    </head>
    <body>
        <div id="myMap" style=";width:600px;height:400px;"></div>
    </body>
    </html>

    Friday, April 14, 2017 2:28 AM

Answers

  • I believe this is related to another issue that is being investigated. Note that you really should add your events to the layer and not individual shapes. This will make your app les memory intensive and slightly faster. It also removes memory leaks.

    [Blog] [twitter] [LinkedIn]

    • Proposed as answer by Ricky_Brundritt Friday, April 14, 2017 4:21 PM
    • Marked as answer by s000rd Monday, April 17, 2017 1:28 AM
    Friday, April 14, 2017 4:21 PM

All replies

  • I believe this is related to another issue that is being investigated. Note that you really should add your events to the layer and not individual shapes. This will make your app les memory intensive and slightly faster. It also removes memory leaks.

    [Blog] [twitter] [LinkedIn]

    • Proposed as answer by Ricky_Brundritt Friday, April 14, 2017 4:21 PM
    • Marked as answer by s000rd Monday, April 17, 2017 1:28 AM
    Friday, April 14, 2017 4:21 PM
  • I'm also having a new problem which might be related. My pushpin events get lost whenever the map is moved. Clustered pin events still work, but individual pins won't. I changed to the frozen branch and things started working again.
    Monday, April 17, 2017 12:48 PM
  • Yes, this is the other issue that is being investigated.

    [Blog] [twitter] [LinkedIn]

    Monday, April 17, 2017 10:13 PM