Thanks for your reply!

So I tried to so something with the LoadURL. The SLD file is well called (I can see it in firebug), but the problem is that I now don't know how to link it with its layer. I'm still a newbie in webmapping. I think, what I want to do is quite easy, but I'm still not used to! Here is my current code:

                createWFSLayer: function(data, featureType) {
                        
                        //Style definition                      
                        var sld;
                        var layername = featureType.name;
                        var url_sld = "sld/"+layername+".xml";
                        
                        var format_sld = new OpenLayers.Format.SLD();
                        
                        OpenLayers.loadURL(url_sld, null, null, complete)
                        
                        function getDefaultStyle(sld, layerName) {
                                var styles = 
sld.namedLayers[layerName].userStyles;
                                var style;
                                for(var i=0; i<styles.length; ++i) {
                                        style = styles[i];
                                        if(style.isDefault) {
                                                break;
                                        }
                                }
                                return style;
                        };
                        
                        function complete(req) {
                                sld = format_sld.read(req.responseXML || 
req.responseText);
                                
                                var styleMap = new OpenLayers.StyleMap({
                                                "default": getDefaultStyle(sld, 
layername)
                                });
                                return styleMap;
                        }
                        
                        var styleWFS = {styleMap: styleMap}
                        
                        //Layer options
                        var layerOptions, protocolOptions;
                        //Layer options definition
                        protocolOptions = {
                                url: 
data.capability.request.getfeature.href.post,
                                featureType: featureType.name,
                                featureNS: featureType.featureNS,
                                outputFormat: "json",
                                readFormat: new OpenLayers.Format.GeoJSON()
                        };
                        //Layer protocol definition
                        layerOptions = {
                                protocol: new 
OpenLayers.Protocol.WFS(protocolOptions),
                                strategies: [new OpenLayers.Strategy.Fixed()]
                        };
                        return  new OpenLayers.Layer.Vector(
                                featureType.title,
                                layerOptions,
                                styleWFS
                        );
                },

My problem comes from the "complete" function. I can't get its result for the styleMap property of my layer!

Geoffrey


On Mon, 18 Jul 2011 18:17:07 +0200, Arnd Wippermann <[email protected]> wrote:

Hi,

As far as I know you can't load data with OpenLayers.Format.SLD(url). You
have to do it with an ajax call, i.e LoadUrl.

Arnd

-----Ursprüngliche Nachricht-----
Von: [email protected]
[mailto:[email protected]] Im Auftrag von gbrun
Gesendet: Montag, 18. Juli 2011 12:32
An: [email protected]
Betreff: [OpenLayers-Users] Call a SLD file for a Vector Layer

Hi list!

I would like to apply SLD styles to my vector layers. It should work like in
this example : http://www.openlayers.org/dev/examples/sld.html

But what I want to do is a little bit different: each layer has its own
style. So I want that each vector layer calls its default style from a
folder in my web application where styles are stored with the same name as their specific layer. For example, my application has a vector layer named
"vector". In this case, this layer must called a SLD file named
"vector.xml".

The OpenLayers example uses a "OpenLayers.LoadURL()" method. I'm looking for a different way: I would like to read the SLD response without this method.
It should look like this:

var url_sld = "../sld/"+featureType.name+".xml";
                        var format_sld = new OpenLayers.Format.SLD(url_sld);
                        
                        processResponse : function (response){
                                var sld =
format_sld.read(response.responseXML ||
response.responseText);                                 
                        };

But it doesn't work. I think, there is something that I don't understand
when I read the SLD response.

Can someone clarify me this?

Geoffrey


--
Using Opera's revolutionary email client: http://www.opera.com/mail/
_______________________________________________
Users mailing list
[email protected]
http://lists.osgeo.org/mailman/listinfo/openlayers-users



--
Using Opera's revolutionary email client: http://www.opera.com/mail/
_______________________________________________
Users mailing list
[email protected]
http://lists.osgeo.org/mailman/listinfo/openlayers-users

Reply via email to