-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathleaflet.sector.js
More file actions
45 lines (38 loc) · 1.38 KB
/
leaflet.sector.js
File metadata and controls
45 lines (38 loc) · 1.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
/*
* L.Sector is a circle sector overlay (with a certain radius in meters, theta angle and azimuth).
*/
L.Sector = L.Circle.extend({
initialize: function (latlng, radius, theta, azimuth, options) {
L.Circle.prototype.initialize.call(this, latlng, radius, options);
this._theta = (theta < 360 ? theta : 359.9999) * Math.PI / 180;
this._azimuth = (azimuth % 360 - 90) * Math.PI / 180 ;
},
getPathString: function () {
var p = this._point;
var r = this._radius;
var a = {
x: p.x + r * Math.cos(this._azimuth + this._theta / 2),
y: p.y + r * Math.sin(this._azimuth + this._theta / 2)
};
var b = {
x: p.x + r * Math.cos(this._azimuth - this._theta / 2),
y: p.y + r * Math.sin(this._azimuth - this._theta / 2)
};
if (this._checkIfEmpty()) {
return '';
}
if (L.Browser.svg) {
return 'M' + p.x + ',' + p.y +
' L' + a.x + ',' + a.y +
' A' + r + ',' + r + ',0,' + (this._theta < Math.PI ? 0 : 1) + ',0,' + b.x + ',' + b.y +
' z';
} else {
p._round();
r = Math.round(r);
return 'AL ' + p.x + ',' + p.y + ' ' + r + ',' + r + ' 0,' + (65535 * 360); // TODO: support non-svg browsers
}
}
});
L.sector = function (latlng, radius, theta, azimuth, options) {
return new L.Sector(latlng, radius, theta, azimuth, options);
};