<< Click to Display Table of Contents >>

 

new sg.geometry.Polygon()

 

 

Description

create a polygon object.

 

Position

Geometry.js

 

 

Properties

 

Properties

Type

Description

extent

sg.geometry.Extent

Geometry extent

type

String

Geometry type

area

Number

Polygon area

rings

Array.<sg.geometry.LinearRing>

Array of polygon rings

 

 

Methods

 

Methods

Type

Description

getExtent()

Returns:

sg.geometry.Extent

Return geometry extent object.

Returns:

Type

Description

sg.geometry.Extent

The extent

toWkt()

Returns:

String

Convert to WKT string

Returns:

Type

Description

String

wkt string

addRing(ring)

sg.geometry.LinearRing

Add rings to polygon

Name

Type

Description

ring

sg.geometry.LinearRing

An array of points.

contains(pt)

pt:sg.geometry.Point

Returns:Boolean

Define whether a point is contained in the polygon

Name

Type

Description

pt

sg.geometry.Point

The location defined by an X- and Y- coordinate in map units.

Returns:

Type

Description

Boolean

Check on the client if the specific point is inside the polygon

True: Inside the polygon

False:Not inside

getArea()

Returns:

Number

Return geometry area

Returns:

Type

Description

Number

The area

getCentroid()

Returns:

sg.geometry.Point

Return geometry centroid

Returns:

Type

Description

sg.geometry.Point

The point

isClockwise(ring)

ring:sg.geometry.LinearRing

Returns:Boolean

Check if the polygon ring is clockwise.

Name

Type

Description

ring

sg.geometry.LinearRing

rings

Returns:

Type

Description

Boolean

True:The ring is clockwise.
False:The ring is not clockwise.

update()


Update geometry extent, area etc.

forEachVertex(callback)        

function

Get the each vertex by a callback function.

callback(context)

{

  //Each point  (sg.geometry.Point)

  context.point;

  //The index of ring

  context.ringIndex;

  //The index of point

  context.pointIndex;

}

getFirstPoint_()        

 

Returns:

sg.geometry.point

Get the first vertex of a polygon

Returns:

Type

Description

sg.geometry.Point

The point

 

 

Example

 

 

<script type="text/javascript" src="scripts/Geometry.js"></script>

                         

var polygon = new sg.geometry.Polygon;

var ring = new sg.geometry.LinearRing;

ring.path.push(new sg.geometry.Point(1528256, 5628329));

ring.path.push(new sg.geometry.Point(2001868, 5663128));

ring.path.push(new sg.geometry.Point(2174538, 5446056));

ring.path.push(new sg.geometry.Point(1841530, 5458390));

polygon.addRing(ring);

polygon.update();

 

 

See live example

 


©2015 Supergeo Technologies Inc.