Open azophy opened 5 years ago
i just having the same error similar conditions
I am having the same issue. I had to downgrade the Leaflet
to 1.4.0
in order for the leaflet-draw
plugin to be worked without the error. It would be nice to see another workaround for this.
Seems that Leaflet has changed the logic in the Path.prototype.setStyle method (https://github.com/Leaflet/Leaflet/blob/master/src/layer/vector/Path.js#L108), so it causes the JavaScript error if you pass null
or undefined
in that method (https://github.com/Leaflet/Leaflet.draw/blob/develop/src/edit/handler/Edit.Poly.js#L152).
If you don't want to change the source files, you should enable edit mode this way
var polygon = new L.Polygon([
[51.51, -0.1],
[51.5, -0.06],
[51.52, -0.03]
], {
editing: {},
original: {}
});
polygon.editing.enable();
map.addLayer(polygon);
var polyline = new L.Polyline([
[51.50, -0.04],
[51.49, -0.02],
[51.51, 0],
[51.52, -0.02]
], {
editing: {},
original: {}
});
polyline.editing.enable();
map.addLayer(polyline);
var circleMarker = L.circleMarker([51.50, -0.08], {
editing: {},
original: {}
});
circleMarker.editing.enable();
map.addLayer(circleMarker);
var circle = L.circle([51.53, -0.06], 600, {
editing: {},
original: {}
});
circle.editing.enable();
map.addLayer(circle);
var rectangle = L.rectangle([
[51.49, -0.1],
[51.48, -0.06]
], {
editing: {},
original: {}
});
rectangle.editing.enable();
var rectangle = L.rectangle([
[51.49, -0.1],
[51.48, -0.06]
], {
editing: {},
original: {}
});
rectangle.editing.enable();
Now everything works fine :)
Has anybody patched this and submitted a PR? I would like to use leaflet 1.5.1 so I need to patch leaflet draw 1.0.4 to work with it.
Have the same error, looks like Leaflet.draw repo died
I am having a similar problems, except with
shape.editing.disable()
Are the authors/contributors @jacobtoye @ddproxy still maintaining this? What are people planning to use instead? @destus90 @tinjaw
@joshkopecek I have got lots of things associated with Leaflet.Draw plugin. It now pains me to replace this. The best way for me to fork this plugin and maintain it by myself.
@destus90 I would have thought this project would be 'too big to fail'? There are 20k downloads per week recorded on npmjs, but no changes to the npm package in the last 9 months. Latest commit to the repo is 13/09/2018, which means there are some private commits sitting around somewhere for 1.0.4. @ddproxy is still active according to github - perhaps Leaflet.Draw needs a new maintainer? @jacobtoye
I don't want to see this rot. It is a good extension. I'd be willing to help on in any way I can.
@tinjaw @destus90 we're just a handful among many users for whom this is a critical tool.
@slurmalon @cimanzano seem to have been working on a more recent, popular fork here https://www.npmjs.com/package/@ceresimaging/leaflet-draw but the core plugin really needs some love. It's certainly holding me back from updating to Leaflet > 1.3.0
Mapbox and Leaflet must have vested interests in this plugin. How can we generate some support?
sometimes shape.options.editing===undefine
, override L.Path.prototype.setStyle
just check empty;
L.Path.prototype.setStyle = function (style) { L.setOptions(this, style); if (this._renderer) { this._renderer._updateStyle(this); if (this.options.stroke && typeof style === 'object' && style.hasOwnProperty('weight')) { this._updateBounds(); } } return this; }; L.Circle.prototype.setStyle = function (style) { L.setOptions(this, style); if (this._renderer) { this._renderer._updateStyle(this); if (this.options.stroke && typeof style === 'object' && style.hasOwnProperty('weight')) { this._updateBounds(); } } return this; };
@xxbld thanks for this, but overriding functions like that is not something I like doing. Seems very hacky.
I would prefer the Leaflet <<
❤️ solution
PLS forgive me @ddproxy for pinging you, but you seem to be the main maintainer of this code. Do you have time to work on this, or, if not, can you provide some guidance on what to fix and maybe one of us can work on it.
Solution by @destus90 really works! https://github.com/Leaflet/Leaflet.draw/issues/943#issuecomment-503438437
With Leaflet@1.6.0 you don't need to enable editing mode with my comment above. They have changed setStyle
method (https://github.com/Leaflet/Leaflet/pull/6728) so you can pass null
to this method. Working demo can be found here https://stackblitz.com/edit/typescript-mzi9or?file=index.html
@destus90 it's a good example, but if you are using dynamic editing this it gonna help you:
After many hours, I resolved!
L.Circle.include({
options: {
editing: {},
original: {},
}
})
L.Rectangle.include({
options: {
editing: {},
original: {},
}
})
L.Polygon.include({
options: {
editing: {},
original: {},
}
})
Each shape that you will use it's necessary use the include to set options.
How to reproduce
What behaviour I'm expecting and which behaviour I'm seeing
When run, it encounter error
Minimal example reproducing the issue