Another day working with openlayers and another problem.
Namely - i have multiple vector layers on top of each other for different types of stuff (cars, trips from history and areas). They all have events that im trying to catch... But as Niklas found out, when you activate events on one layer, it gets moved on top and events on layers below wont fire.
Is there a way to bypass this? Because when i move over area polygon i want event firing and displaying its name and when i move mouse over to car marker i want the event fire too. And no - i dont want to put them on same layer, cause i want it to be possible to turn them off or on fast and without looping through all the features and disabling them each.
Alan
Edit1: I did some searching, and found out, that you could use same control on multiple layers. that could probably fix this problem for me. im checking it out atm and testing if adding more layers to single control is solution to my problem or not.
import VectorLayer from 'ol/layer/Vector'; Vector data is rendered client-side, as vectors. This layer type provides most accurate rendering even during animations.
filter(layer => layer. get('name') === 'Marker') . forEach(layer => map. removeLayer(layer));
OpenLayers makes it easy to put a dynamic map in any web page. It can display map tiles, vector data and markers loaded from any source. OpenLayers has been developed to further the use of geographic information of all kinds.
this solve my problem :
before :
map.addLayer(layer);
layer.events.register("loadend", layer, function(){
$("#progress").hide();
});
after :
layer.events.register("loadend", layer, function(){
$("#progress").hide();
});
map.addLayer(layer);
Hope it helps
I found this when I had the same issue, trying to get multiple layers to react to mouse events.
The solution, just in case anyone else finds this thread is much simpler.
The SelectFeature control takes an array of Vector layers and if all the laters you need to react to mouse events (hover and click) are in that array, they ALL work, not just the one that was moved to the top.
So, in the approved solution to this thread, it can be much simplified by doing this:
this.carSelect = new OpenLayers.Control.SelectFeature(
[this.vectorsLayer, this.carsLayer],
{
'hover':true,
'callbacks': {
blah blah blah
}
});
This will register the appropriate events on both layers and make them both live.
I hope this helps anyone else stumbling on this issue.
As said elsewhere, using OpenLayers is not hard, finding the correct way to do things with it is.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With