0

I am a complete beginner in JavaScript, XML and coding in general (so if there's anyway for me make my question more clear please tell me).

I have loaded a WMS onto my OpenLayers 3 map. The relevant code looks like this

var vectorLayer3 = new ol.layer.Tile({
    source: new ol.source.TileWMS({
        preload: Infinity,
        url: 'http://localhost:8080/geoserver/wms',
        serverType:'geoserver',
        params:{
            'LAYERS':"jazz", 'TILED':false, 'STYLES':'mostbasic'
        }
    })

}); 
    map.addLayer(vectorLayer3);

The map loads, but I get the generic style instead the 'most basic' style. I can get the style to show properly using the preview on WMS, so I don't think the problem is with the SLD. Looking at the documentation for ol.source.TileWMS it looks like there should be someway to get the style like I tried, but I am having trouble seeing it.

If I am completely off base, would following this tutorial be the best way to go, should I use a vector, WFS or is there a better strategy?

1 Answer 1

1

The answer to my question is actually quite simple.

var vectorLayer3 = new ol.layer.Tile({
    source: new ol.source.TileWMS({
        preload: Infinity,
        url: 'http://localhost:8080/geoserver/wms',
        serverType:'geoserver',
        params:{
            LAYERS:'jazz', TILED:false, STYLES:'mostbasic'
        }
    })

}); 
    map.addLayer(vectorLayer3);

As you can see, I needed to get rid of the single quotes around the params, and add quotes around the names of the paramaters I was using.

1
  • And now you should have enough rep to comment anywhere. :) As a side note, just including the line that changed in your answer and/or pointing out what needed to change would have been sufficient. I had to start reading line by line to figure out what changed in all that codeblock.
    – Chris W
    Dec 11, 2014 at 23:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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