I would like to use OpenLayers 3 spyglass example inside my project.
The problem is when I want to use selection for layer, which will be inside spyglass circle. I can't get it working, I don't know how to update it on every user's selection correctly.
Anyone more skilled can help me?
Here is my fiddle with it partially working:
http://jsfiddle.net/dkcz/8a3pdavv/
Best Answer
Here's an example that accomplishes what you want (I think): http://jsfiddle.net/tschaub/Lkgx0qaa/
I've created a map with three layers, only the first one (named
roads
) is visible:The
imagery
andlabeled
layers are going to be toggled on/off with radio inputs. When a radio input is checked, the layer is made visible (withlayer.setVisible(true)
), and listeners are registered forprecompose
andpostcompse
events (withlayer.on(...)
).In addition, any previously chosen layer will be made invisible (with
layer.setVisible(false)
), and listeners will be unregistered (withlayer.un(...)
).The function that handles this radio change event looks like this:
That's really the meat of the solution. The rest pretty much follows the hosted layer-spy.html example.
For completeness, I'll dump the rest below.