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'm trying to alter the colour of displayed points using addUniqueValueRules in OpenLayers. If I don't use addUniqueValueRules all my points display the default colour (green). However, when I add addUniqueValueRules, only those points that meet the rules are drawn.

The relevant code:

var styleMap = new OpenLayers.StyleMap({
    fillOpacity: 1,
    fillColor: "green",
    pointRadius: 5
});

var styleLookup = {
    "Hög": { fillColor: "red" },
    "Måttlig": { fillColor: "yellow" },
    "Undersöka": { fillColor: "cyan" }
};

styleMap.addUniqueValueRules( "default", "risk", styleLookup );

wfs = new OpenLayers.Layer.Vector("Editable Features", {
    strategies : [new OpenLayers.Strategy.Fixed(), saveStrategy],
    projection: new OpenLayers.Projection("EPSG:4326"),
    protocol: new OpenLayers.Protocol.WFS({
        version: "1.1.0",
        srsName: "EPSG:4326",
        url: "http://localhost/cgi-bin/tinyows",
        featurePrefix: "tows",
        featureNS :  "http://www.tinyows.org/",
        featureType: "tradcopy",
        geometryName: "geom"
    }),
    styleMap: styleMap
}); 

Can anyone help me draw all the points - both default and the ones that meet the rules?

Thanks

Mini

share|improve this question

1 Answer 1

up vote 2 down vote accepted

The addUniqueValueRules implies that features that do not match the lookup object won't be rendered. I don't know if this is by design but the responsible code is here. If your Style have rules (which is not the case when you don't use addUniqueValueRules) and none of them were matched, then the feature is hidden.

This is the workaround I came up with:

var lookup = {
    "OpenLayers.Feature.Vector_1329": {
        fillColor: '#FF0000'
    }
};

this.drawingLayer.styleMap.addUniqueValueRules('default','name',lookup);
this.drawingLayer.styleMap.styles.default.rules.push(new OpenLayers.Rule({
    elseFilter: true,
    symbolizer: this.drawingLayer.styleMap.styles.default.defaultStyle
}));

What it does is simply defining an else rule that takes the default style as a symbolizer.

share|improve this answer

Your Answer

 
discard

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.