1function cloneOptions(options) { 2 var ret = {}; 3 for (var i in options) { 4 var item = options[i]; 5 if (item && item.clone) { 6 ret[i] = item.clone(); 7 } else if (item instanceof L.Layer) { 8 ret[i] = cloneLayer(item); 9 } else { 10 ret[i] = item; 11 } 12 } 13 return ret; 14} 15 16function cloneInnerLayers(layer) { 17 var layers = []; 18 layer.eachLayer(function (inner) { 19 layers.push(cloneLayer(inner)); 20 }); 21 return layers; 22} 23 24function cloneLayer(layer) { 25 var options = cloneOptions(layer.options); 26 27 // we need to test for the most specific class first, i.e. 28 // Circle before CircleMarker 29 30 // Renderers 31 if (layer instanceof L.SVG) { 32 return L.svg(options); 33 } 34 if (layer instanceof L.Canvas) { 35 return L.canvas(options); 36 } 37 38 // GoogleMutant GridLayer 39 if (L.GridLayer.GoogleMutant && layer instanceof L.GridLayer.GoogleMutant) { 40 var googleLayer = L.gridLayer.googleMutant(options); 41 42 layer._GAPIPromise.then(function () { 43 var subLayers = Object.keys(layer._subLayers); 44 45 for (var i in subLayers) { 46 googleLayer.addGoogleLayer(subLayers[i]); 47 } 48 }); 49 50 return googleLayer; 51 } 52 53 // Tile layers 54 if (layer instanceof L.TileLayer.WMS) { 55 return L.tileLayer.wms(layer._url, options); 56 } 57 if (layer instanceof L.TileLayer) { 58 return L.tileLayer(layer._url, options); 59 } 60 if (layer instanceof L.ImageOverlay) { 61 return L.imageOverlay(layer._url, layer._bounds, options); 62 } 63 64 // Marker layers 65 if (layer instanceof L.Marker) { 66 return L.marker(layer.getLatLng(), options); 67 } 68 69 if (layer instanceof L.Circle) { 70 return L.circle(layer.getLatLng(), layer.getRadius(), options); 71 } 72 if (layer instanceof L.CircleMarker) { 73 return L.circleMarker(layer.getLatLng(), options); 74 } 75 76 if (layer instanceof L.Rectangle) { 77 return L.rectangle(layer.getBounds(), options); 78 } 79 if (layer instanceof L.Polygon) { 80 return L.polygon(layer.getLatLngs(), options); 81 } 82 if (layer instanceof L.Polyline) { 83 return L.polyline(layer.getLatLngs(), options); 84 } 85 86 if (layer instanceof L.GeoJSON) { 87 return L.geoJson(layer.toGeoJSON(), options); 88 } 89 90 if (layer instanceof L.FeatureGroup) { 91 return L.featureGroup(cloneInnerLayers(layer)); 92 } 93 if (layer instanceof L.LayerGroup) { 94 return L.layerGroup(cloneInnerLayers(layer)); 95 } 96 throw 'Unknown layer, cannot clone this layer. Leaflet-version: ' + L.version; 97} 98 99if (typeof exports === 'object') { 100 module.exports = cloneLayer; 101}
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.