Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I want to custom my stylemap (OpenLayers.Style) in that way:
set the value of the fillOpacity depending of the fillColor of the same feature.

Here is the actual code:

StyleBlockWithOpacity : new OpenLayers.Style({
            strokeWidth :1,
            strokeColor : '#000000',
            fillColor : "${getBlockColor}",
            fillOpacity : "${getBlockOpacity}",
            display : "${getBlockDisplay}"
        },{context: context})

The context contains the methods that return values. Here an example of getBlockColor:

getBlockColor: function (feature) {
            var featureFID = feature.fid.split('.'), blockId = featureFID[1];

            var color =  VMMS.GIS.chooseBlockColor(blockId);
            return color;

But what I'd like to do, is that inside getBlockOpacity, the returned value would depend of the fillColor (value returned by getBlockColor).
Example: for each feature, if the color is let's say black, so the opacity would be 0.5. And I don't know how to do.

I have check some articles how to custom style maps with Openlayers: http://geoanalytics.renci.org/uncategorized/adding-style-to-your-openlayers/

and here (with rules): http://workshops.opengeo.org/openlayers-intro/vector/style-intro.html

But I don't see how to apply it to my problem. Do you have any idea?


share|improve this question
add comment

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.