[OpenLayers-Users] Custom control isn't working properly - how to unregister?

Pascal Ehlert dadark at dadark.de
Fri Nov 16 10:14:57 EST 2007


Hi mailing list!

I'm trying to build my own control to enable the user to query some  
information depending on where he clicked.
Now I'd like to add this control to my panel and change between  
normal navigation and query mode.

Unfortunately there are two problems with it:
The first is that the class for the control element in my panel  
doesn't change to olControlODAQueryItemActive when I click it,  
although the
event is registered.
The second is that I don't really know how to unregister it so that  
normal navigation is possible again.

Oh, okay, there's just another problem that came to my mind:
I'd also like it to unregister all default mouse handlers upon  
activation, so that you can't navigate in query mode.

Thank you in advance!


Regards,

Pascal



This is the code of my control:
// Query Control
var query_control = new OpenLayers.Control();
OpenLayers.Util.extend(query_control, {
	displayClass: 'olControlODAQuery',
	type: 3,
	activate: function() {
		map.events.registerPriority("click", map, function(e) {
			alert("This is the click event handler!");
			
			var lonlat = map.getLonLatFromViewPortPx(e.xy);
			if (map.getZoom() < 3)
				var url = 'http://odamap.hacksrus.net/gidbylatlon.rb? 
query=province&lat=' + lonlat.lat + '&lon=' + lonlat.lon;
			else
				var url = 'http://odamap.hacksrus.net/gidbylatlon.rb? 
query=district&lat=' + lonlat.lat + '&lon=' + lonlat.lon;

			new OpenLayers.Ajax.Request(url, {
			  method: 'get',
			  onSuccess: function(transport) {
					if (transport.responseText == '') {
						alert("Please select a region within Mozambique!");
					}	else {
						var district = transport.responseText;

			   		window.open('http://www.odamoz.org.mz/reports/ 
rpt_district1.asp?district='+ district + '&DONOR=',
							"ODAmoz Query Results",
							"menubar=no,width=800,height=600,toolbar=no,scrollbars=yes");
			  	}
				},

				onFailure: function(transport) {
					alert("Could not get information from database. Please try again  
later.");
				}
			});
			return true;
		});
	},
	
	draw: function() {
	},
								
	CLASS_NAME: "OpenLayers.Control.ODAQuery"
});





More information about the Users mailing list