-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
61 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"name": "leaflet.sector", | ||
"main": "leaflet.sector.js", | ||
"homepage": "https://github.com/tookko/leaflet.sector", | ||
"description": "A circle sector overlay with a certain radius in meters, theta angle and rotation angle for Leaflet.", | ||
"moduleType": [], | ||
"keywords": [ | ||
"leaflet", | ||
"sector", | ||
"circle" | ||
], | ||
"authors": [ | ||
"Sampsa Tuokko" | ||
], | ||
"license": "MIT" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/* | ||
* L.Sector is a circle sector overlay (with a certain radius in meters, theta angle and rotation angle). | ||
*/ | ||
|
||
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); | ||
}; |