Powered by Zoomin Software. For more details please contactZoomin

HERE Maps API for JavaScript - API Reference

Product category
Technology
Doc type
Version
Product lifecycle
This publication

HERE Maps API for JavaScript - API Reference: Class: LineString

Table of Contents

Class: LineString

H.geo.LineString

new H.geo.LineString (opt_latLngAlts)

A LineString is a geometry of connected line segments in geographic space.

Name Type Description
opt_latLngAlts Array.<number> optional

An optional array of latitude, longitude and altitude triples to initialize the LineString with.

Throws:

in case of invalid lat, lng, alt values

Type
H.lang.InvalidArgumentError
Examples
Polygon on the map
Polyline on the map

Extends

Methods

H.geo.LineString.fromFlexiblePolyline (encodedPolyline)H.geo.LineString static

Decodes the specified Flexible Polyline and converts it to the LineString.

Name Type Description
encodedPolyline string
Throws:
  • If the specified data has an invalid encoding.

    Type
    Error
  • If the third dimension type is other then ABSENT or ALTITUDE.

    Type
    H.lang.InvalidArgumentError
Returns:
Type Description
H.geo.LineString

H.geo.LineString.fromLatLngArray (latLngs)H.geo.LineString static

This method initializes a new LineString with an array of lat, lng values. Arrays are expected to have an even length with the format [lat, lng, lat, lng, ...].

Name Type Description
latLngs Array.<number>

the array of lat, lng value.

Throws:

throws an error in case the latLngs array has an odd length

Type
H.lang.InvalidArgumentError
Returns:
Type Description
H.geo.LineString The LineString containing the lat, lng values

H.geo.LineString.isDBC (lng1, lng2)boolean static

To obtain whether a leg (formed by the given two longitudes) crosses the International Date Line.

Name Type Description
lng1 H.geo.Longitude

The start longitude of the leg

lng2 H.geo.Longitude

The end longitude of the leg

Returns:
Type Description
boolean

eachLatLngAlt (eachFn, opt_start, opt_end)

A utility method to iterate over the points of a line string.

Example
// Log the coordinates for certain points of the line string:
function eachFn(lat, lng, alt, idx) {
  console.log("point %i (%f, %f, %f)", idx, lat, lng, alt);
}
myLineString.eachLatLngAlt(eachFn, 1, 3);

equals (other)boolean inherited overrides

Checks whether the geometry is equal to the geometry supplied by the caller. Two geometries are considered as equal if they represent the same geometry type and have equal coordinate values.

Name Type Description
other *

The geometry to check against

Returns:
Type Description
boolean true if the two geometries are equal, otherwise false

extractPoint (pointIndex, opt_out)H.geo.Point

This method extracts a H.geo.Point from this LineString at the virtual point index. If the extracted point has an alt value, the LineString's altitude context will be supplied to the point.

Name Type Description
pointIndex number

the virtual point index in the LineString

opt_out H.geo.Point optional

an optional point object to store the lat, lng, alt values

Returns:
Type Description
H.geo.Point Returns either the 'opt_out' point object or a new point object.

getBoundingBox ()H.geo.Rect inherited overrides

This method returns the bounding box of this LineString.

Note: The LineString is treated as an open path. If the bounding rectangle for a closed shape is required, the closing leg must be merged in an extra step.

Returns:
Type Description
H.geo.Rect the bounding rectangle of the geometry or null if the bounding rectangle can't be computed (e.g. for a geometry without coordinates)

getDBCs (opt_asClosed)number

To obtain the number of times that this LineString cross the International Date Line.

Name Type Description
opt_asClosed boolean optional

Indicates whether the LineString is treated as closed (the LineString's last and first coordinates form the closing leg of a polygon). It defaults to false.

Returns:
Type Description
number

getLatLngAltArray ()Array.<number>

Returns the vertices of the line segments as an array of alternating latitude, longitude and altitude coordinates. The returned array must be treated as read-only to not violate the integrity of the line-string.

Returns:
Type Description
Array.<number> Returns the raw lat, lng, alt values of this LineString

getPointCount ()number

This method return the number of points stored in this LineString.

Returns:
Type Description
number The number of points in this LineString

insertLatLngAlt (index, lat, lng, alt)

This method inserts one set of lat, lng, alt values into the LineString at the specified index.

insertPoint (pointIndex, geoPoint)

This method inserts the lat, lng, alt values of a H.geo.Point into the list at the specified index.

Name Type Description
pointIndex number
geoPoint H.geo.IPoint

pushLatLngAlt (lat, lng, alt)

This method pushes a lat, lng, alt to the end of this LineString.

Throws:

pushPoint (geoPoint)

This method pushes the lat, lng, alt values of a H.geo.Point to the end of this LineString.

Name Type Description
geoPoint H.geo.IPoint
Throws:

in case of invalid geoPoint argument

Type
H.lang.InvalidArgumentError

removeLatLngAlt (index)

This method removes one set of lat, lng, alt values from the LineString at the specified index.

Name Type Description
index number

removePoint (pointIndex)

This method removes one set of lat, lng, alt values from this LineString at the virtual point index specified.

Name Type Description
pointIndex number

the virtual point index

spliceLatLngAlts (index, opt_nRemove, opt_latLngAlts)Array.<number>

This method splices the LineString at the provided index, removing the specified number of items at that index and inserting the lat, lng, alt array.

Throws:

in case of invalid opt_latLngAlts argument

Type
H.lang.InvalidArgumentError
Returns:
Type Description
Array.<number> An array of removed elements

toFlexiblePolyline (precision)string

To obtain a Flexible Polyline encoded representation of the geometry.

Name Type Default Description
precision number 5 optional

How many decimal digits of precision to store the values, default is 5.

Returns:
Type Description
string the resulting encoded string.

toGeoJSON ()Object inherited

To obtain a GeoJSON representation of the given geometry.

Returns:
Type Description
Object A GeoJSON Geometry object representing the given geometry.

toString () inherited

To obtain a Well-Known-Text (WKT) representation of the geometry.

Was this article helpful?
TitleResults for “How to create a CRG?”Also Available inAlert