AW: [OpenLayers-Users] vector polygon styling with rules

Arnd Wippermann arnd.wippermann at web.de
Wed Apr 6 18:00:44 EDT 2011


Hi,
 
look at the OpenLayers examples
 
http://dev.openlayers.org/releases/OpenLayers-2.10/examples/styles-unique.ht
ml
http://dev.openlayers.org/releases/OpenLayers-2.10/examples/style-rules.html
 
Below some code how I do things.
 
Arnd
 
/*
    * OpenLayers.Filter.Comparison.EQUAL_TO = "==";
    * OpenLayers.Filter.Comparison.NOT_EQUAL_TO = "!=";
    * OpenLayers.Filter.Comparison.LESS_THAN = "<";
    * OpenLayers.Filter.Comparison.GREATER_THAN = ">";
    * OpenLayers.Filter.Comparison.LESS_THAN_OR_EQUAL_TO = "<=";
    * OpenLayers.Filter.Comparison.GREATER_THAN_OR_EQUAL_TO = ">=";
    * OpenLayers.Filter.Comparison.BETWEEN = "..";
    * OpenLayers.Filter.Comparison.LIKE = "~";
 

    * OpenLayers.Filter.Logical.AND = "&&";
    * OpenLayers.Filter.Logical.OR = "||";
    * OpenLayers.Filter.Logical.NOT = "!";
*/
 
function createRule(theField, theValue, theType, theGeom, theSymbolizer,
theElseFilter, theRuleName)
{
    var filter = new OpenLayers.Filter.Comparison({
        type: theType,
        property: theField,
        value: theValue
    });
 
    var rule = new OpenLayers.Rule({
        name : theRuleName,
        filter: filter,
        elseFilter:theElseFilter
    });
 
    rule.symbolizer[ theGeom /* "Point" or "Line" or "Polygon" */] =
theSymbolizer;
    return(rule);
}
 
var styleMapTest;
 
var Symbolizers = {
    Turm: {
        strokeColor: "#0000FF",
        strokeOpacity: 1,
        strokeWidth: 3,
        fillColor: "#00AAFF",
        fillOpacity: 1,
        pointRadius: 5
    },
    Kirche: {
        strokeColor: "#FF00FF",
        strokeOpacity: 1,
        strokeWidth: 3,
        fillColor: "#00AAFF",
        fillOpacity: 1,
        pointRadius: 5
    },
    Denkmal: {
        strokeColor: "#00FF00",
        strokeOpacity: 1,
        strokeWidth: 3,
        fillColor: "#00AAFF",
        fillOpacity: 1,
        pointRadius: 5
    },
    Else: {
        strokeColor: "#FF0000",
        strokeOpacity: 1,
        strokeWidth: 3,
        fillColor: "#00AAFF",
        fillOpacity: 1,
        graphicName:"star",
        pointRadius: 5
    },
    Line : {
        strokeColor: "#00FF00",
        strokeOpacity: 1,
        strokeWidth: 3,
        pointRadius: 5
    },
    Polygon: {
        strokeColor: "#FF0000",
        strokeOpacity: 1,
        strokeWidth: 3,
        fillColor: "#FFAA00",
        fillOpacity: 1,
        pointRadius: 5
    },
    Text: {
        label : "${name}",
        labelXOffset: "10",
        labelYOffset: "-10",
        fontColor: "red",
        fontSize: "12px",
        fontFamily: "Arial",
        fontWeight: "bold",
        display:"${getVisibility}",
        labelAlign: "lt"
    }
};
 
styleMapTest = new OpenLayers.StyleMap();
 
var rules = [];
rules.push(createRule("kategorie", "TURM",
OpenLayers.Filter.Comparison.EQUAL_TO, "Point", Symbolizers["Turm"], false,
"TURM"));
rules.push(createRule("kategorie", "KIRCHE",
OpenLayers.Filter.Comparison.EQUAL_TO, "Point", Symbolizers["Kirche"],
false, "KIRCHE"));
rules.push(createRule("kategorie", "DENKMAL",
OpenLayers.Filter.Comparison.EQUAL_TO, "Point", Symbolizers["Denkmal"],
false, "DENKMAL"));
rules.push(createRule("kategorie", "DENKMAL",
OpenLayers.Filter.Comparison.NOT_EQUAL_TO, "Text", Symbolizers["Text"],
true, "ELSE"));
 
styleMapTest.styles["default"].addRules(rules);
 
map.layers[map.aktLayer]["styleMap"]=styleMapTest;
map.layers[map.aktLayer].redraw();

 

  _____  

Von: openlayers-users-bounces at lists.osgeo.org
[mailto:openlayers-users-bounces at lists.osgeo.org] Im Auftrag von Robert
Buckley
Gesendet: Mittwoch, 6. April 2011 22:17
An: users at openlayers.org
Betreff: [OpenLayers-Users] vector polygon styling with rules


Hi,

I´m having a bad time trying to set styles to vector features,

I have made this...



var style_solar = new OpenLayers.StyleMap({
                    "default": new
OpenLayers.Style(OpenLayers.Util.applyDefaults({
                            fillOpacity: 0.6, 
                            fillColor: '#000000'
                        }, OpenLayers.Feature.Vector.style["default"])),
                    "select": new
OpenLayers.Style(OpenLayers.Util.applyDefaults({
                            fillOpacity: 0.6, 
                            fillColor: '#FF0000'
                    }, OpenLayers.Feature.Vector.style["select"]))
                });


which works ok...but I really need to add rules according to the wfs
property "solar_kopf"

How can I apply rules to the stylemap?

I have tried numerous times but they all fail.

Could anyone provide me with a couple of examples?

yours,

Robert

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/openlayers-users/attachments/20110407/8a2450a0/attachment.html


More information about the Users mailing list