Search code examples
vectorrasteropenlayers-3

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


Solution

  • 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