3

I am trying to toggle visibility of a GeoServer WMS layer.

The code below doesn't render the layer, regardless of if setVisibility is true or false

var countryParks = new ol.layer.Tile({
                 title: 'Country Parks',
                 source: new ol.source.TileWMS({
                 url: 'http://localhost:8080/geoserver/opengeo/wms',
                 params: {"LAYERS": 'opengeo:country_parks'},
                 serverType: 'geoserver'    }),
});
countryParks.setVisibility(true);
map.addLayer(countryParks);

And this code does render the layer, true or false regardless

var countryParks = new ol.layer.Tile({
                 title: 'Country Parks',
                 visiblity: false,
                 source: new ol.source.TileWMS({
                 url: 'http://localhost:8080/geoserver/opengeo/wms',
                 params: {"LAYERS": 'opengeo:country_parks'},
                 serverType: 'geoserver'    }),
});
map.addLayer(countryParks);

How does one toggle layer visibility, if not as in these attempts?

5

In ol-3 the property is called visible and setVisible() not "visiblity" - see API

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.