0

I'm using OpenLayers 3 and i need to load a Geoserver group-layer

In OL2 i used a code like this and it worked:

var layer_group = new OpenLayers.Layer.WMS(
        "Sample Layer Group",
        "http://localhost:8081/geoserver/wms",
        {layers: "layer_group_name", transparent: true},
        {isBaseLayer: false, visibility: false}
    );
    map.addLayers([layer_group]);

I have no idea how OL3 loads a group.. simple layers he can load correctly

1 Answer 1

2

OL3 API is changed. You could check examples.

Explore this one.

var layers = [
  new ol.layer.Tile({
    source: new ol.source.MapQuest({layer: 'sat'})
  }),
  new ol.layer.Image({
    source: new ol.source.ImageWMS({
      url: 'http://demo.opengeo.org/geoserver/wms',
      params: {'LAYERS': 'topp:states'},
      serverType: 'geoserver',
      extent: [-13884991, 2870341, -7455066, 6338219]
    })
  })
];
var map = new ol.Map({
  layers: layers,
  target: 'map',
  view: new ol.View2D({
    center: [-10997148, 4569099],
    zoom: 4
  })
});
1
  • For me, the missing part was the 'topp:' in 'topp:states' I wrote it without it and the layer failed to draw
    – gil kr
    Commented May 14, 2014 at 4:21

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.