如何添加 2+组中的层?

发布于 2024-12-13 23:22:24 字数 1212 浏览 3 评论 0原文

如何在组中添加两个或多个图层,以便我可以在图层切换器中看到它们并进行分类,并可以选择或取消选择全部!?
这是我的代码:

            var line_1 = new OpenLayers.Layer.Vector(" Line no - 1", {
                    visibility: true,
                    projection: dproj,
                    strategies: [new OpenLayers.Strategy.Fixed()],
                    style: {strokeWidth: 4, strokeColor: "#ff0000", strokeOpacity: 1},
                    protocol: new OpenLayers.Protocol.HTTP({
                        url: "lines/en/line_1.kml",
                        format: new OpenLayers.Format.KML
                    })
            });

            var line_2 = new OpenLayers.Layer.Vector(" Line no - 2", {
                    visibility: true,
                    projection: dproj,
                    strategies: [new OpenLayers.Strategy.Fixed()],
                    style: {strokeWidth: 4, strokeColor: "#008000", strokeOpacity: 1},
                    protocol: new OpenLayers.Protocol.HTTP({
                        url: "lines/en/line_2.kml",
                        format: new OpenLayers.Format.KML
                    })
            });
 var layers = [line_1, line_2]
 map.addLayers(layers);

现在我怎样才能将这两个合二为一,名称为“Lines”?

How can I add two or more layers in a group so that I can see them in layerswitcher categorised and can select or unselect all !?
Here is the code I have:

            var line_1 = new OpenLayers.Layer.Vector(" Line no - 1", {
                    visibility: true,
                    projection: dproj,
                    strategies: [new OpenLayers.Strategy.Fixed()],
                    style: {strokeWidth: 4, strokeColor: "#ff0000", strokeOpacity: 1},
                    protocol: new OpenLayers.Protocol.HTTP({
                        url: "lines/en/line_1.kml",
                        format: new OpenLayers.Format.KML
                    })
            });

            var line_2 = new OpenLayers.Layer.Vector(" Line no - 2", {
                    visibility: true,
                    projection: dproj,
                    strategies: [new OpenLayers.Strategy.Fixed()],
                    style: {strokeWidth: 4, strokeColor: "#008000", strokeOpacity: 1},
                    protocol: new OpenLayers.Protocol.HTTP({
                        url: "lines/en/line_2.kml",
                        format: new OpenLayers.Format.KML
                    })
            });
 var layers = [line_1, line_2]
 map.addLayers(layers);

Now how can I gorup these two in 1 with the name "Lines" ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

提笔书几行 2024-12-20 23:22:24

我认为 GeoExt.tree 就是你想要的。

请参阅此邮件:

OpenLayers 的图层切换器不支持图层层次结构,并且会
可能永远不会。我建议检查一下图层树
MapFish (http://www.mapfish.org)。 MapFish 图层树是
根据 OpenLayers 中配置的层自动配置或
通过用户指定的模型进行配置

http://www.osgeo。 org/pipermail/openlayers-users/2008-June/006358.html

在这里查看:
http://trac.osgeo .org/openlayers/browser/sandbox/jachym/openlayers/examples/layer-groups.html?rev=4958 它看起来像一个旧的支持它的 openlayers 分支。

让我们看看这个:
http://api.geoext.org/1.0/examples/tree.html

我认为 GeoExt.tree 就是你想要的。

I think GeoExt.tree is what you want.

See this mail :

OpenLayers' layer switcher does not support layer hierarchy and will
probably never do. I'd recommend checking out the layer tree of
MapFish (http://www.mapfish.org). MapFish layer tree is either
auto-configured based on the layers configured in OpenLayers or
configured through a user-specified model

http://www.osgeo.org/pipermail/openlayers-users/2008-June/006358.html

Check out here :
http://trac.osgeo.org/openlayers/browser/sandbox/jachym/openlayers/examples/layer-groups.html?rev=4958 it looks like a old branch of openlayers that supports it.

So lets look at this :
http://api.geoext.org/1.0/examples/tree.html

I think GeoExt.tree is what you want.

清风无影 2024-12-20 23:22:24

我知道这已经很旧了,但我正在回答以防有人有同样的问题。

如果您使用 ol3-layerswitcher,您只需创建一个新的图层组,其中包含所有定义的图层,以将它们显示在组下。图层组的标题将其与图层分开。

var overlay1 = new ol.layer.Tile({
    title: 'Overlay1',
    source: new ol.source.TileWMS({
        url: 'http://localhost:8080/geoserver/WORKSPACE/wms',
        params:{
            'LAYERS': 'Overlay1',
            'TILED': true
        },
        serverType: 'geoserver'
    }),
});

var basemap1 = new ol.layer.Tile({
    title: 'Basemap1',
    type: 'base'
    source: new ol.source.OSM()
});

var basemaps = [basemap1, basemap2 ...]

var overlays = [overlay1, overlay2 ...]

var map = new ol.Map({
    controls: [
        new ol.control.LayerSwitcher({
            tipLabel: 'Layers'
        })
    ],
    target: 'map',
    layers: [
        new ol.layer.Group({
            title: 'Base Maps',
            layers: basemaps
        }),
        new ol.layer.Group({
            title: 'Overlays',
            layers: overlays
        })
    view: view
});

I know this is old but I am answering in case if any one has the same question.

If you are using ol3-layerswitcher you can just create a new layer group with all your defined layers to show them under a group. The title of the layer group separates it from the layers.

var overlay1 = new ol.layer.Tile({
    title: 'Overlay1',
    source: new ol.source.TileWMS({
        url: 'http://localhost:8080/geoserver/WORKSPACE/wms',
        params:{
            'LAYERS': 'Overlay1',
            'TILED': true
        },
        serverType: 'geoserver'
    }),
});

var basemap1 = new ol.layer.Tile({
    title: 'Basemap1',
    type: 'base'
    source: new ol.source.OSM()
});

var basemaps = [basemap1, basemap2 ...]

var overlays = [overlay1, overlay2 ...]

var map = new ol.Map({
    controls: [
        new ol.control.LayerSwitcher({
            tipLabel: 'Layers'
        })
    ],
    target: 'map',
    layers: [
        new ol.layer.Group({
            title: 'Base Maps',
            layers: basemaps
        }),
        new ol.layer.Group({
            title: 'Overlays',
            layers: overlays
        })
    view: view
});
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文