Migrate Map MouseControls to MouseDefaults.js. This moves event handling into a control, where we can modify it and edit it without mucking about in the main map class, bringing this portion of the code more into line with the way other aspects of the controls situation work.

git-svn-id: http://svn.openlayers.org/trunk/openlayers@204 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
crschmidt
2006-05-20 02:29:39 +00:00
parent 83030847a1
commit 563b828ede
3 changed files with 65 additions and 48 deletions

View File

@@ -54,6 +54,7 @@ catch(e){
"OpenLayers/Layer/WMS.js",
"OpenLayers/Layer/WFS.js",
"OpenLayers/Control.js",
"OpenLayers/Control/MouseDefaults.js",
"OpenLayers/Control/PanZoom.js",
"OpenLayers/Control/PanZoomBar.js",
"OpenLayers/Control/LayerSwitcher.js"

View File

@@ -0,0 +1,59 @@
OpenLayers.Control.MouseDefaults = Class.create();
OpenLayers.Control.MouseDefaults.prototype =
Object.extend( new OpenLayers.Control(), {
initialize: function() {
OpenLayers.Control.prototype.initialize.apply(this, arguments);
},
draw: function() {
this.map.events.register( "dblclick", this.map, this.defaultDblClick );
this.map.events.register( "mousedown", this.map, this.defaultMouseDown );
this.map.events.register( "mouseup", this.map, this.defaultMouseUp );
this.map.events.register( "mousemove", this.map, this.defaultMouseMove );
this.map.events.register( "mouseout", this.map, this.defaultMouseUp );
},
/**
* @param {Event} evt
*/
defaultDblClick: function (evt) {
var newCenter = this.getLonLatFromPixel( evt.xy );
this.setCenter(newCenter, this.zoom + 1);
},
/**
* @param {Event} evt
*/
defaultMouseDown: function (evt) {
this.mouseDragStart = evt.xy.copyOf();
this.div.style.cursor = "move";
Event.stop(evt);
},
/**
* @param {Event} evt
*/
defaultMouseMove: function (evt) {
if (this.mouseDragStart != null) {
var deltaX = this.mouseDragStart.x - evt.xy.x;
var deltaY = this.mouseDragStart.y - evt.xy.y
var size = this.getSize();
var newXY = new OpenLayers.Pixel(size.w / 2 + deltaX,
size.h / 2 + deltaY);
var newCenter = this.getLonLatFromPixel( newXY );
this.setCenter(newCenter);
this.mouseDragStart = evt.xy.copyOf();
}
},
/**
* @param {Event} evt
*/
defaultMouseUp: function (evt) {
this.mouseDragStart = null;
this.div.style.cursor = "default";
}
});

View File

@@ -93,12 +93,7 @@ OpenLayers.Map.prototype = {
this.controls = [];
this.addControl( new OpenLayers.Control.PanZoom() );
this.events.register( "dblclick", this, this.defaultDblClick );
this.events.register( "mousedown", this, this.defaultMouseDown );
this.events.register( "mouseup", this, this.defaultMouseUp );
this.events.register( "mousemove", this, this.defaultMouseMove );
this.events.register( "mouseout", this, this.defaultMouseUp );
this.addControl( new OpenLayers.Control.MouseDefaults() );
// always call map.destroy()
Event.observe(window, 'unload',
@@ -149,7 +144,10 @@ OpenLayers.Map.prototype = {
addControl: function (control) {
control.map = this;
this.controls.push(control);
this.controlDiv.appendChild( control.draw() );
var div = control.draw();
if (div) {
this.controlDiv.appendChild( div );
}
},
/**
@@ -345,46 +343,5 @@ OpenLayers.Map.prototype = {
container.style.top = (offsetTop - deltaY) + "px";
},
/**
* @param {Event} evt
*/
defaultDblClick: function (evt) {
var newCenter = this.getLonLatFromPixel( evt.xy );
this.setCenter(newCenter, this.zoom + 1);
},
/**
* @param {Event} evt
*/
defaultMouseDown: function (evt) {
this.mouseDragStart = evt.xy.copyOf();
this.div.style.cursor = "move";
Event.stop(evt);
},
/**
* @param {Event} evt
*/
defaultMouseMove: function (evt) {
if (this.mouseDragStart != null) {
var deltaX = this.mouseDragStart.x - evt.xy.x;
var deltaY = this.mouseDragStart.y - evt.xy.y
var size = this.getSize();
var newXY = new OpenLayers.Pixel(size.w / 2 + deltaX,
size.h / 2 + deltaY);
var newCenter = this.getLonLatFromPixel( newXY );
this.setCenter(newCenter);
this.mouseDragStart = evt.xy.copyOf();
}
},
/**
* @param {Event} evt
*/
defaultMouseUp: function (evt) {
this.mouseDragStart = null;
this.div.style.cursor = "default";
},
CLASS_NAME: "OpenLayers.Map"
};