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 have a simple wfs layer from geoserver, here is code:

  //wfs-t editable overlay
  var wfs_layer = new OpenLayers.Layer.Vector("Vector sample", {
  strategies: [new OpenLayers.Strategy.Fixed()],
  //projection: new OpenLayers.Projection("EPSG:4326"),
  protocol: new OpenLayers.Protocol.WFS({
  version: "1.1.0",
  // loading data through localhost url path
  url: ".....",
  featureNS :  ".....",
  extractAttributes: true,
  // layer name
  featureType: "....",
  geometryName: "geom",
  schema: "localhost:8080/geoserver......"

 //vector style:
var vector_style = new OpenLayers.Style({ 
'fillColor': '#669933', 
'fillOpacity': .8, 
'strokeColor': '#aaee77', 
'strokeWidth': 3, 
'pointRadius': 8 

var vector_style_select = new OpenLayers.Style({ 
'fillColor': '#FF0000', 
'fillOpacity': .10,
'graphicName': 'circle', 
//'label': 'klik',
'pointRadius': 8, 
'strokeColor': '#f86633', 
'strokeDashstyle': 'solid', 
'strokeWidth': 4 

var vector_style_iz_table = new OpenLayers.Style({
'cursor': 'pointer', 
'fillColor': '#669933', 
'fillOpacity': .8, 
'fontColor': '#343434', 
'label': '${table1}', 
'pointRadius': '8', 
'strokeColor': '#aaee77',
'strokeWidth': 3, 
'strokeDashstyle': 'solid', 
'strokeWidth': '${4}' 
var vector_style_map = new OpenLayers.StyleMap({ 
'default': vector_style_iz_table,
'select': vector_style_select 
wfs_layer.styleMap = vector_style_map;

I have table from "table1" database, where is three different value: "yes", "no" and "null".

Everything works fine, in this style I can view vector layer with green fillcolor with label "yes" or "no" from my "table1".

I want 3 different style, for "yes"-> green fillcolor, for "no"-> red fillcolor and "null"-> black fillcolor.

Is that posible having 3 styles for one vector layer? I think that I must write rule filter for all three different value?


share|improve this question
up vote 1 down vote accepted

You can create a style object with custom rules, with which you can style features depending on their properties. Please have a look at this page.

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.