Export (0) Print
Expand All
3 out of 4 rated this helpful - Rate this topic

EntityCollection Class

Bing

Contains a collection of entities. An Entity can be any one of the following types: Infobox, Polygon, Polyline, Pushpin, TileLayer, or EntityCollection.

Constructor

Name Definition Description

EntityCollection

EntityCollection(options?: EntityCollectionOptions )

Initializes a new instance of the EntityCollection class.

Methods

Name Definition Return Value Description

clear

clear()

None

Removes all entities from the collection.

get

get(index:number)

Entity*

Returns the entity at the specified index in the collection.

getLength

getLength()

number

Returns the number of entities in the collection.

getVisible

getVisible()

boolean

Returns whether the entity collection is visible on the map.

getZIndex

getZIndex()

number

Gets the z-index of the entity collection with respect to other items on the map.

indexOf

indexOf(entity:Entity*)

number

Returns the index of the specified entity in the collection. If the entity is not found in the collection, -1 is returned.

insert

insert(entity:Entity*, index:number)

None

Inserts the specified entity into the collection at the given index.

pop

pop()

Entity*

Removes the last entity from the collection and returns it.

push

push(entity:Entity*)

None

Adds the specified entity to the last position in the collection.

remove

remove(entity:Entity*)

Entity*

Removes the specified entity from the collection and returns it.

removeAt

removeAt(index:number)

Entity*

Removes the entity at the specified index from the collection and returns it.

setOptions

setOptions(options: EntityCollectionOptions )

None

Sets the options for the entity collection.

toString

toString()

string

Converts the EntityCollection object to a string.

* An Entity can be any one of the following types: Infobox, Polygon, Polyline, Pushpin, TileLayer, or EntityCollection.

Events

Name Arguments Description

entityadded

object: {collection: EntityCollection, entity:Entity*}

Occurs when one of the following happens:

  • An entity is added to the collection.

  • One of the entities of the collection (such as another entity collection) fires the entityadded event.

For example, if collection #1 contains an entity, which is another collection #2, then when an entity is added to collection #2, two entityadded events are fired.

entitychanged

object: {collection: EntityCollection, entity:Entity*}

Occurs when one of the following happens:

  • The collection changes.

  • An entity of the collection changes.

  • One of the entities of the collection (such as another entity collection) fires the entitychanged event.

For example, if collection #1 contains an entity, which is another collection #2, then when an entity of collection #2 changes, two entitychanged events are fired.

entityremoved

object: {collection: EntityCollection, entity:Entity*}

Occurs when one of the following happens:

  • An entity of the collection is removed.

  • One of the entities of the collection (such as another entity collection) fires the entityremoved event.

For example, if collection #1 contains an entity, which is another collection #2, then when an entity of collection #2 is removed, two entityremoved events are fired.

* An Entity can be any one of the following types: Infobox, Polygon, Polyline, Pushpin, TileLayer, or EntityCollection.

Example

<!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;         
         var pinTotal = 0;

         function GetMap()
         {
            // Initialize the map
            map = new Microsoft.Maps.Map(document.getElementById("mapDiv"),
{credentials:"Bing Maps Key"}); 

            // Add handler for the map click event - add a pin to the click location.
            Microsoft.Maps.Events.addHandler(map, 'click', addPin);
            

         }

         function addPin(e) {

              if (e.targetType == "map") {

                  // Return the location where the map was clicked and create the pin.
                  var point = new Microsoft.Maps.Point(e.getX(), e.getY());
                  var loc = e.target.tryPixelToLocation(point);
                  var pin = new Microsoft.Maps.Pushpin(loc);

                  // Attach a handler to the pin so that it is removed when it is clicked
                  Microsoft.Maps.Events.addHandler(pin, 'click', removePin);
               

                  // Add the pushpin
                  map.entities.push(pin);
                  

              }
         }

         function removePin(e)
         {
              var indexOfPinToRemove = map.entities.indexOf(e.target);

              map.entities.removeAt(indexOfPinToRemove);

         }



      </script>
   </head>
   <body onload="GetMap();">
      <div id='mapDiv' style="position:relative; width:400px; height:400px;"></div>       
      <b>Click the map to add a pin, or click a pin to remove it.<b/>
   </body>
</html>
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.