2

I'm trying to add multiple layers from a single Geoserver source to my Openlayers map. I can get each layer to appear by changing a single line of code. but when I attempt to have both layers on at once, I get a blank map. How do I add both? One is a raster, the other is a vector.

I've attempted via having the additional layer in a new variable and using map.addlayer. This didn't break the map, but it still didn't load the additional layer. I tried by just adding the additional layer into the layer variable, broke the map. I also tried by adding it to the params. So it was

params:{'LAYERS': 'Test:TestImagery', 'Test:Vector'},

This broke the map. How do I make this work?

Code:

<script>
  var layers = [
    new ol.layer.Tile({
      source: new ol.source.OSM()
    }),

    new ol.layer.Image({
      extent: [-20000000, 1000000, -5000000, 9000000],
      source: new ol.source.ImageWMS({
        url: 'http://localhost/geoserver/Test/wms',
        params: {'LAYERS': 'Test:TestImagery'},
        ratio: 1,
        serverType: 'geoserver'
      })
    })

  ];
  var map = new ol.Map({
    layers: layers,
    target: 'map',
    view: new ol.View({
      center: [0,0],
      zoom: 14
    })
  });

</script>
  • What was the error message when you requested both layers? – Ian Turton Aug 10 '17 at 22:56
  • I didn't get an error message the page just didn't load. Unless the error message appears elsewhere, in which case, where do I look? – NorthLand Aug 10 '17 at 22:58
  • The error message is in the response sent to you by geoserver – Ian Turton Aug 10 '17 at 22:59
  • 2
    What if you use : params:{'LAYERS': 'Test:TestImagery,Test:Vector'}, Also check what actual http request is made – nmtoken Aug 11 '17 at 7:44
  • @nmtoken This change worked. – NorthLand Aug 11 '17 at 15:42
3

Credit to nmtoken.

for having multiple layers from the same WMS, code should read:

params:{'LAYERS': 'Test:TestImagery,Test:Vector'},

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.