From f4f8c06c75b5c8d4922174d556fb933cd009c939 Mon Sep 17 00:00:00 2001 From: Vladimir Agafonkin Date: Mon, 16 Dec 2013 18:55:15 -0500 Subject: [PATCH] fix adding/removal of vectors and renderers --- debug/vector/vector2.html | 12 ++++++++++++ src/layer/vector/Canvas.js | 5 +++++ src/layer/vector/CircleMarker.js | 6 +++++- src/layer/vector/SVG.js | 12 ++++++++---- 4 files changed, 30 insertions(+), 5 deletions(-) diff --git a/debug/vector/vector2.html b/debug/vector/vector2.html index b112e45c..6d649940 100644 --- a/debug/vector/vector2.html +++ b/debug/vector/vector2.html @@ -38,6 +38,18 @@ var circleMarker = L.circleMarker([35, 30], {color: 'magenta', radius: 30}).addTo(map); map.setView([36, 52], 3); + + var layersControl = new L.Control.Layers({ + }, { + 'poly': poly, + 'path': path, + // 'rect': rect, + 'circle': circle, + 'circleMarker': circleMarker, + 'canvas': canvas, + 'svg': L.SVG.instance, + }, {collapsed: false}); + map.addControl(layersControl); diff --git a/src/layer/vector/Canvas.js b/src/layer/vector/Canvas.js index afa39263..f0efd0ff 100644 --- a/src/layer/vector/Canvas.js +++ b/src/layer/vector/Canvas.js @@ -15,6 +15,8 @@ L.Canvas = L.Renderer.extend({ this.getPane().appendChild(container); this._update(); + + this.fire('redraw'); }, onRemove: function () { @@ -48,6 +50,9 @@ L.Canvas = L.Renderer.extend({ }, _initPath: function (layer) { + if (!layer._updatePath) { + debugger; + } this.on('redraw', layer._updatePath, layer); if (layer.options.clickable) { diff --git a/src/layer/vector/CircleMarker.js b/src/layer/vector/CircleMarker.js index 1612ec06..048e7533 100644 --- a/src/layer/vector/CircleMarker.js +++ b/src/layer/vector/CircleMarker.js @@ -48,10 +48,14 @@ L.CircleMarker = L.Path.extend({ _update: function () { if (this._map) { - this._renderer._updateCircle(this); + this._updatePath(); } }, + _updatePath: function () { + this._renderer._updateCircle(this); + }, + _empty: function () { var b = this._renderer._bounds, r = this._radius + (this.options.stroke ? this.options.weight / 2 : 0), diff --git a/src/layer/vector/SVG.js b/src/layer/vector/SVG.js index 31ca9979..f63ee644 100644 --- a/src/layer/vector/SVG.js +++ b/src/layer/vector/SVG.js @@ -2,11 +2,15 @@ L.SVG = L.Renderer.extend({ onAdd: function () { - var container = this._container = L.SVG.create('svg'); - container.setAttribute('pointer-events', 'none'); + var container = this._container; - if (this._zoomAnimated) { - L.DomUtil.addClass(container, 'leaflet-zoom-animated'); + if (!container) { + container = this._container = L.SVG.create('svg'); + container.setAttribute('pointer-events', 'none'); + + if (this._zoomAnimated) { + L.DomUtil.addClass(container, 'leaflet-zoom-animated'); + } } this.getPane().appendChild(container);