Now I understood that WMS returns an image only, without a possibility to use rules. Then how to practically turn the WMS in a WFS vector layer? My aim is to implement in OpenLayers what I did first in SLD (which cannot be parametrised like Java Script): that a parcel with a certain PID attribute value is shown differently. http://osgeo-org.1803224.n2.nabble.com/Style-WFS-layer-by-attributes-SOLVED-td3559456.htmlis close to what I'm after, but can I proceed something like below? How to change the WFS layer as a base layer? I could also keep the WMS as base layer, and as WFS only bring (propertyFilter?) the correct PID polygon to be shown differently upon it.
var wfsURL = "http://dbs2:8080/geoserver/wfs"; //wms merely changed to wfs, OK? Areas = new OpenLayers.Layer.Vector("WFS Parcels", { styleMap: parcelstyle, strategies: [new OpenLayers.Strategy.BBOX()], //filter: propertyFilter, style:parcelstyle, protocol: new OpenLayers.Protocol.WFS({ url: wfsURL, extractAttributes:true, featureType: "Parcels", geometryName:"the_geom" }) }); map.addLayer(Areas); Arto 2010/10/20 Arto Vuorela > Hello > > I have tried to apply some Rule Based Style from > http://docs.openlayers.org/library/feature_styling.html and > http://openlayers.org/dev/examples/, but the default SLD style defined for > the layer remains. Any hints? Below some code with two techniques tried. The > layer definition code at hand seems to have has a fifth parameter > {isBaseLayer: 'true', opacity: '0.5'}, but > http://dev.openlayers.org/docs/files/OpenLayers/Layer/WMS-js.html#OpenLayers.Layer.WMS.OpenLayers.Layer.WMSlists > only four...? In any case, with or without the line > styleMap: new OpenLayers.StyleMap(parcelstyle), > the map looks just the same. > > var parcelstyle = new OpenLayers.Style( > // the first argument is a base symbolizer > // all other symbolizers in rules will extend this one > { > strokeWidth: 0.2, // from Parcels_for_Certificate.sld > strokeColor: '#000000', > sfillColor: "#FF5500", > //fillOpacity: 0.5, > label: "${Parcel_No}", // label will be this attribute value > //pointRadius: 0, > fontColor: '#000000', > fontOpacity: 0.8, > fontSize: 12, // from Parcels_for_Certificate.sld > fontFamily: "verdana" //"Courier New, monospace", or "Arial" > }, > // the second argument will include all rules > { > rules: [ > new OpenLayers.Rule({ > // a rule contains an optional filter > filter: new OpenLayers.Filter.Comparison({ > type: OpenLayers.Filter.Comparison.EQUAL_TO, > property: "PID", // the "PID" feature attribute > value: 1121 //1691 is DoSUP example, 1121 its > neighbour. > }), > // If a feature matches the above filter, use this > symbolizer hash: > symbolizer: { > strokeWidth: 2.0, > strokeColor: '#CC0039', // from > Parcels_for_Certificate.sld > fontWeight: "bold", > fontStyle: "italic" > } > }) > ] //Only one rule, no "otherwise" option given now > } > ); > > var parcelstyle2 = new OpenLayers.Style(); > > var ruleLow = new OpenLayers.Rule({ > filter: new OpenLayers.Filter.Comparison({ > type: OpenLayers.Filter.Comparison.LESS_THAN, > property: "PID", > value: 1600, > }), > symbolizer: {pointRadius: 10, fillColor: "green", > fillOpacity: 0.5, strokeColor: "black"} > }); > > var ruleHigh = new OpenLayers.Rule({ > filter: new OpenLayers.Filter.Comparison({ > type: OpenLayers.Filter.Comparison.GREATER_THAN_OR_EQUAL_TO, > property: "PID", > value: 1600, > }), > symbolizer: {pointRadius: 20, fillColor: "red", > fillOpacity: 0.7, strokeColor: "yellow"} > }); > > parcelstyle2.addRules([ruleLow, ruleHigh]); > > //------------------ LAYER DEFINITIONS > ---------------------------------------------------- > > var parcels = new OpenLayers.Layer.WMS("Parcels"," > http://dbs2:8080/geoserver/wms" , > {bbox: '518921.40245480876,9310002.394840041,528518.0741880973, > 9328387.88151105', > layers: 'MPCADASTRE:Parcels_for_Certificate', > srs: 'EPSG:21037', > transparent:'false', > //style: parcelstyle, //The rule-based style > format: 'image/jpeg'}, > //Using 3x3 Geoserver metatiling seems to cause multiple labels for > polygons, using singletile instead > {singleTile: true, > ratio: 1, > maxExtent: bounds, > projection: "EPSG:21037", > styleMap: new OpenLayers.StyleMap(parcelstyle), //The rule-based > style used for a StyleMap. parcelstyle2 also tried here. > buffer: 0}, > {isBaseLayer: 'true', opacity: '0.5'}); //This one as the base > layer now > > > Arto >
_______________________________________________ Users mailing list [email protected] http://lists.osgeo.org/mailman/listinfo/openlayers-users
