gpt4 book ai didi

javascript - 基于缩放级别显示 WMS 图层

转载 作者:数据小太阳 更新时间:2023-10-29 05:47:20 27 4
gpt4 key购买 nike

我整天都在做这个,老实说,我没有主意了。我有一些 WMS 层,我想根据当前的缩放级别显示/不显示。是的,我已经阅读了 API 文档,它们似乎一如既往地清晰,但我遵循了所有建议,但没有得到想要的结果:(

这是我查看的来源之一:http://trac.osgeo.org/openlayers/wiki/SettingZoomLevels

然后更糟糕的是,我发现如果您有一个在加载时显示的 Open Street Map 基础层,它似乎会限制您对 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}
);

Take 2:tib_villages 层应该只在缩放级别为 8-10 时显示, map 应该只有 10 个缩放级别,但 Open Street Map Layer 强制要求它有 19 个,这是行不通的!

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 基础图层后, 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}
);

非常感谢您的所有建议!

艾莎

最佳答案

尝试使用 minResolutionmaxResolution 而不是 minZoomLevel。它通常工作正常。如果您调用 map.getResolution() 方法,您可以获得任何变焦杆的分辨率。

另一种选择是监听 OpenLayers.Mapzoomend 事件并相应地切换图层可见性。像这样:

map.events.on({ "zoomend": function (e) {
if (this.getZoom() > 2) {
layer1.setVisibility(false);
layer2.setVisibility(true);
}
else {
layer2.setVisibility(false);
layer1.setVisibility(true);
}
}
});

关于javascript - 基于缩放级别显示 WMS 图层,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4000734/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com