From 67e5e5d941d9a4b625742374875e1b2e5b9f25d5 Mon Sep 17 00:00:00 2001 From: Alan Beccati Date: Thu, 14 Apr 2016 17:46:29 +0200 Subject: [PATCH] Added support to pane option --- README.md | 1 + leaflet.textpath.js | 35 ++++++++++++++++++++++++++++++----- 2 files changed, 31 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 291481f..accbbf6 100644 --- a/README.md +++ b/README.md @@ -35,6 +35,7 @@ For example, show path orientation on mouse over : * `center` Centers the text according to the polyline's bounding box (Default: `false`) * `attributes` Object containing the attributes applied to the `text` tag. Check valid attributes [here](https://developer.mozilla.org/en-US/docs/Web/SVG/Element/text#Attributes) (Default: `{}`) * `below` Show text below the path (Default: false) +* `pane` Name of the pane where the text has to be drawn Screenshot ---------- diff --git a/leaflet.textpath.js b/leaflet.textpath.js index ad25ede..6d8ace7 100755 --- a/leaflet.textpath.js +++ b/leaflet.textpath.js @@ -20,8 +20,19 @@ var PolylineTextPath = { onRemove: function (map) { map = map || this._map; - if (map && this._textNode) - map._renderer._container.removeChild(this._textNode); + if (map && this._textNode) { + var svg = map._renderer._container; + if (this._textOptions.pane) { + paned_svg = this._map._getPaneRenderer(this._textOptions.pane); + try{ + svg = paned_svg._container; + } + catch (err) { + var svg = this._map._renderer._container; + } + } + svg.removeChild(this._textNode); + } __onRemove.call(this, map); }, @@ -39,7 +50,7 @@ var PolylineTextPath = { var text = this._text, options = this._textOptions; if (text) { - this.setText(null).setText(text, options); + this.setText(null, options).setText(text, options); } }, @@ -61,10 +72,24 @@ var PolylineTextPath = { }; options = L.Util.extend(defaults, options); + var svg = this._map._renderer._container; + if (options.pane) { + paned_svg = this._map._getPaneRenderer(options.pane); + try{ + svg = paned_svg._container; + } + catch (err) { + var svg = this._map._renderer._container; + } + } + /* If empty text, hide */ if (!text) { if (this._textNode && this._textNode.parentNode) { - this._map._renderer._container.removeChild(this._textNode); + try { + svg.removeChild(this._textNode); + } + catch (err) { ; } /* delete the node, so it will not be removed a 2nd time if the layer is later removed from the map */ delete this._textNode; @@ -74,7 +99,7 @@ var PolylineTextPath = { text = text.replace(/ /g, '\u00A0'); // Non breakable spaces var id = 'pathdef-' + L.Util.stamp(this); - var svg = this._map._renderer._container; + this._path.setAttribute('id', id); if (options.repeat) {