简体   繁体   中英

openlayers-3 - select with multiple layers

I'm working on a mapping tool based ol3 using GeoServer backend. 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. 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. 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)? 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. 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? (The interaction for vectors and the latter for the WMS layers?)

Thanks in advance, 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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