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
asked Jul 18, 2017 at 22:29
2
  • what does the geoserver log file say? Commented Jul 19, 2017 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? Commented Jul 19, 2017 at 14:19

1 Answer 1

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.

answered Jul 19, 2017 at 14:26
2
  • 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. Commented Jul 19, 2017 at 14:38
  • I just added projection: 'EPSG:4326' to my view and it seems to be working now. Commented Jul 19, 2017 at 14:48

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.