0

Trying to add an infobox to each pin, each pin is loaded from a separate function and attaches the corresponding title, description, lat/lon, etc from an xml file. (source if needed)

In the function that receives the array of pins I'm trying to loop through each item and add infoboxes accordingly. Any ideas as to what I'm missing here?

      function GeoRSSImportedCallback(items, bounds) {
          map.entities.push(items);

          for (var i = 0; i<items.length; i++) {
            items.Title = items.title;
            items.Description = items.description;
            Microsoft.Maps.Events.addHandler(itmes, 'click', displayInfoBox);
          }

          map.entities.push(infoboxLayer);
          map.setView({ bounds: bounds });
      }

    function displayInfoBox(e) {
        pinInfoBox.setOptions({title: e.target.Title, description: e.target.Description, visible:true, offset: new Microsoft.Maps.Point(0,25)});
        pinInfoBox.setLocation(e.target.getLocation());
}

I do initialize the following in the GetMap() function

        pinInfoBox = new Microsoft.Maps.Infobox(new Microsoft.Maps.Location(0, 0), { visible: false });
        infoboxLayer.push(pinInfoBox);
gSaenz
  • 679
  • 6
  • 23

1 Answers1

0

Your code uses properties that are not part of the various Bing Maps objects, so I am going to assume that is your intent. There are also errors with your for loop, the following should be more correct:

  function GeoRSSImportedCallback(items, bounds) {
      map.entities.push(items);

      for (var i = 0; i<items.length; i++) {
        items[i].Title = items[i].title; // Assumes .title is defined
        items[i].Description = items[i].description; // Assumes .description is defined
        Microsoft.Maps.Events.addHandler(items[i], 'click', displayInfoBox);
      }

      map.entities.push(infoboxLayer);
      map.setView({ bounds: bounds });
  }
Bojin Li
  • 5,769
  • 2
  • 24
  • 37
  • Yes, .title and .description are defined in the import module. Fixing the loop, the infoboxes fail to appear. Also, what objects are not natively to Bing Maps? – gSaenz Nov 02 '12 at 19:26
  • as far as I know .title and .description are not native properties on the PushPin object. I recommend using the javascript debugger in your browser to debug your script to see exactly where the problem is. It is not practical for me to debug your code on SO for you. – Bojin Li Nov 02 '12 at 20:43
  • agreed the pushpin object does not have .title and .description. All these attributes are being passes in a single array by a module. The module -which I have listed the source for- parses information from an xml file. – gSaenz Nov 05 '12 at 20:01