node-red-contrib-jwht-map/worldmap/leaflet/l.ellipse.min.js
Dave Conway-Jones f8b5755d50 initial commit
2016-04-01 11:31:07 +01:00

1 line
2.4 KiB
JavaScript

L.Ellipse=L.Path.extend({initialize:function(d,c,a,b){L.Path.prototype.initialize.call(this,b);this._latlng=L.latLng(d);if(a){this._tiltDeg=a}else{this._tiltDeg=0}if(c){this._mRadiusX=c[0];this._mRadiusY=c[1]}},options:{fill:true,startAngle:0,endAngle:359.9},setLatLng:function(a){this._latlng=L.latLng(a);return this.redraw()},setRadius:function(a){this._mRadiusX=a[0];this._mRadiusY=a[1];return this.redraw()},setTilt:function(a){this._tiltDeg=a;return this.redraw()},projectLatlngs:function(){var e=this._getLngRadius(),c=this._getLatRadius(),d=this._latlng,a=this._map.latLngToLayerPoint([d.lat,d.lng-e]),b=this._map.latLngToLayerPoint([d.lat-c,d.lng]);this._point=this._map.latLngToLayerPoint(d);this._radiusX=Math.max(this._point.x-a.x,1);this._radiusY=Math.max(b.y-this._point.y,1);this._endPointParams=this._centerPointToEndPoint()},getBounds:function(){var c=this._getLngRadius(),a=this._getLatRadius(),b=this._latlng;return new L.LatLngBounds([b.lat-a,b.lng-c],[b.lat+a,b.lng+c])},getLatLng:function(){return this._latlng},getPathString:function(){var f=this._point,e=this._radiusX,d=this._radiusY,b=this._tiltDeg,a=this._endPointParams;if(this._checkIfEmpty()){return""}if(L.Browser.svg){return"M"+a.x0+","+a.y0+"A"+e+","+d+","+b+","+a.largeArc+","+a.sweep+","+a.x1+","+a.y1+" z"}else{f._round();e=Math.round(e);d=Math.round(d);return"AL "+f.x+","+f.y+" "+e+","+d+" "+b+","+(65535*360)}},getRadius:function(){return new L.point(this._mRadiusX,this._mRadiusY)},_centerPointToEndPoint:function(){var j=this._point,e=this._radiusX,a=this._radiusY,g=(this.options.startAngle+this.options.endAngle)*L.LatLng.DEG_TO_RAD,h=this.options.startAngle*L.LatLng.DEG_TO_RAD,m=this.options.endAngle,i=this._tiltDeg*L.LatLng.DEG_TO_RAD;var f=j.x+Math.cos(i)*e*Math.cos(h)+Math.sin(-i)*a*Math.sin(h);var l=j.y+Math.sin(i)*e*Math.cos(h)+Math.cos(i)*a*Math.sin(h);var d=j.x+Math.cos(i)*e*Math.cos(g)+Math.sin(-i)*a*Math.sin(g);var k=j.y+Math.sin(i)*e*Math.cos(g)+Math.cos(i)*a*Math.sin(g);var b=(m>180)?1:0;var n=(m>0)?1:0;return{x0:f,y0:l,tilt:i,largeArc:b,sweep:n,x1:d,y1:k}},_getLatRadius:function(){return(this._mRadiusY/40075017)*360},_getLngRadius:function(){return((this._mRadiusX/40075017)*360)/Math.cos(L.LatLng.DEG_TO_RAD*this._latlng.lat)},_checkIfEmpty:function(){if(!this._map){return false}var a=this._map._pathViewport,b=this._radiusX,c=this._point;return c.x-b>a.max.x||c.y-b>a.max.y||c.x+b<a.min.x||c.y+b<a.min.y}});L.ellipse=function(d,c,a,b){return new L.Ellipse(d,c,a,b)};