none
URGENT ! EntityCollection class doesn't work ! RRS feed

  • Question

  • Hello, this day, the EntityCollection class doesn't work !

    What happens?

    • Moved by Ricky_Brundritt Friday, March 9, 2012 5:26 PM (From:Bing Maps: Map Control and Web services Development)
    Wednesday, May 4, 2011 7:14 AM

Answers

  • Actually, your problem is a common one.

    Bing Maps API is loaded via a method that delays the loading of other scripts and dependancies. So when you make a reference to the Microsoft.Maps namespace and specific classes, it can take time to get the Bing Maps scripts to get loaded and so you get an error that appears to be on a specific class but in fact concerns each of Bing Maps classes as for the document and JS engine, the scripts are not loaded and all Bing Maps types are not defined.

    Event by using the "onload" event on the body or anyother element, you might sometimes get this error if there is a great delay to get dependancies. But it's is by design and in order to reduce the first load on the map control.


    MVP - Bing Maps - My blog (FR): http://blogs.developpeur.org/nicoboo/ Twitter: http://twitter.com/nicolasboonaert/
    Wednesday, May 4, 2011 9:52 AM
    Moderator

All replies

  • The problem does not occur here and seems to be in your code.

    EntityCollection is one of the basic classes and is used in the default map control. Make sure you added the correct script, that you wait for it to load and that you use the good namespace (Microsoft.Maps.EntityCollection).

     

    In order to help you, you might post the part of your code that does not seem to work.


    MVP - Bing Maps - My blog (FR): http://blogs.developpeur.org/nicoboo/ Twitter: http://twitter.com/nicolasboonaert/
    Wednesday, May 4, 2011 7:31 AM
    Moderator
  • Désolé mais le problème ne vient pas de mon code, l'erreur remonte depuis ce matin alors que l'application est en ligne depuis la mise en ligne de la V7.

    Je suis allez voir d'autres applications sur le web qui marchais jusqu'à présent, et elle ne marche plus, avec la même erreur.

     

    "Microsoft.Maps.EntityCollection is not a constructor"

     

    Exemple ici :

    http://www.garzilla.net/vemaps/Layers-via-the-Entity-Collection-with-Bing-Maps-7.aspx

     

    Quelque chose à changé depuis hier?


    Wednesday, May 4, 2011 7:36 AM
  • EntityCollection is working fine for me, and the example on Mike's page also works fine under FF4/IE9/Chrome on Win64.

    I suspect it's in the way you're trying to use the class, but unless you show us the exact code you are using it's going to be impossible to help you further.


    twitter: @alastaira blog: http://alastaira.wordpress.com/
    Wednesday, May 4, 2011 7:53 AM
    Moderator
  • I think it came from the way Mike is loading his scripts.

    Try this and see that it works perfectly:

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <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 = null;
    		function GetMap() {
    		  map = new Microsoft.Maps.Map(document.getElementById("mapDiv"),
    				{
    					credentials: "YOUR KEY",
    					center: new Microsoft.Maps.Location(45.5, 2),
    					mapTypeId: Microsoft.Maps.MapTypeId.road,
    					zoom: 4
    				});
    			
    			var pinLayer = new Microsoft.Maps.EntityCollection();
    			map.entities.push(pinLayer);
    
    			// Add a pin to the center of the map
          for (var i = 0; i < 40; i++) {
            pinLayer.push(new Microsoft.Maps.Pushpin(new Microsoft.Maps.Location(45 + i, 2), { zIndex: (90 - i) }));  
          }			
    			
    		}
      </script>
    </head>
    <body onload="GetMap();">
    	<div id='mapDiv' style="position: absolute; width: 95%; height: 95%;">
    	</div>
    </body>
    </html>
    
    


    MVP - Bing Maps - My blog (FR): http://blogs.developpeur.org/nicoboo/ Twitter: http://twitter.com/nicolasboonaert/
    Wednesday, May 4, 2011 7:54 AM
    Moderator
  • EntityCollection is not working for me on the example on Mike's page under FF4 (4.0.1) /Chrome on Win64 !

     

    Error is :"Microsoft.Maps.EntityCollection is not a constructor"

     

    On IE9 it's working fine !

     

     

    Wednesday, May 4, 2011 8:07 AM
  • Yeah I can see that it does not work on Mike's sample.

    But if you take a look at the error, you can see that an error also occured on the Location class while instanciating an object. I'm pretty sure that it comes from the way the script are loaded and when the entity code is executed.

    My sample code here is working fine, so the problem is not on Microsoft side and is more about your (or here, Mike's) code.


    MVP - Bing Maps - My blog (FR): http://blogs.developpeur.org/nicoboo/ Twitter: http://twitter.com/nicolasboonaert/
    Wednesday, May 4, 2011 8:11 AM
    Moderator
  • Thank you for the example, I found the error:

     
    declaration "my_layer
    new  Microsoft.Maps.EntityCollection(); " was outside the function GetMap ();

    Until this morning, this code work fine :

    var my_layer =
    new Microsoft.Maps.EntityCollection();
    var map = null;

      function
    getMap () {code here ...}

    I replaced by:

     function
    getMap () {

       
    var my_layer = new Microsoft.Maps.EntityCollection();
        code here

    }



    It is disturbing that for months the code was working fine.

    Thank you very much for your response and your help.

     

    (Sorry for my english :p )




    Wednesday, May 4, 2011 8:19 AM
  • @Nicolas Boonaert Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers MedalsYes, what disturbed me is that the error occurs the next day and not only on my application. I thought it was a maintenance Bing Maps.
    Wednesday, May 4, 2011 8:30 AM
  • Actually, your problem is a common one.

    Bing Maps API is loaded via a method that delays the loading of other scripts and dependancies. So when you make a reference to the Microsoft.Maps namespace and specific classes, it can take time to get the Bing Maps scripts to get loaded and so you get an error that appears to be on a specific class but in fact concerns each of Bing Maps classes as for the document and JS engine, the scripts are not loaded and all Bing Maps types are not defined.

    Event by using the "onload" event on the body or anyother element, you might sometimes get this error if there is a great delay to get dependancies. But it's is by design and in order to reduce the first load on the map control.


    MVP - Bing Maps - My blog (FR): http://blogs.developpeur.org/nicoboo/ Twitter: http://twitter.com/nicolasboonaert/
    Wednesday, May 4, 2011 9:52 AM
    Moderator
  • This issue is still happening.

    My code was working fine yesterday, and today the map loads intermittently in Chrome and FF. It loads just fine in IE9!

    Here is a snippet of my code:

     

      var map = null;
    
    	function createBaseMap() {
    		  var options = {
            credentials: "YOUR KEY",
            center: new Microsoft.Maps.Location(0,0),
            height: 468,
            width: 468,
            mapTypeId: Microsoft.Maps.MapTypeId.mercator,
            showScalebar: false,
            showMapTypeSelector:false,
            enableSearchLogo:false,
            enableClickableLogo:false
    		  };
    		  map = new Microsoft.Maps.Map(document.getElementById("seatMap"), options);
    		  try {
            // tiles are here
    
    
    // Create the tile source
            var tileSource = new Microsoft.Maps.TileSource({ uriConstructor: getTilePath });
    
    // Construct the layer using the tile source
            var tilelayer = new Microsoft.Maps.TileLayer({ mercator: tileSource, opacity: 1, zIndex: 1 });
    
    
    
            var restrictZoom = function () {
             if (map.getZoom() <= map.getZoomRange().min)
             {
              map.setView({
               'zoom':    map.getZoomRange().min,
               'animate':  false
              });
             }
             else if (map.getZoom() >= map.getZoomRange().max)
             {
              map.setView({
               'zoom':    map.getZoomRange().max,
               'animate':  false
              });
             }
            };
    
    
    
            map.getZoomRange = function () {
             return {
              min:   0,
              max:   5
             };
            };
    
    
    
            Microsoft.Maps.Events.addHandler(map,'viewchangestart',restrictZoom);
         //   alert('zoom is', map.getZoom());
            map.entities.push(tilelayer);
          }
    
          catch(err) {
            alert( 'Error Message:' + err.message);
          }
    
    
         $('.MicrosoftMap').wrapInner("<div class='whiteBackground'></div>");;
     function getTilePath(tile) {
          // Construct the URI path for an OSM tile based on tile zoom/x/y
          return "images/tiles/" + tile.levelOfDetail + "/" + tile.x + "/" + (Math.pow(2,tile.levelOfDetail)-tile.y-1) + ".png";
      }
    	}
    
    
     

    Thursday, May 5, 2011 9:28 PM