2

I am trying to use the GetFeatureInfo functionality of Openlayers v3.

I am taking the layer name dynamically from the layerswitcher and trying to pass it into WMS like:

var temp=JSON.stringify(LayerName);
var newTemp = temp.replace(/"/g, "'");
var wmsSource = new ol.source.TileWMS({
      url: 'http://localhost:8080/geoserver/wms',
      params: {'LAYERS': newTemp},
      serverType: 'geoserver'
    });

Is it possible to pass a JavaScript object to "Layers:"?

If I pass the layer name directly it works smoothly but I need a dynamic functionality.

1
  • why are you replacing quotes? if LayerName is a simple string just use that in the LAYERS param. If it isn't a simple string then it won't work anyway – Ian Turton Feb 23 '16 at 17:12
1

Change

var newTemp = temp.replace(/"/g, "'");

to

var newTemp = temp.replace(/"/g, '');

Replace double quotes with nothing not with single quotes.

Now you can add layers dynamically.....

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.