0

I am getting the following error messages: How do I define add control and prevent passive event listener? enter image description here

Below is the code:

<!DOCTYPE html>
<html lang='en'>
<head>
 <meta charset='utf-8' />
 <title>My OpenLayers Map</title>
 <script type='text/javascript' src='OpenLayers.js'></script>
 <script type='text/javascript'>
OpenLayers.ProxyHost = "/cgi-bin/proxy.cgi?url=";

 var map;

 function init() {
 map = new OpenLayers.Map('ch05_wmsfeatureinfo', {});

// Setup our two layer objects
var wms_layer_map = new OpenLayers.Layer.WMS(
'Base layer',
'http://vmap0.tiles.osgeo.org/wms/vmap0',
{layers: 'basic'},
{isBaseLayer: true}
);

var Boundary = new OpenLayers.Layer.WMS(
'Boundary',
'http://localhost:8080/geoserver/wms',
{layers: ':Boundary',
transparent: true,
isBaseLayer: false},
{visibility: false, opacity:0.5}
);

var Ext = new OpenLayers.Layer.WMS(
'Ext',
'http://localhost:8080/geoserver/wms',
{layers: 'Ext',
transparent: true,
isBaseLayer: false},
{visibility: false, opacity:0.5}
);



var Erv = new OpenLayers.Layer.WMS(
'Erv',
'http://localhost:8080/geoserver/wms',
{layers: 'Erv',
transparent: true,
isBaseLayer: false},
{visibility: false, opacity:0.5}
);

var Parcels = new OpenLayers.Layer.WMS(
'Parcels',
'http://localhost:8080/geoserve/wms',
{layers: ':Parcels',
transparent: true,
isBaseLayer: false},
{visibility: false, opacity:0.5}
);

map.addLayers([
wms_layer_map,
Townland_Boundary,
Ext,
Erv,
Parcels]);

 map.addControl(new OpenLayers.Control.LayerSwitcher({}));

 if(!map.getCenter()){
 map.zoomToMaxExtent();
 }
 }

var featureInfo = new OpenLayers.Control.WMSGetFeatureInfo({
url: 'http://localhost:8080/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);

function featureInfoChange(checked) {
if(checked) {
featureInfo.activate();
} else {
featureInfo.deactivate();
}
}

 </script>
</head>

<body onload='init();'>
<div id='map_element' style='width: 500px; height: 500px;'>
<button dojoType="dijit.form.ToggleButton" id="featureInfoButton"
onChange="featureInfoChange" iconClass='dijitCheckBoxIcon'
checked="false">Activated</button>
<div id='ch05_wmsfeatureinfo' style='width: 500px; height: 500px;'>
</div>
</body>
</html>

Additional question is regarding this line:

 function init() {
 map = new OpenLayers.Map('ch05_wmsfeatureinfo', {});

what is ch05_wmsfeatureinfo, is this the wms layer one trying to query? I am following the book tutorials. Please see book code at this link: No GetFeatureInfo response when clicking on a map in OpenLayers 2

  • @Mike I saw the answer you provided on StackOverflow, tried it before. I do not know where to put it on my code. – Amelia Nicodemus Oct 9 at 12:05
  • It can be anywhere before the map is displayed, but I would suggest start of the init() function. Without it there can be problems with mouse wheel zoom unless you have a full page map – Mike Oct 9 at 12:22
  • Yes, it worked on the map shown above, thanks, but on the one that covers the entire page, it does not work. I have two maps. I am stuck with defining 'addControl'. Please bear with me as I am new to programming. – Amelia Nicodemus Oct 9 at 12:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.