HTML of custom pushpin not added to HTML document when zoomed in RRS feed

  • Question

  • Starting with the code in Ricky Brundritt's "HTML5 Canvas Pushpins in JavaScript" sample and adding 'zoom: 8' to the map creation call:

                  map = new Microsoft.Maps.Map(document.getElementById("myMap"),
                      credentials: "MAP KEY",
                      zoom: 8

    and then using the UI to zoom out reveals that none of the pushpins are displayed.  I've seen a reference to a known bug that sounds similar, but I can't tell for sure.

    The problem appears to be that the HTML of the custom pushpin is NOT added to the HTML document if it is 'off screen' (for some definition of 'off').  The 'entityadded' event is fired and then the redraw code doesn't find it (since it searchs the document by id) and thus doesn't (re)draw it. 

    Perhaps there is some way to cause the refresh of the HTML into the document on a change in zoom?  Or is this a bug?


    Thursday, August 22, 2013 1:14 AM


  • Turns out that the problem is not that the HTML isn't there, but that the canvas pushpins don't get redrawn when the zoom changes.  That is, the HTML is added when the zoom changes such that the PIN should be visible.  The problem was that the pin._renderCanvas() wasn't called again when the HTML was added.

    To fix this, I added an event handler to the map on the 'viewchangeend' event and when that event fires I look for pins that just appeared in the HTML and draw them.  By marking the pin after drawing I avoid drawing them more than necessary.  If they disappear and reappear they will get drawn again.

    Ricky, perhaps you can update your sample.


    Friday, August 23, 2013 12:16 AM