如何添加 2+组中的层?
如何在组中添加两个或多个图层,以便我可以在图层切换器中看到它们并进行分类,并可以选择或取消选择全部!?
这是我的代码:
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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为 GeoExt.tree 就是你想要的。
请参阅此邮件:
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 :
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.
我知道这已经很旧了,但我正在回答以防有人有同样的问题。
如果您使用 ol3-layerswitcher,您只需创建一个新的图层组,其中包含所有定义的图层,以将它们显示在组下。图层组的标题将其与图层分开。
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.