More

OpenLayers feature styling change by the baselayer

OpenLayers feature styling change by the baselayer


How can I have the style of the features on a vector layer depending on the OpenLayers' "base layer"?

For example, some base layers are dark images and I need (for the contrast) the features to be displayed bright in the vector layer upon the base layer. And as soon as base layer changes to a bright one, features should be redrawn dark.

How can I achieve this with OpenLayers code?


You can do this using a Stylemap and a context function.

This example shows it in operation http://openlayers.org/dev/examples/styles-context.html

Your function would return the value based upon the features layer, eg:-

var context = { getColor: function(feature) { var baselayer = feature.map.baseLayer;… SELECT and return your color based upon the baselayer… } };

Watch the video: OpenLayers Add Vector Layer to Web Map