diff --git a/examples/panel.html b/examples/panel.html index 685bdacf37..be9785c192 100644 --- a/examples/panel.html +++ b/examples/panel.html @@ -16,14 +16,6 @@ background-color:white; } - .olControlPanel .olControlMouseDefaultsItemActive { - background-color: blue; - background-image: url("../theme/default/img/pan_on.png"); - } - .olControlPanel .olControlMouseDefaultsItemInactive { - background-color: orange; - background-image: url("../theme/default/img/pan_off.png"); - } .olControlPanel .olControlDrawFeatureItemActive { width: 22px; height: 22px; @@ -75,8 +67,6 @@ {title:"Zoom box: Selecting it you can zoom on an area by clicking and dragging."}); var panel = new OpenLayers.Control.Panel({defaultControl: zb}); panel.addControls([ - new OpenLayers.Control.MouseDefaults( - {title:'You can use the default mouse configuration'}), zb, new OpenLayers.Control.DrawFeature(vlayer, OpenLayers.Handler.Path, {title:'Draw a feature'}), diff --git a/examples/zoomify.html b/examples/zoomify.html index 3bec55bb9f..6b610aad83 100644 --- a/examples/zoomify.html +++ b/examples/zoomify.html @@ -23,7 +23,6 @@ /* Map with raster coordinates (pixels) from Zoomify image */ var options = { - controls: [], maxExtent: new OpenLayers.Bounds(0, 0, zoomify_width, zoomify_height), maxResolution: Math.pow(2, zoomify.numberOfTiers-1 ), numZoomLevels: zoomify.numberOfTiers, @@ -33,11 +32,6 @@ map = new OpenLayers.Map("map", options); map.addLayer(zoomify); - map.addControl(new OpenLayers.Control.MousePosition()); - map.addControl(new OpenLayers.Control.PanZoomBar()); - map.addControl(new OpenLayers.Control.MouseDefaults()); - map.addControl(new OpenLayers.Control.KeyboardDefaults()); - map.setBaseLayer(zoomify); map.zoomToMaxExtent(); }; diff --git a/lib/OpenLayers.js b/lib/OpenLayers.js index ea8db02c37..e0c7ea19c1 100644 --- a/lib/OpenLayers.js +++ b/lib/OpenLayers.js @@ -185,7 +185,6 @@ "OpenLayers/Control/Navigation.js", "OpenLayers/Control/PinchZoom.js", "OpenLayers/Control/TouchNavigation.js", - "OpenLayers/Control/MouseDefaults.js", "OpenLayers/Control/MousePosition.js", "OpenLayers/Control/OverviewMap.js", "OpenLayers/Control/KeyboardDefaults.js", @@ -343,7 +342,6 @@ "OpenLayers/Format/OGCExceptionReport.js", "OpenLayers/Layer/WFS.js", "OpenLayers/Control/GetFeature.js", - "OpenLayers/Control/MouseToolbar.js", "OpenLayers/Control/NavToolbar.js", "OpenLayers/Control/PanPanel.js", "OpenLayers/Control/Pan.js", diff --git a/lib/OpenLayers/Control.js b/lib/OpenLayers/Control.js index 2b127b991d..0ca4627c29 100644 --- a/lib/OpenLayers/Control.js +++ b/lib/OpenLayers/Control.js @@ -22,7 +22,6 @@ * > var map = new OpenLayers.Map('map', { controls: [] }); * > * > map.addControl(new OpenLayers.Control.PanZoomBar()); - * > map.addControl(new OpenLayers.Control.MouseToolbar()); * > map.addControl(new OpenLayers.Control.LayerSwitcher({'ascending':false})); * > map.addControl(new OpenLayers.Control.Permalink()); * > map.addControl(new OpenLayers.Control.Permalink('permalink')); diff --git a/lib/OpenLayers/Control/MouseDefaults.js b/lib/OpenLayers/Control/MouseDefaults.js deleted file mode 100644 index cc71164b4a..0000000000 --- a/lib/OpenLayers/Control/MouseDefaults.js +++ /dev/null @@ -1,368 +0,0 @@ -/* Copyright (c) 2006-2011 by OpenLayers Contributors (see authors.txt for - * full list of contributors). 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.js - */ - -/** - * Class: OpenLayers.Control.MouseDefaults - * This class is DEPRECATED in 2.4 and will be removed by 3.0. - * If you need this functionality, use - * instead!!! - * - * This class is DEPRECATED in 2.4 and will be removed by 3.0. - * If you need this functionality, use Control.Navigation instead!!! - * - * Inherits from: - * - - */ -OpenLayers.Control.MouseDefaults = OpenLayers.Class(OpenLayers.Control, { - - /** WARNING WARNING WARNING!!! - This class is DEPRECATED in 2.4 and will be removed by 3.0. - If you need this functionality, use Control.Navigation instead!!! */ - - /** - * Property: performedDrag - * {Boolean} - */ - performedDrag: false, - - /** - * Property: wheelObserver - * {Function} - */ - wheelObserver: null, - - /** - * Constructor: OpenLayers.Control.MouseDefaults - */ - initialize: function() { - OpenLayers.Control.prototype.initialize.apply(this, arguments); - }, - - /** - * APIMethod: destroy - */ - destroy: function() { - - if (this.handler) { - this.handler.destroy(); - } - this.handler = null; - - this.map.events.un({ - "click": this.defaultClick, - "dblclick": this.defaultDblClick, - "mousedown": this.defaultMouseDown, - "mouseup": this.defaultMouseUp, - "mousemove": this.defaultMouseMove, - "mouseout": this.defaultMouseOut, - scope: this - }); - - //unregister mousewheel events specifically on the window and document - OpenLayers.Event.stopObserving(window, "DOMMouseScroll", - this.wheelObserver); - OpenLayers.Event.stopObserving(window, "mousewheel", - this.wheelObserver); - OpenLayers.Event.stopObserving(document, "mousewheel", - this.wheelObserver); - this.wheelObserver = null; - - OpenLayers.Control.prototype.destroy.apply(this, arguments); - }, - - /** - * Method: draw - */ - draw: function() { - this.map.events.on({ - "click": this.defaultClick, - "dblclick": this.defaultDblClick, - "mousedown": this.defaultMouseDown, - "mouseup": this.defaultMouseUp, - "mousemove": this.defaultMouseMove, - "mouseout": this.defaultMouseOut, - scope: this - }); - - this.registerWheelEvents(); - - }, - - /** - * Method: registerWheelEvents - */ - registerWheelEvents: function() { - - this.wheelObserver = OpenLayers.Function.bindAsEventListener( - this.onWheelEvent, this - ); - - //register mousewheel events specifically on the window and document - OpenLayers.Event.observe(window, "DOMMouseScroll", this.wheelObserver); - OpenLayers.Event.observe(window, "mousewheel", this.wheelObserver); - OpenLayers.Event.observe(document, "mousewheel", this.wheelObserver); - }, - - /** - * Method: defaultClick - * - * Parameters: - * evt - {Event} - * - * Returns: - * {Boolean} - */ - defaultClick: function (evt) { - if (!OpenLayers.Event.isLeftClick(evt)) { - return; - } - var notAfterDrag = !this.performedDrag; - this.performedDrag = false; - return notAfterDrag; - }, - - /** - * Method: defaultDblClick - * - * Parameters: - * evt - {Event} - */ - defaultDblClick: function (evt) { - var newCenter = this.map.getLonLatFromViewPortPx( evt.xy ); - this.map.setCenter(newCenter, this.map.zoom + 1); - OpenLayers.Event.stop(evt); - return false; - }, - - /** - * Method: defaultMouseDown - * - * Parameters: - * evt - {Event} - */ - defaultMouseDown: function (evt) { - if (!OpenLayers.Event.isLeftClick(evt)) { - return; - } - this.mouseDragStart = evt.xy.clone(); - this.performedDrag = false; - if (evt.shiftKey) { - this.map.div.style.cursor = "crosshair"; - this.zoomBox = OpenLayers.Util.createDiv('zoomBox', - this.mouseDragStart, - null, - null, - "absolute", - "2px solid red"); - this.zoomBox.style.backgroundColor = "white"; - this.zoomBox.style.filter = "alpha(opacity=50)"; // IE - this.zoomBox.style.opacity = "0.50"; - this.zoomBox.style.fontSize = "1px"; - this.zoomBox.style.zIndex = this.map.Z_INDEX_BASE["Popup"] - 1; - this.map.eventsDiv.appendChild(this.zoomBox); - } - document.onselectstart = OpenLayers.Function.False; - OpenLayers.Event.stop(evt); - }, - - /** - * Method: defaultMouseMove - * - * Parameters: - * evt - {Event} - */ - defaultMouseMove: function (evt) { - // record the mouse position, used in onWheelEvent - this.mousePosition = evt.xy.clone(); - - if (this.mouseDragStart != null) { - if (this.zoomBox) { - var deltaX = Math.abs(this.mouseDragStart.x - evt.xy.x); - var deltaY = Math.abs(this.mouseDragStart.y - evt.xy.y); - this.zoomBox.style.width = Math.max(1, deltaX) + "px"; - this.zoomBox.style.height = Math.max(1, deltaY) + "px"; - if (evt.xy.x < this.mouseDragStart.x) { - this.zoomBox.style.left = evt.xy.x+"px"; - } - if (evt.xy.y < this.mouseDragStart.y) { - this.zoomBox.style.top = evt.xy.y+"px"; - } - } else { - var deltaX = this.mouseDragStart.x - evt.xy.x; - var deltaY = this.mouseDragStart.y - evt.xy.y; - var size = this.map.getSize(); - var newXY = new OpenLayers.Pixel(size.w / 2 + deltaX, - size.h / 2 + deltaY); - var newCenter = this.map.getLonLatFromViewPortPx( newXY ); - this.map.setCenter(newCenter, null, true); - this.mouseDragStart = evt.xy.clone(); - this.map.div.style.cursor = "move"; - } - this.performedDrag = true; - } - }, - - /** - * Method: defaultMouseUp - * - * Parameters: - * evt - {} - */ - defaultMouseUp: function (evt) { - if (!OpenLayers.Event.isLeftClick(evt)) { - return; - } - if (this.zoomBox) { - this.zoomBoxEnd(evt); - } else { - if (this.performedDrag) { - this.map.setCenter(this.map.center); - } - } - document.onselectstart=null; - this.mouseDragStart = null; - this.map.div.style.cursor = ""; - }, - - /** - * Method: defaultMouseOut - * - * Parameters: - * evt - {Event} - */ - defaultMouseOut: function (evt) { - if (this.mouseDragStart != null && - OpenLayers.Util.mouseLeft(evt, this.map.eventsDiv)) { - if (this.zoomBox) { - this.removeZoomBox(); - } - this.mouseDragStart = null; - } - }, - - - /** - * Method: defaultWheelUp - * User spun scroll wheel up - * - */ - defaultWheelUp: function(evt) { - if (this.map.getZoom() <= this.map.getNumZoomLevels()) { - this.map.setCenter(this.map.getLonLatFromPixel(evt.xy), - this.map.getZoom() + 1); - } - }, - - /** - * Method: defaultWheelDown - * User spun scroll wheel down - */ - defaultWheelDown: function(evt) { - if (this.map.getZoom() > 0) { - this.map.setCenter(this.map.getLonLatFromPixel(evt.xy), - this.map.getZoom() - 1); - } - }, - - /** - * Method: zoomBoxEnd - * Zoombox function. - */ - zoomBoxEnd: function(evt) { - if (this.mouseDragStart != null) { - if (Math.abs(this.mouseDragStart.x - evt.xy.x) > 5 || - Math.abs(this.mouseDragStart.y - evt.xy.y) > 5) { - var start = this.map.getLonLatFromViewPortPx( this.mouseDragStart ); - var end = this.map.getLonLatFromViewPortPx( evt.xy ); - var top = Math.max(start.lat, end.lat); - var bottom = Math.min(start.lat, end.lat); - var left = Math.min(start.lon, end.lon); - var right = Math.max(start.lon, end.lon); - var bounds = new OpenLayers.Bounds(left, bottom, right, top); - this.map.zoomToExtent(bounds); - } else { - var end = this.map.getLonLatFromViewPortPx( evt.xy ); - this.map.setCenter(new OpenLayers.LonLat( - (end.lon), - (end.lat) - ), this.map.getZoom() + 1); - } - this.removeZoomBox(); - } - }, - - /** - * Method: removeZoomBox - * Remove the zoombox from the screen and nullify our reference to it. - */ - removeZoomBox: function() { - this.map.eventsDiv.removeChild(this.zoomBox); - this.zoomBox = null; - }, - - -/** - * Mouse ScrollWheel code thanks to http://adomas.org/javascript-mouse-wheel/ - */ - - - /** - * Method: onWheelEvent - * Catch the wheel event and handle it xbrowserly - * - * Parameters: - * e - {Event} - */ - 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 && window.opera.version() < 9.2) { - delta = -delta; - } - } else if (e.detail) { - delta = -e.detail / 3; - } - if (delta) { - // add the mouse position to the event because mozilla has a bug - // with clientX and clientY (see https://bugzilla.mozilla.org/show_bug.cgi?id=352179) - // getLonLatFromViewPortPx(e) returns wrong values - e.xy = this.mousePosition; - - if (delta < 0) { - this.defaultWheelDown(e); - } else { - this.defaultWheelUp(e); - } - } - - //only wheel the map, not the window - OpenLayers.Event.stop(e); - } - }, - - CLASS_NAME: "OpenLayers.Control.MouseDefaults" -}); diff --git a/lib/OpenLayers/Control/MouseToolbar.js b/lib/OpenLayers/Control/MouseToolbar.js deleted file mode 100644 index 9400c1791a..0000000000 --- a/lib/OpenLayers/Control/MouseToolbar.js +++ /dev/null @@ -1,406 +0,0 @@ -/* Copyright (c) 2006-2011 by OpenLayers Contributors (see authors.txt for - * full list of contributors). 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.js - * @requires OpenLayers/Control/MouseDefaults.js - */ - -/** - * Class: OpenLayers.Control.MouseToolbar - * This class is DEPRECATED in 2.4 and will be removed by 3.0. - * If you need this functionality, use - * instead!!! - */ -OpenLayers.Control.MouseToolbar = OpenLayers.Class( - OpenLayers.Control.MouseDefaults, { - - /** - * Property: mode - */ - mode: null, - /** - * Property: buttons - */ - buttons: null, - - /** - * APIProperty: direction - * {String} 'vertical' or 'horizontal' - */ - direction: "vertical", - - /** - * Property: buttonClicked - * {String} - */ - buttonClicked: null, - - /** - * Constructor: OpenLayers.Control.MouseToolbar - * - * Parameters: - * position - {} - * direction - {String} - */ - initialize: function(position, direction) { - OpenLayers.Control.prototype.initialize.apply(this, arguments); - this.position = new OpenLayers.Pixel(OpenLayers.Control.MouseToolbar.X, - OpenLayers.Control.MouseToolbar.Y); - if (position) { - this.position = position; - } - if (direction) { - this.direction = direction; - } - this.measureDivs = []; - }, - - /** - * APIMethod: destroy - */ - destroy: function() { - for( var btnId in this.buttons) { - var btn = this.buttons[btnId]; - btn.map = null; - btn.events.destroy(); - } - OpenLayers.Control.MouseDefaults.prototype.destroy.apply(this, - arguments); - }, - - /** - * Method: draw - */ - draw: function() { - OpenLayers.Control.prototype.draw.apply(this, arguments); - OpenLayers.Control.MouseDefaults.prototype.draw.apply(this, arguments); - this.buttons = {}; - var sz = new OpenLayers.Size(28,28); - var centered = new OpenLayers.Pixel(OpenLayers.Control.MouseToolbar.X,0); - this._addButton("zoombox", "drag-rectangle-off.png", "drag-rectangle-on.png", centered, sz, "Shift->Drag to zoom to area"); - centered = centered.add((this.direction == "vertical" ? 0 : sz.w), (this.direction == "vertical" ? sz.h : 0)); - this._addButton("pan", "panning-hand-off.png", "panning-hand-on.png", centered, sz, "Drag the map to pan."); - centered = centered.add((this.direction == "vertical" ? 0 : sz.w), (this.direction == "vertical" ? sz.h : 0)); - this.switchModeTo("pan"); - - return this.div; - }, - - /** - * Method: _addButton - */ - _addButton:function(id, img, activeImg, xy, sz, title) { - var imgLocation = OpenLayers.Util.getImagesLocation() + img; - var activeImgLocation = OpenLayers.Util.getImagesLocation() + activeImg; - // var btn = new ol.AlphaImage("_"+id, imgLocation, xy, sz); - var btn = OpenLayers.Util.createAlphaImageDiv( - "OpenLayers_Control_MouseToolbar_" + id, - xy, sz, imgLocation, "absolute"); - - //we want to add the outer div - this.div.appendChild(btn); - btn.imgLocation = imgLocation; - btn.activeImgLocation = activeImgLocation; - - btn.events = new OpenLayers.Events(this, btn, null, true); - btn.events.on({ - "mousedown": this.buttonDown, - "mouseup": this.buttonUp, - "dblclick": OpenLayers.Event.stop, - scope: this - }); - btn.action = id; - btn.title = title; - btn.alt = title; - btn.map = this.map; - - //we want to remember/reference the outer div - this.buttons[id] = btn; - return btn; - }, - - /** - * Method: buttonDown - * - * Parameters: - * evt - {Event} - */ - buttonDown: function(evt) { - if (!OpenLayers.Event.isLeftClick(evt)) { - return; - } - this.buttonClicked = evt.element.action; - OpenLayers.Event.stop(evt); - }, - - /** - * Method: buttonUp - * - * Parameters: - * evt - {Event} - */ - buttonUp: function(evt) { - if (!OpenLayers.Event.isLeftClick(evt)) { - return; - } - if (this.buttonClicked != null) { - if (this.buttonClicked == evt.element.action) { - this.switchModeTo(evt.element.action); - } - OpenLayers.Event.stop(evt); - this.buttonClicked = null; - } - }, - - /** - * Method: defaultDblClick - * - * Parameters: - * evt - {Event} - */ - defaultDblClick: function (evt) { - this.switchModeTo("pan"); - this.performedDrag = false; - var newCenter = this.map.getLonLatFromViewPortPx( evt.xy ); - this.map.setCenter(newCenter, this.map.zoom + 1); - OpenLayers.Event.stop(evt); - return false; - }, - - /** - * Method: defaultMouseDown - * - * Parameters: - * evt - {Event} - */ - defaultMouseDown: function (evt) { - if (!OpenLayers.Event.isLeftClick(evt)) { - return; - } - this.mouseDragStart = evt.xy.clone(); - this.performedDrag = false; - this.startViaKeyboard = false; - if (evt.shiftKey && this.mode !="zoombox") { - this.switchModeTo("zoombox"); - this.startViaKeyboard = true; - } else if (evt.altKey && this.mode !="measure") { - this.switchModeTo("measure"); - } else if (!this.mode) { - this.switchModeTo("pan"); - } - - switch (this.mode) { - case "zoombox": - this.map.div.style.cursor = "crosshair"; - this.zoomBox = OpenLayers.Util.createDiv('zoomBox', - this.mouseDragStart, - null, - null, - "absolute", - "2px solid red"); - this.zoomBox.style.backgroundColor = "white"; - this.zoomBox.style.filter = "alpha(opacity=50)"; // IE - this.zoomBox.style.opacity = "0.50"; - this.zoomBox.style.fontSize = "1px"; - this.zoomBox.style.zIndex = this.map.Z_INDEX_BASE["Popup"] - 1; - this.map.eventsDiv.appendChild(this.zoomBox); - this.performedDrag = true; - break; - case "measure": - var distance = ""; - if (this.measureStart) { - var measureEnd = this.map.getLonLatFromViewPortPx(this.mouseDragStart); - distance = OpenLayers.Util.distVincenty(this.measureStart, measureEnd); - distance = Math.round(distance * 100) / 100; - distance = distance + "km"; - this.measureStartBox = this.measureBox; - } - this.measureStart = this.map.getLonLatFromViewPortPx(this.mouseDragStart);; - this.measureBox = OpenLayers.Util.createDiv(null, - this.mouseDragStart.add( - -2-parseInt(this.map.layerContainerDiv.style.left), - -2-parseInt(this.map.layerContainerDiv.style.top)), - null, - null, - "absolute"); - this.measureBox.style.width="4px"; - this.measureBox.style.height="4px"; - this.measureBox.style.fontSize = "1px"; - this.measureBox.style.backgroundColor="red"; - this.measureBox.style.zIndex = this.map.Z_INDEX_BASE["Popup"] - 1; - this.map.layerContainerDiv.appendChild(this.measureBox); - if (distance) { - this.measureBoxDistance = OpenLayers.Util.createDiv(null, - this.mouseDragStart.add( - -2-parseInt(this.map.layerContainerDiv.style.left), - 2-parseInt(this.map.layerContainerDiv.style.top)), - null, - null, - "absolute"); - - this.measureBoxDistance.innerHTML = distance; - this.measureBoxDistance.style.zIndex = this.map.Z_INDEX_BASE["Popup"] - 1; - this.map.layerContainerDiv.appendChild(this.measureBoxDistance); - this.measureDivs.push(this.measureBoxDistance); - } - this.measureBox.style.zIndex = this.map.Z_INDEX_BASE["Popup"] - 1; - this.map.layerContainerDiv.appendChild(this.measureBox); - this.measureDivs.push(this.measureBox); - break; - default: - this.map.div.style.cursor = "move"; - break; - } - document.onselectstart = OpenLayers.Function.False; - OpenLayers.Event.stop(evt); - }, - - /** - * Method: switchModeTo - * - * Parameters: - * mode - {String} - */ - switchModeTo: function(mode) { - if (mode != this.mode) { - - - if (this.mode && this.buttons[this.mode]) { - OpenLayers.Util.modifyAlphaImageDiv(this.buttons[this.mode], null, null, null, this.buttons[this.mode].imgLocation); - } - if (this.mode == "measure" && mode != "measure") { - for(var i=0, len=this.measureDivs.length; i + * instead!!! + * + * This class is DEPRECATED in 2.4 and will be removed by 3.0. + * If you need this functionality, use Control.Navigation instead!!! + * + * Inherits from: + * - + */ +OpenLayers.Control.MouseDefaults = OpenLayers.Class(OpenLayers.Control, { + + /** WARNING WARNING WARNING!!! + This class is DEPRECATED in 2.4 and will be removed by 3.0. + If you need this functionality, use Control.Navigation instead!!! */ + + /** + * Property: performedDrag + * {Boolean} + */ + performedDrag: false, + + /** + * Property: wheelObserver + * {Function} + */ + wheelObserver: null, + + /** + * Constructor: OpenLayers.Control.MouseDefaults + */ + initialize: function() { + OpenLayers.Control.prototype.initialize.apply(this, arguments); + }, + + /** + * APIMethod: destroy + */ + destroy: function() { + + if (this.handler) { + this.handler.destroy(); + } + this.handler = null; + + this.map.events.un({ + "click": this.defaultClick, + "dblclick": this.defaultDblClick, + "mousedown": this.defaultMouseDown, + "mouseup": this.defaultMouseUp, + "mousemove": this.defaultMouseMove, + "mouseout": this.defaultMouseOut, + scope: this + }); + + //unregister mousewheel events specifically on the window and document + OpenLayers.Event.stopObserving(window, "DOMMouseScroll", + this.wheelObserver); + OpenLayers.Event.stopObserving(window, "mousewheel", + this.wheelObserver); + OpenLayers.Event.stopObserving(document, "mousewheel", + this.wheelObserver); + this.wheelObserver = null; + + OpenLayers.Control.prototype.destroy.apply(this, arguments); + }, + + /** + * Method: draw + */ + draw: function() { + this.map.events.on({ + "click": this.defaultClick, + "dblclick": this.defaultDblClick, + "mousedown": this.defaultMouseDown, + "mouseup": this.defaultMouseUp, + "mousemove": this.defaultMouseMove, + "mouseout": this.defaultMouseOut, + scope: this + }); + + this.registerWheelEvents(); + + }, + + /** + * Method: registerWheelEvents + */ + registerWheelEvents: function() { + + this.wheelObserver = OpenLayers.Function.bindAsEventListener( + this.onWheelEvent, this + ); + + //register mousewheel events specifically on the window and document + OpenLayers.Event.observe(window, "DOMMouseScroll", this.wheelObserver); + OpenLayers.Event.observe(window, "mousewheel", this.wheelObserver); + OpenLayers.Event.observe(document, "mousewheel", this.wheelObserver); + }, + + /** + * Method: defaultClick + * + * Parameters: + * evt - {Event} + * + * Returns: + * {Boolean} + */ + defaultClick: function (evt) { + if (!OpenLayers.Event.isLeftClick(evt)) { + return; + } + var notAfterDrag = !this.performedDrag; + this.performedDrag = false; + return notAfterDrag; + }, + + /** + * Method: defaultDblClick + * + * Parameters: + * evt - {Event} + */ + defaultDblClick: function (evt) { + var newCenter = this.map.getLonLatFromViewPortPx( evt.xy ); + this.map.setCenter(newCenter, this.map.zoom + 1); + OpenLayers.Event.stop(evt); + return false; + }, + + /** + * Method: defaultMouseDown + * + * Parameters: + * evt - {Event} + */ + defaultMouseDown: function (evt) { + if (!OpenLayers.Event.isLeftClick(evt)) { + return; + } + this.mouseDragStart = evt.xy.clone(); + this.performedDrag = false; + if (evt.shiftKey) { + this.map.div.style.cursor = "crosshair"; + this.zoomBox = OpenLayers.Util.createDiv('zoomBox', + this.mouseDragStart, + null, + null, + "absolute", + "2px solid red"); + this.zoomBox.style.backgroundColor = "white"; + this.zoomBox.style.filter = "alpha(opacity=50)"; // IE + this.zoomBox.style.opacity = "0.50"; + this.zoomBox.style.fontSize = "1px"; + this.zoomBox.style.zIndex = this.map.Z_INDEX_BASE["Popup"] - 1; + this.map.eventsDiv.appendChild(this.zoomBox); + } + document.onselectstart = OpenLayers.Function.False; + OpenLayers.Event.stop(evt); + }, + + /** + * Method: defaultMouseMove + * + * Parameters: + * evt - {Event} + */ + defaultMouseMove: function (evt) { + // record the mouse position, used in onWheelEvent + this.mousePosition = evt.xy.clone(); + + if (this.mouseDragStart != null) { + if (this.zoomBox) { + var deltaX = Math.abs(this.mouseDragStart.x - evt.xy.x); + var deltaY = Math.abs(this.mouseDragStart.y - evt.xy.y); + this.zoomBox.style.width = Math.max(1, deltaX) + "px"; + this.zoomBox.style.height = Math.max(1, deltaY) + "px"; + if (evt.xy.x < this.mouseDragStart.x) { + this.zoomBox.style.left = evt.xy.x+"px"; + } + if (evt.xy.y < this.mouseDragStart.y) { + this.zoomBox.style.top = evt.xy.y+"px"; + } + } else { + var deltaX = this.mouseDragStart.x - evt.xy.x; + var deltaY = this.mouseDragStart.y - evt.xy.y; + var size = this.map.getSize(); + var newXY = new OpenLayers.Pixel(size.w / 2 + deltaX, + size.h / 2 + deltaY); + var newCenter = this.map.getLonLatFromViewPortPx( newXY ); + this.map.setCenter(newCenter, null, true); + this.mouseDragStart = evt.xy.clone(); + this.map.div.style.cursor = "move"; + } + this.performedDrag = true; + } + }, + + /** + * Method: defaultMouseUp + * + * Parameters: + * evt - {} + */ + defaultMouseUp: function (evt) { + if (!OpenLayers.Event.isLeftClick(evt)) { + return; + } + if (this.zoomBox) { + this.zoomBoxEnd(evt); + } else { + if (this.performedDrag) { + this.map.setCenter(this.map.center); + } + } + document.onselectstart=null; + this.mouseDragStart = null; + this.map.div.style.cursor = ""; + }, + + /** + * Method: defaultMouseOut + * + * Parameters: + * evt - {Event} + */ + defaultMouseOut: function (evt) { + if (this.mouseDragStart != null && + OpenLayers.Util.mouseLeft(evt, this.map.eventsDiv)) { + if (this.zoomBox) { + this.removeZoomBox(); + } + this.mouseDragStart = null; + } + }, + + + /** + * Method: defaultWheelUp + * User spun scroll wheel up + * + */ + defaultWheelUp: function(evt) { + if (this.map.getZoom() <= this.map.getNumZoomLevels()) { + this.map.setCenter(this.map.getLonLatFromPixel(evt.xy), + this.map.getZoom() + 1); + } + }, + + /** + * Method: defaultWheelDown + * User spun scroll wheel down + */ + defaultWheelDown: function(evt) { + if (this.map.getZoom() > 0) { + this.map.setCenter(this.map.getLonLatFromPixel(evt.xy), + this.map.getZoom() - 1); + } + }, + + /** + * Method: zoomBoxEnd + * Zoombox function. + */ + zoomBoxEnd: function(evt) { + if (this.mouseDragStart != null) { + if (Math.abs(this.mouseDragStart.x - evt.xy.x) > 5 || + Math.abs(this.mouseDragStart.y - evt.xy.y) > 5) { + var start = this.map.getLonLatFromViewPortPx( this.mouseDragStart ); + var end = this.map.getLonLatFromViewPortPx( evt.xy ); + var top = Math.max(start.lat, end.lat); + var bottom = Math.min(start.lat, end.lat); + var left = Math.min(start.lon, end.lon); + var right = Math.max(start.lon, end.lon); + var bounds = new OpenLayers.Bounds(left, bottom, right, top); + this.map.zoomToExtent(bounds); + } else { + var end = this.map.getLonLatFromViewPortPx( evt.xy ); + this.map.setCenter(new OpenLayers.LonLat( + (end.lon), + (end.lat) + ), this.map.getZoom() + 1); + } + this.removeZoomBox(); + } + }, + + /** + * Method: removeZoomBox + * Remove the zoombox from the screen and nullify our reference to it. + */ + removeZoomBox: function() { + this.map.eventsDiv.removeChild(this.zoomBox); + this.zoomBox = null; + }, + + +/** + * Mouse ScrollWheel code thanks to http://adomas.org/javascript-mouse-wheel/ + */ + + + /** + * Method: onWheelEvent + * Catch the wheel event and handle it xbrowserly + * + * Parameters: + * e - {Event} + */ + 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 && window.opera.version() < 9.2) { + delta = -delta; + } + } else if (e.detail) { + delta = -e.detail / 3; + } + if (delta) { + // add the mouse position to the event because mozilla has a bug + // with clientX and clientY (see https://bugzilla.mozilla.org/show_bug.cgi?id=352179) + // getLonLatFromViewPortPx(e) returns wrong values + e.xy = this.mousePosition; + + if (delta < 0) { + this.defaultWheelDown(e); + } else { + this.defaultWheelUp(e); + } + } + + //only wheel the map, not the window + OpenLayers.Event.stop(e); + } + }, + + CLASS_NAME: "OpenLayers.Control.MouseDefaults" +}); + +/** + * Class: OpenLayers.Control.MouseToolbar + * This class is DEPRECATED in 2.4 and will be removed by 3.0. + * If you need this functionality, use + * instead!!! + */ +OpenLayers.Control.MouseToolbar = OpenLayers.Class( + OpenLayers.Control.MouseDefaults, { + + /** + * Property: mode + */ + mode: null, + /** + * Property: buttons + */ + buttons: null, + + /** + * APIProperty: direction + * {String} 'vertical' or 'horizontal' + */ + direction: "vertical", + + /** + * Property: buttonClicked + * {String} + */ + buttonClicked: null, + + /** + * Constructor: OpenLayers.Control.MouseToolbar + * + * Parameters: + * position - {} + * direction - {String} + */ + initialize: function(position, direction) { + OpenLayers.Control.prototype.initialize.apply(this, arguments); + this.position = new OpenLayers.Pixel(OpenLayers.Control.MouseToolbar.X, + OpenLayers.Control.MouseToolbar.Y); + if (position) { + this.position = position; + } + if (direction) { + this.direction = direction; + } + this.measureDivs = []; + }, + + /** + * APIMethod: destroy + */ + destroy: function() { + for( var btnId in this.buttons) { + var btn = this.buttons[btnId]; + btn.map = null; + btn.events.destroy(); + } + OpenLayers.Control.MouseDefaults.prototype.destroy.apply(this, + arguments); + }, + + /** + * Method: draw + */ + draw: function() { + OpenLayers.Control.prototype.draw.apply(this, arguments); + OpenLayers.Control.MouseDefaults.prototype.draw.apply(this, arguments); + this.buttons = {}; + var sz = new OpenLayers.Size(28,28); + var centered = new OpenLayers.Pixel(OpenLayers.Control.MouseToolbar.X,0); + this._addButton("zoombox", "drag-rectangle-off.png", "drag-rectangle-on.png", centered, sz, "Shift->Drag to zoom to area"); + centered = centered.add((this.direction == "vertical" ? 0 : sz.w), (this.direction == "vertical" ? sz.h : 0)); + this._addButton("pan", "panning-hand-off.png", "panning-hand-on.png", centered, sz, "Drag the map to pan."); + centered = centered.add((this.direction == "vertical" ? 0 : sz.w), (this.direction == "vertical" ? sz.h : 0)); + this.switchModeTo("pan"); + + return this.div; + }, + + /** + * Method: _addButton + */ + _addButton:function(id, img, activeImg, xy, sz, title) { + var imgLocation = OpenLayers.Util.getImagesLocation() + img; + var activeImgLocation = OpenLayers.Util.getImagesLocation() + activeImg; + // var btn = new ol.AlphaImage("_"+id, imgLocation, xy, sz); + var btn = OpenLayers.Util.createAlphaImageDiv( + "OpenLayers_Control_MouseToolbar_" + id, + xy, sz, imgLocation, "absolute"); + + //we want to add the outer div + this.div.appendChild(btn); + btn.imgLocation = imgLocation; + btn.activeImgLocation = activeImgLocation; + + btn.events = new OpenLayers.Events(this, btn, null, true); + btn.events.on({ + "mousedown": this.buttonDown, + "mouseup": this.buttonUp, + "dblclick": OpenLayers.Event.stop, + scope: this + }); + btn.action = id; + btn.title = title; + btn.alt = title; + btn.map = this.map; + + //we want to remember/reference the outer div + this.buttons[id] = btn; + return btn; + }, + + /** + * Method: buttonDown + * + * Parameters: + * evt - {Event} + */ + buttonDown: function(evt) { + if (!OpenLayers.Event.isLeftClick(evt)) { + return; + } + this.buttonClicked = evt.element.action; + OpenLayers.Event.stop(evt); + }, + + /** + * Method: buttonUp + * + * Parameters: + * evt - {Event} + */ + buttonUp: function(evt) { + if (!OpenLayers.Event.isLeftClick(evt)) { + return; + } + if (this.buttonClicked != null) { + if (this.buttonClicked == evt.element.action) { + this.switchModeTo(evt.element.action); + } + OpenLayers.Event.stop(evt); + this.buttonClicked = null; + } + }, + + /** + * Method: defaultDblClick + * + * Parameters: + * evt - {Event} + */ + defaultDblClick: function (evt) { + this.switchModeTo("pan"); + this.performedDrag = false; + var newCenter = this.map.getLonLatFromViewPortPx( evt.xy ); + this.map.setCenter(newCenter, this.map.zoom + 1); + OpenLayers.Event.stop(evt); + return false; + }, + + /** + * Method: defaultMouseDown + * + * Parameters: + * evt - {Event} + */ + defaultMouseDown: function (evt) { + if (!OpenLayers.Event.isLeftClick(evt)) { + return; + } + this.mouseDragStart = evt.xy.clone(); + this.performedDrag = false; + this.startViaKeyboard = false; + if (evt.shiftKey && this.mode !="zoombox") { + this.switchModeTo("zoombox"); + this.startViaKeyboard = true; + } else if (evt.altKey && this.mode !="measure") { + this.switchModeTo("measure"); + } else if (!this.mode) { + this.switchModeTo("pan"); + } + + switch (this.mode) { + case "zoombox": + this.map.div.style.cursor = "crosshair"; + this.zoomBox = OpenLayers.Util.createDiv('zoomBox', + this.mouseDragStart, + null, + null, + "absolute", + "2px solid red"); + this.zoomBox.style.backgroundColor = "white"; + this.zoomBox.style.filter = "alpha(opacity=50)"; // IE + this.zoomBox.style.opacity = "0.50"; + this.zoomBox.style.fontSize = "1px"; + this.zoomBox.style.zIndex = this.map.Z_INDEX_BASE["Popup"] - 1; + this.map.eventsDiv.appendChild(this.zoomBox); + this.performedDrag = true; + break; + case "measure": + var distance = ""; + if (this.measureStart) { + var measureEnd = this.map.getLonLatFromViewPortPx(this.mouseDragStart); + distance = OpenLayers.Util.distVincenty(this.measureStart, measureEnd); + distance = Math.round(distance * 100) / 100; + distance = distance + "km"; + this.measureStartBox = this.measureBox; + } + this.measureStart = this.map.getLonLatFromViewPortPx(this.mouseDragStart);; + this.measureBox = OpenLayers.Util.createDiv(null, + this.mouseDragStart.add( + -2-parseInt(this.map.layerContainerDiv.style.left), + -2-parseInt(this.map.layerContainerDiv.style.top)), + null, + null, + "absolute"); + this.measureBox.style.width="4px"; + this.measureBox.style.height="4px"; + this.measureBox.style.fontSize = "1px"; + this.measureBox.style.backgroundColor="red"; + this.measureBox.style.zIndex = this.map.Z_INDEX_BASE["Popup"] - 1; + this.map.layerContainerDiv.appendChild(this.measureBox); + if (distance) { + this.measureBoxDistance = OpenLayers.Util.createDiv(null, + this.mouseDragStart.add( + -2-parseInt(this.map.layerContainerDiv.style.left), + 2-parseInt(this.map.layerContainerDiv.style.top)), + null, + null, + "absolute"); + + this.measureBoxDistance.innerHTML = distance; + this.measureBoxDistance.style.zIndex = this.map.Z_INDEX_BASE["Popup"] - 1; + this.map.layerContainerDiv.appendChild(this.measureBoxDistance); + this.measureDivs.push(this.measureBoxDistance); + } + this.measureBox.style.zIndex = this.map.Z_INDEX_BASE["Popup"] - 1; + this.map.layerContainerDiv.appendChild(this.measureBox); + this.measureDivs.push(this.measureBox); + break; + default: + this.map.div.style.cursor = "move"; + break; + } + document.onselectstart = OpenLayers.Function.False; + OpenLayers.Event.stop(evt); + }, + + /** + * Method: switchModeTo + * + * Parameters: + * mode - {String} + */ + switchModeTo: function(mode) { + if (mode != this.mode) { + + + if (this.mode && this.buttons[this.mode]) { + OpenLayers.Util.modifyAlphaImageDiv(this.buttons[this.mode], null, null, null, this.buttons[this.mode].imgLocation); + } + if (this.mode == "measure" && mode != "measure") { + for(var i=0, len=this.measureDivs.length; i - + +