Class geometry

A general geometry which can represent a point, line, polygon, mulitpoint, multilinestring

class

geometry

Hierarchy

Index

Classes

Constructor methods

Methods

Classes

polygon: polygon

A polyline object which is a closed path geometry with one or more paths.

class

polygon

constructor(geom: geometry): polygon

Parameters

Returns

polygon

public addPointToLastSet(pt: point): { setIdx: number; idx: number; }

Adds point to the last set in geometry's set collection. If the geometry is empty, a new set is added to the geometry first.

Parameters

  • pt: point

    The point to add.

Returns

{ setIdx: number; idx: number; }

Object of the form {setIdx, idx} where setIdx is the 0-based index of the set the point was added to and idx is the 0-based index of the point in its set.

public clone(): polygon

Creates a new polygon object from a deep copy of the underlying geometry.

Returns

polygon

Thew new cloned polygon.

public contains(pt: point): boolean

Tests whether this geometry contains a given point/

Parameters

  • pt: point

    The reference point.

Returns

boolean

Result of the containment test.

public factoryPoly(): any

Creates a new polygon or polyline form the geometry according to whether the geometry is closed.

Returns

any

A new polyline or polygon geometry.

public findNearestSegment(pt: point, close?: boolean): { setIdx: number; ptIdx: number; pt: 'mapsjs'.point; distance: number; }

Finds point along boundary of geometry nearest to the given point

Parameters

  • pt: point

    Reference point.

  • close?: boolean optional

Returns

{ setIdx: number; ptIdx: number; pt: 'mapsjs'.point; distance: number; }

An object of the form {setIdx, ptIdx, pt, distance} where setIdx is the index of the set the point is in, ptIdx is the index of the point in the set, pt is the point object, and distance is the distance of the point to the reference point in map units.

public findNearestVertex(pt: point): { setIdx: number; ptIdx: number; pt: 'mapsjs'.point; distance: number; }

Finds the point in this geometry nearest to the given point.

Parameters

  • pt: point

    Reference point.

Returns

{ setIdx: number; ptIdx: number; pt: 'mapsjs'.point; distance: number; }

An object of the form {setIdx, ptIdx, pt, distance} where setIdx is the index of the set the point is in, ptIdx is the index of the point in the set, pt is the point object, and distance is the distance of the point to the reference point in map units.

public foreachVertex(action: (setIdx: number, idx: number, x: number, y: number, s: number[]) => void)

Iterates every vertex in the geometry and passes to the supplied callback. Return true from in the callback will break the iteration.

Parameters

  • action: (setIdx: number, idx: number, x: number, y: number, s: number[]) => void

    Callback with the signature action(setIdx, idx, x, y, set).

public getActualArea(idx?: number): number

Calculates area of a ring in a polygon by index according to the actual area. If no index is provided, uses the last ring in the polygon's ring collection.

Parameters

  • idx?: number optional

Returns

number

Area in square meters of the ring.

public getActualPerimeter(idx?: number): number

Calculates perimeter of a ring in a polygon by index according to actual distance. If no index is provided, uses the last ring in the polygon's ring collection.

Parameters

  • idx?: number optional

Returns

number

Length in meters of the perimeter of the ring.

public getBounds(): envelope

Returns the geometry's bounding box as an envelope.

Returns

envelope

The bounding box of the geometry as an envelope.

public getGeometry(): geometry

Gets the underlying geometry of the polygon.

Returns

geometry

The polygon's underlying geometry object.

public getIsClosed(): boolean

Checks whether or not this geometry is closed.

Returns

boolean

Result of the closed check.

public getIsPath(): boolean

Checks whether or not this geometry is closed.

Returns

boolean

Result of the path check.

public getLabelingPoint(idx?: number): point

Finds coordinates in map units of the midpoint of this geometry. If this geometry is an open path, the midpoint is the midpoint of the path. If this geometry is a closed path, the midpoint is the centroid of the polygon. If a set index is not provided, finds the labeling point for the last set in this geometry's set collection.

Parameters

  • idx?: number optional

Returns

point

Midpoint of this geometry.

public getProjectedArea(idx: number): number

Calculates area of a ring in a polygon by index according to projected map cooordinates. If no index is provided, uses the last ring in the polygon's ring collection.

Parameters

  • idx: number

Returns

number

Area in square projected units of the ring.

public getProjectedPerimeter(idx: number): number

Calculates perimeter of a ring in a polygon by index according to projected map cooordinates. If no index is provided, uses the last ring in the polygon's ring collection.

Parameters

  • idx: number

Returns

number

Length in projected units of the distance of the ring.

public getRing(idx: number): Array<number>

Gets a ring from this polygon's set collection by index, or, if no index is provided, gets the last ring.

Parameters

  • idx: number

Returns

Array<number>

A ring as an array of points in the form [xn,yn].

public getRingCount(): number

Gets number of rings in this polygon.

Returns

number

Number of rings.

public getSet(idx: number): Array<number>

Gets a set from this geometry's set collection by index, or, if no index is provided, gets the last set. Note: for polygons, first set is primary ring and subsequent ones are holes.

Parameters

  • idx: number

Returns

Array<number>

A set as an array of points in the form [xn,yn].

public getSetCount(): number

Gets the number of sets in this geometry.

Returns

number

Number of sets.

public intersects(geom: geometry): boolean

Determines whether this polygon intersects a given geometry.

Parameters

  • geom: geometry

    Geometry to test against.

Returns

boolean

Result of the intersection test.

public isValid(): boolean

Tests the validity of this geometry. An open path geometry is valid if it has at least one set with at least two points. A closed geometry is valid if it has at least one set with at least three points. A point (non-path) geometry is always valid.

Returns

boolean

valid geometry is true, otherwise false.

public overlaps(poly: polygon): boolean

Determines whether this polyline overlaps a given geometry.

Parameters

Returns

boolean

Result of the intersection test.

public popRing(): Array<number>

Gets the last ring in the polygon's ring collection and removes it from the collection.

Returns

Array<number>

Ring removed as an array of points in the form [xn,yn].

public popSet(): Array<number>

Gets the last set in the geometry's set collection and removes it from the collection.

Returns

Array<number>

Set removed as an array of points in the form [xn,yn].

public pushRing(s: Array<number>)

Adds a new ring to this polygon's ring collection.

Parameters

  • s: Array<number>

    Ring to add as an array of points in the form [xn,yn].

public pushSet(s: Array<number>)

Adds a new set to this geometry's collection of sets.

Parameters

  • s: Array<number>

    Set to add as an array of points in the form [xn,yn].

public toMultiPolygon(): polygon[]

Convert this polygon into an array of OGC compliant polygons where the first set is a ring and all subsequent contained sets are holes.

Returns

polygon[]

An array of OGC polygons.

public toString(): string

Creates a wkt string from this geometry.

Returns

string

A string of well known text.

public toSvgPathData(): string

Creates SVG path data from this geometry if it is a path.

Returns

string

String of the SVG path or null the geometry is not a path.

public toWkt(): string

Returns

string

polyline: polyline

A polyline object which is an open path geometry with one or more paths.

class

polyline

constructor(geom: geometry): polyline

Parameters

Returns

polyline

public addPointToLastSet(pt: point): { setIdx: number; idx: number; }

Adds point to the last set in geometry's set collection. If the geometry is empty, a new set is added to the geometry first.

Parameters

  • pt: point

    The point to add.

Returns

{ setIdx: number; idx: number; }

Object of the form {setIdx, idx} where setIdx is the 0-based index of the set the point was added to and idx is the 0-based index of the point in its set.

public clone(): polyline

Creates a new polyline object from a deep copy of the underlying geometry.

Returns

polyline

Thew new cloned polyline.

public contains(pt: point): boolean

Tests whether this geometry contains a given point/

Parameters

  • pt: point

    The reference point.

Returns

boolean

Result of the containment test.

public factoryPoly(): any

Creates a new polygon or polyline form the geometry according to whether the geometry is closed.

Returns

any

A new polyline or polygon geometry.

public findNearestSegment(pt: point, close?: boolean): { setIdx: number; ptIdx: number; pt: 'mapsjs'.point; distance: number; }

Finds point along boundary of geometry nearest to the given point

Parameters

  • pt: point

    Reference point.

  • close?: boolean optional

Returns

{ setIdx: number; ptIdx: number; pt: 'mapsjs'.point; distance: number; }

An object of the form {setIdx, ptIdx, pt, distance} where setIdx is the index of the set the point is in, ptIdx is the index of the point in the set, pt is the point object, and distance is the distance of the point to the reference point in map units.

public findNearestVertex(pt: point): { setIdx: number; ptIdx: number; pt: 'mapsjs'.point; distance: number; }

Finds the point in this geometry nearest to the given point.

Parameters

  • pt: point

    Reference point.

Returns

{ setIdx: number; ptIdx: number; pt: 'mapsjs'.point; distance: number; }

An object of the form {setIdx, ptIdx, pt, distance} where setIdx is the index of the set the point is in, ptIdx is the index of the point in the set, pt is the point object, and distance is the distance of the point to the reference point in map units.

public foreachVertex(action: (setIdx: number, idx: number, x: number, y: number, s: number[]) => void)

Iterates every vertex in the geometry and passes to the supplied callback. Return true from in the callback will break the iteration.

Parameters

  • action: (setIdx: number, idx: number, x: number, y: number, s: number[]) => void

    Callback with the signature action(setIdx, idx, x, y, set).

public getActualDistance(idx?: number): number

Calculates distance of a line in a polyline by index according to actual distance. If no index is provided, uses the last line in the polyline's set collection.

Parameters

  • idx?: number optional

Returns

number

Distance in meters of the line.

public getBounds(): envelope

Returns the geometry's bounding box as an envelope.

Returns

envelope

The bounding box of the geometry as an envelope.

public getGeometry(): geometry

Gets the underlying geometry of the polyline.

Returns

geometry

The polyline's underlying geometry object.

public getIsClosed(): boolean

Checks whether or not this geometry is closed.

Returns

boolean

Result of the closed check.

public getIsPath(): boolean

Checks whether or not this geometry is closed.

Returns

boolean

Result of the path check.

public getLabelingPoint(idx?: number): point

Finds coordinates in map units of the midpoint of this geometry. If this geometry is an open path, the midpoint is the midpoint of the path. If this geometry is a closed path, the midpoint is the centroid of the polygon. If a set index is not provided, finds the labeling point for the last set in this geometry's set collection.

Parameters

  • idx?: number optional

Returns

point

Midpoint of this geometry.

public getLine(idx: number): Array<number>

Gets a line from this polyline's liune collection by index, or, if no index is provided, gets the last line.

Parameters

  • idx: number

Returns

Array<number>

A line as an array of points in the form [xn,yn].

public getLineCount(): number

Gets number of lines in this polyline.

Returns

number

Number of lines.

public getProjectedDistance(idx: number): number

Calculates distance of a line in a polyline by index according to projected map cooordinates. If no index is provided, uses the last line in the polyline's set collection.

Parameters

  • idx: number

Returns

number

Length in projected units of the distance of the line.

public getSet(idx: number): Array<number>

Gets a set from this geometry's set collection by index, or, if no index is provided, gets the last set. Note: for polygons, first set is primary ring and subsequent ones are holes.

Parameters

  • idx: number

Returns

Array<number>

A set as an array of points in the form [xn,yn].

public getSetCount(): number

Gets the number of sets in this geometry.

Returns

number

Number of sets.

public intersects(geom: geometry): boolean

Determines whether this polyline intersects a given geometry.

Parameters

  • geom: geometry

    Geometry to test against.

Returns

boolean

Result of the intersection test.

public isValid(): boolean

Tests the validity of this geometry. An open path geometry is valid if it has at least one set with at least two points. A closed geometry is valid if it has at least one set with at least three points. A point (non-path) geometry is always valid.

Returns

boolean

valid geometry is true, otherwise false.

public popLine(): Array<number>

Gets the last line in the polyline's set collection and removes it from the collection.

Returns

Array<number>

Line removed as an array of points in the form [xn,yn].

public popSet(): Array<number>

Gets the last set in the geometry's set collection and removes it from the collection.

Returns

Array<number>

Set removed as an array of points in the form [xn,yn].

public pushLine(s: Array<number>)

Adds a new line to this polyline's line collection.

Parameters

  • s: Array<number>

    Line to add as an array of points in the form [xn,yn].

public pushSet(s: Array<number>)

Adds a new set to this geometry's collection of sets.

Parameters

  • s: Array<number>

    Set to add as an array of points in the form [xn,yn].

public toString(): string

Creates a wkt string from this geometry.

Returns

string

A string of well known text.

public toSvgPathData(): string

Creates SVG path data from this geometry if it is a path.

Returns

string

String of the SVG path or null the geometry is not a path.

public toWkt(): string

Returns

string

Constructor methods

constructor(isPath?: boolean, isClosed?: boolean): geometry

Parameters

  • isPath?: boolean optional
  • isClosed?: boolean optional

Returns

geometry

Methods

public addPointToLastSet(pt: point): { setIdx: number; idx: number; }

Adds point to the last set in geometry's set collection. If the geometry is empty, a new set is added to the geometry first.

Parameters

  • pt: point

    The point to add.

Returns

{ setIdx: number; idx: number; }

Object of the form {setIdx, idx} where setIdx is the 0-based index of the set the point was added to and idx is the 0-based index of the point in its set.

public clone(): geometry

Creates a deep copy of this geometry.

Returns

geometry

The new cloned geometry.

public contains(pt: point): boolean

Tests whether this geometry contains a given point/

Parameters

  • pt: point

    The reference point.

Returns

boolean

Result of the containment test.

public factoryPoly(): any

Creates a new polygon or polyline form the geometry according to whether the geometry is closed.

Returns

any

A new polyline or polygon geometry.

public findNearestSegment(pt: point, close?: boolean): { setIdx: number; ptIdx: number; pt: 'mapsjs'.point; distance: number; }

Finds point along boundary of geometry nearest to the given point

Parameters

  • pt: point

    Reference point.

  • close?: boolean optional

Returns

{ setIdx: number; ptIdx: number; pt: 'mapsjs'.point; distance: number; }

An object of the form {setIdx, ptIdx, pt, distance} where setIdx is the index of the set the point is in, ptIdx is the index of the point in the set, pt is the point object, and distance is the distance of the point to the reference point in map units.

public findNearestVertex(pt: point): { setIdx: number; ptIdx: number; pt: 'mapsjs'.point; distance: number; }

Finds the point in this geometry nearest to the given point.

Parameters

  • pt: point

    Reference point.

Returns

{ setIdx: number; ptIdx: number; pt: 'mapsjs'.point; distance: number; }

An object of the form {setIdx, ptIdx, pt, distance} where setIdx is the index of the set the point is in, ptIdx is the index of the point in the set, pt is the point object, and distance is the distance of the point to the reference point in map units.

public foreachVertex(action: (setIdx: number, idx: number, x: number, y: number, s: number[]) => void)

Iterates every vertex in the geometry and passes to the supplied callback. Return true from in the callback will break the iteration.

Parameters

  • action: (setIdx: number, idx: number, x: number, y: number, s: number[]) => void

    Callback with the signature action(setIdx, idx, x, y, set).

public getBounds(): envelope

Returns the geometry's bounding box as an envelope.

Returns

envelope

The bounding box of the geometry as an envelope.

public getIsClosed(): boolean

Checks whether or not this geometry is closed.

Returns

boolean

Result of the closed check.

public getIsPath(): boolean

Checks whether or not this geometry is closed.

Returns

boolean

Result of the path check.

public getLabelingPoint(idx?: number): point

Finds coordinates in map units of the midpoint of this geometry. If this geometry is an open path, the midpoint is the midpoint of the path. If this geometry is a closed path, the midpoint is the centroid of the polygon. If a set index is not provided, finds the labeling point for the last set in this geometry's set collection.

Parameters

  • idx?: number optional

Returns

point

Midpoint of this geometry.

public getSet(idx: number): Array<number>

Gets a set from this geometry's set collection by index, or, if no index is provided, gets the last set. Note: for polygons, first set is primary ring and subsequent ones are holes.

Parameters

  • idx: number

Returns

Array<number>

A set as an array of points in the form [xn,yn].

public getSetCount(): number

Gets the number of sets in this geometry.

Returns

number

Number of sets.

public isValid(): boolean

Tests the validity of this geometry. An open path geometry is valid if it has at least one set with at least two points. A closed geometry is valid if it has at least one set with at least three points. A point (non-path) geometry is always valid.

Returns

boolean

valid geometry is true, otherwise false.

public popSet(): Array<number>

Gets the last set in the geometry's set collection and removes it from the collection.

Returns

Array<number>

Set removed as an array of points in the form [xn,yn].

public pushSet(s: Array<number>)

Adds a new set to this geometry's collection of sets.

Parameters

  • s: Array<number>

    Set to add as an array of points in the form [xn,yn].

public toString(): string

Creates a wkt string from this geometry.

Returns

string

A string of well known text.

public toSvgPathData(): string

Creates SVG path data from this geometry if it is a path.

Returns

string

String of the SVG path or null the geometry is not a path.

public toWkt(): string

Returns

string