git-svn-id: http://svn.openlayers.org/trunk/openlayers@5614 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
157 lines
4.5 KiB
JavaScript
157 lines
4.5 KiB
JavaScript
/* Copyright (c) 2006-2008 MetaCarta, Inc., published under the Clear BSD
|
|
* license. See http://svn.openlayers.org/trunk/openlayers/license.txt for the
|
|
* full text of the license. */
|
|
|
|
/**
|
|
* @requires OpenLayers/Control/ZoomBox.js
|
|
* @requires OpenLayers/Control/DragPan.js
|
|
* @requires OpenLayers/Handler/MouseWheel.js
|
|
* @requires OpenLayers/Handler/Click.js
|
|
*/
|
|
|
|
/**
|
|
* Class: OpenLayers.Control.Navigation
|
|
* The navigation control handles map browsing with mouse events (dragging,
|
|
* double-clicking, and scrolling the wheel). Create a new navigation
|
|
* control with the <OpenLayers.Control.Navigation> control.
|
|
*
|
|
* Note that this control is added to the map by default (if no controls
|
|
* array is sent in the options object to the <OpenLayers.Map>
|
|
* constructor).
|
|
*
|
|
* Inherits:
|
|
* - <OpenLayers.Control>
|
|
*/
|
|
OpenLayers.Control.Navigation = OpenLayers.Class(OpenLayers.Control, {
|
|
|
|
/**
|
|
* Property: dragPan
|
|
* {<OpenLayers.Control.DragPan>}
|
|
*/
|
|
dragPan: null,
|
|
|
|
/**
|
|
* Property: zoomBox
|
|
* {<OpenLayers.Control.ZoomBox>}
|
|
*/
|
|
zoomBox: null,
|
|
|
|
/**
|
|
* Property: wheelHandler
|
|
* {<OpenLayers.Handler.MouseWheel>}
|
|
*/
|
|
wheelHandler: null,
|
|
|
|
/**
|
|
* Constructor: OpenLayers.Control.Navigation
|
|
* Create a new navigation control
|
|
*
|
|
* Parameters:
|
|
* options - {Object} An optional object whose properties will be set on
|
|
* the control
|
|
*/
|
|
initialize: function(options) {
|
|
OpenLayers.Control.prototype.initialize.apply(this, arguments);
|
|
},
|
|
|
|
/**
|
|
* Method: activate
|
|
*/
|
|
activate: function() {
|
|
this.dragPan.activate();
|
|
this.wheelHandler.activate();
|
|
this.clickHandler.activate();
|
|
this.zoomBox.activate();
|
|
return OpenLayers.Control.prototype.activate.apply(this,arguments);
|
|
},
|
|
|
|
/**
|
|
* Method: deactivate
|
|
*/
|
|
deactivate: function() {
|
|
this.zoomBox.deactivate();
|
|
this.dragPan.deactivate();
|
|
this.clickHandler.deactivate();
|
|
this.wheelHandler.deactivate();
|
|
return OpenLayers.Control.prototype.deactivate.apply(this,arguments);
|
|
},
|
|
|
|
/**
|
|
* Method: draw
|
|
*/
|
|
draw: function() {
|
|
this.clickHandler = new OpenLayers.Handler.Click(this,
|
|
{ 'dblclick': this.defaultDblClick },
|
|
{
|
|
'double': true,
|
|
'stopDouble': true
|
|
});
|
|
this.dragPan = new OpenLayers.Control.DragPan({map: this.map});
|
|
this.zoomBox = new OpenLayers.Control.ZoomBox(
|
|
{map: this.map, keyMask: OpenLayers.Handler.MOD_SHIFT});
|
|
this.dragPan.draw();
|
|
this.zoomBox.draw();
|
|
this.wheelHandler = new OpenLayers.Handler.MouseWheel(
|
|
this, {"up" : this.wheelUp,
|
|
"down": this.wheelDown} );
|
|
this.activate();
|
|
},
|
|
|
|
/**
|
|
* Method: defaultDblClick
|
|
*
|
|
* Parameters:
|
|
* evt - {Event}
|
|
*/
|
|
defaultDblClick: function (evt) {
|
|
var newCenter = this.map.getLonLatFromViewPortPx( evt.xy );
|
|
this.map.setCenter(newCenter, this.map.zoom + 1);
|
|
},
|
|
|
|
/**
|
|
* Method: wheelChange
|
|
*
|
|
* Parameters:
|
|
* evt - {Event}
|
|
*/
|
|
wheelChange: function(evt, deltaZ) {
|
|
var newZoom = this.map.getZoom() + deltaZ;
|
|
if (!this.map.isValidZoomLevel(newZoom)) {
|
|
return;
|
|
}
|
|
var size = this.map.getSize();
|
|
var deltaX = size.w/2 - evt.xy.x;
|
|
var deltaY = evt.xy.y - size.h/2;
|
|
var newRes = this.map.baseLayer.resolutions[newZoom];
|
|
var zoomPoint = this.map.getLonLatFromPixel(evt.xy);
|
|
var newCenter = new OpenLayers.LonLat(
|
|
zoomPoint.lon + deltaX * newRes,
|
|
zoomPoint.lat + deltaY * newRes );
|
|
this.map.setCenter( newCenter, newZoom );
|
|
},
|
|
|
|
/**
|
|
* Method: wheelUp
|
|
* User spun scroll wheel up
|
|
*
|
|
* Parameters:
|
|
* evt - {Event}
|
|
*/
|
|
wheelUp: function(evt) {
|
|
this.wheelChange(evt, 1);
|
|
},
|
|
|
|
/**
|
|
* Method: wheelDown
|
|
* User spun scroll wheel down
|
|
*
|
|
* Parameters:
|
|
* evt - {Event}
|
|
*/
|
|
wheelDown: function(evt) {
|
|
this.wheelChange(evt, -1);
|
|
},
|
|
|
|
CLASS_NAME: "OpenLayers.Control.Navigation"
|
|
});
|