1
/* Copyright (c) 2006-2008 MetaCarta, Inc., published under the Clear BSD
2
* license. See http://svn.openlayers.org/trunk/openlayers/license.txt for the
3
* full text of the license. */
6
* @requires OpenLayers/Control.js
10
* Class: OpenLayers.Control.MouseDefaults
12
* This class is DEPRECATED in 2.4 and will be removed by 3.0.
13
* If you need this functionality, use Control.Navigation instead!!!
16
* - <OpenLayers.Control>
18
OpenLayers.Control.MouseDefaults = OpenLayers.Class(OpenLayers.Control, {
20
/** WARNING WARNING WARNING!!!
21
This class is DEPRECATED in 2.4 and will be removed by 3.0.
22
If you need this functionality, use Control.Navigation instead!!! */
25
* Property: performedDrag
31
* Property: wheelObserver
37
* Constructor: OpenLayers.Control.MouseDefaults
39
initialize: function() {
40
OpenLayers.Control.prototype.initialize.apply(this, arguments);
49
this.handler.destroy();
54
"click": this.defaultClick,
55
"dblclick": this.defaultDblClick,
56
"mousedown": this.defaultMouseDown,
57
"mouseup": this.defaultMouseUp,
58
"mousemove": this.defaultMouseMove,
59
"mouseout": this.defaultMouseOut,
63
//unregister mousewheel events specifically on the window and document
64
OpenLayers.Event.stopObserving(window, "DOMMouseScroll",
66
OpenLayers.Event.stopObserving(window, "mousewheel",
68
OpenLayers.Event.stopObserving(document, "mousewheel",
70
this.wheelObserver = null;
72
OpenLayers.Control.prototype.destroy.apply(this, arguments);
80
"click": this.defaultClick,
81
"dblclick": this.defaultDblClick,
82
"mousedown": this.defaultMouseDown,
83
"mouseup": this.defaultMouseUp,
84
"mousemove": this.defaultMouseMove,
85
"mouseout": this.defaultMouseOut,
89
this.registerWheelEvents();
94
* Method: registerWheelEvents
96
registerWheelEvents: function() {
98
this.wheelObserver = OpenLayers.Function.bindAsEventListener(
99
this.onWheelEvent, this
102
//register mousewheel events specifically on the window and document
103
OpenLayers.Event.observe(window, "DOMMouseScroll", this.wheelObserver);
104
OpenLayers.Event.observe(window, "mousewheel", this.wheelObserver);
105
OpenLayers.Event.observe(document, "mousewheel", this.wheelObserver);
109
* Method: defaultClick
117
defaultClick: function (evt) {
118
if (!OpenLayers.Event.isLeftClick(evt)) {
121
var notAfterDrag = !this.performedDrag;
122
this.performedDrag = false;
127
* Method: defaultDblClick
132
defaultDblClick: function (evt) {
133
var newCenter = this.map.getLonLatFromViewPortPx( evt.xy );
134
this.map.setCenter(newCenter, this.map.zoom + 1);
135
OpenLayers.Event.stop(evt);
140
* Method: defaultMouseDown
145
defaultMouseDown: function (evt) {
146
if (!OpenLayers.Event.isLeftClick(evt)) {
149
this.mouseDragStart = evt.xy.clone();
150
this.performedDrag = false;
152
this.map.div.style.cursor = "crosshair";
153
this.zoomBox = OpenLayers.Util.createDiv('zoomBox',
159
this.zoomBox.style.backgroundColor = "white";
160
this.zoomBox.style.filter = "alpha(opacity=50)"; // IE
161
this.zoomBox.style.opacity = "0.50";
162
this.zoomBox.style.fontSize = "1px";
163
this.zoomBox.style.zIndex = this.map.Z_INDEX_BASE["Popup"] - 1;
164
this.map.viewPortDiv.appendChild(this.zoomBox);
166
document.onselectstart=function() { return false; };
167
OpenLayers.Event.stop(evt);
171
* Method: defaultMouseMove
176
defaultMouseMove: function (evt) {
177
// record the mouse position, used in onWheelEvent
178
this.mousePosition = evt.xy.clone();
180
if (this.mouseDragStart != null) {
182
var deltaX = Math.abs(this.mouseDragStart.x - evt.xy.x);
183
var deltaY = Math.abs(this.mouseDragStart.y - evt.xy.y);
184
this.zoomBox.style.width = Math.max(1, deltaX) + "px";
185
this.zoomBox.style.height = Math.max(1, deltaY) + "px";
186
if (evt.xy.x < this.mouseDragStart.x) {
187
this.zoomBox.style.left = evt.xy.x+"px";
189
if (evt.xy.y < this.mouseDragStart.y) {
190
this.zoomBox.style.top = evt.xy.y+"px";
193
var deltaX = this.mouseDragStart.x - evt.xy.x;
194
var deltaY = this.mouseDragStart.y - evt.xy.y;
195
var size = this.map.getSize();
196
var newXY = new OpenLayers.Pixel(size.w / 2 + deltaX,
197
size.h / 2 + deltaY);
198
var newCenter = this.map.getLonLatFromViewPortPx( newXY );
199
this.map.setCenter(newCenter, null, true);
200
this.mouseDragStart = evt.xy.clone();
201
this.map.div.style.cursor = "move";
203
this.performedDrag = true;
208
* Method: defaultMouseUp
211
* evt - {<OpenLayers.Event>}
213
defaultMouseUp: function (evt) {
214
if (!OpenLayers.Event.isLeftClick(evt)) {
218
this.zoomBoxEnd(evt);
220
if (this.performedDrag) {
221
this.map.setCenter(this.map.center);
224
document.onselectstart=null;
225
this.mouseDragStart = null;
226
this.map.div.style.cursor = "";
230
* Method: defaultMouseOut
235
defaultMouseOut: function (evt) {
236
if (this.mouseDragStart != null &&
237
OpenLayers.Util.mouseLeft(evt, this.map.div)) {
239
this.removeZoomBox();
241
this.mouseDragStart = null;
247
* Method: defaultWheelUp
248
* User spun scroll wheel up
251
defaultWheelUp: function(evt) {
252
if (this.map.getZoom() <= this.map.getNumZoomLevels()) {
253
this.map.setCenter(this.map.getLonLatFromPixel(evt.xy),
254
this.map.getZoom() + 1);
259
* Method: defaultWheelDown
260
* User spun scroll wheel down
262
defaultWheelDown: function(evt) {
263
if (this.map.getZoom() > 0) {
264
this.map.setCenter(this.map.getLonLatFromPixel(evt.xy),
265
this.map.getZoom() - 1);
273
zoomBoxEnd: function(evt) {
274
if (this.mouseDragStart != null) {
275
if (Math.abs(this.mouseDragStart.x - evt.xy.x) > 5 ||
276
Math.abs(this.mouseDragStart.y - evt.xy.y) > 5) {
277
var start = this.map.getLonLatFromViewPortPx( this.mouseDragStart );
278
var end = this.map.getLonLatFromViewPortPx( evt.xy );
279
var top = Math.max(start.lat, end.lat);
280
var bottom = Math.min(start.lat, end.lat);
281
var left = Math.min(start.lon, end.lon);
282
var right = Math.max(start.lon, end.lon);
283
var bounds = new OpenLayers.Bounds(left, bottom, right, top);
284
this.map.zoomToExtent(bounds);
286
var end = this.map.getLonLatFromViewPortPx( evt.xy );
287
this.map.setCenter(new OpenLayers.LonLat(
290
), this.map.getZoom() + 1);
292
this.removeZoomBox();
297
* Method: removeZoomBox
298
* Remove the zoombox from the screen and nullify our reference to it.
300
removeZoomBox: function() {
301
this.map.viewPortDiv.removeChild(this.zoomBox);
307
* Mouse ScrollWheel code thanks to http://adomas.org/javascript-mouse-wheel/
312
* Method: onWheelEvent
313
* Catch the wheel event and handle it xbrowserly
318
onWheelEvent: function(e){
320
// first determine whether or not the wheeling was inside the map
322
var elem = OpenLayers.Event.element(e);
323
while(elem != null) {
324
if (this.map && elem == this.map.div) {
328
elem = elem.parentNode;
338
delta = e.wheelDelta/120;
339
if (window.opera && window.opera.version() < 9.2) {
342
} else if (e.detail) {
343
delta = -e.detail / 3;
346
// add the mouse position to the event because mozilla has a bug
347
// with clientX and clientY (see https://bugzilla.mozilla.org/show_bug.cgi?id=352179)
348
// getLonLatFromViewPortPx(e) returns wrong values
349
e.xy = this.mousePosition;
352
this.defaultWheelDown(e);
354
this.defaultWheelUp(e);
358
//only wheel the map, not the window
359
OpenLayers.Event.stop(e);
363
CLASS_NAME: "OpenLayers.Control.MouseDefaults"