[OpenLayers-Commits] r2049 - in sandbox/camptocamp/advancedcontrol/lib: . OpenLayers OpenLayers/Control
commits at openlayers.org
commits at openlayers.org
Thu Dec 14 04:43:26 EST 2006
Author: bertil
Date: 2006-12-14 04:43:22 -0500 (Thu, 14 Dec 2006)
New Revision: 2049
Modified:
sandbox/camptocamp/advancedcontrol/lib/OpenLayers.js
sandbox/camptocamp/advancedcontrol/lib/OpenLayers/Control.js
sandbox/camptocamp/advancedcontrol/lib/OpenLayers/Control/MouseDefaults.js
sandbox/camptocamp/advancedcontrol/lib/OpenLayers/Control/MouseListener.js
sandbox/camptocamp/advancedcontrol/lib/OpenLayers/Map.js
Log:
a new mouseListener class manage the mouse events
Modified: sandbox/camptocamp/advancedcontrol/lib/OpenLayers/Control/MouseDefaults.js
===================================================================
--- sandbox/camptocamp/advancedcontrol/lib/OpenLayers/Control/MouseDefaults.js 2006-12-13 20:22:30 UTC (rev 2048)
+++ sandbox/camptocamp/advancedcontrol/lib/OpenLayers/Control/MouseDefaults.js 2006-12-14 09:43:22 UTC (rev 2049)
@@ -10,63 +10,19 @@
*/
OpenLayers.Control.MouseDefaults = OpenLayers.Class.create();
OpenLayers.Control.MouseDefaults.prototype =
- OpenLayers.Class.inherit( OpenLayers.Control, {
+ OpenLayers.Class.inherit( OpenLayers.Control.MouseListener, {
/** @type Boolean */
performedDrag: false,
- image: "transform-move.gif",
-
- size: new OpenLayers.Size(22,22),
-
/**
* @constructor
*/
initialize: function() {
OpenLayers.Control.prototype.initialize.apply(this, arguments);
},
-
- turnOn: function() {
- this.map.events.register( "click", this, this.defaultClick );
- this.map.events.register( "dblclick", this, this.defaultDblClick );
- this.map.events.register( "mousedown", this, this.defaultMouseDown );
- this.map.events.register( "mouseup", this, this.defaultMouseUp );
- this.map.events.register( "mousemove", this, this.defaultMouseMove );
- this.map.events.register( "mouseout", this, this.defaultMouseOut );
- this.onWheelEvent = this.onWheelEvent.bindAsEventListener(this);
- OpenLayers.Event.observe(window, "DOMMouseScroll",this.onWheelEvent , false);
- OpenLayers.Event.observe(window, "mousewheel",this.onWheelEvent , false);
- OpenLayers.Event.observe(document, "mousewheel",this.onWheelEvent , false);
- },
-
- turnOff: function() {
- this.map.events.unregister( "click", this, this.defaultClick );
- this.map.events.unregister( "dblclick", this, this.defaultDblClick );
- this.map.events.unregister( "mousedown", this, this.defaultMouseDown );
- this.map.events.unregister( "mouseup", this, this.defaultMouseUp );
- this.map.events.unregister( "mousemove", this, this.defaultMouseMove );
- this.map.events.unregister( "mouseout", this, this.defaultMouseOut );
-
- OpenLayers.Event.stopObserving(window, "DOMMouseScroll",this.onWheelEvent , false);
- OpenLayers.Event.stopObserving(window, "mousewheel",this.onWheelEvent , false);
- OpenLayers.Event.stopObserving(document, "mousewheel",this.onWheelEvent , false);
- },
-
-
/**
- *
- */
- draw: function() {
- this.map.events.register( "click", this, this.defaultClick );
- this.map.events.register( "dblclick", this, this.defaultDblClick );
- this.map.events.register( "mousedown", this, this.defaultMouseDown );
- this.map.events.register( "mouseup", this, this.defaultMouseUp );
- this.map.events.register( "mousemove", this, this.defaultMouseMove );
- this.map.events.register( "mouseout", this, this.defaultMouseOut );
- },
-
- /**
* @param {Event} evt
*
* @type Boolean
@@ -91,7 +47,7 @@
/**
* @param {Event} evt
*/
- defaultMouseDown: function (evt) {
+ mouseDown: function (evt) {
if (!OpenLayers.Event.isLeftClick(evt)) return;
this.mouseDragStart = evt.xy.clone();
this.performedDrag = false;
@@ -117,7 +73,7 @@
/**
* @param {Event} evt
*/
- defaultMouseMove: function (evt) {
+ mouseMove: function (evt) {
if (this.mouseDragStart != null) {
if (this.zoomBox) {
var deltaX = Math.abs(this.mouseDragStart.x - evt.xy.x);
@@ -148,7 +104,7 @@
/**
* @param {Event} evt
*/
- defaultMouseUp: function (evt) {
+ mouseUp: function (evt) {
if (!OpenLayers.Event.isLeftClick(evt)) return;
if (this.zoomBox) {
this.zoomBoxEnd(evt);
@@ -165,7 +121,7 @@
/**
* @param {Event} evt
*/
- defaultMouseOut: function (evt) {
+ mouseOut: function (evt) {
if (this.mouseDragStart != null &&
OpenLayers.Util.mouseLeft(evt, this.map.div)) {
if (this.zoomBox) {
@@ -175,20 +131,67 @@
}
},
+ /**
+ * Mouse ScrollWheel code thanks to http://adomas.org/javascript-mouse-wheel/
+ */
+ /** Catch the wheel event and handle it xbrowserly
+ *
+ * @param {Event} e
+ */
+ mouseWheel: function(e) {
+
+ // first determine whether or not the wheeling was inside the map
+ var inMap = false;
+ var elem = OpenLayers.Event.element(e);
+ while(elem != null) {
+ if (this.map && elem == this.map.div) {
+ inMap = true;
+ break;
+ }
+ elem = elem.parentNode;
+ }
+
+ if (inMap) {
+
+ var delta = 0;
+ if (!e) {
+ e = window.event;
+ }
+ if (e.wheelDelta) {
+ delta = e.wheelDelta/120;
+ if (window.opera) {
+ delta = -delta;
+ }
+ } else if (e.detail) {
+ delta = -e.detail / 3;
+ }
+ if (delta) {
+ if (delta < 0) {
+ this.mouseWheelDown();
+ } else {
+ this.mouseWheelUp();
+ }
+ }
+
+ //only wheel the map, not the window
+ OpenLayers.Event.stop(e);
+ }
+ },
+
/** User spun scroll wheel up
*
*/
- defaultWheelUp: function() {
+ mouseWheelUp: function() {
this.map.zoomIn();
},
/** User spun scroll wheel down
*
*/
- defaultWheelDown: function() {
+ mouseWheelDown: function() {
this.map.zoomOut();
- },
+ },
/** Zoombox function.
*
@@ -222,59 +225,8 @@
removeZoomBox: function() {
this.map.viewPortDiv.removeChild(this.zoomBox);
this.zoomBox = null;
- },
+ },
-
-/**
- * Mouse ScrollWheel code thanks to http://adomas.org/javascript-mouse-wheel/
- */
-
-
- /** Catch the wheel event and handle it xbrowserly
- *
- * @param {Event} e
- */
- onWheelEvent: function(e) {
-
- // first determine whether or not the wheeling was inside the map
- var inMap = false;
- var elem = OpenLayers.Event.element(e);
- while(elem != null) {
- if (this.map && elem == this.map.div) {
- inMap = true;
- break;
- }
- elem = elem.parentNode;
- }
-
- if (inMap) {
-
- var delta = 0;
- if (!e) {
- e = window.event;
- }
- if (e.wheelDelta) {
- delta = e.wheelDelta/120;
- if (window.opera) {
- delta = -delta;
- }
- } else if (e.detail) {
- delta = -e.detail / 3;
- }
- if (delta) {
- if (delta < 0) {
- this.defaultWheelDown();
- } else {
- this.defaultWheelUp();
- }
- }
-
- //only wheel the map, not the window
- OpenLayers.Event.stop(e);
- }
- },
-
-
/** @final @type String */
CLASS_NAME: "OpenLayers.Control.MouseDefaults"
});
Modified: sandbox/camptocamp/advancedcontrol/lib/OpenLayers/Control/MouseListener.js
===================================================================
--- sandbox/camptocamp/advancedcontrol/lib/OpenLayers/Control/MouseListener.js 2006-12-13 20:22:30 UTC (rev 2048)
+++ sandbox/camptocamp/advancedcontrol/lib/OpenLayers/Control/MouseListener.js 2006-12-14 09:43:22 UTC (rev 2049)
@@ -1,21 +1,76 @@
+/* Copyright (c) 2006 MetaCarta, Inc., published under a modified BSD license.
+ * See http://svn.openlayers.org/trunk/openlayers/repository-license.txt
+ * for the full text of the license. */
+
+/**
+ * @class
+ */
OpenLayers.Control.MouseListener = OpenLayers.Class.create();
OpenLayers.Control.MouseListener.prototype = {
+
initialize: function () {},
- /** Set the map property for the control. This is done through an accessor
- * so that subclasses can override this and take special action once
- * they have their map variable set.
+
+ /** Set the map property for the MouseListener.
*
* @param {OpenLayers.Map} map
*/
setMap: function(map) {
this.map = map;
},
+
+ /**
+ * @param {Event} evt
+ *
+ * @type Boolean
+ */
mouseClick: function (evt) {},
+
+ /**
+ * @param {Event} evt
+ *
+ * @type Boolean
+ */
mouseDblClick: function (evt) {},
+
+ /**
+ * @param {Event} evt
+ *
+ * @type Boolean
+ */
mouseUp: function (evt) {},
- mouseDown: function (evt) {console.log("test")},
+
+ /**
+ * @param {Event} evt
+ *
+ * @type Boolean
+ */
+ mouseDown: function (evt) {},
+
+ /**
+ * @param {Event} evt
+ *
+ * @type Boolean
+ */
mouseOver: function (evt) {},
+
+ /**
+ * @param {Event} evt
+ *
+ * @type Boolean
+ */
mouseOut: function (evt) {},
+
+ /**
+ * @param {Event} evt
+ *
+ * @type Boolean
+ */
mouseMove: function (evt) {},
- mouseWheel: function (evt) {}
+
+ /**
+ * @param {Event} evt
+ *
+ * @type Boolean
+ */
+ mouseWheel: function (evt) {}
}
\ No newline at end of file
Modified: sandbox/camptocamp/advancedcontrol/lib/OpenLayers/Control.js
===================================================================
--- sandbox/camptocamp/advancedcontrol/lib/OpenLayers/Control.js 2006-12-13 20:22:30 UTC (rev 2048)
+++ sandbox/camptocamp/advancedcontrol/lib/OpenLayers/Control.js 2006-12-14 09:43:22 UTC (rev 2049)
@@ -32,7 +32,9 @@
*/
initialize: function (options) {
OpenLayers.Util.extend(this, options);
- this.id = OpenLayers.Util.createUniqueID(this.CLASS_NAME + "_");
+
+ this.id = OpenLayers.Util.createUniqueID(this.CLASS_NAME + "_");
+ this.controlName = "olControl";
},
/**
@@ -52,7 +54,7 @@
setMap: function(map) {
this.map = map;
},
-
+
/**
* @param {OpenLayers.Pixel} px
*
@@ -61,16 +63,16 @@
*/
draw: function (px) {
if (this.div == null) {
- this.div = OpenLayers.Util.createDiv();
+ this.div = document.createElement("div");
this.div.id = this.id;
- this.div.className = 'olControl';
+ this.div.className = this.controlName;
}
if (px != null) {
this.position = px.clone();
}
this.moveTo(this.position);
return this.div;
- },
+ },
/**
* @param {OpenLayers.Pixel} px
Modified: sandbox/camptocamp/advancedcontrol/lib/OpenLayers/Map.js
===================================================================
--- sandbox/camptocamp/advancedcontrol/lib/OpenLayers/Map.js 2006-12-13 20:22:30 UTC (rev 2048)
+++ sandbox/camptocamp/advancedcontrol/lib/OpenLayers/Map.js 2006-12-14 09:43:22 UTC (rev 2049)
@@ -178,8 +178,7 @@
if (this.controls == null) {
if (OpenLayers.Control != null) { // running full or lite?
- this.controls = [ new OpenLayers.Control.MouseDefaults(),
- new OpenLayers.Control.PanZoom(),
+ this.controls = [ new OpenLayers.Control.PanZoom(),
new OpenLayers.Control.ArgParser()
];
} else {
@@ -197,6 +196,9 @@
OpenLayers.Event.observe(window,
'unload',
this.destroy.bindAsEventListener(this));
+
+ // initialize default mouseListener
+ this.setMouseListener(new OpenLayers.Control.MouseDefaults());
},
@@ -529,6 +531,9 @@
}
},
+ /**
+ * @param {OpenLayers.Control.MouseListener} mouseListener
+ */
setMouseListener: function(mouseListener) {
if (this.mouseListener) {
Modified: sandbox/camptocamp/advancedcontrol/lib/OpenLayers.js
===================================================================
--- sandbox/camptocamp/advancedcontrol/lib/OpenLayers.js 2006-12-13 20:22:30 UTC (rev 2048)
+++ sandbox/camptocamp/advancedcontrol/lib/OpenLayers.js 2006-12-14 09:43:22 UTC (rev 2049)
@@ -91,6 +91,8 @@
"OpenLayers/Popup/Anchored.js",
"OpenLayers/Popup/AnchoredBubble.js",
"OpenLayers/Control.js",
+ "OpenLayers/Control/Container.js",
+ "OpenLayers/Control/MouseListener.js",
"OpenLayers/Control/MouseDefaults.js",
"OpenLayers/Control/MouseToolbar.js",
"OpenLayers/Control/MousePosition.js",
More information about the Commits
mailing list