Improved clone method for Layer.XYZ; gave Layer.OSM its own clone method. Thanks aratcliffe for bringing this up. r=tschaub (closes #2738)
git-svn-id: http://svn.openlayers.org/trunk/openlayers@10507 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
+10
-10
@@ -65,7 +65,7 @@ OpenLayers.Layer.XYZ = OpenLayers.Class(OpenLayers.Layer.Grid, {
|
|||||||
* obj - {Object} Is this ever used?
|
* obj - {Object} Is this ever used?
|
||||||
*
|
*
|
||||||
* Returns:
|
* Returns:
|
||||||
* {<OpenLayers.Layer.Grid>} An exact clone of this OpenLayers.Layer.Grid
|
* {<OpenLayers.Layer.XYZ>} An exact clone of this OpenLayers.Layer.XYZ
|
||||||
*/
|
*/
|
||||||
clone: function (obj) {
|
clone: function (obj) {
|
||||||
|
|
||||||
@@ -76,15 +76,7 @@ OpenLayers.Layer.XYZ = OpenLayers.Class(OpenLayers.Layer.Grid, {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//get all additions from superclasses
|
//get all additions from superclasses
|
||||||
obj = OpenLayers.Layer.HTTPRequest.prototype.clone.apply(this, [obj]);
|
obj = OpenLayers.Layer.Grid.prototype.clone.apply(this, [obj]);
|
||||||
|
|
||||||
// copy/set any non-init, non-simple values here
|
|
||||||
if (this.tileSize != null) {
|
|
||||||
obj.tileSize = this.tileSize.clone();
|
|
||||||
}
|
|
||||||
|
|
||||||
// we do not want to copy reference to grid, so we make a new array
|
|
||||||
obj.grid = [];
|
|
||||||
|
|
||||||
return obj;
|
return obj;
|
||||||
},
|
},
|
||||||
@@ -174,5 +166,13 @@ OpenLayers.Layer.OSM = OpenLayers.Class(OpenLayers.Layer.XYZ, {
|
|||||||
attribution: "Data CC-By-SA by <a href='http://openstreetmap.org/'>OpenStreetMap</a>",
|
attribution: "Data CC-By-SA by <a href='http://openstreetmap.org/'>OpenStreetMap</a>",
|
||||||
sphericalMercator: true,
|
sphericalMercator: true,
|
||||||
url: 'http://tile.openstreetmap.org/${z}/${x}/${y}.png',
|
url: 'http://tile.openstreetmap.org/${z}/${x}/${y}.png',
|
||||||
|
clone: function(obj) {
|
||||||
|
if (obj == null) {
|
||||||
|
obj = new OpenLayers.Layer.OSM(
|
||||||
|
this.name, this.url, this.getOptions());
|
||||||
|
}
|
||||||
|
obj = OpenLayers.Layer.XYZ.prototype.clone.apply(this, [obj]);
|
||||||
|
return obj;
|
||||||
|
},
|
||||||
CLASS_NAME: "OpenLayers.Layer.OSM"
|
CLASS_NAME: "OpenLayers.Layer.OSM"
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -173,6 +173,19 @@
|
|||||||
map.destroy();
|
map.destroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function test_clone(t) {
|
||||||
|
t.plan(2);
|
||||||
|
|
||||||
|
var clone;
|
||||||
|
|
||||||
|
layer = new OpenLayers.Layer.XYZ(name, url, options);
|
||||||
|
clone = layer.clone();
|
||||||
|
t.ok(clone instanceof OpenLayers.Layer.XYZ, "clone is a Layer.XYZ instance");
|
||||||
|
|
||||||
|
layer = new OpenLayers.Layer.OSM();
|
||||||
|
clone = layer.clone();
|
||||||
|
t.ok(clone instanceof OpenLayers.Layer.OSM, "clone is a Layer.OSM instance");
|
||||||
|
}
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
</head>
|
</head>
|
||||||
|
|||||||
Reference in New Issue
Block a user