Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I have a problem with styling a WFS in OpenLayers. I tried different ways (from the examples) to style the WFS, but I could only get the default style in orange. Then I found one way, which worked for me. The problem is that in the legend is written "Untitled 1" next to the now correct symbol as with the default style. How can I change this title or remove it?

Has anybody have a solution on how to style the WFS with an external SLD? I also tried different examples found on the web but I couldn't get it to work.

Here's the code I am using to style the WFS but that displays the wrong title:

var StyleObjekt = new OpenLayers.StyleMap({
                            "default": new OpenLayers.Style({
                                                          fillColor: "#fff000",
                                                          strokeColor: "#666666",
                            }),
                            "select": new OpenLayers.Style({
                                                            fillColor: "#ffffff",
                                                            strokeColor: "#666666",
                                                            }),
                            "temporary": new OpenLayers.Style({
                                                            fillColor: "#ffffff",
                                                            strokeColor: "#666666",
                                                            })
            }); 

 var gwg_f_wfs = new OpenLayers.Layer.Vector("Flurstuecke_WFS", {
            styleMap: StyleObjekt,
            strategies: [new OpenLayers.Strategy.BBOX()],
            protocol: new OpenLayers.Protocol.WFS({
                version: "1.1.0",
                url: "http://localhost:8080/geoserver/wfs",
                featurePrefix: "NewGeo",
                featureType: "Flurstuecke_GWG",
                featureNS: "http://www.newgeo.de/GeoServer",
                srsName: "EPSG:2398"
            })              
        });
share|improve this question
    
Its giving an error as ReferenceError: format is not defined –  Preeti Gupta May 3 '13 at 6:22

1 Answer 1

Yes, i got it... Both problems! : ) Now i can work with an external SLD, that´s how it works:

        var gwg_f_wfs = new OpenLayers.Layer.Vector("Flurstuecke_GWG", {
            strategies: [new OpenLayers.Strategy.BBOX()],
            protocol: new OpenLayers.Protocol.WFS({
                version: "1.1.0",
                url: "http://localhost:8080/geoserver/wfs",
                featurePrefix: "NewGeo",
                featureType: "Flurstuecke_GWG",
                featureNS: "http://www.newgeo.de/GeoServer",
                srsName: "EPSG:2398"
            })              
        });


        var gwg_g_wfs = new OpenLayers.Layer.Vector("Grundstuecke_GWG", {
            strategies: [new OpenLayers.Strategy.BBOX()],
            protocol: new OpenLayers.Protocol.WFS({
                version: "1.1.0",
                url: "http://localhost:8080/geoserver/wfs",
                featurePrefix: "NewGeo",
                featureType: "Grundstuecke_GWG",
                featureNS: "http://www.newgeo.de/GeoServer",
                srsName: "EPSG:2398"
            })              
        });

        var format = new OpenLayers.Format.SLD();

        OpenLayers.Request.GET({
            url: "SLD.xml",
            success: sldparser
        });

        function sldparser(req) {
            sld = format.read(req.responseXML || req.responseText);
            styles_Flst = sld.namedLayers["Flurstuecke_GWG"].userStyles[0];
            gwg_f_wfs.styleMap.styles.default = styles_Flst;
            styles_Grst = sld.namedLayers["Grundstuecke_GWG"].userStyles[0];
            gwg_g_wfs.styleMap.styles.default = styles_Grst;
        } 

And to change the title next to the symbol in the legend you have to insert in the SLD a -Tag with a -Tag. If you know it, it´s simple ; )

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.