Class: LineString
- Last UpdatedJun 30, 2025
- 4 minute read
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
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
orALTITUDE
.
-
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
Returns:
Type Description H.geo.LineString The LineString containing the lat, lng values -
-
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 -
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);
-
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, otherwisefalse
-
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) -
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 -
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 -
This method return the number of points stored in this LineString.
Returns:
Type Description number The number of points in this LineString -
This method inserts one set of lat, lng, alt values into the LineString at the specified index.
-
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 -
This method pushes a lat, lng, alt to the end of this LineString.
Throws:
-
-
in case of invalid lat, lng, alt values
-
-
-
in case of invalid lat, lng, alt values
-
-
-
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
-
-
This method removes one set of lat, lng, alt values from the LineString at the specified index.
Name Type Description index
number -
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
-
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
Returns:
Type Description Array.<number> An array of removed elements -
-
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.