1

I have a WFS layer working correctly. I configured the style in the GeoServer, but I am not able to fetch this style already defined in the GeoServer to show in OpenLayers.

On the GeoServer, the style is named

style_layer1

How can I do this?

var layer1 = new ol.layer.Vector({
    title: 'Layer 1',
    visible: false,
    zIndex: abrangencia,
    style: style_cadastro_lote,
    source: new ol.source.Vector({
        format: new ol.format.GeoJSON(),
        url: function (extent) {
            return urlGeoserver + 'wfs?service=WFS&' +
                'version=' + versionGeoserver + '&request=GetFeature&typename=geo:LAYER1&' +
                'outputFormat=application/json&srsname=EPSG:4326&' +
                'all=' + extent.join(',') + ',EPSG:4326';

        },
        strategy: ol.loadingstrategy.bbox
    })
}); 

[EDIT]

Edit

var geojsonSource = new ol.source.Vector({
   format: new ol.format.GeoJSON(),
    url: function(extent) {
       return urlGeoserver + 'wfs?service=WFS&' +
            'version=' + versionGeoserver + '&request=GetFeature&' +
            'typename=nome_da_camada&outputFormat=application/json&' +
            'srsname=EPSG:4326&' +
            'all=' + extent.join(',') + ',EPSG:4326' +
           '&sld_url='+urlGeoserver +'/arquivo.sld';
},
 strategy: ol.loadingstrategy.bbox
});

var vectorLayer = new ol.layer.Vector({
  source: geojsonSource
});

ol.format.SLD().readUrl(+urlGeoserver +'/arquivo.sld', function(sld) {
  var style = 
   ol.xml.getAllTextContent(sld.getElementsByTagName('CssParameter')[0]);
  vectorLayer.setStyle(style);
});
2

1 Answer 1

0

OpenLayers cannot use SLD styling out of the box. You can use GeoStyler to convert SLD to OpenLayers style.

If you want to see the styled features, you can simply the use the WMS service from GeoServer. Indeed, you can use both WMS and WFS together in the same map. WMS could be used to displayed the styled features, whereas you can use the WFS to access the raw data.

1
  • Thanks, I'll look into GeoStyler Apr 28 at 14:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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