Clone leaflet layers
JavaScript HTML
Permalink
Failed to load latest commit information.
test
.eslintrc Bump leaflet version for tests to 1.0.0-rc.1 Apr 22, 2016
.mversionrc
.travis.yml use 'node' to get the latest node version in travis Jan 31, 2017
README.md Start a changelog in README.md Jan 31, 2017
index.js
package.json

README.md

leaflet-clonelayer

Leaflet layer instances cannot be added to different maps in one javascript runtime. leaflet-clonelayer clones layers to allow reuse.

Example

var cloneLayer = require('leaflet-clonelayer');

var layer = L.tileLayer('http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
    attribution: '&copy; <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a>'
}).addTo(map1);
console.log(L.stamp(layer));  // 1

var cloned = cloneLayer(layer);
console.log(L.stamp(cloned));  // 2

// Different _leaflet_id, so now we can safely add it to another map
cloned.addTo(map2);

Changelog

1.0.4 (2017-01-31)

  • Drop leaflet 0.7.7 support, use leaflet-clonelayer@1.0.2
  • Also clones a layer's options (including renderers)