StyleMap

classic Classic list List threaded Threaded
4 messages Options
MB
Reply | Threaded
Open this post in threaded view
|

StyleMap

MB
Hi
I'm reading in a .TXT file of the format "lat lon Title Description" (Tab spaced).
The data loads fine, Popups work fine etc.

The problem I have is with the StyleMap.
I've created two style maps:

                var defaultStyle1 = new OpenLayers.Style({
                                        strokeColor: "#00FF00",
                                                         strokeOpacity: 1,
                                                         strokeWidth: 3,
                                                   fillColor: "#FF5500",
                                                         fillOpacity: 0.5,
                                                         pointRadius: 60
                });

                var selectStyle1 = new OpenLayers.Style({
                                  strokeColor: "#FF5500",
                                                        strokeOpacity: 1,
                                                   strokeWidth: 3,
                                                        fillColor: "#00FF00",
                                                   fillOpacity: 0.5,
                                                        pointRadius: 60
                });

                new OpenLayers.StyleMap({'default': defaultStyle1,
                                                                 'select': selectStyle1});



And then when I read the Layer in I'm using:

Bridges = new OpenLayers.Layer.GML("Bridges", "txt/test.txt",
                               {
                                format: OpenLayers.Format.Text,
                                formatOptions: {
                                  extractStyles: false,
                                  extractAttributes: true,
                                  maxDepth: 2,
                          styleMap: defaultStyle1
                                          }
                               });

However - The Layer is appears to be ignoring the Style map(s) and defaulting to Orange Circles.
Can anyone suggest what I've done wrong? Full Code extract attached.

thanks
Mark

Query1.txt
Reply | Threaded
Open this post in threaded view
|

Re: StyleMap

Steffen G
Hallo,
here ist a snipset that works fine for me:

var oStyleMap = new OpenLayers.StyleMap()
        var rulesDefault = [new OpenLayers.Rule({
            symbolizer: {strokeColor: "#000000",strokeWidth: 2, fillColor: "#000000", fillOpacity: 0.15},
            elseFilter: true
        })];

        var rulesSelect = [new OpenLayers.Rule({
            symbolizer: {strokeColor:"red",strokeWidth: 2},
            elseFilter: true
        })];

        oStyleMap.styles["default"].addRules(rulesDefault);
        oStyleMap.styles["select"].addRules(rulesSelect);

and:

Bridges = new OpenLayers.Layer.GML("Bridges", "txt/test.txt",
                               {
                                format: OpenLayers.Format.Text,
                                formatOptions: {
                                  extractStyles: false,
                                  extractAttributes: true,
                                  maxDepth: 2,
                          styleMap: oStyleMap,
                                          }
                               });

Regards
Steffen
MB
Reply | Threaded
Open this post in threaded view
|

Re: StyleMap

MB
Steffen

Thank very much for your code.
Its works - but unfortunately the result is just the same as I was getting - Orange circles.

Any further suggestions from anyone welcome.

thanks
Mark
Reply | Threaded
Open this post in threaded view
|

Re: StyleMap

Steffen G
Hi,
is the line:
styleMap: oStyleMap,

in correct position? I work with wfs layers. Here a example:

olOL = new OpenLayers.Layer.Vector("Locations", {
            strategies: [new OpenLayers.Strategy.BBOX(), oSaveStrategyOL],
            projection: new OpenLayers.Projection("EPSG:4326"),
            styleMap: oStyleMap,
            protocol: new OpenLayers.Protocol.WFS({
                url:  "http://localhost/geoserver/wfs",
                featureType: "orte_label",
                featureNS: "http://localhost/geoserver",
                geometryName: "sp_geometry"
            })
        });

Debug your layer object. Under Bridges.styleMap.styles.default.rules must be the symbolizer configuration. (For the example: strokeColor:"red",strokeWidth: 2).

regards
Steffen