CanvasMap
Getting Started Tutorials 3D Reference

Changing the Behavior of the Map When Clicked On

We've looked at overriding the MouseDown function within a layer but if you want to get full control of what happens when the user clicks in the Canvas, you can override the "MouseDown", "MouseUp", "MouseMove", and/or "MouseWheel" functions within the CMView class. The view recieves the standard "event" object from the browser but can then convert the x and y value in the event to reference coordinates within the map as shown in the example below.

	TheView.MouseDown=function(TheEvent)
	{
		if (!TheEvent) { TheEvent=window.event; }
		
		CMMainContainer.HidePopupWindows();
		
		var Coordinate=CMUtilities.GetElementCoordinate(TheEvent.clientX,TheEvent.clientY,this.TheCanvasElement);
		var PixelX=Coordinate.x;
		var PixelY=Coordinate.y;
		var RefX=this.GetRefXFromPixelX(PixelX);
		var RefY=this.GetRefYFromPixelY(PixelY);
		
		alert("RefX="+RefX);
	}