Fix lots of EOL SSTyle line ending problems.
git-svn-id: http://svn.openlayers.org/trunk/openlayers@6131 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
@@ -1,238 +1,238 @@
|
||||
/* 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/Handler.js
|
||||
*/
|
||||
|
||||
/**
|
||||
* Class: OpenLayers.Handler.Click
|
||||
* A handler for mouse clicks. The intention of this handler is to give
|
||||
* controls more flexibility with handling clicks. Browsers trigger
|
||||
* click events twice for a double-click. In addition, the mousedown,
|
||||
* mousemove, mouseup sequence fires a click event. With this handler,
|
||||
* controls can decide whether to ignore clicks associated with a double
|
||||
* click. By setting a <pixelTolerance>, controls can also ignore clicks
|
||||
* that include a drag. Create a new instance with the
|
||||
* <OpenLayers.Handler.Click> constructor.
|
||||
*
|
||||
* Inherits from:
|
||||
* - <OpenLayers.Handler>
|
||||
*/
|
||||
OpenLayers.Handler.Click = OpenLayers.Class(OpenLayers.Handler, {
|
||||
|
||||
/**
|
||||
* APIProperty: delay
|
||||
* {Number} Number of milliseconds between clicks before the event is
|
||||
* considered a double-click.
|
||||
*/
|
||||
delay: 300,
|
||||
|
||||
/**
|
||||
* APIProperty: single
|
||||
* {Boolean} Handle single clicks. Default is true. If false, clicks
|
||||
* will not be reported. If true, single-clicks will be reported.
|
||||
*/
|
||||
single: true,
|
||||
|
||||
/**
|
||||
* APIProperty: double
|
||||
* {Boolean} Handle double-clicks. Default is false.
|
||||
*/
|
||||
'double': false,
|
||||
|
||||
/**
|
||||
* APIProperty: pixelTolerance
|
||||
* {Number} Maximum number of pixels between mouseup and mousedown for an
|
||||
* event to be considered a click. Default is 0. If set to an
|
||||
* integer value, clicks with a drag greater than the value will be
|
||||
* ignored. This property can only be set when the handler is
|
||||
* constructed.
|
||||
*/
|
||||
pixelTolerance: 0,
|
||||
|
||||
/**
|
||||
* APIProperty: stopSingle
|
||||
* {Boolean} Stop other listeners from being notified of clicks. Default
|
||||
* is false. If true, any click listeners registered before this one
|
||||
* will not be notified of *any* click event (associated with double
|
||||
* or single clicks).
|
||||
*/
|
||||
stopSingle: false,
|
||||
|
||||
/**
|
||||
* APIProperty: stopDouble
|
||||
* {Boolean} Stop other listeners from being notified of double-clicks.
|
||||
* Default is false. If true, any click listeners registered before
|
||||
* this one will not be notified of *any* double-click events.
|
||||
*
|
||||
* The one caveat with stopDouble is that given a map with two click
|
||||
* handlers, one with stopDouble true and the other with stopSingle
|
||||
* true, the stopSingle handler should be activated last to get
|
||||
* uniform cross-browser performance. Since IE triggers one click
|
||||
* with a dblclick and FF triggers two, if a stopSingle handler is
|
||||
* activated first, all it gets in IE is a single click when the
|
||||
* second handler stops propagation on the dblclick.
|
||||
*/
|
||||
stopDouble: false,
|
||||
|
||||
/**
|
||||
* Property: timerId
|
||||
* {Number} The id of the timeout waiting to clear the <delayedEvent>.
|
||||
*/
|
||||
timerId: null,
|
||||
|
||||
/**
|
||||
* Property: down
|
||||
* {<OpenLayers.Pixel>} The pixel location of the last mousedown.
|
||||
*/
|
||||
down: null,
|
||||
|
||||
/**
|
||||
* Constructor: OpenLayers.Handler.Click
|
||||
* Create a new click handler.
|
||||
*
|
||||
* Parameters:
|
||||
* control - {<OpenLayers.Control>} The control that is making use of
|
||||
* this handler. If a handler is being used without a control, the
|
||||
* handler's setMap method must be overridden to deal properly with
|
||||
* the map.
|
||||
* callbacks - {Object} An object with keys corresponding to callbacks
|
||||
* that will be called by the handler. The callbacks should
|
||||
* expect to recieve a single argument, the click event.
|
||||
* Callbacks for 'click' and 'dblclick' are supported.
|
||||
* options - {Object} Optional object whose properties will be set on the
|
||||
* handler.
|
||||
*/
|
||||
initialize: function(control, callbacks, options) {
|
||||
OpenLayers.Handler.prototype.initialize.apply(this, arguments);
|
||||
// optionally register for mouseup and mousedown
|
||||
if(this.pixelTolerance != null) {
|
||||
this.mousedown = function(evt) {
|
||||
this.down = evt.xy;
|
||||
return true;
|
||||
};
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Method: mousedown
|
||||
* Handle mousedown. Only registered as a listener if pixelTolerance is
|
||||
* a non-zero value at construction.
|
||||
*
|
||||
* Returns:
|
||||
* {Boolean} Continue propagating this event.
|
||||
*/
|
||||
mousedown: null,
|
||||
|
||||
/**
|
||||
* Method: dblclick
|
||||
* Handle dblclick. For a dblclick, we get two clicks in some browsers
|
||||
* (FF) and one in others (IE). So we need to always register for
|
||||
* dblclick to properly handle single clicks.
|
||||
*
|
||||
* Returns:
|
||||
* {Boolean} Continue propagating this event.
|
||||
*/
|
||||
dblclick: function(evt) {
|
||||
if(this.passesTolerance(evt)) {
|
||||
if(this["double"]) {
|
||||
this.callback('dblclick', [evt]);
|
||||
}
|
||||
this.clearTimer();
|
||||
}
|
||||
return !this.stopDouble;
|
||||
},
|
||||
|
||||
/**
|
||||
* Method: click
|
||||
* Handle click.
|
||||
*
|
||||
* Returns:
|
||||
* {Boolean} Continue propagating this event.
|
||||
*/
|
||||
click: function(evt) {
|
||||
if(this.passesTolerance(evt)) {
|
||||
if(this.timerId != null) {
|
||||
// already received a click
|
||||
this.clearTimer();
|
||||
} else {
|
||||
// set the timer, send evt only if single is true
|
||||
var clickEvent = this.single ? evt : null;
|
||||
this.timerId = window.setTimeout(
|
||||
OpenLayers.Function.bind(this.delayedCall, this, clickEvent),
|
||||
this.delay
|
||||
);
|
||||
}
|
||||
}
|
||||
return !this.stopSingle;
|
||||
},
|
||||
|
||||
/**
|
||||
* Method: passesTolerance
|
||||
* Determine whether the event is within the optional pixel tolerance. Note
|
||||
* that the pixel tolerance check only works if mousedown events get to
|
||||
* the listeners registered here. If they are stopped by other elements,
|
||||
* the <pixelTolerance> will have no effect here (this method will always
|
||||
* return true).
|
||||
*
|
||||
* Returns:
|
||||
* {Boolean} The click is within the pixel tolerance (if specified).
|
||||
*/
|
||||
passesTolerance: function(evt) {
|
||||
var passes = true;
|
||||
if(this.pixelTolerance != null && this.down) {
|
||||
var dpx = Math.sqrt(
|
||||
Math.pow(this.down.x - evt.xy.x, 2) +
|
||||
Math.pow(this.down.y - evt.xy.y, 2)
|
||||
);
|
||||
if(dpx > this.pixelTolerance) {
|
||||
passes = false;
|
||||
}
|
||||
}
|
||||
return passes;
|
||||
},
|
||||
|
||||
/**
|
||||
* Method: clearTimer
|
||||
* Clear the timer and set <timerId> to null.
|
||||
*/
|
||||
clearTimer: function() {
|
||||
if(this.timerId != null) {
|
||||
window.clearTimeout(this.timerId);
|
||||
this.timerId = null;
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Method: delayedCall
|
||||
* Sets <timerId> to null. And optionally triggers the click callback if
|
||||
* evt is set.
|
||||
*/
|
||||
delayedCall: function(evt) {
|
||||
this.timerId = null;
|
||||
if(evt) {
|
||||
this.callback('click', [evt]);
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* APIMethod: deactivate
|
||||
* Deactivate the handler.
|
||||
*
|
||||
* Returns:
|
||||
* {Boolean} The handler was successfully deactivated.
|
||||
*/
|
||||
deactivate: function() {
|
||||
var deactivated = false;
|
||||
if(OpenLayers.Handler.prototype.deactivate.apply(this, arguments)) {
|
||||
this.clearTimer();
|
||||
this.down = null;
|
||||
deactivated = true;
|
||||
}
|
||||
return deactivated;
|
||||
},
|
||||
|
||||
CLASS_NAME: "OpenLayers.Handler.Click"
|
||||
});
|
||||
/* 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/Handler.js
|
||||
*/
|
||||
|
||||
/**
|
||||
* Class: OpenLayers.Handler.Click
|
||||
* A handler for mouse clicks. The intention of this handler is to give
|
||||
* controls more flexibility with handling clicks. Browsers trigger
|
||||
* click events twice for a double-click. In addition, the mousedown,
|
||||
* mousemove, mouseup sequence fires a click event. With this handler,
|
||||
* controls can decide whether to ignore clicks associated with a double
|
||||
* click. By setting a <pixelTolerance>, controls can also ignore clicks
|
||||
* that include a drag. Create a new instance with the
|
||||
* <OpenLayers.Handler.Click> constructor.
|
||||
*
|
||||
* Inherits from:
|
||||
* - <OpenLayers.Handler>
|
||||
*/
|
||||
OpenLayers.Handler.Click = OpenLayers.Class(OpenLayers.Handler, {
|
||||
|
||||
/**
|
||||
* APIProperty: delay
|
||||
* {Number} Number of milliseconds between clicks before the event is
|
||||
* considered a double-click.
|
||||
*/
|
||||
delay: 300,
|
||||
|
||||
/**
|
||||
* APIProperty: single
|
||||
* {Boolean} Handle single clicks. Default is true. If false, clicks
|
||||
* will not be reported. If true, single-clicks will be reported.
|
||||
*/
|
||||
single: true,
|
||||
|
||||
/**
|
||||
* APIProperty: double
|
||||
* {Boolean} Handle double-clicks. Default is false.
|
||||
*/
|
||||
'double': false,
|
||||
|
||||
/**
|
||||
* APIProperty: pixelTolerance
|
||||
* {Number} Maximum number of pixels between mouseup and mousedown for an
|
||||
* event to be considered a click. Default is 0. If set to an
|
||||
* integer value, clicks with a drag greater than the value will be
|
||||
* ignored. This property can only be set when the handler is
|
||||
* constructed.
|
||||
*/
|
||||
pixelTolerance: 0,
|
||||
|
||||
/**
|
||||
* APIProperty: stopSingle
|
||||
* {Boolean} Stop other listeners from being notified of clicks. Default
|
||||
* is false. If true, any click listeners registered before this one
|
||||
* will not be notified of *any* click event (associated with double
|
||||
* or single clicks).
|
||||
*/
|
||||
stopSingle: false,
|
||||
|
||||
/**
|
||||
* APIProperty: stopDouble
|
||||
* {Boolean} Stop other listeners from being notified of double-clicks.
|
||||
* Default is false. If true, any click listeners registered before
|
||||
* this one will not be notified of *any* double-click events.
|
||||
*
|
||||
* The one caveat with stopDouble is that given a map with two click
|
||||
* handlers, one with stopDouble true and the other with stopSingle
|
||||
* true, the stopSingle handler should be activated last to get
|
||||
* uniform cross-browser performance. Since IE triggers one click
|
||||
* with a dblclick and FF triggers two, if a stopSingle handler is
|
||||
* activated first, all it gets in IE is a single click when the
|
||||
* second handler stops propagation on the dblclick.
|
||||
*/
|
||||
stopDouble: false,
|
||||
|
||||
/**
|
||||
* Property: timerId
|
||||
* {Number} The id of the timeout waiting to clear the <delayedEvent>.
|
||||
*/
|
||||
timerId: null,
|
||||
|
||||
/**
|
||||
* Property: down
|
||||
* {<OpenLayers.Pixel>} The pixel location of the last mousedown.
|
||||
*/
|
||||
down: null,
|
||||
|
||||
/**
|
||||
* Constructor: OpenLayers.Handler.Click
|
||||
* Create a new click handler.
|
||||
*
|
||||
* Parameters:
|
||||
* control - {<OpenLayers.Control>} The control that is making use of
|
||||
* this handler. If a handler is being used without a control, the
|
||||
* handler's setMap method must be overridden to deal properly with
|
||||
* the map.
|
||||
* callbacks - {Object} An object with keys corresponding to callbacks
|
||||
* that will be called by the handler. The callbacks should
|
||||
* expect to recieve a single argument, the click event.
|
||||
* Callbacks for 'click' and 'dblclick' are supported.
|
||||
* options - {Object} Optional object whose properties will be set on the
|
||||
* handler.
|
||||
*/
|
||||
initialize: function(control, callbacks, options) {
|
||||
OpenLayers.Handler.prototype.initialize.apply(this, arguments);
|
||||
// optionally register for mouseup and mousedown
|
||||
if(this.pixelTolerance != null) {
|
||||
this.mousedown = function(evt) {
|
||||
this.down = evt.xy;
|
||||
return true;
|
||||
};
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Method: mousedown
|
||||
* Handle mousedown. Only registered as a listener if pixelTolerance is
|
||||
* a non-zero value at construction.
|
||||
*
|
||||
* Returns:
|
||||
* {Boolean} Continue propagating this event.
|
||||
*/
|
||||
mousedown: null,
|
||||
|
||||
/**
|
||||
* Method: dblclick
|
||||
* Handle dblclick. For a dblclick, we get two clicks in some browsers
|
||||
* (FF) and one in others (IE). So we need to always register for
|
||||
* dblclick to properly handle single clicks.
|
||||
*
|
||||
* Returns:
|
||||
* {Boolean} Continue propagating this event.
|
||||
*/
|
||||
dblclick: function(evt) {
|
||||
if(this.passesTolerance(evt)) {
|
||||
if(this["double"]) {
|
||||
this.callback('dblclick', [evt]);
|
||||
}
|
||||
this.clearTimer();
|
||||
}
|
||||
return !this.stopDouble;
|
||||
},
|
||||
|
||||
/**
|
||||
* Method: click
|
||||
* Handle click.
|
||||
*
|
||||
* Returns:
|
||||
* {Boolean} Continue propagating this event.
|
||||
*/
|
||||
click: function(evt) {
|
||||
if(this.passesTolerance(evt)) {
|
||||
if(this.timerId != null) {
|
||||
// already received a click
|
||||
this.clearTimer();
|
||||
} else {
|
||||
// set the timer, send evt only if single is true
|
||||
var clickEvent = this.single ? evt : null;
|
||||
this.timerId = window.setTimeout(
|
||||
OpenLayers.Function.bind(this.delayedCall, this, clickEvent),
|
||||
this.delay
|
||||
);
|
||||
}
|
||||
}
|
||||
return !this.stopSingle;
|
||||
},
|
||||
|
||||
/**
|
||||
* Method: passesTolerance
|
||||
* Determine whether the event is within the optional pixel tolerance. Note
|
||||
* that the pixel tolerance check only works if mousedown events get to
|
||||
* the listeners registered here. If they are stopped by other elements,
|
||||
* the <pixelTolerance> will have no effect here (this method will always
|
||||
* return true).
|
||||
*
|
||||
* Returns:
|
||||
* {Boolean} The click is within the pixel tolerance (if specified).
|
||||
*/
|
||||
passesTolerance: function(evt) {
|
||||
var passes = true;
|
||||
if(this.pixelTolerance != null && this.down) {
|
||||
var dpx = Math.sqrt(
|
||||
Math.pow(this.down.x - evt.xy.x, 2) +
|
||||
Math.pow(this.down.y - evt.xy.y, 2)
|
||||
);
|
||||
if(dpx > this.pixelTolerance) {
|
||||
passes = false;
|
||||
}
|
||||
}
|
||||
return passes;
|
||||
},
|
||||
|
||||
/**
|
||||
* Method: clearTimer
|
||||
* Clear the timer and set <timerId> to null.
|
||||
*/
|
||||
clearTimer: function() {
|
||||
if(this.timerId != null) {
|
||||
window.clearTimeout(this.timerId);
|
||||
this.timerId = null;
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Method: delayedCall
|
||||
* Sets <timerId> to null. And optionally triggers the click callback if
|
||||
* evt is set.
|
||||
*/
|
||||
delayedCall: function(evt) {
|
||||
this.timerId = null;
|
||||
if(evt) {
|
||||
this.callback('click', [evt]);
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* APIMethod: deactivate
|
||||
* Deactivate the handler.
|
||||
*
|
||||
* Returns:
|
||||
* {Boolean} The handler was successfully deactivated.
|
||||
*/
|
||||
deactivate: function() {
|
||||
var deactivated = false;
|
||||
if(OpenLayers.Handler.prototype.deactivate.apply(this, arguments)) {
|
||||
this.clearTimer();
|
||||
this.down = null;
|
||||
deactivated = true;
|
||||
}
|
||||
return deactivated;
|
||||
},
|
||||
|
||||
CLASS_NAME: "OpenLayers.Handler.Click"
|
||||
});
|
||||
|
||||
@@ -1,393 +1,393 @@
|
||||
/* 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/Handler/Drag.js
|
||||
*/
|
||||
|
||||
/**
|
||||
* Class: OpenLayers.Handler.RegularPolygon
|
||||
* Handler to draw a regular polygon on the map. Polygon is displayed on mouse
|
||||
* down, moves or is modified on mouse move, and is finished on mouse up.
|
||||
* The handler triggers callbacks for 'done' and 'cancel'. Create a new
|
||||
* instance with the <OpenLayers.Handler.RegularPolygon> constructor.
|
||||
*
|
||||
* Inherits from:
|
||||
* - <OpenLayers.Handler>
|
||||
*/
|
||||
OpenLayers.Handler.RegularPolygon = OpenLayers.Class(OpenLayers.Handler.Drag, {
|
||||
|
||||
/**
|
||||
* APIProperty: sides
|
||||
* {Integer} Number of sides for the regular polygon. Needs to be greater
|
||||
* than 2. Defaults to 4.
|
||||
*/
|
||||
sides: 4,
|
||||
|
||||
/**
|
||||
* APIProperty: radius
|
||||
* {Float} Optional radius in map units of the regular polygon. If this is
|
||||
* set to some non-zero value, a polygon with a fixed radius will be
|
||||
* drawn and dragged with mose movements. If this property is not
|
||||
* set, dragging changes the radius of the polygon. Set to null by
|
||||
* default.
|
||||
*/
|
||||
radius: null,
|
||||
|
||||
/**
|
||||
* APIProperty: snapAngle
|
||||
* {Float} If set to a non-zero value, the handler will snap the polygon
|
||||
* rotation to multiples of the snapAngle. Value is an angle measured
|
||||
* in degrees counterclockwise from the positive x-axis.
|
||||
*/
|
||||
snapAngle: null,
|
||||
|
||||
/**
|
||||
* APIProperty: snapToggle
|
||||
* {String} If set, snapToggle is checked on mouse events and will set
|
||||
* the snap mode to the opposite of what it currently is. To disallow
|
||||
* toggling between snap and non-snap mode, set freehandToggle to
|
||||
* null. Acceptable toggle values are 'shiftKey', 'ctrlKey', and
|
||||
* 'altKey'. Snap mode is only possible if this.snapAngle is set to a
|
||||
* non-zero value.
|
||||
*/
|
||||
snapToggle: 'shiftKey',
|
||||
|
||||
/**
|
||||
* APIProperty: persist
|
||||
* {Boolean} Leave the feature rendered until clear is called. Default
|
||||
* is false. If set to true, the feature remains rendered until
|
||||
* clear is called, typically by deactivating the handler or starting
|
||||
* another drawing.
|
||||
*/
|
||||
persist: false,
|
||||
|
||||
/**
|
||||
* APIProperty: irregular
|
||||
* {Boolean} Draw an irregular polygon instead of a regular polygon.
|
||||
* Default is false. If true, the initial mouse down will represent
|
||||
* one corner of the polygon bounds and with each mouse movement, the
|
||||
* polygon will be stretched so the opposite corner of its bounds
|
||||
* follows the mouse position. This property takes precedence over
|
||||
* the radius property. If set to true, the radius property will
|
||||
* be ignored.
|
||||
*/
|
||||
irregular: false,
|
||||
|
||||
/**
|
||||
* Property: angle
|
||||
* {Float} The angle from the origin (mouse down) to the current mouse
|
||||
* position, in radians. This is measured counterclockwise from the
|
||||
* positive x-axis.
|
||||
*/
|
||||
angle: null,
|
||||
|
||||
/**
|
||||
* Property: fixedRadius
|
||||
* {Boolean} The polygon has a fixed radius. True if a radius is set before
|
||||
* drawing begins. False otherwise.
|
||||
*/
|
||||
fixedRadius: false,
|
||||
|
||||
/**
|
||||
* Property: feature
|
||||
* {<OpenLayers.Feature.Vector>} The currently drawn polygon feature
|
||||
*/
|
||||
feature: null,
|
||||
|
||||
/**
|
||||
* Property: layer
|
||||
* {<OpenLayers.Layer.Vector>} The temporary drawing layer
|
||||
*/
|
||||
layer: null,
|
||||
|
||||
/**
|
||||
* Property: origin
|
||||
* {<OpenLayers.Geometry.Point>} Location of the first mouse down
|
||||
*/
|
||||
origin: null,
|
||||
|
||||
/**
|
||||
* Constructor: OpenLayers.Handler.RegularPolygon
|
||||
* Create a new regular polygon handler.
|
||||
*
|
||||
* Parameters:
|
||||
* control - {<OpenLayers.Control>} The control that owns this handler
|
||||
* callbacks - {Array} An object with a 'done' property whos value is a
|
||||
* function to be called when the polygon drawing is finished.
|
||||
* The callback should expect to recieve a single argument,
|
||||
* the polygon 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.
|
||||
* options - {Object} An object with properties to be set on the handler.
|
||||
* If the options.sides property is not specified, the number of sides
|
||||
* will default to 4.
|
||||
*/
|
||||
initialize: function(control, callbacks, options) {
|
||||
this.style = OpenLayers.Util.extend(OpenLayers.Feature.Vector.style['default'], {});
|
||||
|
||||
OpenLayers.Handler.prototype.initialize.apply(this,
|
||||
[control, callbacks, options]);
|
||||
this.options = (options) ? options : new Object();
|
||||
},
|
||||
|
||||
/**
|
||||
* APIMethod: setOptions
|
||||
*
|
||||
* Parameters:
|
||||
* newOptions - {Object}
|
||||
*/
|
||||
setOptions: function (newOptions) {
|
||||
OpenLayers.Util.extend(this.options, newOptions);
|
||||
OpenLayers.Util.extend(this, newOptions);
|
||||
},
|
||||
|
||||
/**
|
||||
* APIMethod: activate
|
||||
* Turn on the handler.
|
||||
*
|
||||
* Return:
|
||||
* {Boolean} The handler was successfully activated
|
||||
*/
|
||||
activate: function() {
|
||||
var activated = false;
|
||||
if(OpenLayers.Handler.prototype.activate.apply(this, arguments)) {
|
||||
// create temporary vector layer for rendering geometry sketch
|
||||
var options = {displayInLayerSwitcher: false};
|
||||
this.layer = new OpenLayers.Layer.Vector(this.CLASS_NAME, options);
|
||||
this.map.addLayer(this.layer);
|
||||
activated = true;
|
||||
}
|
||||
return activated;
|
||||
},
|
||||
|
||||
/**
|
||||
* APIMethod: deactivate
|
||||
* Turn off the handler.
|
||||
*
|
||||
* Return:
|
||||
* {Boolean} The handler was successfully deactivated
|
||||
*/
|
||||
deactivate: function() {
|
||||
var deactivated = false;
|
||||
if(OpenLayers.Handler.Drag.prototype.deactivate.apply(this, arguments)) {
|
||||
// call the cancel callback if mid-drawing
|
||||
if(this.dragging) {
|
||||
this.cancel();
|
||||
}
|
||||
// If a layer's map property is set to null, it means that that
|
||||
// layer isn't added to the map. Since we ourself added the layer
|
||||
// to the map in activate(), we can assume that if this.layer.map
|
||||
// is null it means that the layer has been destroyed (as a result
|
||||
// of map.destroy() for example.
|
||||
if (this.layer.map != null) {
|
||||
this.layer.destroy(false);
|
||||
if (this.feature) {
|
||||
this.feature.destroy();
|
||||
}
|
||||
}
|
||||
this.layer = null;
|
||||
this.feature = null;
|
||||
deactivated = true;
|
||||
}
|
||||
return deactivated;
|
||||
},
|
||||
|
||||
/**
|
||||
* Method: downFeature
|
||||
* Start drawing a new feature
|
||||
*
|
||||
* Parameters:
|
||||
* evt - {Event} The drag start event
|
||||
*/
|
||||
down: function(evt) {
|
||||
this.fixedRadius = !!(this.radius);
|
||||
var maploc = this.map.getLonLatFromPixel(evt.xy);
|
||||
this.origin = new OpenLayers.Geometry.Point(maploc.lon, maploc.lat);
|
||||
// create the new polygon
|
||||
if(!this.fixedRadius || this.irregular) {
|
||||
// smallest radius should not be less one pixel in map units
|
||||
// VML doesn't behave well with smaller
|
||||
this.radius = this.map.getResolution();
|
||||
}
|
||||
if(this.persist) {
|
||||
this.clear();
|
||||
}
|
||||
this.feature = new OpenLayers.Feature.Vector();
|
||||
this.createGeometry();
|
||||
this.layer.addFeatures([this.feature], {silent: true});
|
||||
this.layer.drawFeature(this.feature, this.style);
|
||||
},
|
||||
|
||||
/**
|
||||
* Method: move
|
||||
* Respond to drag move events
|
||||
*
|
||||
* Parameters:
|
||||
* evt - {Evt} The move event
|
||||
*/
|
||||
move: function(evt) {
|
||||
var maploc = this.map.getLonLatFromPixel(evt.xy);
|
||||
var point = new OpenLayers.Geometry.Point(maploc.lon, maploc.lat);
|
||||
if(this.irregular) {
|
||||
var ry = Math.sqrt(2) * Math.abs(point.y - this.origin.y) / 2;
|
||||
this.radius = Math.max(this.map.getResolution() / 2, ry);
|
||||
} else if(this.fixedRadius) {
|
||||
this.origin = point;
|
||||
} else {
|
||||
this.calculateAngle(point, evt);
|
||||
this.radius = Math.max(this.map.getResolution() / 2,
|
||||
point.distanceTo(this.origin));
|
||||
}
|
||||
this.modifyGeometry();
|
||||
if(this.irregular) {
|
||||
var dx = point.x - this.origin.x;
|
||||
var dy = point.y - this.origin.y;
|
||||
var ratio;
|
||||
if(dy == 0) {
|
||||
ratio = dx / (this.radius * Math.sqrt(2));
|
||||
} else {
|
||||
ratio = dx / dy;
|
||||
}
|
||||
this.feature.geometry.resize(1, this.origin, ratio);
|
||||
this.feature.geometry.move(dx / 2, dy / 2);
|
||||
}
|
||||
this.layer.drawFeature(this.feature, this.style);
|
||||
},
|
||||
|
||||
/**
|
||||
* Method: up
|
||||
* Finish drawing the feature
|
||||
*
|
||||
* Parameters:
|
||||
* evt - {Event} The mouse up event
|
||||
*/
|
||||
up: function(evt) {
|
||||
this.finalize();
|
||||
},
|
||||
|
||||
/**
|
||||
* Method: out
|
||||
* Finish drawing the feature.
|
||||
*
|
||||
* Parameters:
|
||||
* evt - {Event} The mouse out event
|
||||
*/
|
||||
out: function(evt) {
|
||||
this.finalize();
|
||||
},
|
||||
|
||||
/**
|
||||
* Method: createGeometry
|
||||
* Create the new polygon geometry. This is called at the start of the
|
||||
* drag and at any point during the drag if the number of sides
|
||||
* changes.
|
||||
*/
|
||||
createGeometry: function() {
|
||||
this.angle = Math.PI * ((1/this.sides) - (1/2));
|
||||
if(this.snapAngle) {
|
||||
this.angle += this.snapAngle * (Math.PI / 180);
|
||||
}
|
||||
this.feature.geometry = OpenLayers.Geometry.Polygon.createRegularPolygon(
|
||||
this.origin, this.radius, this.sides, this.snapAngle
|
||||
);
|
||||
},
|
||||
|
||||
/**
|
||||
* Method: modifyGeometry
|
||||
* Modify the polygon geometry in place.
|
||||
*/
|
||||
modifyGeometry: function() {
|
||||
var angle, dx, dy, point;
|
||||
var ring = this.feature.geometry.components[0];
|
||||
// if the number of sides ever changes, create a new geometry
|
||||
if(ring.components.length != (this.sides + 1)) {
|
||||
this.createGeometry();
|
||||
ring = this.feature.geometry.components[0];
|
||||
}
|
||||
for(var i=0; i<this.sides; ++i) {
|
||||
point = ring.components[i];
|
||||
angle = this.angle + (i * 2 * Math.PI / this.sides);
|
||||
point.x = this.origin.x + (this.radius * Math.cos(angle));
|
||||
point.y = this.origin.y + (this.radius * Math.sin(angle));
|
||||
point.clearBounds();
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Method: calculateAngle
|
||||
* Calculate the angle based on settings.
|
||||
*
|
||||
* Parameters:
|
||||
* point - {<OpenLayers.Geometry.Point>}
|
||||
* evt - {Event}
|
||||
*/
|
||||
calculateAngle: function(point, evt) {
|
||||
var alpha = Math.atan2(point.y - this.origin.y,
|
||||
point.x - this.origin.x);
|
||||
if(this.snapAngle && (this.snapToggle && !evt[this.snapToggle])) {
|
||||
var snapAngleRad = (Math.PI / 180) * this.snapAngle;
|
||||
this.angle = Math.round(alpha / snapAngleRad) * snapAngleRad;
|
||||
} else {
|
||||
this.angle = alpha;
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* APIMethod: cancel
|
||||
* Finish the geometry and call the "cancel" callback.
|
||||
*/
|
||||
cancel: function() {
|
||||
// the polygon geometry gets cloned in the callback method
|
||||
this.callback("cancel", null);
|
||||
this.finalize();
|
||||
},
|
||||
|
||||
/**
|
||||
* Method: finalize
|
||||
* Finish the geometry and call the "done" callback.
|
||||
*/
|
||||
finalize: function() {
|
||||
this.origin = null;
|
||||
this.radius = this.options.radius;
|
||||
},
|
||||
|
||||
/**
|
||||
* APIMethod: clear
|
||||
* Clear any rendered features on the temporary layer. This is called
|
||||
* when the handler is deactivated, canceled, or done (unless persist
|
||||
* is true).
|
||||
*/
|
||||
clear: function() {
|
||||
this.layer.renderer.clear();
|
||||
this.layer.destroyFeatures();
|
||||
},
|
||||
|
||||
/**
|
||||
* Method: callback
|
||||
* Trigger the control's named callback with the given arguments
|
||||
*
|
||||
* Parameters:
|
||||
* name - {String} The key for the callback that is one of the properties
|
||||
* of the handler's callbacks object.
|
||||
* args - {Array} An array of arguments with which to call the callback
|
||||
* (defined by the control).
|
||||
*/
|
||||
callback: function (name, args) {
|
||||
// override the callback method to always send the polygon geometry
|
||||
if (this.callbacks[name]) {
|
||||
this.callbacks[name].apply(this.control,
|
||||
[this.feature.geometry.clone()]);
|
||||
}
|
||||
// since sketch features are added to the temporary layer
|
||||
// they must be cleared here if done or cancel
|
||||
if(!this.persist && (name == "done" || name == "cancel")) {
|
||||
this.clear();
|
||||
}
|
||||
},
|
||||
|
||||
CLASS_NAME: "OpenLayers.Handler.RegularPolygon"
|
||||
});
|
||||
/* 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/Handler/Drag.js
|
||||
*/
|
||||
|
||||
/**
|
||||
* Class: OpenLayers.Handler.RegularPolygon
|
||||
* Handler to draw a regular polygon on the map. Polygon is displayed on mouse
|
||||
* down, moves or is modified on mouse move, and is finished on mouse up.
|
||||
* The handler triggers callbacks for 'done' and 'cancel'. Create a new
|
||||
* instance with the <OpenLayers.Handler.RegularPolygon> constructor.
|
||||
*
|
||||
* Inherits from:
|
||||
* - <OpenLayers.Handler>
|
||||
*/
|
||||
OpenLayers.Handler.RegularPolygon = OpenLayers.Class(OpenLayers.Handler.Drag, {
|
||||
|
||||
/**
|
||||
* APIProperty: sides
|
||||
* {Integer} Number of sides for the regular polygon. Needs to be greater
|
||||
* than 2. Defaults to 4.
|
||||
*/
|
||||
sides: 4,
|
||||
|
||||
/**
|
||||
* APIProperty: radius
|
||||
* {Float} Optional radius in map units of the regular polygon. If this is
|
||||
* set to some non-zero value, a polygon with a fixed radius will be
|
||||
* drawn and dragged with mose movements. If this property is not
|
||||
* set, dragging changes the radius of the polygon. Set to null by
|
||||
* default.
|
||||
*/
|
||||
radius: null,
|
||||
|
||||
/**
|
||||
* APIProperty: snapAngle
|
||||
* {Float} If set to a non-zero value, the handler will snap the polygon
|
||||
* rotation to multiples of the snapAngle. Value is an angle measured
|
||||
* in degrees counterclockwise from the positive x-axis.
|
||||
*/
|
||||
snapAngle: null,
|
||||
|
||||
/**
|
||||
* APIProperty: snapToggle
|
||||
* {String} If set, snapToggle is checked on mouse events and will set
|
||||
* the snap mode to the opposite of what it currently is. To disallow
|
||||
* toggling between snap and non-snap mode, set freehandToggle to
|
||||
* null. Acceptable toggle values are 'shiftKey', 'ctrlKey', and
|
||||
* 'altKey'. Snap mode is only possible if this.snapAngle is set to a
|
||||
* non-zero value.
|
||||
*/
|
||||
snapToggle: 'shiftKey',
|
||||
|
||||
/**
|
||||
* APIProperty: persist
|
||||
* {Boolean} Leave the feature rendered until clear is called. Default
|
||||
* is false. If set to true, the feature remains rendered until
|
||||
* clear is called, typically by deactivating the handler or starting
|
||||
* another drawing.
|
||||
*/
|
||||
persist: false,
|
||||
|
||||
/**
|
||||
* APIProperty: irregular
|
||||
* {Boolean} Draw an irregular polygon instead of a regular polygon.
|
||||
* Default is false. If true, the initial mouse down will represent
|
||||
* one corner of the polygon bounds and with each mouse movement, the
|
||||
* polygon will be stretched so the opposite corner of its bounds
|
||||
* follows the mouse position. This property takes precedence over
|
||||
* the radius property. If set to true, the radius property will
|
||||
* be ignored.
|
||||
*/
|
||||
irregular: false,
|
||||
|
||||
/**
|
||||
* Property: angle
|
||||
* {Float} The angle from the origin (mouse down) to the current mouse
|
||||
* position, in radians. This is measured counterclockwise from the
|
||||
* positive x-axis.
|
||||
*/
|
||||
angle: null,
|
||||
|
||||
/**
|
||||
* Property: fixedRadius
|
||||
* {Boolean} The polygon has a fixed radius. True if a radius is set before
|
||||
* drawing begins. False otherwise.
|
||||
*/
|
||||
fixedRadius: false,
|
||||
|
||||
/**
|
||||
* Property: feature
|
||||
* {<OpenLayers.Feature.Vector>} The currently drawn polygon feature
|
||||
*/
|
||||
feature: null,
|
||||
|
||||
/**
|
||||
* Property: layer
|
||||
* {<OpenLayers.Layer.Vector>} The temporary drawing layer
|
||||
*/
|
||||
layer: null,
|
||||
|
||||
/**
|
||||
* Property: origin
|
||||
* {<OpenLayers.Geometry.Point>} Location of the first mouse down
|
||||
*/
|
||||
origin: null,
|
||||
|
||||
/**
|
||||
* Constructor: OpenLayers.Handler.RegularPolygon
|
||||
* Create a new regular polygon handler.
|
||||
*
|
||||
* Parameters:
|
||||
* control - {<OpenLayers.Control>} The control that owns this handler
|
||||
* callbacks - {Array} An object with a 'done' property whos value is a
|
||||
* function to be called when the polygon drawing is finished.
|
||||
* The callback should expect to recieve a single argument,
|
||||
* the polygon 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.
|
||||
* options - {Object} An object with properties to be set on the handler.
|
||||
* If the options.sides property is not specified, the number of sides
|
||||
* will default to 4.
|
||||
*/
|
||||
initialize: function(control, callbacks, options) {
|
||||
this.style = OpenLayers.Util.extend(OpenLayers.Feature.Vector.style['default'], {});
|
||||
|
||||
OpenLayers.Handler.prototype.initialize.apply(this,
|
||||
[control, callbacks, options]);
|
||||
this.options = (options) ? options : new Object();
|
||||
},
|
||||
|
||||
/**
|
||||
* APIMethod: setOptions
|
||||
*
|
||||
* Parameters:
|
||||
* newOptions - {Object}
|
||||
*/
|
||||
setOptions: function (newOptions) {
|
||||
OpenLayers.Util.extend(this.options, newOptions);
|
||||
OpenLayers.Util.extend(this, newOptions);
|
||||
},
|
||||
|
||||
/**
|
||||
* APIMethod: activate
|
||||
* Turn on the handler.
|
||||
*
|
||||
* Return:
|
||||
* {Boolean} The handler was successfully activated
|
||||
*/
|
||||
activate: function() {
|
||||
var activated = false;
|
||||
if(OpenLayers.Handler.prototype.activate.apply(this, arguments)) {
|
||||
// create temporary vector layer for rendering geometry sketch
|
||||
var options = {displayInLayerSwitcher: false};
|
||||
this.layer = new OpenLayers.Layer.Vector(this.CLASS_NAME, options);
|
||||
this.map.addLayer(this.layer);
|
||||
activated = true;
|
||||
}
|
||||
return activated;
|
||||
},
|
||||
|
||||
/**
|
||||
* APIMethod: deactivate
|
||||
* Turn off the handler.
|
||||
*
|
||||
* Return:
|
||||
* {Boolean} The handler was successfully deactivated
|
||||
*/
|
||||
deactivate: function() {
|
||||
var deactivated = false;
|
||||
if(OpenLayers.Handler.Drag.prototype.deactivate.apply(this, arguments)) {
|
||||
// call the cancel callback if mid-drawing
|
||||
if(this.dragging) {
|
||||
this.cancel();
|
||||
}
|
||||
// If a layer's map property is set to null, it means that that
|
||||
// layer isn't added to the map. Since we ourself added the layer
|
||||
// to the map in activate(), we can assume that if this.layer.map
|
||||
// is null it means that the layer has been destroyed (as a result
|
||||
// of map.destroy() for example.
|
||||
if (this.layer.map != null) {
|
||||
this.layer.destroy(false);
|
||||
if (this.feature) {
|
||||
this.feature.destroy();
|
||||
}
|
||||
}
|
||||
this.layer = null;
|
||||
this.feature = null;
|
||||
deactivated = true;
|
||||
}
|
||||
return deactivated;
|
||||
},
|
||||
|
||||
/**
|
||||
* Method: downFeature
|
||||
* Start drawing a new feature
|
||||
*
|
||||
* Parameters:
|
||||
* evt - {Event} The drag start event
|
||||
*/
|
||||
down: function(evt) {
|
||||
this.fixedRadius = !!(this.radius);
|
||||
var maploc = this.map.getLonLatFromPixel(evt.xy);
|
||||
this.origin = new OpenLayers.Geometry.Point(maploc.lon, maploc.lat);
|
||||
// create the new polygon
|
||||
if(!this.fixedRadius || this.irregular) {
|
||||
// smallest radius should not be less one pixel in map units
|
||||
// VML doesn't behave well with smaller
|
||||
this.radius = this.map.getResolution();
|
||||
}
|
||||
if(this.persist) {
|
||||
this.clear();
|
||||
}
|
||||
this.feature = new OpenLayers.Feature.Vector();
|
||||
this.createGeometry();
|
||||
this.layer.addFeatures([this.feature], {silent: true});
|
||||
this.layer.drawFeature(this.feature, this.style);
|
||||
},
|
||||
|
||||
/**
|
||||
* Method: move
|
||||
* Respond to drag move events
|
||||
*
|
||||
* Parameters:
|
||||
* evt - {Evt} The move event
|
||||
*/
|
||||
move: function(evt) {
|
||||
var maploc = this.map.getLonLatFromPixel(evt.xy);
|
||||
var point = new OpenLayers.Geometry.Point(maploc.lon, maploc.lat);
|
||||
if(this.irregular) {
|
||||
var ry = Math.sqrt(2) * Math.abs(point.y - this.origin.y) / 2;
|
||||
this.radius = Math.max(this.map.getResolution() / 2, ry);
|
||||
} else if(this.fixedRadius) {
|
||||
this.origin = point;
|
||||
} else {
|
||||
this.calculateAngle(point, evt);
|
||||
this.radius = Math.max(this.map.getResolution() / 2,
|
||||
point.distanceTo(this.origin));
|
||||
}
|
||||
this.modifyGeometry();
|
||||
if(this.irregular) {
|
||||
var dx = point.x - this.origin.x;
|
||||
var dy = point.y - this.origin.y;
|
||||
var ratio;
|
||||
if(dy == 0) {
|
||||
ratio = dx / (this.radius * Math.sqrt(2));
|
||||
} else {
|
||||
ratio = dx / dy;
|
||||
}
|
||||
this.feature.geometry.resize(1, this.origin, ratio);
|
||||
this.feature.geometry.move(dx / 2, dy / 2);
|
||||
}
|
||||
this.layer.drawFeature(this.feature, this.style);
|
||||
},
|
||||
|
||||
/**
|
||||
* Method: up
|
||||
* Finish drawing the feature
|
||||
*
|
||||
* Parameters:
|
||||
* evt - {Event} The mouse up event
|
||||
*/
|
||||
up: function(evt) {
|
||||
this.finalize();
|
||||
},
|
||||
|
||||
/**
|
||||
* Method: out
|
||||
* Finish drawing the feature.
|
||||
*
|
||||
* Parameters:
|
||||
* evt - {Event} The mouse out event
|
||||
*/
|
||||
out: function(evt) {
|
||||
this.finalize();
|
||||
},
|
||||
|
||||
/**
|
||||
* Method: createGeometry
|
||||
* Create the new polygon geometry. This is called at the start of the
|
||||
* drag and at any point during the drag if the number of sides
|
||||
* changes.
|
||||
*/
|
||||
createGeometry: function() {
|
||||
this.angle = Math.PI * ((1/this.sides) - (1/2));
|
||||
if(this.snapAngle) {
|
||||
this.angle += this.snapAngle * (Math.PI / 180);
|
||||
}
|
||||
this.feature.geometry = OpenLayers.Geometry.Polygon.createRegularPolygon(
|
||||
this.origin, this.radius, this.sides, this.snapAngle
|
||||
);
|
||||
},
|
||||
|
||||
/**
|
||||
* Method: modifyGeometry
|
||||
* Modify the polygon geometry in place.
|
||||
*/
|
||||
modifyGeometry: function() {
|
||||
var angle, dx, dy, point;
|
||||
var ring = this.feature.geometry.components[0];
|
||||
// if the number of sides ever changes, create a new geometry
|
||||
if(ring.components.length != (this.sides + 1)) {
|
||||
this.createGeometry();
|
||||
ring = this.feature.geometry.components[0];
|
||||
}
|
||||
for(var i=0; i<this.sides; ++i) {
|
||||
point = ring.components[i];
|
||||
angle = this.angle + (i * 2 * Math.PI / this.sides);
|
||||
point.x = this.origin.x + (this.radius * Math.cos(angle));
|
||||
point.y = this.origin.y + (this.radius * Math.sin(angle));
|
||||
point.clearBounds();
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Method: calculateAngle
|
||||
* Calculate the angle based on settings.
|
||||
*
|
||||
* Parameters:
|
||||
* point - {<OpenLayers.Geometry.Point>}
|
||||
* evt - {Event}
|
||||
*/
|
||||
calculateAngle: function(point, evt) {
|
||||
var alpha = Math.atan2(point.y - this.origin.y,
|
||||
point.x - this.origin.x);
|
||||
if(this.snapAngle && (this.snapToggle && !evt[this.snapToggle])) {
|
||||
var snapAngleRad = (Math.PI / 180) * this.snapAngle;
|
||||
this.angle = Math.round(alpha / snapAngleRad) * snapAngleRad;
|
||||
} else {
|
||||
this.angle = alpha;
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* APIMethod: cancel
|
||||
* Finish the geometry and call the "cancel" callback.
|
||||
*/
|
||||
cancel: function() {
|
||||
// the polygon geometry gets cloned in the callback method
|
||||
this.callback("cancel", null);
|
||||
this.finalize();
|
||||
},
|
||||
|
||||
/**
|
||||
* Method: finalize
|
||||
* Finish the geometry and call the "done" callback.
|
||||
*/
|
||||
finalize: function() {
|
||||
this.origin = null;
|
||||
this.radius = this.options.radius;
|
||||
},
|
||||
|
||||
/**
|
||||
* APIMethod: clear
|
||||
* Clear any rendered features on the temporary layer. This is called
|
||||
* when the handler is deactivated, canceled, or done (unless persist
|
||||
* is true).
|
||||
*/
|
||||
clear: function() {
|
||||
this.layer.renderer.clear();
|
||||
this.layer.destroyFeatures();
|
||||
},
|
||||
|
||||
/**
|
||||
* Method: callback
|
||||
* Trigger the control's named callback with the given arguments
|
||||
*
|
||||
* Parameters:
|
||||
* name - {String} The key for the callback that is one of the properties
|
||||
* of the handler's callbacks object.
|
||||
* args - {Array} An array of arguments with which to call the callback
|
||||
* (defined by the control).
|
||||
*/
|
||||
callback: function (name, args) {
|
||||
// override the callback method to always send the polygon geometry
|
||||
if (this.callbacks[name]) {
|
||||
this.callbacks[name].apply(this.control,
|
||||
[this.feature.geometry.clone()]);
|
||||
}
|
||||
// since sketch features are added to the temporary layer
|
||||
// they must be cleared here if done or cancel
|
||||
if(!this.persist && (name == "done" || name == "cancel")) {
|
||||
this.clear();
|
||||
}
|
||||
},
|
||||
|
||||
CLASS_NAME: "OpenLayers.Handler.RegularPolygon"
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user