0

I'm simply trying to add new layers with each as their own variable so I can turn them on and off, instead of just stacking all the layers under the variable layers.

See script below

<script>
var layers = [
  new ol.layer.Tile({
    source: new ol.source.MapQuest({layer: 'osm'})
  }),
];

var poly1 = new ol.layer.Tile({
    source: new ol.source.TileWMS({
      url: 'http://localhost:8080/geoserver/wms',
      params: {'LAYERS': 'sample:sample', 'TILED': true},
      serverType: 'geoserver',
    })
  });

var map = new ol.Map({
  layers: poly1, layers,
  target: 'map',
  view: new ol.View({
    center: [lat, lon],
    zoom: 4
  })
});
</script>

For some reason when add more than one layer to the layers line of code here

var map = new ol.Map({
layers: poly1, layers,

they both will not display, if I have one of the other they work, but can't get more than one variable working... I assume this is a simple syntax error but has me stumped and cannot seem to get it working.

1 Answer 1

1

layers config accepts an ol.Collection or a js array. try this

var map = new ol.Map({
layers: [poly1, layers],
1
  • Cheers for the reply, I've decided though to switch from openlayers to leaflet
    – cmca
    Commented May 7, 2016 at 8:59

Your Answer

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

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