Leaflet / Leaflet.draw

Vector drawing and editing plugin for Leaflet
https://leaflet.github.io/Leaflet.draw/docs/leaflet-draw-latest.html
MIT License
1.96k stars 992 forks source link

Drawing a circle doesn't work. #450

Open Brutusn opened 8 years ago

Brutusn commented 8 years ago

I updated Leaflet to the latest dev version. In that version they changed L.Circle and added the radius to the options. I changed that inside the draw plugin inside L.Draw.Circle in the following two functions.

        _drawShape: function (latlng) {
            if (!this._shape) {
                this.options.shapeOptions.radius = this._startLatLng.distanceTo(latlng);
                this._shape = new L.Circle(this._startLatLng, this.options.shapeOptions);
                this._map.addLayer(this._shape);
            } else {
                this._shape.setRadius(this._startLatLng.distanceTo(latlng));
            }
        },

        _fireCreatedEvent: function () {
            this.options.shapeOptions.radius = this._shape.getRadius();
            var circle = new L.Circle(this._startLatLng, this.options.shapeOptions);
            L.Draw.SimpleShape.prototype._fireCreatedEvent.call(this, circle);
        },
ValentinH commented 8 years ago

:+1:

thomas-peyric commented 8 years ago

thanks ;-)

iH8 commented 8 years ago

Had the same problem, came here with the same intent but you beat me to the punch. I have one remark on the proposed solution. Adding the radius property to the shapeOptions object in the _drawShape method is unnecessary since L.Circle which is extended from L.CircleMarker has a default radius: https://github.com/Leaflet/Leaflet/blob/master/src/layer/vector/CircleMarker.js#L9

Brutusn commented 8 years ago

Well if I remove that radius option it generates some weird behaviour. It will use the radius of the last circle drawn as a start, and then it will have the correct size.

iH8 commented 8 years ago

Weird behaviour? Please elaborate. Instanciating a L.Circle with no radius option in the optionsobject should work just fine.

Brutusn commented 8 years ago

It will shortly use the radius of the last circle. After that it will get the new radius calculated from the mouseposition.

iH8 commented 8 years ago

Absolutely right, didn't notice, thanks!

Nick-t-go commented 8 years ago

Why hasn't this update been added to the latest version that is on the master branch(think it is beta)? Or did I download the wrong one?

ddproxy commented 8 years ago

@Nick-t-go Leaflet.draw doesn't fully support Leaflet 1.x yet. I see iH8's commit but I don't see any pull requests for this from @iH8. His repository also seems to be out of date.

The projected release for 1.x support (and dropping older versions) is 0.5.

The Leaflet-master branch seems to be where most 1.x support has been merged.