I can view a layer (called wmsSource), created as a vector point-set, and stored in a PostGIS table from an Esri shapefile, in my OpenLayers map, as a WMS Image layer, using this code, a modification from the OpenLayers sample:
<!DOCTYPE html>
<html>
<head>
<title>WMS GetFeatureInfo (Image Layer)</title>
<link rel="stylesheet" href="https://openlayers.org/en/v4.6.5/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.6.5/build/ol.js"></script>
</head>
<body>
<div id="map" class="map"></div>
<div id="info"> </div>
<script>
var geosource = new ol.source.ImageWMS({
url: 'http://localhost:8080/geoserver/Workspace/wms',
params: {'LAYERS': 'Workspace:Shapefile layers for the Bay of Plenty'},
ratio: 1,
serverType: 'geoserver'
});
var geolayer = new ol.layer.Image ({source: geosource,});
var view = new ol.View({
center: [19687000, -4573021],
zoom: 11
});
var map = new ol.Map({
layers: [geolayer],
target: 'map',
view: view
});
map.on('singleclick', function(evt) {
document.getElementById('info').innerHTML = '';
var viewResolution = /** @type {number} */ (view.getResolution());
var url = geosource.getGetFeatureInfoUrl(
evt.coordinate, viewResolution, 'EPSG:3857',
{'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>
The example displays all the data as an image in a frame (although Firefox blocks the image as an inset and forces me to open it in another tab), but I would like to be able to click an item on the map and get a pop-up of information, just the fid
would be a start.
The layer covers a small area, so native SRS used is EPSG:2106.
What is the syntax I should use to get data from the fid
field into innerHTML
for a pop-up?
geometry
type, but at that point it is no longer a shapefile.{'INFO_FORMAT': 'application/json'}
will return the feature in GeoJSON format.application/json
is not supported you could trytest/plain
and then extract field data using regular expressions. codesandbox.io/s/getfeatureinfo-image-forked-7hs4pi?file=/…