Index

Leaflet.GeometryUtil

[Build Status

  • Tested with stable Leaflet 0.6.4

Usage

Check out online documentation.

Development

Running tests in command-line

sudo apt-get install nodejs phantomjs

  • Ready !

make test

Changelog

0.2.0

  • Locate point on line
  • Rotate point around center
  • Fixed bug if closest point was on last segment

0.1.0

  • Line subpart extraction
  • Line lengths
  • Angle and slope computation
  • Line reverse
  • Line interpolation

0.0.1

  • Initial working version

Authors

[Makina Corpus

L.GeometryUtil

Leaflet Geometry utilities for distances and linear referencing.
Source:

Methods

<static> accumulatedLengths(coords) → {Number}

Returns a list of accumulated length along a line.
Parameters:
Name Type Description
coords L.Polyline | Array<L.Point> | Array<L.LatLng>
Source:
Returns:
in meters
Type
Number

<static> belongsSegment(latlngA, latlngB, tolerance) → {boolean}

Returns true if the latlng belongs to segment. param {L.LatLng} latlng
Parameters:
Name Type Argument Default Description
latlngA L.LatLng
latlngB L.LatLng
tolerance Number <optional>
<nullable>
0.2
Source:
Returns:
Type
boolean

<static> closest(map, layer, latlng, vertices) → {L.LatLng}

Returns the closest latlng on layer.
Parameters:
Name Type Argument Default Description
map L.Map
layer Array<L.LatLng> | L.PolyLine Layer that contains the result.
latlng L.LatLng
vertices boolean <optional>
<nullable>
false Whether to restrict to path vertices.
Source:
Returns:
Type
L.LatLng

<static> closestLayer(map, layers, latlng) → {object}

Returns the closest layer to latlng among a list of layers.
Parameters:
Name Type Description
map L.Map
layers Array<L.ILayer>
latlng L.LatLng
Source:
Returns:
with layer, latlng and distance or {null} if list is empty;
Type
object

<static> closestLayerSnap(map, layers, latlng, tolerance, withVertices) → {object}

Returns the closest position from specified {LatLng} among specified layers, with a maximum tolerance in pixels, providing snapping behaviour.
Parameters:
Name Type Argument Default Description
map L.Map
layers Array<ILayer> A list of layers to snap on.
latlng L.LatLng The position to snap.
tolerance Number <optional>
<nullable>
Infinity Maximum number of pixels.
withVertices boolean <optional>
<nullable>
true Snap to layers vertices.
Source:
Returns:
with snapped {LatLng} and snapped {Layer} or null if tolerance exceeded.
Type
object

<static> closestOnSegment(map, latlng, latlngA, latlngB) → {L.LatLng}

Returns the closest point of a {L.LatLng} on the segment (A-B)
Parameters:
Name Type Description
map L.Map
latlng L.LatLng
latlngA L.LatLng
latlngB L.LatLng
Source:
Returns:
Type
L.LatLng

<static> computeAngle(a, b) → {float}

Returns horizontal angle in degres between two points.
Parameters:
Name Type Description
a L.Point
b L.Point
Source:
Returns:
Type
float

<static> computeSlope(a, b) → {Object}

Returns slope (Ax+B) between two points.
Parameters:
Name Type Description
a L.Point
b L.Point
Source:
Returns:
with ``a`` and ``b`` properties.
Type
Object

<static> distance(map, latlngA, latlngB) → {Number}

Shortcut function for planar distance between two {L.LatLng} at current zoom.
Parameters:
Name Type Description
map L.Map
latlngA L.LatLng
latlngB L.LatLng
Source:
Returns:
in pixels
Type
Number

<static> distanceSegment(map, latlng, latlngA, latlngB) → {Number}

Shortcut function for planar distance between a {L.LatLng} and a segment (A-B).
Parameters:
Name Type Description
map L.Map
latlng L.LatLng
latlngA L.LatLng
latlngB L.LatLng
Source:
Returns:
in pixels
Type
Number

<static> extract(map, latlngs, start, end) → {Array<L.LatLng>}

Returns a sub-part of the polyline, from start to end. If start is superior to end, returns extraction from inverted line.
Parameters:
Name Type Description
map L.Map
latlngs L.PolyLine
start Number ratio, expressed as a decimal between 0 and 1, inclusive
end Number ratio, expressed as a decimal between 0 and 1, inclusive
Source:
Returns:
Type
Array<L.LatLng>

<static> interpolateOnLine(map, latlngs, the) → {Object}

Returns the coordinate of the point located on a line at the specified ratio of the line length.
Parameters:
Name Type Description
map L.Map
latlngs Array<L.LatLng> | L.PolyLine
the Number length ratio, expressed as a decimal between 0 and 1, inclusive
Source:
Returns:
an object with latLng ({LatLng}) and predecessor ({Number}), the index of the preceding vertex in the Polyline (-1 if the interpolated point is the first vertex)
Type
Object

<static> interpolateOnPointSegment(pA, pB, the) → {L.Point}

Returns the Point located on a segment at the specified ratio of the segment length.
Parameters:
Name Type Description
pA L.Point
pB L.Point
the Number length ratio, expressed as a decimal between 0 and 1, inclusive.
Source:
Returns:
the interpolated point.
Type
L.Point

<static> isAfter(polyline, other) → {bool}

Returns true if first polyline starts where second ends.
Parameters:
Name Type Description
polyline L.PolyLine
other L.PolyLine
Source:
Returns:
Type
bool

<static> isBefore(polyline, other) → {bool}

Returns true if first polyline ends where other second starts.
Parameters:
Name Type Description
polyline L.PolyLine
other L.PolyLine
Source:
Returns:
Type
bool

<static> length(coords) → {Number}

Returns total length of line
Parameters:
Name Type Description
coords L.Polyline | Array<L.Point> | Array<L.LatLng>
Source:
Returns:
in meters
Type
Number

<static> locateOnLine(map, polyline, latlng) → {Number}

Returns a float between 0 and 1 representing the location of the closest point on polyline to the given latlng, as a fraction of total 2d line length. (opposite of L.GeometryUtil.interpolateOnLine())
Parameters:
Name Type Description
map L.Map
polyline L.PolyLine
latlng L.LatLng
Source:
Returns:
Type
Number

<static> reverse(polyline) → {L.PolyLine}

Returns a clone with reversed coordinates.
Parameters:
Name Type Description
polyline L.PolyLine
Source:
Returns:
Type
L.PolyLine

<static> rotatePoint(latlngPoint:, angleDeg:, latlngCenter:) → {L.LatLng}

Returns LatLng of rotated point around specified LatLng center.
Parameters:
Name Type Description
latlngPoint: L.LatLng point to rotate
angleDeg: double angle to rotate in degrees
latlngCenter: L.LatLng center of rotation
Source:
Returns:
rotated point
Type
L.LatLng

<static> startsAtExtremity(polyline, other) → {bool}

Returns true if first polyline starts where second ends or start.
Parameters:
Name Type Description
polyline L.PolyLine
other L.PolyLine
Source:
Returns:
Type
bool