[OpenLayers-Users] Can't restrict Openlayers.Layer.OSM to use
specific zoom levels
Adrian Popa
adrian_gh.popa at romtelecom.ro
Wed Jul 7 08:44:49 EDT 2010
Hello,
I have a map that uses just 12 zoom levels by defining numZoomLevels: 12
and an array of allowed resolutions. All base layers (Google, Yahoo and
Mapserver) have a similar configuration (e.g. for Google:
MIN_ZOOM_LEVEL: 7, MAX_ZOOM_LEVEL:19, RESOLUTIONS: res) and work as
expected.
However, the OSM layer allows me to zoom beyond these resolutions if I
define it like this:
var osm = new OpenLayers.Layer.OSM.Osmarender('OpenStreetMaps',
{numZoomLevels: 12, minZoomLevel: 7, maxZoomLevel: 19});
If I add the resolutions parameter something interesting happens: the
zoom is restricted, but I loose the tiles, because they can no longer be
found (404 errors):
var osm = new OpenLayers.Layer.OSM.Osmarender('OpenStreetMaps',
{numZoomLevels: 12, minZoomLevel: 7, maxZoomLevel: 19, resolutions: res});
My "res" array is: var res = [2445.9849046875, 1222.99245234375,
611.496226171875, 305.7481130859375, 152.87405654296876,
76.43702827148438, 38.21851413574219, 19.109257067871095,
9.554628533935547, 4.777314266967774, 2.388657133483887,
1.1943285667419434, 0.597164283];
The tiles requested have the following URLs: "NetworkError: 404 Not
Found - http://a.tah.openstreetmap.org/Tiles/tile/1/76/42.png" (this is
for a zoom level 1, which coresponds to a normal zoom level of 7 (I think))
My question is - is this a bug, or is there a way to instruct the layer
to "adjust" the value of zoom by a constant (6+x)?
I've looked over the OpenLayers.Layer.OSM definition, and I should be
able to adjust the url attribute, but I have no idea how to force it to
do an addition, or if this is the right way to go:
OpenLayers.Layer.OSM = OpenLayers.Class(OpenLayers.Layer.XYZ, {
name: "OpenStreetMap",
attribution: "Data CC-By-SA by <a
href='http://openstreetmap.org/'>OpenStreetMap</a>",
sphericalMercator: true,
url: 'http://tile.openstreetmap.org/${z}/${x}/${y}.png',
CLASS_NAME: "OpenLayers.Layer.OSM"
});
Regards,
Adrian
More information about the Users
mailing list