Skip to content

Commit

Permalink
Initial version.
Browse files Browse the repository at this point in the history
  • Loading branch information
tookko committed Nov 22, 2015
1 parent 85377dd commit 789efff
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 0 deletions.
16 changes: 16 additions & 0 deletions bower.json
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"
}
45 changes: 45 additions & 0 deletions leaflet.sector.js
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);
};

0 comments on commit 789efff

Please sign in to comment.