我整天都在做这个,老实说,我没有想法。我有一些 WMS 图层,我想根据当前的缩放级别显示/不显示。是的,我已经浏览了 API 文档,它们似乎很清楚,但是我遵循了建议的所有内容,但没有得到想要的结果:(
这是我查看的来源之一: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}
);
采取 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:在加载时去掉 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}
);
衷心感谢您的所有建议!
艾尔谢