我整天都在这里,说实话,我没有想法。我有一些WMS图层,我想显示/不显示,具体取决于当前的缩放级别。是的,我已经浏览了API文档,它们似乎很清楚,但我遵循建议的所有内容,但我没有得到所需的结果:(
这是我看过的消息来源之一: http://trac.osgeo.org/openlayers/wiki/SettingZoomLevels
然后更糟糕的是,我发现如果你有一个开放的街道地图基础层显示加载它似乎限制你对地图的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}
);
拍摄2:tib_villages图层应仅在缩放级别为8-10时显示,地图应该只有10个缩放级别,而是有19个,因为Open Street Map Layer强制执行它,不起作用!
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}
)
采取3:在加载后摆脱开放街道地图基础层后,地图只有指定的10个缩放级别,但tib_villages图层只应在缩放级别为8-10时显示,不起作用!< / p>
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
答案 0 :(得分:9)
尝试使用minResolution
和maxResolution
代替minZoomLevel
。它通常工作正常。如果您调用map.getResolution()
方法,则可以获得任何变焦杆的分辨率。
另一种选择是收听OpenLayers.Map
的{{1}}事件,并相应地切换图层可见性。像这样:
zoomend
答案 1 :(得分:5)
我建议在图层上使用maxScale和minScale而不是分辨率,但这可能是一个品味问题。 :-)我无法与分辨率值相关联,但是当其他人查看您的代码时,缩放很容易理解并且可以在较长时间内维护。