diff --git a/lib/OpenLayers/Layer/ArcGISCache.js b/lib/OpenLayers/Layer/ArcGISCache.js index 377a3132c6..30563da276 100644 --- a/lib/OpenLayers/Layer/ArcGISCache.js +++ b/lib/OpenLayers/Layer/ArcGISCache.js @@ -172,21 +172,23 @@ OpenLayers.Layer.ArcGISCache = OpenLayers.Class(OpenLayers.Layer.XYZ, { this.lods = []; for(var key in info.tileInfo.lods) { - var lod = info.tileInfo.lods[key]; - if (this.useScales) { - this.scales.push(lod.scale); - } else { - this.resolutions.push(lod.resolution); + if (info.tileInfo.lods.hasOwnProperty(key)) { + var lod = info.tileInfo.lods[key]; + if (this.useScales) { + this.scales.push(lod.scale); + } else { + this.resolutions.push(lod.resolution); + } + + var start = this.getContainingTileCoords(upperLeft, lod.resolution); + lod.startTileCol = start.x; + lod.startTileRow = start.y; + + var end = this.getContainingTileCoords(bottomRight, lod.resolution); + lod.endTileCol = end.x; + lod.endTileRow = end.y; + this.lods.push(lod); } - - var start = this.getContainingTileCoords(upperLeft, lod.resolution); - lod.startTileCol = start.x; - lod.startTileRow = start.y; - - var end = this.getContainingTileCoords(bottomRight, lod.resolution); - lod.endTileCol = end.x; - lod.endTileRow = end.y; - this.lods.push(lod); } this.maxExtent = this.calculateMaxExtentWithLOD(this.lods[0]); diff --git a/tests/Layer/ArcGISCache.html b/tests/Layer/ArcGISCache.html index b6fb2d9904..23cd99a5ab 100644 --- a/tests/Layer/ArcGISCache.html +++ b/tests/Layer/ArcGISCache.html @@ -219,6 +219,32 @@ t.ok((tile.x >= 0 && tile.y >= 0), 'layer should not generate negative tile ranges for level of detail'); } + /* + * Test that functions don't end up in the lods of the layer. This messes up zooming when + * resolutions are very small/scales are very large/zoomed way in. + */ + function test_Layer_ARCGISCACHE_lods (t) { + t.plan( 2 ); + var layerInfo = capabilitiesObject; + + lods = layerInfo.tileInfo.lods.length; + + // mess up the Array prototype + Array.prototype.foo = function() { }; + + t.ok( lods == layerInfo.tileInfo.lods.length, 'proper number of "Levels of Detail" before initialization' ); + + // initialize the layer using the JSON object from an arcgis server + // see: ArcGISCache.json + var layer = new OpenLayers.Layer.ArcGISCache(name, url, { + layerInfo: layerInfo + }); + + t.ok( lods == layer.lods.length, 'proper number of "Levels of Detail" after initialization.' ); + // restore the Array prototype + delete Array.prototype.foo; + } +