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 created a vector layer by reading a geojson file and I have a SLD file created for this layer. I am wondering how do I link the SLD file to the layer. I had a read of this example on Openlayers website:

http://openlayers.org/dev/examples/sld.html

I am having a bit of trouble understanding the code for this example- which are using radiobuttons to change the style to the selected button. I believe the linking in my situation will be much simple than what is showing in the example- just linking one SLD file to one single vector layer.

Any guidance will be greatly appreciated.

share|improve this question
    
are you using GeoServer or just OpenLayers? –  iant Jul 10 '13 at 7:41
    
I am using geoserver, iant –  user1829700 Jul 10 '13 at 14:07

2 Answers 2

up vote 0 down vote accepted

The ideal way to apply a style to a vector layer, is by using a Style Object. You will find more examples on this page: Styling.

But given that you have a SLD, you need to do what is done in the Lined Example. You need to use OpenLayers.Format.SLD to read the SLD, and once it is parsed, you need to apply the style that it contains to your vector Layer.

share|improve this answer
    
Thanks, The sld file is linked to my vector layer now. Thanks. –  user1829700 Jul 11 '13 at 6:40
    
I'm glad to help you out. –  Devdatta Tengshe Jul 11 '13 at 6:58

Well, to apply the style through GeoServer, you would add the style to GeoServer's Style catalogue, then select that style in the layer's configuration. GeoServer would then provide rendered map tiles via WMS, which you could use in OpenLayers.

I'm afraid I'm not as familiar with applying the style inside OpenLayers though.

share|improve this answer
    
Thanks smithkm, I already did this but it doesnt work for me. i think because it is a vector layer. –  user1829700 Jul 10 '13 at 23:20
    
Yes the WMS method would be rendering your vector layer into raster tiles on the server. If you need the layer to be vector inside OL, then it wouldn't work. If you just mean that the layer is based on a vector dataset, that shouldn't be an issue though although it would require telling OL to use a raster tile layer instead of a vector one. –  smithkm Jul 16 '13 at 17:36

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.