diff --git a/l.ellipse.js b/l.ellipse.js index f4d7ba3..a8953fc 100644 --- a/l.ellipse.js +++ b/l.ellipse.js @@ -40,7 +40,14 @@ L.Canvas.include ({ r = layer._radiusX, s = (layer._radiusY || r) / r; - this._drawnLayers[layer._leaflet_id] = layer; + if (this.hasOwnProperty('_drawnLayers')) { + this._drawnlayers[layer._leaflet_id] = layer; + } else if (this.hasOwnProperty('_layers')) { + this._layers[layer._leaflet_id] = layer; + } else { + throw new Error("Cannot find property _drawnLayers or _layers"); + } + ctx.save(); diff --git a/l.ellipse.min.js b/l.ellipse.min.js index dbe75cc..8fdb8e5 100644 --- a/l.ellipse.min.js +++ b/l.ellipse.min.js @@ -1 +1 @@ -L.SVG.include({_updateEllipse:function(a){var c=(a._point,a._radiusX),d=a._radiusY,e=a._tiltDeg,f=a._endPointParams,g="M"+f.x0+","+f.y0+"A"+c+","+d+","+e+","+f.largeArc+","+f.sweep+","+f.x1+","+f.y1+" z";this._setPath(a,g)}}),L.Canvas.include({_updateEllipse:function(a){if(!a._empty()){var b=a._point,c=this._ctx,d=a._radiusX,e=(a._radiusY||d)/d;this._drawnLayers[a._leaflet_id]=a,c.save(),c.translate(b.x,b.y),0!==a._tilt&&c.rotate(a._tilt),1!==e&&c.scale(1,e),c.beginPath(),c.arc(0,0,d,0,2*Math.PI),c.restore(),this._fillStroke(c,a)}}}),L.Ellipse=L.Path.extend({options:{fill:!0,startAngle:0,endAngle:359.9},initialize:function(a,b,c,d){L.setOptions(this,d),this._latlng=L.latLng(a),c?this._tiltDeg=c:this._tiltDeg=0,b&&(this._mRadiusX=b[0],this._mRadiusY=b[1])},setRadius:function(a){return this._mRadiusX=a[0],this._mRadiusY=a[1],this.redraw()},getRadius:function(){return new L.point(this._mRadiusX,this._mRadiusY)},setTilt:function(a){return this._tiltDeg=a,this.redraw()},getBounds:function(){var a=this._getLngRadius(),b=this._getLatRadius(),c=this._latlng;return new L.LatLngBounds([c.lat-b,c.lng-a],[c.lat+b,c.lng+a])},setLatLng:function(a){return this._latlng=L.latLng(a),this.redraw(),this.fire("move",{latlng:this._latlng})},getLatLng:function(){return this._latlng},setStyle:L.Path.prototype.setStyle,_project:function(){var a=this._getLngRadius(),b=this._getLatRadius(),c=this._latlng,d=this._map.latLngToLayerPoint([c.lat,c.lng-a]),e=this._map.latLngToLayerPoint([c.lat-b,c.lng]);this._point=this._map.latLngToLayerPoint(c),this._radiusX=Math.max(this._point.x-d.x,1),this._radiusY=Math.max(e.y-this._point.y,1),this._tilt=Math.PI*this._tiltDeg/180,this._endPointParams=this._centerPointToEndPoint(),this._updateBounds()},_updateBounds:function(){var a=Math.sin(this._tilt),b=Math.cos(this._tilt),c=a*a,d=b*b,e=this._radiusX*this._radiusX,f=this._radiusY*this._radiusY,g=Math.sqrt(e*d+f*c),h=Math.sqrt(e*c+f*d),i=this._clickTolerance(),j=[g+i,h+i];this._pxBounds=new L.Bounds(this._point.subtract(j),this._point.add(j))},_update:function(){this._map&&this._updatePath()},_updatePath:function(){this._renderer._updateEllipse(this)},_getLatRadius:function(){return this._mRadiusY/40075017*360},_getLngRadius:function(){return this._mRadiusX/40075017*360/Math.cos(Math.PI/180*this._latlng.lat)},_centerPointToEndPoint:function(){var a=this._point,b=this._radiusX,c=this._radiusY,d=(this.options.startAngle+this.options.endAngle)*(Math.PI/180),e=this.options.startAngle*(Math.PI/180),f=this.options.endAngle,g=this._tiltDeg*(Math.PI/180),h=a.x+Math.cos(g)*b*Math.cos(e)+Math.sin(-g)*c*Math.sin(e),i=a.y+Math.sin(g)*b*Math.cos(e)+Math.cos(g)*c*Math.sin(e),j=a.x+Math.cos(g)*b*Math.cos(d)+Math.sin(-g)*c*Math.sin(d),k=a.y+Math.sin(g)*b*Math.cos(d)+Math.cos(g)*c*Math.sin(d),l=f>180?1:0,m=f>0?1:0;return{x0:h,y0:i,tilt:g,largeArc:l,sweep:m,x1:j,y1:k}},_empty:function(){return this._radiusX&&this._radiusY&&!this._renderer._bounds.intersects(this._pxBounds)},_containsPoint:function(a){var b=Math.sin(this._tilt),c=Math.cos(this._tilt),d=a.x-this._point.x,e=a.y-this._point.y,f=c*d+b*e,g=b*d-c*e;return f*f/(this._radiusX*this._radiusX)+g*g/(this._radiusY*this._radiusY)<=1}}),L.ellipse=function(a,b,c,d){return new L.Ellipse(a,b,c,d)}; \ No newline at end of file +L.SVG.include({_updateEllipse:function(t){t._point;var i=t._radiusX,s=t._radiusY,n=t._tiltDeg,a=t._endPointParams,e="M"+a.x0+","+a.y0+"A"+i+","+s+","+n+","+a.largeArc+","+a.sweep+","+a.x1+","+a.y1+" z";this._setPath(t,e)}}),L.Canvas.include({_updateEllipse:function(t){if(!t._empty()){var i=t._point,s=this._ctx,n=t._radiusX,a=(t._radiusY||n)/n;if(this.hasOwnProperty("_drawnLayers"))this._drawnlayers[t._leaflet_id]=t;else{if(!this.hasOwnProperty("_layers"))throw new Error("Cannot find property _drawnLayers or _layers");this._layers[t._leaflet_id]=t}s.save(),s.translate(i.x,i.y),0!==t._tilt&&s.rotate(t._tilt),1!==a&&s.scale(1,a),s.beginPath(),s.arc(0,0,n,0,2*Math.PI),s.restore(),this._fillStroke(s,t)}}}),L.Ellipse=L.Path.extend({options:{fill:!0,startAngle:0,endAngle:359.9},initialize:function(t,i,s,n){L.setOptions(this,n),this._latlng=L.latLng(t),this._tiltDeg=s||0,i&&(this._mRadiusX=i[0],this._mRadiusY=i[1])},setRadius:function(t){return this._mRadiusX=t[0],this._mRadiusY=t[1],this.redraw()},getRadius:function(){return new L.point(this._mRadiusX,this._mRadiusY)},setTilt:function(t){return this._tiltDeg=t,this.redraw()},getBounds:function(){var t=this._getLngRadius(),i=this._getLatRadius(),s=this._latlng;return new L.LatLngBounds([s.lat-i,s.lng-t],[s.lat+i,s.lng+t])},setLatLng:function(t){return this._latlng=L.latLng(t),this.redraw(),this.fire("move",{latlng:this._latlng})},getLatLng:function(){return this._latlng},setStyle:L.Path.prototype.setStyle,_project:function(){var t=this._getLngRadius(),i=this._getLatRadius(),s=this._latlng,n=this._map.latLngToLayerPoint([s.lat,s.lng-t]),a=this._map.latLngToLayerPoint([s.lat-i,s.lng]);this._point=this._map.latLngToLayerPoint(s),this._radiusX=Math.max(this._point.x-n.x,1),this._radiusY=Math.max(a.y-this._point.y,1),this._tilt=Math.PI*this._tiltDeg/180,this._endPointParams=this._centerPointToEndPoint(),this._updateBounds()},_updateBounds:function(){var t=Math.sin(this._tilt),i=Math.cos(this._tilt),s=t*t,n=i*i,a=this._radiusX*this._radiusX,e=this._radiusY*this._radiusY,h=Math.sqrt(a*n+e*s),r=Math.sqrt(a*s+e*n),_=this._clickTolerance(),o=[h+_,r+_];this._pxBounds=new L.Bounds(this._point.subtract(o),this._point.add(o))},_update:function(){this._map&&this._updatePath()},_updatePath:function(){this._renderer._updateEllipse(this)},_getLatRadius:function(){return this._mRadiusY/40075017*360},_getLngRadius:function(){return this._mRadiusX/40075017*360/Math.cos(Math.PI/180*this._latlng.lat)},_centerPointToEndPoint:function(){var t=this._point,i=this._radiusX,s=this._radiusY,n=(this.options.startAngle+this.options.endAngle)*(Math.PI/180),a=this.options.startAngle*(Math.PI/180),e=this.options.endAngle,h=this._tiltDeg*(Math.PI/180);return{x0:t.x+Math.cos(h)*i*Math.cos(a)+Math.sin(-h)*s*Math.sin(a),y0:t.y+Math.sin(h)*i*Math.cos(a)+Math.cos(h)*s*Math.sin(a),tilt:h,largeArc:e>180?1:0,sweep:e>0?1:0,x1:t.x+Math.cos(h)*i*Math.cos(n)+Math.sin(-h)*s*Math.sin(n),y1:t.y+Math.sin(h)*i*Math.cos(n)+Math.cos(h)*s*Math.sin(n)}},_empty:function(){return this._radiusX&&this._radiusY&&!this._renderer._bounds.intersects(this._pxBounds)},_containsPoint:function(t){var i=Math.sin(this._tilt),s=Math.cos(this._tilt),n=t.x-this._point.x,a=t.y-this._point.y,e=s*n+i*a,h=i*n-s*a;return e*e/(this._radiusX*this._radiusX)+h*h/(this._radiusY*this._radiusY)<=1}}),L.ellipse=function(t,i,s,n){return new L.Ellipse(t,i,s,n)}; \ No newline at end of file