Saturday, 16 July 2016

wms - No GetFeatureInfo response when clicking on a map in OpenLayers 2


I have the code below, however no response when clicking on the map.







My OpenLayers Map












It is based on this tutorial, How to do it?



  1. Create an HTML file with the OpenLayers library dependencies and add the code for the button and the map's div element:







  1. Set the proxy script, and initialize the map instance:


OpenLayers.ProxyHost = "./utils/proxy.php?url=";

// Create map
var map = new OpenLayers.Map("ch05_wmsfeatureinfo");

Adding Controls 176



  1. Now, add two WMS layers. The first will act as the base layer while the second will be an overlay layer with the USA states:


var wms = new OpenLayers.Layer.WMS("Basic", "http://demo.
opengeo.org/geoserver/wms",
{

layers: 'topp:naturalearth'
});
map.addLayer(wms);
var wms2 = new OpenLayers.Layer.WMS("Basic", "http://demo.
opengeo.org/geoserver/wms",
{
layers: 'topp:states',
transparent: true
},{
isBaseLayer: false

});
map.addLayer(wms2);


  1. Add the layer switcher control and center the map's viewport:


map.addControl(new OpenLayers.Control.LayerSwitcher());
map.setCenter(new OpenLayers.LonLat(-90, 40), 4);



  1. Then add the code for the WMSGetFeatureInfo control:


var featureInfo = new OpenLayers.Control.WMSGetFeatureInfo({
url: 'http://demo.opengeo.org/geoserver/wms',
title: 'Identify features by clicking',
queryVisible: true,
eventListeners: {
"getfeatureinfo": function(event) {
map.addPopup(new OpenLayers.Popup.FramedCloud(
"chicken",

map.getLonLatFromPixel(event.xy),
null,
event.text,
null,
true
));
}
}
});
map.addControl(featureInfo);


The same issue also applies to the code provided earlier, Uncaught Reference Error: init is not defined


Here is my current map created using Openlayer2 enter image description here




No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...