I have a map with layers that have similar attributes. I want to add a function that when you select a feature in a layer, it searches for a feature with similar properties in another feature (in this case NAME
) and if a similar feature property is found, then the styling of the matching feature is altered.
I have a JSfiddle that tries to achieve this here: http://jsfiddle.net/TimLucas/nmd2vsww/6/
The function is called by using the second button. As you can see the get()
of features works from the function called by the first button.
Here I mainly have problems with how you can set properties (instead of getting them) in the VectorSource GeoJSON file. I use .attr()
but I am not sure if that actually works.
Does anyone know how to do this?
Best Answer
Edited:
There are several errors in your code, namely:
A style function should be something like:
Pass it a style:
The find-button callback has several errors:
A better function:
Original answer (for context)
Although I'm not sure how I can get the found features to be redrawn using the same style (i guess you could assign it a new style using feature setStyle (http://openlayers.org/en/v3.1.1/apidoc/ol.Feature.html?unstable=true#setStyle)), I've managed to rewrite your code to set the attribute on similar features: