1

I have a map with a point layer and I'm trying to create a popup on click which displays the properties of the points. My issue right now is that I can't get geoserver to return any features when I perform a getFeatureInfo() on my ImageWMS source.

This is the output:

{"type":"FeatureCollection","totalFeatures":"unknown","features":[],"crs":null}

Code:

<!DOCTYPE html>
<html>
  <head>
    <title>Accessible Map</title>
    <link rel="stylesheet" href="https://openlayers.org/en/v4.2.0/css/ol.css" type="text/css">
    <link rel="stylesheet" href="src/ol3-layerswitcher.css" />
    <link rel="stylesheet" href="layerswitcher.css" />
    <link rel="stylesheet" href="src/ol3-popup.css" />
    <link rel="stylesheet" href="popup.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="ol-debug.js"></script>
  </head>
  <body>
    <a class="skiplink" href="#map">Go to map</a>
    <div id="map" class="map" tabindex="0">
        <script src="src/ol3-layerswitcher.js"></script>
        <script src="src/ol3-popup.js"></script>
    </div>
    <div id="info">&nbsp;</div>
    <button id="zoom-out">Zoom out</button>
    <button id="zoom-in">Zoom in</button>
    <script>
      var view = new ol.View({
        center: [0, 0],
        zoom: 2
      });
      var lineLayer = new ol.layer.Image({
        title: 'Object Tail',
        source: new ol.source.ImageWMS({
            url: 'http://localhost/geoserver/workspace/wms',
            params: {'LAYERS': 'workspace:table_lines'},
            maxZoom: 19
            }),
        visible: true,
        });
       var pointLayer = new ol.layer.Image({
        title: 'Object Points',
        source: new ol.source.ImageWMS({
            url: 'http://localhost/geoserver/workspace/wms',
            params: {'LAYERS': 'workspace:table_points'},
            serverType: 'geoserver',
            maxZoom: 19
            }),
        visible: true,
        });
       var vectorLayer = new ol.layer.Image({
        title: 'Object Velocity',
        source: new ol.source.ImageWMS({
            url: 'http://localhost/geoserver/workspace/wms',
            params: {'LAYERS': 'workspace:table_velocity'},
            maxZoom: 19
            }),
        visible: true,
        });
      var map = new ol.Map({
        layers: [
          new ol.layer.Group({
                'title': 'Base maps',
                layers: [
                    new ol.layer.Tile({
                        title: 'OSM',
                        type: 'base',
                        visible: true,
                        source: new ol.source.OSM()
                    })
                ]
            }),
              new ol.layer.Group({
                'title': 'Data layers',
                layers: [
                    lineLayer, vectorLayer, pointLayer
                ]
            })  
        ],
        target: 'map',
        controls: 
            ol.control.defaults({
          attributionOptions: /** @type {olx.control.AttributionOptions} */ ({
            collapsible: false
          }), 
        }),
        view: view
      });

      var layerSwitcher = new ol.control.LayerSwitcher({
        tipLabel: 'Legend' // Optional label for button
        });

    map.addControl(layerSwitcher);

    var popup = new ol.Overlay.Popup();
    map.addOverlay(popup);

    var displayFeatureInfo = function(coord, pixel)
    {
        var features;
        document.getElementById('info').innerHTML = '';
        var viewResolution = /** @type {number} */ (view.getResolution());
        var url = pointLayer.getSource().getGetFeatureInfoUrl(
            coord, viewResolution, 'EPSG:4326',
            {'INFO_FORMAT': 'application/json'});
        if (url) {
          features = url;
          document.getElementById('info').innerHTML = '<iframe seamless src="' + url + '"></iframe>';
        }
        console.info('URL: ' + features);

    };

    map.on('singleclick', function(evt) {
        displayFeatureInfo(evt.coordinate, evt.pixel);
    });


      document.getElementById('zoom-out').onclick = function() {
        var view = map.getView();
        var zoom = view.getZoom();
        view.setZoom(zoom - 1);
      };

      document.getElementById('zoom-in').onclick = function() {
        var view = map.getView();
        var zoom = view.getZoom();
        view.setZoom(zoom + 1);
      };

      var iFrequency = 5000;
      var myInterval = 0;

      myInterval = setInterval("updateLayers()", iFrequency);

      function updateLayers()
      {
        pointLayer.getSource().updateParams({"time": Date.now()});
        lineLayer.getSource().updateParams({"time": Date.now()});
        vectorLayer.getSource().updateParams({"time": Date.now()});
      }
    </script>
  </body>
</html>

Any ideas on how to get it to return the point I'm clicking on?

EDIT: log

2017-07-19 08:09:23,902 DEBUG [org.geotools.rendering] - Querying layer http://workspace.mysite.com:table_points with bbox: ReferencedEnvelope[3349019.462106293 : 3379594.273420363, -9729982.583352817 : -9699047.772038748]
2017-07-19 08:09:23,910 DEBUG [org.geotools.jdbc] - CREATE CONNECTION
2017-07-19 08:09:23,916 DEBUG [org.geotools.jdbc] - SELECT "environment","identity","tracknumber",encode(ST_AsBinary("position"),'base64') as "position" FROM (select environment, identity, track_number as tracknumber, location as position from table
) as "vtable" WHERE   FALSE 
2017-07-19 08:09:23,925 DEBUG [org.geotools.jdbc] - CLOSE CONNECTION
2017-07-19 08:09:23,927 DEBUG [org.geotools.renderer.label] - TOTAL LINE LABELS : 0
2017-07-19 08:09:23,930 DEBUG [org.geotools.renderer.label] - PAINTED LINE LABELS : 0
2017-07-19 08:09:23,932 DEBUG [org.geotools.renderer.label] - REMAINING LINE LABELS : 0
2017-07-19 08:09:23,935 DEBUG [org.geotools.rendering] - Style cache hit ratio: NaN , hits 0, requests 0
2017-07-19 08:09:23,938 INFO [org.geoserver.wms] - 
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[3333120.5602229764 : 3394881.6790773985, -9745269.989009853 : -9683508.870155431]
 layers: workspace:table_points
 styles: cssPoint
    InfoFormat = application/json
    PropertyNames = null
    QueryLayers = [org.geoserver.wms.MapLayerInfo@2da43adf]
    RawKvp = {CRS=EPSG:4326, FORMAT=image/png, INFO_FORMAT=application/json, I=50, STYLES=, J=50, WIDTH=101, TIME=1500473361257, HEIGHT=101, LAYERS=workspace:table_points, REQUEST=GetFeatureInfo, BBOX=3333120.5602229764,-9745269.989009853,3394881.6790773985,-9683508.870155431, VERSION=1.3.0, SERVICE=WMS, QUERY_LAYERS=workspace:table_points, TRANSPARENT=true}
    Request = GetFeatureInfo
    RequestCharset = null
    Version = 1.3.0
    XPixel = 50
    YPixel = 50
  • what does the geoserver log file say? – Ian Turton Jul 19 '17 at 13:23
  • @iant Here are the logs, the only thing that stands out to me is the first line, where it references the table with the namespace URI instead of just workspace:table_points. The openlayers map is in my geoserver www directory, so do I need to change my workspace's namespace URI to something else? – Evan Jul 19 '17 at 14:19
1

It's a projection issue.

Your request is specifying that the SRS is EPSG:4326 but your bounding box is definitely not in 4326, is it EPSG:3857?

If you insist on specifying the SRS for the getFeatureInfo request then you need to transform the bounding box to that projection, but I suspect that will break the rest of the request since the pixel of the click should change too.

  • Everything on my geoserver is in 4326. But I am using the ol.source.OSM() as my baselayer, which uses 3857. I'll see if I can force it to 4326. – Evan Jul 19 '17 at 14:38
  • I just added projection: 'EPSG:4326' to my view and it seems to be working now. – Evan Jul 19 '17 at 14:48

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.