Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support to pane option #48

Open
wants to merge 1 commit into
base: leaflet0.8-dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
----------
Expand Down
35 changes: 30 additions & 5 deletions leaflet.textpath.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
},

Expand All @@ -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);
}
},

Expand All @@ -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;
Expand All @@ -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) {
Expand Down