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

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


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

'<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){
        if(ft.fid.search(/^LAYER1/)==0)
            return '#00FF00';
        else if(ft.fid.search(/^LAYER2/)==0)
            return '#FF00FF';
        else if(ft.fid.search(/^LAYER3/)==0)
            return '#0000FF';
        else
            return '#FF0000';
    }
};


Example :
http://gis.ibbeck.de/ginfo/apps/OLExamples/OL29/WFS_with_multiple_featureTyp
es.asp

Arnd


-----Ursprüngliche Nachricht-----
Von: openlayers-users-bounces at lists.osgeo.org
[mailto:openlayers-users-bounces at lists.osgeo.org] Im Auftrag von Planet)x
Gesendet: Donnerstag, 3. März 2011 23:06
An: users at openlayers.org
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({},
OpenLayers.Feature.Vector.style['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: "http://www.intergraph.com/geomedia/gml",
                 featurePrefix: "gmgml",
                 srsName: "EPSG:3776",
                 geometryName: "Geometry",
                 version: "1.1.0"
                })
                });
   
     //Add Vector Layers to Map
     map.addLayer(layer_AOIs_wfs);

--
View this message in context:
http://osgeo-org.1803224.n2.nabble.com/Multiple-Styles-for-grouped-vector-la
yers-with-multiple-featuretypes-possible-tp6086563p6086563.html
Sent from the OpenLayers Users mailing list archive at Nabble.com.
_______________________________________________
Users mailing list
Users at lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/openlayers-users



More information about the Users mailing list