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?
- Create an HTML file with the OpenLayers library dependencies and add the code for the button and the map's div element:
onChange="featureInfoChange" iconClass='dijitCheckBoxIcon'
checked="false">Activated
- 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
- 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);
- 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);
- 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
No comments:
Post a Comment