简体   繁体   English

openlayers-3-多层选择

[英]openlayers-3 - select with multiple layers

I'm working on a mapping tool based ol3 using GeoServer backend. 我正在使用GeoServer后端开发基于ol3的映射工具。 I will have to publish many GeoJSON base vector layers and WMS raster tiles in it, but a little bit confused about selecting from them. 我将不得不在其中发布许多GeoJSON基本矢量图层和WMS栅格图块,但对于从中进行选择有些困惑。 In the examples, there are really good ones for one vector or WMS layer (ol.interaction.Select and map.on('singleclick'...)), but cannot find solution for more complex situations. 在示例中,一个矢量或WMS层确实有很好的选择(ol.interaction.Select和map.on('singleclick'...)),但找不到更复杂情况的解决方案。 My questions: 我的问题:

If you have multiple vector layers , using the ol.interaction.Select, is there a way to determine for each selected feature where do they come from (which layer does they belong to)? 如果您有多个矢量层 ,可以使用ol.interaction.Select来确定每个选定要素的来源(它们属于哪一层)? I have to style them and present information about them based on their type (it's not my case but for example do other thing if you select a road or a city). 我必须对它们进行样式设置并根据其类型显示有关它们的信息(这不是我的情况,但是例如,如果您选择道路或城市,则要做其他事情)。 For now, I attach a property to each feature before loading them to the ServerVector source, so when they selected, I can determine what to do with them. 现在,我将属性附加到每个功能,然后再将其加载到ServerVector源,因此,当选择它们时,我可以确定如何处理它们。 Without going into details: I have a working solution this problem but wondering, is there any other (official-preferred) way to do this? 无需赘述:我有一个可以解决此问题的可行解决方案,但想知道是否还有其他(官方首选)方法可以做到这一点?

The other one: what can I do if the map has vector and raster layers too? 另一个:如果地图也同时具有矢量和栅格图层,该怎么办? I want it to be transparent for the users: they click and get the information and it's for the code to decide how to do this. 我希望它对用户透明:他们单击并获取信息,并且代码决定如何执行此操作。 Is there any solution for this? 有什么解决办法吗? Maybe ol.interaction.Select and the map's 'singleclick' event together? 也许是ol.interaction.Select和地图的“ singleclick”事件在一起? (The interaction for vectors and the latter for the WMS layers?) (矢量与WMS图层的交互是交互的?)

Thanks in advance, Balazs Eigner 在此先感谢Balazs Eigner

you can add click event on the map 您可以在地图上添加点击事件

so we get the pixel and then 所以我们得到像素,然后

we call forEachLayerAtPixel on map in the call back we get the layers 我们在回叫中在地图上调用forEachLayerAtPixel我们得到了图层

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM