我已经在这里工作了整整一天,但老实说我已经没有任何想法了。我有一些WMS图层,希望根据当前缩放级别显示/隐藏。是的,我已经阅读了API文档,但是我按照建议的一切去做,却没有得到期望的结果:(
以下是我查看的其中一个来源:http://trac.osgeo.org/openlayers/wiki/SettingZoomLevels
更糟糕的是,我发现如果您在加载时显示Open Street Map基础图层,则似乎会限制您对地图的numZoomLevels的控制,这正是我需要的,因为我确实想将其用作我的加载基础图层...
所以我的问题是:
我做错了什么吗? 使用Open Street Map基础图层加载时,是否真的没有控制缩放级别的解决方法?还是有些我不知道的东西?
以下是我的一些代码尝试: 尝试1:tib_villages图层只应在缩放级别为8-10时显示,但无效!
以下是我查看的其中一个来源:http://trac.osgeo.org/openlayers/wiki/SettingZoomLevels
更糟糕的是,我发现如果您在加载时显示Open Street Map基础图层,则似乎会限制您对地图的numZoomLevels的控制,这正是我需要的,因为我确实想将其用作我的加载基础图层...
所以我的问题是:
我做错了什么吗? 使用Open Street Map基础图层加载时,是否真的没有控制缩放级别的解决方法?还是有些我不知道的东西?
以下是我的一些代码尝试: 尝试1:tib_villages图层只应在缩放级别为8-10时显示,但无效!
var options = {
controls: [new OpenLayers.Control.Navigation()], //Needed to use GeoExt controls such as the zoomslider
maxExtent: new OpenLayers.Bounds(-20037508.34, -20037508.34, 20037508.34, 20037508.34),
units: 'm',
numZoomLevels: null, //setting the map's zoom levels to null
allOverlays: false
}
var osm = new OpenLayers.Layer.OSM(); //MY base layer
//MY overlay layer
var tib_villages = new OpenLayers.Layer.WMS(
"Villages", "http://localhost:8080/geoserver/wms", {layers: 'cite:tib_villages', transparent: true, numZoomLevels: 10, minZoomLevel: 8}, {isBaseLayer: false, displayInLayerSwitcher: true, visibility: true}
);
第二次尝试:tib_villages图层应仅在缩放级别为8-10时显示,地图应仅有10个缩放级别,但实际上有19个,因为Open Street Map图层强制执行它,这不起作用!
var options = {
controls: [new OpenLayers.Control.Navigation()], //Needed to use GeoExt controls such as the zoomslider
maxExtent: new OpenLayers.Bounds(-20037508.34, -20037508.34, 20037508.34, 20037508.34),
units: 'm',
numZoomLevels: 10, //setting the map's zoom levels to 10 only
allOverlays: false
}
var osm = new OpenLayers.Layer.OSM(); //MY base layer
//MY overlay layer
var tib_villages = new OpenLayers.Layer.WMS(
"Villages", "http://localhost:8080/geoserver/wms", {layers: 'cite:tib_villages', transparent: true, numZoomLevels: null, minZoomLevel: 8}, {isBaseLayer: false, displayInLayerSwitcher: true, visibility: true}
)
第三步:在加载时去除Open Street Map基础图层后,地图仅有10个指定的缩放级别,但tib_villages图层应该只在缩放级别为8-10时显示,但未生效!
var options = {
controls: [new OpenLayers.Control.Navigation()], //Needed to use GeoExt controls such as the zoomslider
maxExtent: new OpenLayers.Bounds(-20037508.34, -20037508.34, 20037508.34, 20037508.34),
units: 'm',
numZoomLevels: 10, //setting the map's zoom levels to 10
allOverlays: false
}
//MY overlay layer
var tib_villages = new OpenLayers.Layer.WMS(
"Villages", "http://localhost:8080/geoserver/wms", {layers: 'cite:tib_villages', transparent: true, numZoomLevels: 10, minZoomLevel: 8}, {isBaseLayer: false, displayInLayerSwitcher: true, visibility: true}
);
非常感谢您提出的所有建议!
elshae