ClippedSVG = {
const { stamp, splitWords } = L.Util;
const { create } = L.SVG;
const parent = L.SVG.prototype;
return L.SVG.extend({
options: {
padding: 0.1,
continuous: true,
},
_initContainer() {
parent._initContainer.call(this);
this._defs = create("defs");
this._container.prepend(this._defs);
},
_destroyContainer() {
parent._destroyContainer.call(this);
delete this._defs;
},
_initPath(layer) {
const layerStamp = stamp(layer);
const clipPath = layer._clipPath = create('clipPath');
clipPath.setAttribute("id", `clip_${layerStamp}`);
const path = layer._path = create('path');
path.setAttribute("id", `path_${layerStamp}`);
clipPath.append(path);
const use = layer._use = create('use');
use.setAttribute("href", "#" + layer._path.id);
if (layer.options.className) {
path.classList.add(...splitWords(layer.options.className));
}
if (layer.options.interactive) {
path.classList.add('leaflet-interactive');
}
this._updateStyle(layer);
this._layers[layerStamp] = layer;
},
_addPath(layer) {
if (!this._rootGroup || !this._defs) { this._initContainer(); }
this._defs.appendChild(layer._clipPath);
this._rootGroup.appendChild(layer._use);
layer.addInteractiveTarget(layer._use);
},
_removePath(layer) {
layer._clipPath.remove();
layer._path.remove();
layer.removeInteractiveTarget(layer._use);
delete this._layers[stamp(layer)];
},
_updateStyle(layer) {
parent._updateStyle.call(this, layer);
const use = layer._use,
options = layer.options;
if (options.clip || options.clip === undefined) {
use.setAttribute('clip-path', `url(#${layer._clipPath.id})`);
}
else {
use.removeAttribute('clip-path');
}
},
_bringToFront(layer) {
L.DomUtil.toFront(layer._use);
},
_bringToBack(layer) {
L.DomUtil.toBack(layer._use);
}
});
}