none
SetView No longer works RRS feed

  • Question

  • Does anyone what can cause the setView to not work properly. It was working before but today when I try it the map no longer changes view. Here are my code

     bingMap = new Microsoft.Maps.Map(document.getElementById(store.session.get("mapId")), { credentials: key }); --> this works
                pin = new Microsoft.Maps.Pushpin(null, { draggable: false }); //change back to true for draggable
                Microsoft.Maps.Events.addHandler(bingMap, 'viewChange', function () { console.log("viewChange"); });
                Microsoft.Maps.Events.addHandler(bingMap, 'viewChangestart', function () { console.log("viewChangestart"); });
                Microsoft.Maps.Events.addHandler(bingMap, 'viewChangeend', function () { console.log("viewChangeend"); });          
                Microsoft.Maps.Events.addHandler(bingMap, 'imagerychanged', function () { console.log("imagerychanged"); });

    As you can see above I created the map and added event handler to listen to when the map view and imagery changes. To set the view I use the below code

    var loc = new Microsoft.Maps.Location(latitude, longitude);
    
    bingMap.setView({ MapTypeId: Microsoft.Maps.MapTypeId.birdseye, center: loc, zoom: zoomLvl });

    Here is where the problem is. The map is not changing, and the view change event is no being triggered. I check the network response using Chrome developer tool and can see that the frames are being return to me.


    Thursday, November 13, 2014 11:36 PM

Answers

  • I'm not able to reproduce this. The one thing that I normally come across that breaks the ability to change the view is passing in latitude and longitude coordinates that are strings rather than numbers. Note '50' != 50. If your values might be strings then wrap them with parseFloat.

    Here is my test code:

    <!DOCTYPE html>
    <html>
    <head>
      <title></title>
      <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    
      <script type="text/javascript" src="http://ecn.dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=7.0"></script>
      
      <script type="text/javascript">
    	var map;
    	
    	function GetMap()
    	{	
    		map = new Microsoft.Maps.Map(document.getElementById("myMap"), { 
    			credentials: "YOUR_BING_MAPS_KEY"
    		});
    		
    		var pin = new Microsoft.Maps.Pushpin(null, { draggable: false }); //change back to true for draggable
    		map.entities.push(map);
    		Microsoft.Maps.Events.addHandler(map, 'viewchange', function () { console.log("viewChange"); });
    		Microsoft.Maps.Events.addHandler(map, 'viewchangestart', function () { console.log("viewChangestart"); });
    		Microsoft.Maps.Events.addHandler(map, 'viewchangeend', function () { console.log("viewChangeend"); });          
    		Microsoft.Maps.Events.addHandler(map, 'imagerychanged', function () { console.log("imagerychanged"); });
    	}
    	
    	function ChangeView(){
    		var loc = new Microsoft.Maps.Location(52, 0);
    		map.setView({ MapTypeId: Microsoft.Maps.MapTypeId.birdseye, center: loc, zoom: 19 });
    	}
    	</script>	
    </head>
    <body onload="GetMap();">
    	<div id='myMap' style=";width:800px;height:600px;"></div><br/>
    	<input type='button' onclick='ChangeView();' value='Change View'/>
    </body>
    </html>
    Note that the view events should have a small C.


    http://rbrundritt.wordpress.com


    Friday, November 14, 2014 11:07 AM
  • That works fine too. Make sure you have specified a valid Bing maps key, otherwise the Birdseye imagery will not load.

    http://rbrundritt.wordpress.com

    Monday, November 17, 2014 9:59 AM
  • I figured it out, there was two map and the second one was being displayed on top of the first one./
    Monday, November 17, 2014 5:24 PM

All replies

  • I'm not able to reproduce this. The one thing that I normally come across that breaks the ability to change the view is passing in latitude and longitude coordinates that are strings rather than numbers. Note '50' != 50. If your values might be strings then wrap them with parseFloat.

    Here is my test code:

    <!DOCTYPE html>
    <html>
    <head>
      <title></title>
      <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    
      <script type="text/javascript" src="http://ecn.dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=7.0"></script>
      
      <script type="text/javascript">
    	var map;
    	
    	function GetMap()
    	{	
    		map = new Microsoft.Maps.Map(document.getElementById("myMap"), { 
    			credentials: "YOUR_BING_MAPS_KEY"
    		});
    		
    		var pin = new Microsoft.Maps.Pushpin(null, { draggable: false }); //change back to true for draggable
    		map.entities.push(map);
    		Microsoft.Maps.Events.addHandler(map, 'viewchange', function () { console.log("viewChange"); });
    		Microsoft.Maps.Events.addHandler(map, 'viewchangestart', function () { console.log("viewChangestart"); });
    		Microsoft.Maps.Events.addHandler(map, 'viewchangeend', function () { console.log("viewChangeend"); });          
    		Microsoft.Maps.Events.addHandler(map, 'imagerychanged', function () { console.log("imagerychanged"); });
    	}
    	
    	function ChangeView(){
    		var loc = new Microsoft.Maps.Location(52, 0);
    		map.setView({ MapTypeId: Microsoft.Maps.MapTypeId.birdseye, center: loc, zoom: 19 });
    	}
    	</script>	
    </head>
    <body onload="GetMap();">
    	<div id='myMap' style=";width:800px;height:600px;"></div><br/>
    	<input type='button' onclick='ChangeView();' value='Change View'/>
    </body>
    </html>
    Note that the view events should have a small C.


    http://rbrundritt.wordpress.com


    Friday, November 14, 2014 11:07 AM
  • If you can :) can you change your reference to the map control to use SSL for your example and see if it still works?

      <script type="text/javascript" src="https://ecn.dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=7.0&s=1"></script>

    I notice that the js return is different between the the secure and insecure content. I would try it my self but I am being blocked from getting insecure content.


    • Edited by Jack Thor Friday, November 14, 2014 8:28 PM
    Friday, November 14, 2014 8:27 PM
  • That works fine too. Make sure you have specified a valid Bing maps key, otherwise the Birdseye imagery will not load.

    http://rbrundritt.wordpress.com

    Monday, November 17, 2014 9:59 AM
  • I figured it out, there was two map and the second one was being displayed on top of the first one./
    Monday, November 17, 2014 5:24 PM