ALKMaps.Geometry

A Geometry is a description of a geographic object.  Create an instance of this class with the ALKMaps.Geometry constructor.  This is a base class, typical geometry types are described by subclasses of this class.

Summary
ALKMaps.GeometryA Geometry is a description of a geographic object.
Properties
id{String} A unique identifier for this geometry.
parent{ALKMaps.Geometry}This is set when a Geometry is added as component of another geometry
bounds{ALKMaps.Bounds} The bounds of this geometry
Constructor
ALKMaps.GeometryCreates a geometry object.
Functions
destroyDestroy this geometry.
cloneCreate a clone of this geometry.
setBoundsSet the bounds for this Geometry.
clearBoundsNullify this components bounds and that of its parent as well.
extendBoundsExtend the existing bounds to include the new bounds.
getBoundsGet the bounds for this Geometry.
calculateBoundsRecalculate the bounds for the geometry.
distanceToCalculate the closest distance between two geometries (on the x-y plane).
getVerticesReturn a list of all points in this geometry.
atPoint
getLengthCalculate the length of this geometry.
getAreaCalculate the area of this geometry.
getCentroidCalculate the centroid of this geometry.
toStringReturns a text representation of the geometry.
ALKMaps.Geometry.fromWKTGenerate a geometry given a Well-Known Text string.
ALKMaps.Geometry.segmentsIntersectDetermine whether two line segments intersect.
ALKMaps.Geometry.distanceToSegment

Properties

id

{String} A unique identifier for this geometry.

parent

{ALKMaps.Geometry}This is set when a Geometry is added as component of another geometry

bounds

{ALKMaps.Bounds} The bounds of this geometry

Constructor

ALKMaps.Geometry

Creates a geometry object.

Functions

destroy

destroy: function()

Destroy this geometry.

clone

clone: function()

Create a clone of this geometry.  Does not set any non-standard properties of the cloned geometry.

Returns

{ALKMaps.Geometry} An exact clone of this geometry.

setBounds

setBounds: function(bounds)

Set the bounds for this Geometry.

Parameters

bounds{ALKMaps.Bounds}

clearBounds

clearBounds: function()

Nullify this components bounds and that of its parent as well.

extendBounds

extendBounds: function(newBounds)

Extend the existing bounds to include the new bounds.  If geometry’s bounds is not yet set, then set a new Bounds.

Parameters

newBounds{ALKMaps.Bounds}

getBounds

getBounds: function()

Get the bounds for this Geometry.  If bounds is not set, it is calculated again, this makes queries faster.

Returns

{ALKMaps.Bounds}

calculateBounds

calculateBounds: function()

Recalculate the bounds for the geometry.

distanceTo

distanceTo: function(geometry,
options)

Calculate the closest distance between two geometries (on the x-y plane).

Parameters

geometry{ALKMaps.Geometry} The target geometry.
options{Object} Optional properties for configuring the distance calculation.

Valid options depend on the specific geometry type.

Returns

{Number | Object} The distance between this geometry and the target.  If details is true, the return will be an object with distance, x0, y0, x1, and x2 properties.  The x0 and y0 properties represent the coordinates of the closest point on this geometry.  The x1 and y1 properties represent the coordinates of the closest point on the target geometry.

getVertices

getVertices: function(nodes)

Return a list of all points in this geometry.

Parameters

nodes{Boolean} For lines, only return vertices that are endpoints.  If false, for lines, only vertices that are not endpoints will be returned.  If not provided, all vertices will be returned.

Returns

{Array} A list of all vertices in the geometry.

atPoint

atPoint: function(lonlat,
toleranceLon,
toleranceLat)
NoteThis is only an approximation based on the bounds of the geometry.

Parameters

lonlat{<ALKMaps.LonLat>|Object} ALKMaps.LonLat or an object with a ‘lon’ and ‘lat’ properties.
toleranceLon{float} Optional tolerance in Geometric Coords
toleranceLat{float} Optional tolerance in Geographic Coords

Returns

{Boolean} Whether or not the geometry is at the specified location

getLength

getLength: function()

Calculate the length of this geometry.  This method is defined in subclasses.

Returns

{Float} The length of the collection by summing its parts

getArea

getArea: function()

Calculate the area of this geometry.  This method is defined in subclasses.

Returns

{Float} The area of the collection by summing its parts

getCentroid

getCentroid: function()

Calculate the centroid of this geometry.  This method is defined in subclasses.

Returns

{ALKMaps.Geometry.Point} The centroid of the collection

toString

toString: function()

Returns a text representation of the geometry.  If the WKT format is included in a build, this will be the Well-Known Text representation.

Returns

{String} String representation of this geometry.

ALKMaps.Geometry.fromWKT

ALKMaps.Geometry.fromWKT = function(wkt)

Generate a geometry given a Well-Known Text string.  For this method to work, you must include the ALKMaps.Format.WKT in your build explicitly.

Parameters

wkt{String} A string representing the geometry in Well-Known Text.

Returns

{ALKMaps.Geometry} A geometry of the appropriate class.

ALKMaps.Geometry.segmentsIntersect

ALKMaps.Geometry.segmentsIntersect = function(seg1,
seg2,
options)

Determine whether two line segments intersect.  Optionally calculates and returns the intersection point.  This function is optimized for cases where seg1.x2 >= seg2.x1 || seg2.x2 >= seg1.x1.  In those obvious cases where there is no intersection, the function should not be called.

Parameters

seg1{Object} Object representing a segment with properties x1, y1, x2, and y2.  The start point is represented by x1 and y1.  The end point is represented by x2 and y2.  Start and end are ordered so that x1 < x2.
seg2{Object} Object representing a segment with properties x1, y1, x2, and y2.  The start point is represented by x1 and y1.  The end point is represented by x2 and y2.  Start and end are ordered so that x1 < x2.
options{Object} Optional properties for calculating the intersection.

Valid options

point{Boolean} Return the intersection point.  If false, the actual intersection point will not be calculated.  If true and the segments intersect, the intersection point will be returned.  If true and the segments do not intersect, false will be returned.  If true and the segments are coincident, true will be returned.
tolerance{Number} If a non-null value is provided, if the segments are within the tolerance distance, this will be considered an intersection.  In addition, if the point option is true and the calculated intersection is within the tolerance distance of an end point, the endpoint will be returned instead of the calculated intersection.  Further, if the intersection is within the tolerance of endpoints on both segments, or if two segment endpoints are within the tolerance distance of each other (but no intersection is otherwise calculated), an endpoint on the first segment provided will be returned.

Returns

{Boolean | ALKMaps.Geometry.Point} The two segments intersect.  If the point argument is true, the return will be the intersection point or false if none exists.  If point is true and the segments are coincident, return will be true (and the intersection is equal to the shorter segment).

ALKMaps.Geometry.distanceToSegment

ALKMaps.Geometry.distanceToSegment = function(point,
segment)

Parameters

point{Object} An object with x and y properties representing the point coordinates.
segment{Object} An object with x1, y1, x2, and y2 properties representing endpoint coordinates.

Returns

{Object} An object with distance, x, and y properties.  The distance will be the shortest distance between the input point and segment.  The x and y properties represent the coordinates along the segment where the shortest distance meets the segment.

Creates a geometry object.
Instances of this class represent bounding boxes.
destroy: function()
Destroy this geometry.
clone: function()
Create a clone of this geometry.
setBounds: function(bounds)
Set the bounds for this Geometry.
clearBounds: function()
Nullify this components bounds and that of its parent as well.
extendBounds: function(newBounds)
Extend the existing bounds to include the new bounds.
getBounds: function()
Get the bounds for this Geometry.
calculateBounds: function()
Recalculate the bounds for the geometry.
distanceTo: function(geometry,
options)
Calculate the closest distance between two geometries (on the x-y plane).
getVertices: function(nodes)
Return a list of all points in this geometry.
atPoint: function(lonlat,
toleranceLon,
toleranceLat)
getLength: function()
Calculate the length of this geometry.
getArea: function()
Calculate the area of this geometry.
getCentroid: function()
Calculate the centroid of this geometry.
toString: function()
Returns a text representation of the geometry.
ALKMaps.Geometry.fromWKT = function(wkt)
Generate a geometry given a Well-Known Text string.
ALKMaps.Geometry.segmentsIntersect = function(seg1,
seg2,
options)
Determine whether two line segments intersect.
ALKMaps.Geometry.distanceToSegment = function(point,
segment)
Point geometry class.
Close