TileWMS JSONP getGetFeatureInfoUrl request using OpenLayers 3

المشرف العام

Administrator
طاقم الإدارة
I have a web map in Open Layers 3 which has some TileWMS layers from GeoServer 2.5 that I would like to query when the user clicks on the map.

I am trying to use the tutorial here (https://astuntechnology.github.io/osgis-ol3-leaflet/ol3/05-WMS-INFO.html) but this was giving me a cross origin error in my console.

After changing it to jsonp and allowing this through GeoServer I am still having problems as now get an error:

"parseResponse is not defined" and "Cannot read property 'responseText' of undefined".

My code is below, do I need to specify an additional function when using jsonp?

Thanks for any help / tips you might be able to give!

var popup = new ol.Overlay.Popup();map.addOverlay(popup);map.on('singleclick', function(evt) { // Hide existing popup and reset it's offset popup.hide(); popup.setOffset([0, 0]); // Attempt to find a marker from the planningAppsLayer var feature = map.forEachFeatureAtPixel(evt.pixel, function(feature, layer) { return feature; }); if (feature) { var coord = feature.getGeometry().getCoordinates(); var props = feature.getProperties(); var info = "something here

"; // Offset the popup so it points at the middle of the marker not the tip popup.setOffset([0, -22]); popup.show(coord, info); } else { var url = layer1 .getSource() .getGetFeatureInfoUrl( evt.coordinate, map.getView().getResolution(), map.getView().getProjection(), { 'INFO_FORMAT': 'text/javascript', 'propertyName': 'definition' } ); reqwest({ url: url, type: 'jsonp', }).then(function (data) { var feature = data.features[0]; var props = feature.properties; var info = "Flood Zone 3

" + props.definition + "

"; popup.show(evt.coordinate, info); }); }});

أكثر...
 
أعلى