0

I have four WMS layers however, only the first layer loaded is identifying.

I have loaded the layers individually and have the layer-switcher to enable individual layer switching, can someone advise on how to get the second code to work?

Single layer code (Works for one layer)

    map.on('click', function(evt) {
      var coordinate = evt.coordinate;
        //document.getElementById('info').innerHTML = '';
        var viewResolution = /** @type {number} */ (view.getResolution());
        var url = wmsSource1.getGetFeatureInfoUrl(
            evt.coordinate, viewResolution, 'EPSG:3857',
            {'INFO_FORMAT': 'text/html'});
        if (url) {
          document.getElementById('info').innerHTML =

                content.innerHTML = '<iframe seamless src="' + url + '"></iframe>';
                }
                });

      map.on('pointermove', function(evt) {
        if (evt.dragging) {
          return;
        }
        var pixel = map.getEventPixel(evt.originalEvent);
        var hit = map.forEachLayerAtPixel(pixel, function() {
          return true;
        });
        map.getTargetElement().style.cursor = hit ? 'pointer' : '';
      });
      map.addOverlay(popup);

Modified code for multiple layers

      map.on('click', function (evt) {
    var url = GetFeatureInfoUrl = 'http://localhost:8080/geoserver/County/wms'
        'evt.coordinate', 'viewResolution', 'viewProjection', 'EPSG:3857',
                {'INFO_FORMAT': 'text/html',
                'QUERY_LAYERS': 'County:Boundary,County:Regions,County:Constituencies,County:Towns'};   
            if (url) {
          document.getElementById('info').innerHTML =
                content.innerHTML = '<iframe seamless src="' + url + '"></iframe>';
                    }
                    });

          map.on('pointermove', function(evt) {
            if (evt.dragging) {
              return;
            }
            var pixel = map.getEventPixel(evt.originalEvent);
            var hit = map.forEachLayerAtPixel(pixel, function() {
              return true;
            });
            map.getTargetElement().style.cursor = hit ? 'pointer' : '';
          });
  • Your multiple layer code seems to come from gis.stackexchange.com/questions/227519/…. Have you edited it to use the names of your own layers? – user30184 May 23 '18 at 6:43
  • Do you mean that the query works now but the result is not shown because of the character encoding problem? As a test, what happens with text/plain? – user30184 May 23 '18 at 8:41
  • What actual request is sent to GeoServer from OpenLayers? What info_formats are listed as supported by GeoServer in the GetCapabilities response? – nmtoken May 24 '18 at 19:26
  • @nmtoken I am using the following OpenLayer example. I am still investigating your question on Request & GetCapabilities response. openlayers.org/en/latest/examples/getfeatureinfo-image.html – Amelia Nicodemus Jun 30 '18 at 10:21
  • @nmtoken can you kindly advise on how to set info_formats/ WMS get feature info parameters, I have been reading on the subject & cannot put out the correct code. I am currently getting an error that WMS does not permit cross origin framing which is because of the way I have sent the request. Thank you. – Amelia Nicodemus Jul 2 '18 at 9:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.