AW: [OpenLayers-Users] Multiple Styles for grouped vector layers with multiple featuretypes possible?

Arnd Wippermann arnd.wippermann at
Sun Mar 6 08:11:44 EST 2011

You can use a styleMap with context. The WFS response from MapServer look

'<ms:LAYER1 fid="LAYER1.WFS, triangle No. 4">'. 

The fid contains the typename and OpenLayers set this as feature.fid. If
that apply to other Mapservers, i don't know.

var context = {
    getColor : function (ft){
            return '#00FF00';
        else if(^LAYER2/)==0)
            return '#FF00FF';
        else if(^LAYER3/)==0)
            return '#0000FF';
            return '#FF0000';

Example :


-----Ursprüngliche Nachricht-----
Von: openlayers-users-bounces at
[mailto:openlayers-users-bounces at] Im Auftrag von Planet)x
Gesendet: Donnerstag, 3. März 2011 23:06
An: users at
Betreff: [OpenLayers-Users] Multiple Styles for grouped vector layers with
multiple featuretypes possible?

 With my below code I have multiple featuretypes grouped into a single WFS
layer and they are both displaying properly. My problem is I need to define
2 different styles one for each featuretype. Can I do it this way somehow or
do I need to modify my code?

//Test Vector Style
   var style_attraction = OpenLayers.Util.extend({},['default']);
       style_attraction.externalGraphic = 'sask.jpg';
       style_attraction.cursor =  'hand';
       style_attraction.graphicHeight = 35;
       style_attraction.graphicWidth = 35;
       style_attraction.graphicOpacity = 0.8;
     //Areas of Interest Group
           var layer_AOIs_wfs = new OpenLayers.Layer.Vector("Attraction", {
                minScale: 125000,
                maxScale: 99,
                styleMap: new OpenLayers.StyleMap(style_attraction),
                strategies: [new OpenLayers.Strategy.BBOX()],
                 protocol: new OpenLayers.Protocol.WFS({
                 url: wfs,
                 featureType: ["Attraction", "Fire_Hall"],
                 featureNS: "",
                 featurePrefix: "gmgml",
                 srsName: "EPSG:3776",
                 geometryName: "Geometry",
                 version: "1.1.0"
     //Add Vector Layers to Map

View this message in context:
Sent from the OpenLayers Users mailing list archive at
Users mailing list
Users at

More information about the Users mailing list