Export (0) Print
Expand All

Polygon Class (AdvancedShapes)

Bing

Represents a complex polygon on the map. When the Microsoft.Maps.AdvancedShapes module is loaded, this class replaces the basic Polygon Class.

Constructor

Name Definition Description

Polygon

Polygon(locationsArrays: [Location[]] , options?: PolygonOptions )

Initializes a new instance of a complex Polygon. The locationsArrays array represents the polygon rings, where each element of the array is an array of Location objects that defines a ring. This constructor can be used to create a normal polygon, a multi-polygon, a polygon with holes, or a combination of polygons.

Methods

Name Definition Return Value Description

getFillColor

getFillColor()

Color

Returns the color of the inside of the polygon.

getLocations

getLocations()

Location[]

Returns the location array that defines the first ring of the polygon.

getRings

getRings()

[ Location[] ]

Returns an array of location arrays, where each location array defines a ring of the polygon.

getStrokeColor

getStrokeColor()

Color

Returns the color of the outline of the polygon.

getStrokeDashArray

getStrokeDashArray()

string

Returns the string that represents the stroke/gap sequence used to draw the outline of the polygon.

getStrokeThickness

getStrokeThickness()

number

Returns the thickness of the outline of the polygon.

getVisible

getVisible()

boolean

Returns whether the polygon is visible. A value of false indicates that the polygon is hidden, although it is still an entity on the map.

setLocations

setLocations(locations: Location[] )

None

Sets the locations that define a basic polygon.

setOptions

setOptions(options: PolygonOptions )

None

Sets options for the polygon.

setRings

setRings(locationArrays: [ Location[] ] )

None

Sets an array of location arrays, where each location array defines a ring of the polygon.

toString

toString()

string

Converts the Polygon object to a string.

Events

Name Arguments Description

click

eventArgs:MouseEventArgs

Occurs when the mouse is used to click the polygon.

dblclick

eventArgs:MouseEventArgs

Occurs when the mouse is used to double click the polygon.

entitychanged

object: {entity:Entity}

Occurs when the location of the polygon or any of the polygon’s options change.

mousedown

eventArgs:MouseEventArgs

Occurs when the left mouse button is pressed when the mouse is over the polygon.

mouseout

eventArgs:MouseEventArgs

Occurs when the mouse cursor moves out of the area covered by the polygon.

mouseover

eventArgs:MouseEventArgs

Occurs when the mouse is over the polygon.

mouseup

eventArgs:MouseEventArgs

Occurs when the left mouse button is lifted up when the mouse is over the polygon.

rightclick

eventArgs:MouseEventArgs

Occurs when the right mouse button is used to click the polygon.

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;

      function GetMap()
      {  

         map = new Microsoft.Maps.Map(document.getElementById("mapDiv"), {credentials: "Bing Maps Key", center: new Microsoft.Maps.Location(47.5, -122.3), zoom: 9 });

         Microsoft.Maps.loadModule('Microsoft.Maps.AdvancedShapes', { callback: shapesModuleLoaded });

      }


      function shapesModuleLoaded()
      {
         var polygonWithHoles = new Microsoft.Maps.Polygon([
[new Microsoft.Maps.Location(47.604, -121.940),
new Microsoft.Maps.Location(47.604, -121.540),
new Microsoft.Maps.Location(47.834, -121.540),
new Microsoft.Maps.Location(47.834, -121.940),
new Microsoft.Maps.Location(47.604, -121.940)],
[new Microsoft.Maps.Location(47.704, -121.740),
new Microsoft.Maps.Location(47.704, -121.640),
new Microsoft.Maps.Location(47.804, -121.640),
new Microsoft.Maps.Location(47.804, -121.740),
new Microsoft.Maps.Location(47.704, -121.740)],
[new Microsoft.Maps.Location(47.744, -121.700),
new Microsoft.Maps.Location(47.744, -121.680),
new Microsoft.Maps.Location(47.764, -121.680),
new Microsoft.Maps.Location(47.764, -121.700),
new Microsoft.Maps.Location(47.744, -121.700)]]);

         map.entities.push(polygonWithHoles);

      }
     
      
      </script>
   </head>
   <body onload="GetMap();">
      <div id='mapDiv' style="position:relative; width:600px; height:600px;"></div> 
   </body>
</html>
Show:
© 2014 Microsoft