locked
Bing Maps AJAX Control, Version 7.0 -- How to invoke map viewchange? RRS feed

  • Question

  • How do I invoke map viewchange from outside the map like from a button in Bing Maps AJAX Control, Version 7.0?

    Thanks.

    • Moved by Ricky_Brundritt Friday, March 9, 2012 5:44 PM (From:Bing Maps: Map Control and Web services Development)
    Thursday, May 26, 2011 12:05 AM

Answers

  • To achieve this, you need to register viewchangeend event & call infobox/alert there to always make sure the sequence is maintained 

    map = new Microsoft.Maps.Map(..);

    mapviewchangeend=Microsoft.Maps.Events.addHandler(map, 'viewchangeend', function(e)
    {
    alert('End');
    });

     


    HemantGoyal
    • Marked as answer by Afshank Thursday, May 26, 2011 11:37 PM
    Thursday, May 26, 2011 10:07 PM

All replies

  • I think you would need to pan/zoom the map to get raise the viewchange event

    use any of setview() options, below is pan to x, y point

     var location = this.tryPixelToLocation(new Microsoft.Maps.Point(this.getWidth()/2 + x, this.getHeight()/2 - y), Microsoft.Maps.PixelReference.control);
    this.setView({ center: location });

     


    HemantGoyal
    Thursday, May 26, 2011 1:22 AM
  • Thanks for the reply.
    On button click() I need to show a custom infobox after the map changes the view. For that I have similar code below. 
    But the alert("Hi"); shows first and then the map view changes. 
    So, I was wondering if there is a way first to invoke an event to change the view of the map first and then the alert.
    function GetMap()
             {
                // Initialize the map
               map = new Microsoft.Maps.Map(document.getElementById("mapDiv"),{credentials:"Bing Key"}); 
    pin = new Microsoft.Maps.Pushpin(new Microsoft.Maps.Location(26.20,-80.154));
    map.entities.push(pin);
             }
     
    function msg(){
    var options = { center: pin.getLocation() };
               map.setView(options);
      
      alert("Hi");    
    }
    <div id='mapDiv'></div>   
    <input type="button" value="Click me" onclick="msg()" />  
    Thursday, May 26, 2011 8:33 PM
  • To achieve this, you need to register viewchangeend event & call infobox/alert there to always make sure the sequence is maintained 

    map = new Microsoft.Maps.Map(..);

    mapviewchangeend=Microsoft.Maps.Events.addHandler(map, 'viewchangeend', function(e)
    {
    alert('End');
    });

     


    HemantGoyal
    • Marked as answer by Afshank Thursday, May 26, 2011 11:37 PM
    Thursday, May 26, 2011 10:07 PM