I am able to fetch the getGetFeatureInfoUrl for the currently selected layer, is it possible to fetch the last added layer FeatureInfo on the map?

My code currently is:

<!DOCTYPE html>
    <title>WMS GetFeatureInfo (Tile Layer)</title>
    <link rel="stylesheet" href="https://openlayers.org/en/v3.19.1/css/ol.css" type="text/css">
    <!-- The line below is only needed for old environments like Internet Explorer and Android 4.x -->
    <script src="https://cdn.polyfill.io/v2/polyfill.min.js?features=requestAnimationFrame,Element.prototype.classList,URL"></script>
    <script src="https://openlayers.org/en/v3.19.1/build/ol.js"></script>
    <script type="text/javascript" src="http://code.jquery.com/jquery-1.7.1.min.js"></script>
    <div class="form-group">
      <select id="dict" class="form-control" onchange="loadfloodlayer(this.id);">
        <option>Select disaster</option>
        <option value="guntur">guntur</option>
        <option value="krishna">krishna</option> 
        <option value="prakasam">prakasam</option>
    <div id="map" class="map"></div>
    <div id="info">&nbsp;</div>
    <div id="info2">&nbsp;</div>
      var wmsSource = new ol.source.TileWMS( {
        url: 'http://ndem.nrsc.gov.in/geoserver/wms',
        params: {'LAYERS': 'ndem50k:stateadmin50census2011'}
      var wmsLayer = new ol.layer.Tile({
        source: wmsSource
      var mapcenter = [79.60,23.44];
      var view = new ol.View({
        projection: 'EPSG:4326',
        center: mapcenter,
        zoom: 5,
        extent: [66.2329, 7.68083, 98.2223, 39.03874],
        minZoom: 4
      var map = new ol.Map({
        layers: [wmsLayer],
        target: 'map',
        view: view
      function loadfloodlayer(idd1) {
        hint = "manjula:";
        hitn = hint + $('#dict').val();
        var  railvar = new ol.source.TileWMS({
            url: 'http://localhost:8089/geoserver/manjula/wms',
            params: {LAYERS: hitn}
        var wmsLayer = new ol.layer.Tile({
        source: railvar
      map.on('singleclick', function(evt) {
        document.getElementById('info').innerHTML = '';
        document.getElementById('info2').innerHTML = '';
        var viewResolution = /** @type {number} */ (view.getResolution());
        var url2 = wmsSource.getGetFeatureInfoUrl(
          evt.coordinate, viewResolution, 'EPSG:4326',
          {'INFO_FORMAT': 'text/html'});
          var url = railvar.getGetFeatureInfoUrl(
            evt.coordinate, viewResolution, 'EPSG:4326',
            {'INFO_FORMAT': 'text/html'});
          if (url) {
            document.getElementById('info').innerHTML =
            '<iframe style="width:100%;height:100%;" src="' + url + '"></iframe>';
          if (url2) {
            document.getElementById('info2').innerHTML =
            '<iframe style="width:100%;height:100%;" src="' + url2 + '"></iframe>';
      map.on('pointermove', function(evt) {
        if (evt.dragging) {
        var pixel = map.getEventPixel(evt.originalEvent);
        var hit = map.forEachLayerAtPixel(pixel, function() {
          return true;
        map.getTargetElement().style.cursor = hit ? 'pointer' : '';
  • Do you mean layers that are in the same WMS service, or layers that are in different services?
    – nmtoken
    Jan 4, 2017 at 18:11

1 Answer 1


I am able to fetch the getGetFeatureInfoUrl for the currently selected layer, is it possible to fetch the last added layer FeatureInfo on the map?

If the layers are from the same service then yes; in any GetFeatureInfo request you can return information from more the one layer, the QUERY_LAYERS parameter defines the layers to be queried, so it's either a single layer name or a list of layer names (separated by a comma).

So for the current map (the result of a GetMap request) in your OpenLayers client you can make a GetFeatureInfo request for the layer shown, for another layer (the previous layer), or indeed for multiple layers.

Your Answer

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

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