Merge vector-2.4 branch back to trunk.
svn merge sandbox/vector-2.4/@2307 sandbox/vector-2.4/@HEAD trunk/openlayers/ git-svn-id: http://svn.openlayers.org/trunk/openlayers@2803 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
126
lib/OpenLayers/Handler/Box.js
Normal file
126
lib/OpenLayers/Handler/Box.js
Normal file
@@ -0,0 +1,126 @@
|
||||
/* 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. */
|
||||
|
||||
/**
|
||||
* Handler for dragging a rectangle across the map. Box is displayed
|
||||
* on mouse down, moves on mouse move, and is finished on mouse up.
|
||||
*
|
||||
* @class
|
||||
* @requires OpenLayers/Handler.js
|
||||
*/
|
||||
OpenLayers.Handler.Box = OpenLayers.Class.create();
|
||||
OpenLayers.Handler.Box.prototype = OpenLayers.Class.inherit( OpenLayers.Handler, {
|
||||
/**
|
||||
* @type OpenLayers.Handler.Drag
|
||||
*/
|
||||
dragHandler: null,
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
*
|
||||
* @param {OpenLayers.Control} control
|
||||
* @param {Object} callbacks An object containing a single function to be
|
||||
* called when the drag operation is finished.
|
||||
* The callback should expect to recieve a single
|
||||
* argument, the point geometry.
|
||||
* @param {Object} options
|
||||
*/
|
||||
initialize: function(control, callbacks, options) {
|
||||
OpenLayers.Handler.prototype.initialize.apply(this, arguments);
|
||||
var callbacks = {
|
||||
"down": this.startBox,
|
||||
"move": this.moveBox,
|
||||
"out": this.removeBox,
|
||||
"up": this.endBox
|
||||
};
|
||||
this.dragHandler = new OpenLayers.Handler.Drag(
|
||||
this, callbacks, {keyMask: this.keyMask});
|
||||
},
|
||||
|
||||
setMap: function (map) {
|
||||
OpenLayers.Handler.prototype.setMap.apply(this, arguments);
|
||||
if (this.dragHandler) {
|
||||
this.dragHandler.setMap(map);
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* @param {Event} evt
|
||||
*/
|
||||
startBox: function (xy) {
|
||||
this.zoomBox = OpenLayers.Util.createDiv('zoomBox',
|
||||
this.dragHandler.start,
|
||||
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.viewPortDiv.appendChild(this.zoomBox);
|
||||
|
||||
// TBD: use CSS classes instead
|
||||
this.map.div.style.cursor = "crosshair";
|
||||
},
|
||||
|
||||
/**
|
||||
*/
|
||||
moveBox: function (xy) {
|
||||
var deltaX = Math.abs(this.dragHandler.start.x - xy.x);
|
||||
var deltaY = Math.abs(this.dragHandler.start.y - xy.y);
|
||||
this.zoomBox.style.width = Math.max(1, deltaX) + "px";
|
||||
this.zoomBox.style.height = Math.max(1, deltaY) + "px";
|
||||
if (xy.x < this.dragHandler.start.x) {
|
||||
this.zoomBox.style.left = xy.x+"px";
|
||||
}
|
||||
if (xy.y < this.dragHandler.start.y) {
|
||||
this.zoomBox.style.top = xy.y+"px";
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
*/
|
||||
endBox: function(end) {
|
||||
var result;
|
||||
if (Math.abs(this.dragHandler.start.x - end.x) > 5 ||
|
||||
Math.abs(this.dragHandler.start.y - end.y) > 5) {
|
||||
var start = this.dragHandler.start;
|
||||
var top = Math.min(start.y, end.y);
|
||||
var bottom = Math.max(start.y, end.y);
|
||||
var left = Math.min(start.x, end.x);
|
||||
var right = Math.max(start.x, end.x);
|
||||
result = new OpenLayers.Bounds(left, bottom, right, top);
|
||||
} else {
|
||||
result = this.dragHandler.start.clone(); // i.e. OL.Pixel
|
||||
}
|
||||
this.removeBox();
|
||||
|
||||
// TBD: use CSS classes instead
|
||||
this.map.div.style.cursor = "default";
|
||||
|
||||
this.callback("done", [result]);
|
||||
},
|
||||
|
||||
/**
|
||||
* Remove the zoombox from the screen and nullify our reference to it.
|
||||
*/
|
||||
removeBox: function() {
|
||||
this.map.viewPortDiv.removeChild(this.zoomBox);
|
||||
this.zoomBox = null;
|
||||
},
|
||||
|
||||
activate: function () {
|
||||
OpenLayers.Handler.prototype.activate.apply(this, arguments);
|
||||
this.dragHandler.activate();
|
||||
},
|
||||
|
||||
deactivate: function () {
|
||||
OpenLayers.Handler.prototype.deactivate.apply(this, arguments);
|
||||
this.dragHandler.deactivate();
|
||||
},
|
||||
|
||||
CLASS_NAME: "OpenLayers.Handler.Box"
|
||||
});
|
||||
110
lib/OpenLayers/Handler/Drag.js
Normal file
110
lib/OpenLayers/Handler/Drag.js
Normal file
@@ -0,0 +1,110 @@
|
||||
/* 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. */
|
||||
|
||||
/**
|
||||
* Handler for dragging a rectangle across the map. Drag is displayed
|
||||
* on mouse down, moves on mouse move, and is finished on mouse up.
|
||||
*
|
||||
* @class
|
||||
* @requires OpenLayers/Handler.js
|
||||
* @requires OpenLayers/Events.js
|
||||
*/
|
||||
OpenLayers.Handler.Drag = OpenLayers.Class.create();
|
||||
OpenLayers.Handler.Drag.prototype = OpenLayers.Class.inherit( OpenLayers.Handler, {
|
||||
/**
|
||||
* When a mousedown event is received, we want to record it, but not set
|
||||
* 'dragging' until the mouse moves after starting.
|
||||
*
|
||||
* @type boolean
|
||||
**/
|
||||
started: false,
|
||||
|
||||
/** @type boolean **/
|
||||
dragging: null,
|
||||
|
||||
/** @type OpenLayers.Pixel **/
|
||||
start: null,
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
*
|
||||
* @param {OpenLayers.Control} control
|
||||
* @param {Object} callbacks An object containing a single function to be
|
||||
* called when the drag operation is finished.
|
||||
* The callback should expect to recieve a single
|
||||
* argument, the point geometry.
|
||||
* @param {Object} options
|
||||
*/
|
||||
initialize: function(control, callbacks, options) {
|
||||
OpenLayers.Handler.prototype.initialize.apply(this, arguments);
|
||||
},
|
||||
|
||||
mousedown: function (evt) {
|
||||
if (this.checkModifiers(evt) && OpenLayers.Event.isLeftClick(evt)) {
|
||||
this.started = true;
|
||||
this.dragging = null;
|
||||
this.start = evt.xy.clone();
|
||||
// TBD replace with CSS classes
|
||||
this.map.div.style.cursor = "move";
|
||||
this.callback("down", [evt.xy]);
|
||||
OpenLayers.Event.stop(evt);
|
||||
return false;
|
||||
}
|
||||
},
|
||||
|
||||
mousemove: function (evt) {
|
||||
if (this.started) {
|
||||
this.dragging = true;
|
||||
this.callback("move", [evt.xy]);
|
||||
}
|
||||
},
|
||||
|
||||
mouseup: function (evt) {
|
||||
if (this.started) {
|
||||
this.started = false;
|
||||
// TBD replace with CSS classes
|
||||
this.map.div.style.cursor = "default";
|
||||
this.callback("up", [evt.xy]);
|
||||
}
|
||||
},
|
||||
|
||||
mouseout: function (evt) {
|
||||
if (this.started && OpenLayers.Util.mouseLeft(evt, this.map.div)) {
|
||||
this.started = false;
|
||||
this.dragging = null;
|
||||
// TBD replace with CSS classes
|
||||
this.map.div.style.cursor = "default";
|
||||
this.callback("out", []);
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* @param {Event} evt
|
||||
*
|
||||
* @type Boolean
|
||||
*/
|
||||
click: function (evt) {
|
||||
// throw away the first left click event that happens after a mouse up
|
||||
if (OpenLayers.Event.isLeftClick(evt) && this.dragging != null) {
|
||||
this.dragging = null;
|
||||
return false;
|
||||
}
|
||||
this.started = false;
|
||||
},
|
||||
|
||||
activate: function (evt) {
|
||||
OpenLayers.Handler.prototype.activate.apply(this, arguments);
|
||||
document.onselectstart = function() { return false; };
|
||||
this.dragging = null;
|
||||
},
|
||||
|
||||
deactivate: function (evt) {
|
||||
OpenLayers.Handler.prototype.deactivate.apply(this, arguments);
|
||||
document.onselectstart = null;
|
||||
this.dragging = null;
|
||||
},
|
||||
|
||||
/** @final @type String */
|
||||
CLASS_NAME: "OpenLayers.Handler.Drag"
|
||||
});
|
||||
59
lib/OpenLayers/Handler/Keyboard.js
Normal file
59
lib/OpenLayers/Handler/Keyboard.js
Normal file
@@ -0,0 +1,59 @@
|
||||
/* 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. */
|
||||
|
||||
/**
|
||||
* Handler for dragging a rectangle across the map. Keyboard is displayed
|
||||
* on mouse down, moves on mouse move, and is finished on mouse up.
|
||||
*
|
||||
* @class
|
||||
* @requires OpenLayers/Handler.js
|
||||
* @requires OpenLayers/Events.js
|
||||
*/
|
||||
OpenLayers.Handler.Keyboard = OpenLayers.Class.create();
|
||||
OpenLayers.Handler.Keyboard.prototype = OpenLayers.Class.inherit( OpenLayers.Handler, {
|
||||
|
||||
/* http://www.quirksmode.org/js/keys.html explains key x-browser
|
||||
key handling quirks in pretty nice detail */
|
||||
|
||||
/* supported named callbacks are: keyup, keydown, keypress */
|
||||
|
||||
/** constant */
|
||||
KEY_EVENTS: ["keydown", "keypress", "keyup"],
|
||||
|
||||
/** @type Function
|
||||
* @private
|
||||
*/
|
||||
eventListener: null,
|
||||
|
||||
initialize: function () {
|
||||
OpenLayers.Handler.prototype.initialize.apply(this, arguments);
|
||||
// cache the bound event listener method so it can be unobserved later
|
||||
this.eventListener = this.handleKeyEvent.bindAsEventListener(this);
|
||||
},
|
||||
|
||||
activate: function() {
|
||||
OpenLayers.Handler.prototype.activate.apply(this, arguments);
|
||||
for (var i = 0; i < this.KEY_EVENTS.length; i++) {
|
||||
OpenLayers.Event.observe(
|
||||
window, this.KEY_EVENTS[i], this.eventListener);
|
||||
}
|
||||
},
|
||||
|
||||
deactivate: function() {
|
||||
OpenLayers.Handler.prototype.activate.apply(this, arguments);
|
||||
for (var i = 0; i < this.KEY_EVENTS.length; i++) {
|
||||
OpenLayers.Event.stopObserving(
|
||||
document, this.KEY_EVENTS[i], this.eventListener);
|
||||
}
|
||||
},
|
||||
|
||||
handleKeyEvent: function (evt) {
|
||||
if (this.checkModifiers(evt)) {
|
||||
this.callback(evt.type, [evt.charCode || evt.keyCode]);
|
||||
}
|
||||
},
|
||||
|
||||
/** @final @type String */
|
||||
CLASS_NAME: "OpenLayers.Handler.Keyboard"
|
||||
});
|
||||
105
lib/OpenLayers/Handler/MouseWheel.js
Normal file
105
lib/OpenLayers/Handler/MouseWheel.js
Normal file
@@ -0,0 +1,105 @@
|
||||
/* 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. */
|
||||
|
||||
/**
|
||||
* Handler for wheel up/down events.
|
||||
*
|
||||
* @class
|
||||
* @requires OpenLayers/Handler.js
|
||||
*/
|
||||
OpenLayers.Handler.MouseWheel = OpenLayers.Class.create();
|
||||
OpenLayers.Handler.MouseWheel.prototype = OpenLayers.Class.inherit( OpenLayers.Handler, {
|
||||
/** @type function **/
|
||||
wheelListener: null,
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
*
|
||||
* @param {OpenLayers.Control} control
|
||||
* @param {Object} callbacks An object containing a single function to be
|
||||
* called when the drag operation is finished.
|
||||
* The callback should expect to recieve a single
|
||||
* argument, the point geometry.
|
||||
* @param {Object} options
|
||||
*/
|
||||
initialize: function(control, callbacks, options) {
|
||||
OpenLayers.Handler.prototype.initialize.apply(this, arguments);
|
||||
this.wheelListener = this.onWheelEvent.bindAsEventListener(this);
|
||||
},
|
||||
|
||||
/**
|
||||
* 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 check keyboard modifiers
|
||||
if (!this.checkModifiers(e)) return;
|
||||
|
||||
// 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) {
|
||||
// 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
|
||||
// TODO FIXME FIXME this might not be the right way to port the 2.3 behavior
|
||||
e.xy = this.map.events.getMousePosition(e);
|
||||
if (delta < 0) {
|
||||
this.callback("down", [e, delta]);
|
||||
} else {
|
||||
this.callback("up", [e, delta]);
|
||||
}
|
||||
}
|
||||
|
||||
//only wheel the map, not the window
|
||||
OpenLayers.Event.stop(e);
|
||||
}
|
||||
},
|
||||
|
||||
activate: function (evt) {
|
||||
OpenLayers.Handler.prototype.activate.apply(this, arguments);
|
||||
//register mousewheel events specifically on the window and document
|
||||
var wheelListener = this.wheelListener;
|
||||
OpenLayers.Event.observe(window, "DOMMouseScroll", wheelListener);
|
||||
OpenLayers.Event.observe(window, "mousewheel", wheelListener);
|
||||
OpenLayers.Event.observe(document, "mousewheel", wheelListener);
|
||||
},
|
||||
|
||||
deactivate: function (evt) {
|
||||
OpenLayers.Handler.prototype.deactivate.apply(this, arguments);
|
||||
// unregister mousewheel events specifically on the window and document
|
||||
var wheelListener = this.wheelListener;
|
||||
OpenLayers.Event.stopObserving(window, "DOMMouseScroll", wheelListener);
|
||||
OpenLayers.Event.stopObserving(window, "mousewheel", wheelListener);
|
||||
OpenLayers.Event.stopObserving(document, "mousewheel", wheelListener);
|
||||
},
|
||||
|
||||
/** @final @type String */
|
||||
CLASS_NAME: "OpenLayers.Handler.MouseWheel"
|
||||
});
|
||||
216
lib/OpenLayers/Handler/Path.js
Normal file
216
lib/OpenLayers/Handler/Path.js
Normal file
@@ -0,0 +1,216 @@
|
||||
/* 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. */
|
||||
|
||||
|
||||
/**
|
||||
* Handler to draw a path on the map. Path is displayed on mouse down,
|
||||
* moves on mouse move, and is finished on mouse up.
|
||||
*
|
||||
* @class
|
||||
* @requires OpenLayers/Handler/Point.js
|
||||
* @requires OpenLayers/Geometry/Point.js
|
||||
* @requires OpenLayers/Geometry/LineString.js
|
||||
*/
|
||||
OpenLayers.Handler.Path = OpenLayers.Class.create();
|
||||
OpenLayers.Handler.Path.prototype =
|
||||
OpenLayers.Class.inherit(OpenLayers.Handler.Point, {
|
||||
|
||||
/**
|
||||
* @type OpenLayers.Geometry.LineString
|
||||
* @private
|
||||
*/
|
||||
line: null,
|
||||
|
||||
/**
|
||||
* In freehand mode, the handler starts the path on mouse down, adds a point
|
||||
* for every mouse move, and finishes the path on mouse up. Outside of
|
||||
* freehand mode, a point is added to the path on every mouse click and
|
||||
* double-click finishes the path.
|
||||
*
|
||||
* @type Boolean
|
||||
*/
|
||||
freehand: false,
|
||||
|
||||
/**
|
||||
* If set, freehandToggle is checked on mouse events and will set the
|
||||
* freehand mode to the opposite of this.freehand. To disallow toggling
|
||||
* between freehand and non-freehand mode, set freehandToggle to null.
|
||||
* Acceptable toggle values are 'shiftKey', 'ctrlKey', and 'altKey'.
|
||||
*
|
||||
* @type String
|
||||
*/
|
||||
freehandToggle: 'shiftKey',
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
*
|
||||
* @param {OpenLayers.Control} control
|
||||
* @param {Array} callbacks An object with a 'done' property whos value is
|
||||
* a function to be called when the path drawing is
|
||||
* finished. The callback should expect to recieve a
|
||||
* single argument, the line string geometry.
|
||||
* If the callbacks object contains a 'point'
|
||||
* property, this function will be sent each point
|
||||
* as they are added. If the callbacks object contains
|
||||
* a 'cancel' property, this function will be called when
|
||||
* the handler is deactivated while drawing. The cancel
|
||||
* should expect to receive a geometry.
|
||||
* @param {Object} options
|
||||
*/
|
||||
initialize: function(control, callbacks, options) {
|
||||
OpenLayers.Handler.Point.prototype.initialize.apply(this, arguments);
|
||||
},
|
||||
|
||||
/**
|
||||
* Add temporary geometries
|
||||
*/
|
||||
createGeometry: function() {
|
||||
this.line = new OpenLayers.Geometry.LineString();
|
||||
this.point = new OpenLayers.Geometry.Point();
|
||||
},
|
||||
|
||||
/**
|
||||
* Destroy temporary geometries
|
||||
*/
|
||||
destroyGeometry: function() {
|
||||
this.line.destroy();
|
||||
this.point.destroy();
|
||||
},
|
||||
|
||||
/**
|
||||
* Add point to geometry
|
||||
*/
|
||||
addPoint: function() {
|
||||
this.line.addComponent(this.point.clone());
|
||||
},
|
||||
|
||||
/**
|
||||
* Determine whether to behanve in freehand mode or not.
|
||||
*
|
||||
* @type Boolean
|
||||
*/
|
||||
freehandMode: function(evt) {
|
||||
return (this.freehandToggle && evt[this.freehandToggle]) ?
|
||||
!this.freehand : this.freehand;
|
||||
},
|
||||
|
||||
/**
|
||||
* Modify the existing geometry given the new point
|
||||
*
|
||||
*/
|
||||
modifyGeometry: function() {
|
||||
var index = this.line.components.length - 1;
|
||||
this.line.components[index].setX(this.point.x);
|
||||
this.line.components[index].setY(this.point.y);
|
||||
},
|
||||
|
||||
/**
|
||||
* Render geometries on the temporary layer.
|
||||
*/
|
||||
drawGeometry: function() {
|
||||
this.layer.renderer.drawGeometry(this.line, this.style);
|
||||
this.layer.renderer.drawGeometry(this.point, this.style);
|
||||
},
|
||||
|
||||
/**
|
||||
* Return a clone of the relevant geometry.
|
||||
*
|
||||
* @type OpenLayers.Geometry.LineString
|
||||
*/
|
||||
geometryClone: function() {
|
||||
return this.line.clone();
|
||||
},
|
||||
|
||||
/**
|
||||
* Handle mouse down. Add a new point to the geometry and render it.
|
||||
* Return determines whether to propagate the event on the map.
|
||||
*
|
||||
* @param {Event} evt
|
||||
* @type Boolean
|
||||
*/
|
||||
mousedown: function(evt) {
|
||||
// ignore double-clicks
|
||||
if (this.lastDown && this.lastDown.equals(evt.xy)) {
|
||||
return false;
|
||||
}
|
||||
if(this.lastDown == null) {
|
||||
this.createGeometry();
|
||||
}
|
||||
this.mouseDown = true;
|
||||
this.lastDown = evt.xy;
|
||||
var lonlat = this.control.map.getLonLatFromPixel(evt.xy);
|
||||
this.point.setX(lonlat.lon);
|
||||
this.point.setY(lonlat.lat);
|
||||
if((this.lastUp == null) || !this.lastUp.equals(evt.xy)) {
|
||||
this.addPoint();
|
||||
}
|
||||
this.drawGeometry();
|
||||
this.drawing = true;
|
||||
return false;
|
||||
},
|
||||
|
||||
/**
|
||||
* Handle mouse move. Adjust the geometry and redraw.
|
||||
* Return determines whether to propagate the event on the map.
|
||||
*
|
||||
* @param {Event} evt
|
||||
* @type Boolean
|
||||
*/
|
||||
mousemove: function (evt) {
|
||||
if(this.drawing) {
|
||||
var lonlat = this.map.getLonLatFromPixel(evt.xy);
|
||||
this.point.setX(lonlat.lon);
|
||||
this.point.setY(lonlat.lat);
|
||||
if(this.mouseDown && this.freehandMode(evt)) {
|
||||
this.addPoint();
|
||||
} else {
|
||||
this.modifyGeometry();
|
||||
}
|
||||
this.drawGeometry();
|
||||
}
|
||||
return true;
|
||||
},
|
||||
|
||||
/**
|
||||
* Handle mouse up. Send the latest point in the geometry to the control.
|
||||
* Return determines whether to propagate the event on the map.
|
||||
*
|
||||
* @param {Event} evt
|
||||
* @type Boolean
|
||||
*/
|
||||
mouseup: function (evt) {
|
||||
this.mouseDown = false;
|
||||
if(this.drawing) {
|
||||
if(this.freehandMode(evt)) {
|
||||
this.finalize();
|
||||
} else {
|
||||
if(this.lastUp == null) {
|
||||
this.addPoint();
|
||||
}
|
||||
this.lastUp = evt.xy;
|
||||
this.callback("point", [this.point]);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
},
|
||||
|
||||
/**
|
||||
* Handle double-clicks. Finish the geometry and send it back
|
||||
* to the control.
|
||||
*
|
||||
* @param {Event} evt
|
||||
*/
|
||||
dblclick: function(evt) {
|
||||
if(!this.freehandMode(evt)) {
|
||||
var index = this.line.components.length - 1;
|
||||
this.line.removeComponent(this.line.components[index]);
|
||||
this.finalize(this.line);
|
||||
}
|
||||
return false;
|
||||
},
|
||||
|
||||
/** @final @type String */
|
||||
CLASS_NAME: "OpenLayers.Handler.Path"
|
||||
});
|
||||
232
lib/OpenLayers/Handler/Point.js
Normal file
232
lib/OpenLayers/Handler/Point.js
Normal file
@@ -0,0 +1,232 @@
|
||||
/* 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. */
|
||||
|
||||
|
||||
/**
|
||||
* Handler to draw a point on the map. Point is displayed on mouse down,
|
||||
* moves on mouse move, and is finished on mouse up.
|
||||
*
|
||||
* @class
|
||||
* @requires OpenLayers/Handler.js
|
||||
* @requires OpenLayers/Geometry/Point.js
|
||||
*/
|
||||
OpenLayers.Handler.Point = OpenLayers.Class.create();
|
||||
OpenLayers.Handler.Point.prototype =
|
||||
OpenLayers.Class.inherit(OpenLayers.Handler, {
|
||||
|
||||
/**
|
||||
* @type OpenLayers.Geometry.Point
|
||||
* @private
|
||||
*/
|
||||
point: null,
|
||||
|
||||
/**
|
||||
* @type OpenLayers.Layer.Vector
|
||||
* @private
|
||||
*/
|
||||
layer: null,
|
||||
|
||||
/**
|
||||
* @type Boolean
|
||||
* @private
|
||||
*/
|
||||
drawing: false,
|
||||
|
||||
/**
|
||||
* @type Boolean
|
||||
* @private
|
||||
*/
|
||||
mouseDown: false,
|
||||
|
||||
/**
|
||||
* @type OpenLayers.Pixel
|
||||
* @private
|
||||
*/
|
||||
lastDown: null,
|
||||
|
||||
/**
|
||||
* @type OpenLayers.Pixel
|
||||
* @private
|
||||
*/
|
||||
lastUp: null,
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
*
|
||||
* @param {OpenLayers.Control} control
|
||||
* @param {Array} callbacks An object with a 'done' property whos value is
|
||||
* a function to be called when the point drawing
|
||||
* is finished. The callback should expect to
|
||||
* recieve a single argument, the point geometry.
|
||||
* If the callbacks object contains a 'cancel' property,
|
||||
* this function will be called when the handler is deactivated
|
||||
* while drawing. The cancel should expect to receive a geometry.
|
||||
* @param {Object} options
|
||||
*/
|
||||
initialize: function(control, callbacks, options) {
|
||||
// TBD: deal with style
|
||||
this.style = OpenLayers.Util.extend(OpenLayers.Feature.Vector.style['default'], {});
|
||||
|
||||
OpenLayers.Handler.prototype.initialize.apply(this, arguments);
|
||||
},
|
||||
|
||||
/**
|
||||
* turn on the handler
|
||||
*/
|
||||
activate: function() {
|
||||
if(!OpenLayers.Handler.prototype.activate.apply(this, arguments)) {
|
||||
return false;
|
||||
}
|
||||
// create temporary vector layer for rendering geometry sketch
|
||||
// TBD: this could be moved to initialize/destroy - setting visibility here
|
||||
var options = {displayInLayerSwitcher: false};
|
||||
this.layer = new OpenLayers.Layer.Vector(this.CLASS_NAME, options);
|
||||
this.map.addLayer(this.layer);
|
||||
return true;
|
||||
},
|
||||
|
||||
/**
|
||||
* Add temporary geometries
|
||||
*/
|
||||
createGeometry: function() {
|
||||
this.point = new OpenLayers.Geometry.Point();
|
||||
},
|
||||
|
||||
/**
|
||||
* turn off the handler
|
||||
*/
|
||||
deactivate: function() {
|
||||
if(!OpenLayers.Handler.prototype.deactivate.apply(this, arguments)) {
|
||||
return false;
|
||||
}
|
||||
// call the cancel callback if mid-drawing
|
||||
if(this.drawing) {
|
||||
this.cancel();
|
||||
}
|
||||
this.map.removeLayer(this.layer, false);
|
||||
this.layer.destroy();
|
||||
return true;
|
||||
},
|
||||
|
||||
/**
|
||||
* Destroy the temporary geometries
|
||||
*/
|
||||
destroyGeometry: function() {
|
||||
this.point.destroy();
|
||||
},
|
||||
|
||||
/**
|
||||
* Finish the geometry and call the "done" callback.
|
||||
*/
|
||||
finalize: function() {
|
||||
this.layer.renderer.clear();
|
||||
this.callback("done", [this.geometryClone()]);
|
||||
this.destroyGeometry();
|
||||
this.drawing = false;
|
||||
this.mouseDown = false;
|
||||
this.lastDown = null;
|
||||
this.lastUp = null;
|
||||
},
|
||||
|
||||
/**
|
||||
* Finish the geometry and call the "cancel" callback.
|
||||
*/
|
||||
cancel: function() {
|
||||
this.layer.renderer.clear();
|
||||
this.callback("cancel", [this.geometryClone()]);
|
||||
this.destroyGeometry();
|
||||
this.drawing = false;
|
||||
this.mouseDown = false;
|
||||
this.lastDown = null;
|
||||
this.lastUp = null;
|
||||
},
|
||||
|
||||
/**
|
||||
* Handle double clicks.
|
||||
*/
|
||||
dblclick: function(evt) {
|
||||
OpenLayers.Event.stop(evt);
|
||||
return false;
|
||||
},
|
||||
|
||||
/**
|
||||
* Render geometries on the temporary layer.
|
||||
*/
|
||||
drawGeometry: function() {
|
||||
this.layer.renderer.drawGeometry(this.point, this.style);
|
||||
},
|
||||
|
||||
/**
|
||||
* Return a clone of the relevant geometry.
|
||||
*
|
||||
* @type OpenLayers.Geometry.Point
|
||||
*/
|
||||
geometryClone: function() {
|
||||
return this.point.clone();
|
||||
},
|
||||
|
||||
/**
|
||||
* Handle mouse down. Add a new point to the geometry and render it.
|
||||
* Return determines whether to propagate the event on the map.
|
||||
*
|
||||
* @param {Event} evt
|
||||
* @type Boolean
|
||||
*/
|
||||
mousedown: function(evt) {
|
||||
// check keyboard modifiers
|
||||
if(!this.checkModifiers(evt)) {
|
||||
return true;
|
||||
}
|
||||
// ignore double-clicks
|
||||
if(this.lastDown && this.lastDown.equals(evt.xy)) {
|
||||
return true;
|
||||
}
|
||||
if(this.lastDown == null) {
|
||||
this.createGeometry();
|
||||
}
|
||||
this.lastDown = evt.xy;
|
||||
this.drawing = true;
|
||||
var lonlat = this.map.getLonLatFromPixel(evt.xy);
|
||||
this.point.setX(lonlat.lon);
|
||||
this.point.setY(lonlat.lat);
|
||||
this.drawGeometry();
|
||||
return false;
|
||||
},
|
||||
|
||||
/**
|
||||
* Handle mouse move. Adjust the geometry and redraw.
|
||||
* Return determines whether to propagate the event on the map.
|
||||
*
|
||||
* @param {Event} evt
|
||||
* @type Boolean
|
||||
*/
|
||||
mousemove: function (evt) {
|
||||
if(this.drawing) {
|
||||
var lonlat = this.map.getLonLatFromPixel(evt.xy);
|
||||
this.point.setX(lonlat.lon);
|
||||
this.point.setY(lonlat.lat);
|
||||
this.drawGeometry();
|
||||
}
|
||||
return true;
|
||||
},
|
||||
|
||||
/**
|
||||
* Handle mouse up. Send the latest point in the geometry to the control.
|
||||
* Return determines whether to propagate the event on the map.
|
||||
*
|
||||
* @param {Event} evt
|
||||
* @type Boolean
|
||||
*/
|
||||
mouseup: function (evt) {
|
||||
if(this.drawing) {
|
||||
this.finalize(this.point);
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
},
|
||||
|
||||
/** @final @type String */
|
||||
CLASS_NAME: "OpenLayers.Handler.Point"
|
||||
});
|
||||
91
lib/OpenLayers/Handler/Polygon.js
Normal file
91
lib/OpenLayers/Handler/Polygon.js
Normal file
@@ -0,0 +1,91 @@
|
||||
/* 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. */
|
||||
|
||||
|
||||
/**
|
||||
* Handler to draw a path on the map. Polygon is displayed on mouse down,
|
||||
* moves on mouse move, and is finished on mouse up.
|
||||
*
|
||||
* @class
|
||||
* @requires OpenLayers/Handler/Path.js
|
||||
* @requires OpenLayers/Geometry/Polygon.js
|
||||
*/
|
||||
OpenLayers.Handler.Polygon = OpenLayers.Class.create();
|
||||
OpenLayers.Handler.Polygon.prototype =
|
||||
OpenLayers.Class.inherit(OpenLayers.Handler.Path, {
|
||||
|
||||
/**
|
||||
* @type OpenLayers.Geometry.Polygon
|
||||
* @private
|
||||
*/
|
||||
polygon: null,
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
*
|
||||
* @param {OpenLayers.Control} control
|
||||
* @param {Array} callbacks An object with a 'done' property whos value is
|
||||
* a function to be called when the path drawing is
|
||||
* finished. The callback should expect to recieve a
|
||||
* single argument, the polygon geometry.
|
||||
* If the callbacks object contains a 'point'
|
||||
* property, this function will be sent each point
|
||||
* as they are added. If the callbacks object contains
|
||||
* a 'cancel' property, this function will be called when
|
||||
* the handler is deactivated while drawing. The cancel
|
||||
* should expect to receive a geometry.
|
||||
* @param {Object} options
|
||||
*/
|
||||
initialize: function(control, callbacks, options) {
|
||||
OpenLayers.Handler.Path.prototype.initialize.apply(this, arguments);
|
||||
},
|
||||
|
||||
/**
|
||||
* Add temporary geometries
|
||||
*/
|
||||
createGeometry: function() {
|
||||
this.polygon = new OpenLayers.Geometry.Polygon();
|
||||
this.line = new OpenLayers.Geometry.LinearRing();
|
||||
this.polygon.addComponent(this.line);
|
||||
this.point = new OpenLayers.Geometry.Point();
|
||||
},
|
||||
|
||||
/**
|
||||
* Destroy temporary geometries
|
||||
*/
|
||||
destroyGeometry: function() {
|
||||
this.polygon.destroy();
|
||||
this.point.destroy();
|
||||
},
|
||||
|
||||
/**
|
||||
* Modify the existing geometry given the new point
|
||||
*
|
||||
*/
|
||||
modifyGeometry: function() {
|
||||
var index = this.line.components.length - 2;
|
||||
this.line.components[index].setX(this.point.x);
|
||||
this.line.components[index].setY(this.point.y);
|
||||
},
|
||||
|
||||
/**
|
||||
* Render geometries on the temporary layer.
|
||||
*/
|
||||
drawGeometry: function() {
|
||||
this.layer.renderer.drawGeometry(this.polygon, this.style);
|
||||
this.layer.renderer.drawGeometry(this.point, this.style);
|
||||
},
|
||||
|
||||
/**
|
||||
* Return a clone of the relevant geometry.
|
||||
*
|
||||
* @type OpenLayers.Geometry.Polygon
|
||||
*/
|
||||
geometryClone: function() {
|
||||
return this.polygon.clone();
|
||||
},
|
||||
|
||||
/** @final @type String */
|
||||
CLASS_NAME: "OpenLayers.Handler.Polygon"
|
||||
});
|
||||
122
lib/OpenLayers/Handler/Select.js
Normal file
122
lib/OpenLayers/Handler/Select.js
Normal file
@@ -0,0 +1,122 @@
|
||||
/* 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. */
|
||||
|
||||
|
||||
/**
|
||||
* Handler to draw a path on the map. Polygon is displayed on mouse down,
|
||||
* moves on mouse move, and is finished on mouse up.
|
||||
*
|
||||
* @class
|
||||
* @requires OpenLayers/Handler.js
|
||||
*/
|
||||
OpenLayers.Handler.Select = OpenLayers.Class.create();
|
||||
OpenLayers.Handler.Select.prototype =
|
||||
OpenLayers.Class.inherit(OpenLayers.Handler, {
|
||||
|
||||
/**
|
||||
* @type {Int}
|
||||
*/
|
||||
layerIndex: null,
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
*
|
||||
* @param {OpenLayers.Control} control
|
||||
* @param {Array} layers List of OpenLayers.Layer.Vector
|
||||
* @param {Array} callbacks An object with a 'over' property whos value is
|
||||
* a function to be called when the mouse is over
|
||||
* a feature. The callback should expect to recieve
|
||||
* a single argument, the geometry.
|
||||
* @param {Object} options
|
||||
*/
|
||||
initialize: function(control, layer, callbacks, options) {
|
||||
OpenLayers.Handler.prototype.initialize.apply(this, [control, callbacks, options]);
|
||||
this.layer = layer;
|
||||
},
|
||||
|
||||
/**
|
||||
* Handle mouse down. Call the "up" callback if down on a feature.
|
||||
*
|
||||
* @param {Event} evt
|
||||
*/
|
||||
mousedown: function(evt) {
|
||||
return this.select('down', evt);
|
||||
},
|
||||
|
||||
/**
|
||||
* Handle mouse moves. Call the "over" callback if over a feature.
|
||||
*
|
||||
* @param {Event} evt
|
||||
*/
|
||||
mousemove: function(evt) {
|
||||
this.select('move', evt);
|
||||
return true;
|
||||
},
|
||||
|
||||
/**
|
||||
* Handle mouse moves. Call the "down" callback if up on a feature.
|
||||
*
|
||||
* @param {Event} evt
|
||||
*/
|
||||
mouseup: function(evt) {
|
||||
return this.select('up', evt);
|
||||
},
|
||||
|
||||
/**
|
||||
* Capture double-clicks.
|
||||
*
|
||||
*/
|
||||
dblclick: function(evt) {
|
||||
return false;
|
||||
},
|
||||
|
||||
/**
|
||||
* Trigger the appropriate callback if a feature is under the mouse.
|
||||
*
|
||||
* @param {String} type Callback key
|
||||
*/
|
||||
select: function(type, evt) {
|
||||
var geometry = this.layer.renderer.getGeometryFromEvent(evt);
|
||||
if(geometry) {
|
||||
if (geometry.parent) {
|
||||
geometry = geometry.parent;
|
||||
}
|
||||
this.callback(type, [geometry]);
|
||||
return false; // stop event propagation
|
||||
}
|
||||
return true;
|
||||
},
|
||||
|
||||
/**
|
||||
* Turn on the handler. Returns false if the handler was already active.
|
||||
*
|
||||
* @type {Boolean}
|
||||
*/
|
||||
activate: function() {
|
||||
if(OpenLayers.Handler.prototype.activate.apply(this, arguments)) {
|
||||
this.layerIndex = this.layer.div.style.zIndex;
|
||||
this.layer.div.style.zIndex = this.map.Z_INDEX_BASE['Popup'] - 1;
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Turn onf the handler. Returns false if the handler was already active.
|
||||
*
|
||||
* @type {Boolean}
|
||||
*/
|
||||
deactivate: function() {
|
||||
if(OpenLayers.Handler.prototype.deactivate.apply(this, arguments)) {
|
||||
this.layer.div.style.zIndex = this.layerIndex;
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
},
|
||||
|
||||
/** @final @type String */
|
||||
CLASS_NAME: "OpenLayers.Handler.Select"
|
||||
});
|
||||
Reference in New Issue
Block a user