Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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 :  "",
        featureType: "tradcopy",
        geometryName: "geom"
    styleMap: styleMap

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



share|improve this question
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.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


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.