TransWikia.com

GetFeatureInfo doesn't return anything

Geographic Information Systems Asked on February 8, 2021

I’m attempting to display some properties from the points on my map. I’m using the example provided on the geoserver site: http://openlayers.org/en/latest/examples/getfeatureinfo-image.html?mode=raw. When I click on my map, it opens up a dialog box, but its empty. I checked the logs and nothing seems unusual other than the fact that no matter where I click on the map, pixelX and pixelY are always 50, which seems to be the center point, as the width and height in the request are both 101.

Code

<html>
  <head>
    <title>WMS GetFeatureInfo (Image Layer)</title>
    <link rel="stylesheet" href="https://openlayers.org/en/v4.2.0/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/v4.2.0/build/ol.js"></script>
  </head>
  <body>
    <div id="map" class="map"></div>
    <div id="info">&nbsp;</div>
    <script>
      var wmsSource = new ol.source.ImageWMS({
        url: 'http://localhost/geoserver/cite/wms',
        params: {'LAYERS': 'cite:points'},
        serverType: 'geoserver',
      });

      var wmsLayer = new ol.layer.Image({
        source: wmsSource
      });

      var view = new ol.View({
        center: [0, 0],
        zoom: 1
      });

      var map = new ol.Map({
        layers: [wmsLayer],
        target: 'map',
        view: view
      });

      map.on('singleclick', function(evt) {
        document.getElementById('info').innerHTML = '';
        var viewResolution = /** @type {number} */ (view.getResolution());
        var url = wmsSource.getGetFeatureInfoUrl(evt.coordinate, viewResolution, 'EPSG:4326', {'INFO_FORMAT': 'text/html'});
        if (url) {
          document.getElementById('info').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' : '';
      });
    </script>
  </body>
</html>

Log

Request: getFeatureInfo
    BaseUrl = http://localhost:80/geoserver/
    Exceptions = application/vnd.ogc.se_xml
    FeatureCount = 1
    Get = false
    GetMapRequest = 
GetMap Request
 version: 1.3.0
 output format: image/png
 width height: 101,101
 bbox: SRSEnvelope[-267350.5296874754 : 7638072.6836785935, 2.086165940819164E7 : 2.876708262155771E7]
 layers: cite:points
 styles: customPoint
     InfoFormat = text/html
     PropertyNames = null
     QueryLayers = [org.geoserver.wms.MapLayerInfo@f58b334c]
     RawKvp = {CRS=EPSG:4326, FORMAT=image/png, INFO_FORMAT=text/html, I=50, STYLES=, J=50, WIDTH=101, HEIGHT=101, LAYERS=cite:points, REQUEST=GetFeatureInfo, BBOX=-267350.5296874754,20861659.40819164,7638072.6836785935,28767082.62155771, VERSION=1.3.0, SERVICE=WMS, QUERY_LAYERS=cite:points, TRANSPARENT=true}
     Request = GetFeatureInfo
     RequestCharset = null
     Version = 1.3.0
     XPixel = 50
     YPixel = 50

The fact the the example doesn’t work makes me think it has something to do with how I set up the layer or server, but I haven’t found anything yet.

One Answer

have the same kind of problem.I think it's geoserver that requires activating wms service locally. Still not sure for 100% but creating new workspace and publishing it should solve the problem, also remember to check wms checkbox while publishing

Answered by user125898 on February 8, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP