Created
March 16, 2013 09:45
-
-
Save mtravis/5175707 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
L.Draw.Circle = L.Draw.SimpleShape.extend({ | |
statics: { | |
TYPE: 'circle' | |
}, | |
options: { | |
shapeOptions: { | |
stroke: true, | |
color: '#f06eaa', | |
weight: 4, | |
opacity: 0.5, | |
fill: true, | |
fillColor: null, //same as color by default | |
fillOpacity: 0.2, | |
clickable: true | |
} | |
}, | |
initialize: function (map, options) { | |
// Save the type so super can fire, need to do this as cannot do this.TYPE :( | |
this.type = L.Draw.Circle.TYPE; | |
L.Draw.SimpleShape.prototype.initialize.call(this, map, options); | |
}, | |
_initialLabelText: 'Click and drag to draw circle.', | |
_drawShape: function (latlng) { | |
if (!this._shape) { | |
this._shape = new L.Circle(this._startLatLng, this._startLatLng.distanceTo(latlng), this.options.shapeOptions); | |
this._map.addLayer(this._shape); | |
} else { | |
this._shape.setRadius(this._startLatLng.distanceTo(latlng)); | |
} | |
}, | |
_onMouseMove: function (e) { | |
var latlng = e.latlng; | |
var rad = this._shape.getRadius(); | |
this._tooltip.updatePosition(latlng); | |
if (this._isDrawing) { | |
this._tooltip.updateContent({ text: 'Release.' , subtext: rad}); | |
this._drawShape(latlng); | |
} | |
}, | |
_fireCreatedEvent: function () { | |
var circle = new L.Circle(this._startLatLng, this._shape.getRadius(), this.options.shapeOptions); | |
L.Draw.SimpleShape.prototype._fireCreatedEvent.call(this, circle); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment