Plugin for Leaflet adding sector (pie-shaped part of a circle) drawing capability to L.Circle
.
Based on jieter / Leaflet-semicircle.
Compatible with Leaflet version 1.0 (tested with 1.0.2, 1.6.0), not compatible with version 0.x.
See demo.
- load
leaflet.js
- load
leaflet.circle-sector.js
- create
L.Circle
instance(s):
var sector = L.circle([50, 5], {
radius: 1234,
startAngle: 60,
endAngle: 120,
}).addTo(map);
or:
var sector = L.circle([50, 5], {radius: 1234}).setAngles(60, 120).addTo(map);
or:
var sector = L.circle([50, 5], {radius: 1234}).setSector(90, 60).addTo(map);
See also demo.html
.
This plugin alters Leaflet's class L.Circle
and adds helper methods to class L.CRS.Earth
as well as private methods to renderer classes L.Canvas
and L.SVG
.
Angles are in degrees, clockwise from North.
L.Circle
additions
Option | Type | Default | Description |
---|---|---|---|
startAngle |
Number |
0 |
Start angle of sector. |
endAngle |
Number |
360 |
End angle of sector. |
Pragmatic assumption: startAngle <= endAngle
. When endAngle - startAngle >= 360
, a full (normal) circle is drawn.
Function | Returns | Description |
---|---|---|
contains(<LatLng> latLng) |
Boolean |
Returns true if the circle (sector) contains the given point. |
getBounds() |
LatLngBounds |
Returns the LatLngBounds of the circle (sector). |
setAngles(<Number> start, <Number> end) |
this |
Sets the start and end angles of a circle (sector), non-numeric values are ignored. |
setSector(<Number> direction, <Number> centralAngle?) |
this |
Alternative angle setter through main direction and central angle; previously set central angle is retained if omitted. |
L.CRS.Earth
additions
Note: these methods require true LatLng
s.
Function | Returns | Description |
---|---|---|
bearing(<LatLng> latLng1, <LatLng> latLng2) |
Number |
Returns initial bearing (degrees normalized to 0-360) on great circle path from latLng1 to latLng2. |
destination(<LatLng> latLng, <Number> bearing, <Number> distance) |
LatLng |
Returns destination point given distance (meters) and bearing (degrees) from latLng. |