Open CedricLCB opened 8 years ago
I've got a similar issue, getting an error when switching my base layers, if there was a line or a polygon created on a map (no problem with rectangles and markers). I use a standard leaflet.draw.js .
Honestly, I didn't get how to apply the solution with checking for this._markers != null. But the console showed that the error raised at this function:
_onZoomEnd: function () { this._updateGuide(); },
So I just commented this._updateGuide();
line and now everything works like a charm.
Thank you both for documenting this. I ran into the same issue with Leaflet Draw 0.3.0 polylines and changing tile layers with Leaflet Layer Control.
reirby's solution also worked, but just commenting out that code will cause the guidlines for the polyline not to update after map is zoomed. I did this:
_onZoomEnd: function () {
if(this._markers != null){
this._updateGuide();
}
},
I'm a beginner with Leaflet so this might be a naive request, but would it be possible to create a PR for this fix? I have ran into this issue myself and the solution above has fixed it in my own project.
(I found a solution (see end of post) myself but wanted to document the problem)
I used a custom dist with only: core, drawhandlers, extensions, commonUI After I drew a map with:
polyLineDrawer = new L.Draw.Polyline(map, { repeatMode: false, shapeOptions: { color: '#0088CE', // Stroke color opacity: 1, // Stroke opacity weight: 4, // Stroke weight } }); polyLineDrawer.enable();
And then switched a layer on my leaflet map (switched a tile layer), I got the following error:
this._markers is undefined L.Draw.Polyline<._updateGuide() leaflet.draw.js:8 L.Draw.Polyline<._onZoomEnd() leaflet.draw.js:8 o.Mixin.Events.fireEvent() leaflet.js:6 o.Map<._updateZoomLevels() leaflet.js:6 o.Map<.removeLayer() leaflet.js:6 o.Control.Layers<._onInputClick() leaflet.js:9 o.DomEvent.addListener/s() leaflet.js:8
Since I am only using the Polyline, I went to the source (Draw.Polyline.js) I had locally (and edited it) and checked for (this._markers != null). This fixed the problem for me.