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:
File diff suppressed because it is too large
Load Diff
@@ -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"
|
||||
});
|
||||
|
||||
@@ -1,141 +1,141 @@
|
||||
/* 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. */
|
||||
|
||||
|
||||
/**
|
||||
* @requires OpenLayers/Util.js
|
||||
* @requires OpenLayers/Style.js
|
||||
*/
|
||||
|
||||
/**
|
||||
* Class: OpenLayers.Rule
|
||||
* This class represents a OGC Rule, as being used for rule-based SLD styling.
|
||||
*/
|
||||
OpenLayers.Rule = OpenLayers.Class({
|
||||
|
||||
/**
|
||||
* APIProperty: name
|
||||
* {String} name of this rule
|
||||
*/
|
||||
name: 'default',
|
||||
|
||||
/**
|
||||
* Property: context
|
||||
* {Object} An optional object with properties that the rule and its
|
||||
* symbolizers' property values should be evaluatad against. If no
|
||||
* context is specified, feature.attributes will be used
|
||||
*/
|
||||
context: null,
|
||||
|
||||
/**
|
||||
* Property: elseFilter
|
||||
* {Boolean} Determines whether this rule is only to be applied only if
|
||||
* no other rules match (ElseFilter according to the SLD specification).
|
||||
* Default is false. For instances of OpenLayers.Rule, if elseFilter is
|
||||
* false, the rule will always apply. For subclasses, the else property is
|
||||
* ignored.
|
||||
*/
|
||||
elseFilter: false,
|
||||
|
||||
/**
|
||||
* Property: symbolizer
|
||||
* {Object} Hash of styles for this rule. Contains hashes of feature
|
||||
* styles. Keys are one or more of ["Point", "Line", "Polygon"]
|
||||
*/
|
||||
symbolizer: null,
|
||||
|
||||
/**
|
||||
* APIProperty: minScaleDenominator
|
||||
* {Number} or {String} minimum scale at which to draw the feature.
|
||||
* In the case of a String, this can be a combination of text and
|
||||
* propertyNames in the form "literal ${propertyName}"
|
||||
*/
|
||||
minScaleDenominator: null,
|
||||
|
||||
/**
|
||||
* APIProperty: maxScaleDenominator
|
||||
* {Number} or {String} maximum scale at which to draw the feature.
|
||||
* In the case of a String, this can be a combination of text and
|
||||
* propertyNames in the form "literal ${propertyName}"
|
||||
*/
|
||||
maxScaleDenominator: null,
|
||||
|
||||
/**
|
||||
* Constructor: OpenLayers.Rule
|
||||
* Creates a Rule.
|
||||
*
|
||||
* Parameters:
|
||||
* options - {Object} An optional object with properties to set on the
|
||||
* rule
|
||||
*
|
||||
* Returns:
|
||||
* {<OpenLayers.Rule>}
|
||||
*/
|
||||
initialize: function(options) {
|
||||
this.symbolizer = {};
|
||||
|
||||
OpenLayers.Util.extend(this, options);
|
||||
},
|
||||
|
||||
/**
|
||||
* APIMethod: destroy
|
||||
* nullify references to prevent circular references and memory leaks
|
||||
*/
|
||||
destroy: function() {
|
||||
for (var i in this.symbolizer) {
|
||||
this.symbolizer[i] = null;
|
||||
}
|
||||
this.symbolizer = null;
|
||||
},
|
||||
|
||||
/**
|
||||
* APIMethod: evaluate
|
||||
* evaluates this rule for a specific feature
|
||||
*
|
||||
* Parameters:
|
||||
* feature - {<OpenLayers.Feature>} feature to apply the rule to.
|
||||
*
|
||||
* Returns:
|
||||
* {boolean} true if the rule applies, false if it does not.
|
||||
* This rule is the default rule and always returns true.
|
||||
*/
|
||||
evaluate: function(feature) {
|
||||
var context = this.getContext(feature);
|
||||
var applies = true;
|
||||
|
||||
if (this.minScaleDenominator || this.maxScaleDenominator) {
|
||||
var scale = feature.layer.map.getScale();
|
||||
}
|
||||
|
||||
// check if within minScale/maxScale bounds
|
||||
if (this.minScaleDenominator) {
|
||||
applies = scale >= OpenLayers.Style.createLiteral(
|
||||
this.minScaleDenominator, context);
|
||||
}
|
||||
if (applies && this.maxScaleDenominator) {
|
||||
applies = scale < OpenLayers.Style.createLiteral(
|
||||
this.maxScaleDenominator, context);
|
||||
}
|
||||
|
||||
return applies;
|
||||
},
|
||||
|
||||
/**
|
||||
* Method: getContext
|
||||
* Gets the context for evaluating this rule
|
||||
*
|
||||
* Paramters:
|
||||
* feature - {<OpenLayers.Feature>} feature to take the context from if
|
||||
* none is specified.
|
||||
*/
|
||||
getContext: function(feature) {
|
||||
var context = this.context;
|
||||
if (!context) {
|
||||
context = feature.attributes || feature.data;
|
||||
}
|
||||
return context;
|
||||
},
|
||||
|
||||
CLASS_NAME: "OpenLayers.Rule"
|
||||
/* 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. */
|
||||
|
||||
|
||||
/**
|
||||
* @requires OpenLayers/Util.js
|
||||
* @requires OpenLayers/Style.js
|
||||
*/
|
||||
|
||||
/**
|
||||
* Class: OpenLayers.Rule
|
||||
* This class represents a OGC Rule, as being used for rule-based SLD styling.
|
||||
*/
|
||||
OpenLayers.Rule = OpenLayers.Class({
|
||||
|
||||
/**
|
||||
* APIProperty: name
|
||||
* {String} name of this rule
|
||||
*/
|
||||
name: 'default',
|
||||
|
||||
/**
|
||||
* Property: context
|
||||
* {Object} An optional object with properties that the rule and its
|
||||
* symbolizers' property values should be evaluatad against. If no
|
||||
* context is specified, feature.attributes will be used
|
||||
*/
|
||||
context: null,
|
||||
|
||||
/**
|
||||
* Property: elseFilter
|
||||
* {Boolean} Determines whether this rule is only to be applied only if
|
||||
* no other rules match (ElseFilter according to the SLD specification).
|
||||
* Default is false. For instances of OpenLayers.Rule, if elseFilter is
|
||||
* false, the rule will always apply. For subclasses, the else property is
|
||||
* ignored.
|
||||
*/
|
||||
elseFilter: false,
|
||||
|
||||
/**
|
||||
* Property: symbolizer
|
||||
* {Object} Hash of styles for this rule. Contains hashes of feature
|
||||
* styles. Keys are one or more of ["Point", "Line", "Polygon"]
|
||||
*/
|
||||
symbolizer: null,
|
||||
|
||||
/**
|
||||
* APIProperty: minScaleDenominator
|
||||
* {Number} or {String} minimum scale at which to draw the feature.
|
||||
* In the case of a String, this can be a combination of text and
|
||||
* propertyNames in the form "literal ${propertyName}"
|
||||
*/
|
||||
minScaleDenominator: null,
|
||||
|
||||
/**
|
||||
* APIProperty: maxScaleDenominator
|
||||
* {Number} or {String} maximum scale at which to draw the feature.
|
||||
* In the case of a String, this can be a combination of text and
|
||||
* propertyNames in the form "literal ${propertyName}"
|
||||
*/
|
||||
maxScaleDenominator: null,
|
||||
|
||||
/**
|
||||
* Constructor: OpenLayers.Rule
|
||||
* Creates a Rule.
|
||||
*
|
||||
* Parameters:
|
||||
* options - {Object} An optional object with properties to set on the
|
||||
* rule
|
||||
*
|
||||
* Returns:
|
||||
* {<OpenLayers.Rule>}
|
||||
*/
|
||||
initialize: function(options) {
|
||||
this.symbolizer = {};
|
||||
|
||||
OpenLayers.Util.extend(this, options);
|
||||
},
|
||||
|
||||
/**
|
||||
* APIMethod: destroy
|
||||
* nullify references to prevent circular references and memory leaks
|
||||
*/
|
||||
destroy: function() {
|
||||
for (var i in this.symbolizer) {
|
||||
this.symbolizer[i] = null;
|
||||
}
|
||||
this.symbolizer = null;
|
||||
},
|
||||
|
||||
/**
|
||||
* APIMethod: evaluate
|
||||
* evaluates this rule for a specific feature
|
||||
*
|
||||
* Parameters:
|
||||
* feature - {<OpenLayers.Feature>} feature to apply the rule to.
|
||||
*
|
||||
* Returns:
|
||||
* {boolean} true if the rule applies, false if it does not.
|
||||
* This rule is the default rule and always returns true.
|
||||
*/
|
||||
evaluate: function(feature) {
|
||||
var context = this.getContext(feature);
|
||||
var applies = true;
|
||||
|
||||
if (this.minScaleDenominator || this.maxScaleDenominator) {
|
||||
var scale = feature.layer.map.getScale();
|
||||
}
|
||||
|
||||
// check if within minScale/maxScale bounds
|
||||
if (this.minScaleDenominator) {
|
||||
applies = scale >= OpenLayers.Style.createLiteral(
|
||||
this.minScaleDenominator, context);
|
||||
}
|
||||
if (applies && this.maxScaleDenominator) {
|
||||
applies = scale < OpenLayers.Style.createLiteral(
|
||||
this.maxScaleDenominator, context);
|
||||
}
|
||||
|
||||
return applies;
|
||||
},
|
||||
|
||||
/**
|
||||
* Method: getContext
|
||||
* Gets the context for evaluating this rule
|
||||
*
|
||||
* Paramters:
|
||||
* feature - {<OpenLayers.Feature>} feature to take the context from if
|
||||
* none is specified.
|
||||
*/
|
||||
getContext: function(feature) {
|
||||
var context = this.context;
|
||||
if (!context) {
|
||||
context = feature.attributes || feature.data;
|
||||
}
|
||||
return context;
|
||||
},
|
||||
|
||||
CLASS_NAME: "OpenLayers.Rule"
|
||||
});
|
||||
@@ -1,206 +1,206 @@
|
||||
/* 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/Rule.js
|
||||
*/
|
||||
|
||||
/**
|
||||
* Class: OpenLayers.Rule.Comparison
|
||||
* This class represents the comparison rules, as being used for rule-based
|
||||
* SLD styling
|
||||
*
|
||||
* Inherits from
|
||||
* - <OpenLayers.Rule>
|
||||
*/
|
||||
OpenLayers.Rule.Comparison = OpenLayers.Class(OpenLayers.Rule, {
|
||||
|
||||
/**
|
||||
* APIProperty: type
|
||||
* {String} type: type of the comparison. This is one of
|
||||
* - OpenLayers.Rule.Comparison.EQUAL_TO = "==";
|
||||
* - OpenLayers.Rule.Comparison.NOT_EQUAL_TO = "!=";
|
||||
* - OpenLayers.Rule.Comparison.LESS_THAN = "<";
|
||||
* - OpenLayers.Rule.Comparison.GREATER_THAN = ">";
|
||||
* - OpenLayers.Rule.Comparison.LESS_THAN_OR_EQUAL_TO = "<=";
|
||||
* - OpenLayers.Rule.Comparison.GREATER_THAN_OR_EQUAL_TO = ">=";
|
||||
* - OpenLayers.Rule.Comparison.BETWEEN = "..";
|
||||
* - OpenLayers.Rule.Comparison.LIKE = "~";
|
||||
*/
|
||||
type: null,
|
||||
|
||||
/**
|
||||
* APIProperty: property
|
||||
* {String}
|
||||
* name of the context property to compare
|
||||
*/
|
||||
property: null,
|
||||
|
||||
/**
|
||||
* APIProperty: value
|
||||
* {Number} or {String}
|
||||
* comparison value for binary comparisons. In the case of a String, this
|
||||
* can be a combination of text and propertyNames in the form
|
||||
* "literal ${propertyName}"
|
||||
*/
|
||||
value: null,
|
||||
|
||||
/**
|
||||
* APIProperty: lowerBoundary
|
||||
* {Number} or {String}
|
||||
* lower boundary for between comparisons. In the case of a String, this
|
||||
* can be a combination of text and propertyNames in the form
|
||||
* "literal ${propertyName}"
|
||||
*/
|
||||
lowerBoundary: null,
|
||||
|
||||
/**
|
||||
* APIProperty: upperBoundary
|
||||
* {Number} or {String}
|
||||
* upper boundary for between comparisons. In the case of a String, this
|
||||
* can be a combination of text and propertyNames in the form
|
||||
* "literal ${propertyName}"
|
||||
*/
|
||||
upperBoundary: null,
|
||||
|
||||
/**
|
||||
* Constructor: OpenLayers.Rule.Comparison
|
||||
* Creates a comparison rule.
|
||||
*
|
||||
* Parameters:
|
||||
* params - {Object} Hash of parameters for this rule:
|
||||
* -
|
||||
* - value:
|
||||
* options - {Object} An optional object with properties to set on the
|
||||
* rule
|
||||
*
|
||||
* Returns:
|
||||
* {<OpenLayers.Rule.Comparison>}
|
||||
*/
|
||||
initialize: function(options) {
|
||||
OpenLayers.Rule.prototype.initialize.apply(this, [options]);
|
||||
},
|
||||
|
||||
/**
|
||||
* APIMethod: evaluate
|
||||
* evaluates this rule for a specific context
|
||||
*
|
||||
* Parameters:
|
||||
* context - {Object} context to apply the rule to.
|
||||
*
|
||||
* Returns:
|
||||
* {boolean} true if the rule applies, false if it does not
|
||||
*/
|
||||
evaluate: function(feature) {
|
||||
if (!OpenLayers.Rule.prototype.evaluate.apply(this, arguments)) {
|
||||
return false;
|
||||
}
|
||||
var context = this.getContext(feature);
|
||||
switch(this.type) {
|
||||
case OpenLayers.Rule.Comparison.EQUAL_TO:
|
||||
case OpenLayers.Rule.Comparison.LESS_THAN:
|
||||
case OpenLayers.Rule.Comparison.GREATER_THAN:
|
||||
case OpenLayers.Rule.Comparison.LESS_THAN_OR_EQUAL_TO:
|
||||
case OpenLayers.Rule.Comparison.GREATER_THAN_OR_EQUAL_TO:
|
||||
return this.binaryCompare(context, this.property, this.value);
|
||||
|
||||
case OpenLayers.Rule.Comparison.BETWEEN:
|
||||
var result =
|
||||
context[this.property] > this.lowerBoundary;
|
||||
result = result &&
|
||||
context[this.property] < this.upperBoundary;
|
||||
return result;
|
||||
case OpenLayers.Rule.Comparison.LIKE:
|
||||
var regexp = new RegExp(this.value,
|
||||
"gi");
|
||||
return regexp.test(context[this.property]);
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* APIMethod: value2regex
|
||||
* Converts the value of this rule into a regular expression string,
|
||||
* according to the wildcard characters specified. This method has to
|
||||
* be called after instantiation of this class, if the value is not a
|
||||
* regular expression already.
|
||||
*
|
||||
* Parameters:
|
||||
* wildCard - {<Char>} wildcard character in the above value, default
|
||||
* is "*"
|
||||
* singleChar - {<Char>) single-character wildcard in the above value
|
||||
* default is "."
|
||||
* escape - {<Char>) escape character in the above value, default is
|
||||
* "!"
|
||||
*
|
||||
* Returns:
|
||||
* {String} regular expression string
|
||||
*/
|
||||
value2regex: function(wildCard, singleChar, escapeChar) {
|
||||
if (wildCard == ".") {
|
||||
var msg = "'.' is an unsupported wildCard character for "+
|
||||
"OpenLayers.Rule.Comparison";
|
||||
OpenLayers.Console.error(msg);
|
||||
return null;
|
||||
}
|
||||
|
||||
// set UMN MapServer defaults for unspecified parameters
|
||||
wildCard = wildCard ? wildCard : "*";
|
||||
singleChar = singleChar ? singleChar : ".";
|
||||
escapeChar = escapeChar ? escapeChar : "!";
|
||||
|
||||
this.value = this.value.replace(
|
||||
new RegExp("\\"+escapeChar, "g"), "\\");
|
||||
this.value = this.value.replace(
|
||||
new RegExp("\\"+singleChar, "g"), ".");
|
||||
this.value = this.value.replace(
|
||||
new RegExp("\\"+wildCard, "g"), ".*");
|
||||
this.value = this.value.replace(
|
||||
new RegExp("\\\\.\\*", "g"), "\\"+wildCard);
|
||||
this.value = this.value.replace(
|
||||
new RegExp("\\\\\\.", "g"), "\\"+singleChar);
|
||||
|
||||
return this.value;
|
||||
},
|
||||
|
||||
/**
|
||||
* Function: binaryCompare
|
||||
* Compares a feature property to a rule value
|
||||
*
|
||||
* Parameters:
|
||||
* context - {Object}
|
||||
* property - {String} or {Number}
|
||||
* value - {String} or {Number}, same as property
|
||||
*
|
||||
* Returns:
|
||||
* {boolean}
|
||||
*/
|
||||
binaryCompare: function(context, property, value) {
|
||||
switch (this.type) {
|
||||
case OpenLayers.Rule.Comparison.EQUAL_TO:
|
||||
return context[property] == value;
|
||||
case OpenLayers.Rule.Comparison.NOT_EQUAL_TO:
|
||||
return context[property] != value;
|
||||
case OpenLayers.Rule.Comparison.LESS_THAN:
|
||||
return context[property] < value;
|
||||
case OpenLayers.Rule.Comparison.GREATER_THAN:
|
||||
return context[property] > value;
|
||||
case OpenLayers.Rule.Comparison.LESS_THAN_OR_EQUAL_TO:
|
||||
return context[property] <= value;
|
||||
case OpenLayers.Rule.Comparison.GREATER_THAN_OR_EQUAL_TO:
|
||||
return context[property] >= value;
|
||||
}
|
||||
},
|
||||
|
||||
CLASS_NAME: "OpenLayers.Rule.Comparison"
|
||||
});
|
||||
|
||||
|
||||
OpenLayers.Rule.Comparison.EQUAL_TO = "==";
|
||||
OpenLayers.Rule.Comparison.NOT_EQUAL_TO = "!=";
|
||||
OpenLayers.Rule.Comparison.LESS_THAN = "<";
|
||||
OpenLayers.Rule.Comparison.GREATER_THAN = ">";
|
||||
OpenLayers.Rule.Comparison.LESS_THAN_OR_EQUAL_TO = "<=";
|
||||
OpenLayers.Rule.Comparison.GREATER_THAN_OR_EQUAL_TO = ">=";
|
||||
OpenLayers.Rule.Comparison.BETWEEN = "..";
|
||||
OpenLayers.Rule.Comparison.LIKE = "~";
|
||||
/* 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/Rule.js
|
||||
*/
|
||||
|
||||
/**
|
||||
* Class: OpenLayers.Rule.Comparison
|
||||
* This class represents the comparison rules, as being used for rule-based
|
||||
* SLD styling
|
||||
*
|
||||
* Inherits from
|
||||
* - <OpenLayers.Rule>
|
||||
*/
|
||||
OpenLayers.Rule.Comparison = OpenLayers.Class(OpenLayers.Rule, {
|
||||
|
||||
/**
|
||||
* APIProperty: type
|
||||
* {String} type: type of the comparison. This is one of
|
||||
* - OpenLayers.Rule.Comparison.EQUAL_TO = "==";
|
||||
* - OpenLayers.Rule.Comparison.NOT_EQUAL_TO = "!=";
|
||||
* - OpenLayers.Rule.Comparison.LESS_THAN = "<";
|
||||
* - OpenLayers.Rule.Comparison.GREATER_THAN = ">";
|
||||
* - OpenLayers.Rule.Comparison.LESS_THAN_OR_EQUAL_TO = "<=";
|
||||
* - OpenLayers.Rule.Comparison.GREATER_THAN_OR_EQUAL_TO = ">=";
|
||||
* - OpenLayers.Rule.Comparison.BETWEEN = "..";
|
||||
* - OpenLayers.Rule.Comparison.LIKE = "~";
|
||||
*/
|
||||
type: null,
|
||||
|
||||
/**
|
||||
* APIProperty: property
|
||||
* {String}
|
||||
* name of the context property to compare
|
||||
*/
|
||||
property: null,
|
||||
|
||||
/**
|
||||
* APIProperty: value
|
||||
* {Number} or {String}
|
||||
* comparison value for binary comparisons. In the case of a String, this
|
||||
* can be a combination of text and propertyNames in the form
|
||||
* "literal ${propertyName}"
|
||||
*/
|
||||
value: null,
|
||||
|
||||
/**
|
||||
* APIProperty: lowerBoundary
|
||||
* {Number} or {String}
|
||||
* lower boundary for between comparisons. In the case of a String, this
|
||||
* can be a combination of text and propertyNames in the form
|
||||
* "literal ${propertyName}"
|
||||
*/
|
||||
lowerBoundary: null,
|
||||
|
||||
/**
|
||||
* APIProperty: upperBoundary
|
||||
* {Number} or {String}
|
||||
* upper boundary for between comparisons. In the case of a String, this
|
||||
* can be a combination of text and propertyNames in the form
|
||||
* "literal ${propertyName}"
|
||||
*/
|
||||
upperBoundary: null,
|
||||
|
||||
/**
|
||||
* Constructor: OpenLayers.Rule.Comparison
|
||||
* Creates a comparison rule.
|
||||
*
|
||||
* Parameters:
|
||||
* params - {Object} Hash of parameters for this rule:
|
||||
* -
|
||||
* - value:
|
||||
* options - {Object} An optional object with properties to set on the
|
||||
* rule
|
||||
*
|
||||
* Returns:
|
||||
* {<OpenLayers.Rule.Comparison>}
|
||||
*/
|
||||
initialize: function(options) {
|
||||
OpenLayers.Rule.prototype.initialize.apply(this, [options]);
|
||||
},
|
||||
|
||||
/**
|
||||
* APIMethod: evaluate
|
||||
* evaluates this rule for a specific context
|
||||
*
|
||||
* Parameters:
|
||||
* context - {Object} context to apply the rule to.
|
||||
*
|
||||
* Returns:
|
||||
* {boolean} true if the rule applies, false if it does not
|
||||
*/
|
||||
evaluate: function(feature) {
|
||||
if (!OpenLayers.Rule.prototype.evaluate.apply(this, arguments)) {
|
||||
return false;
|
||||
}
|
||||
var context = this.getContext(feature);
|
||||
switch(this.type) {
|
||||
case OpenLayers.Rule.Comparison.EQUAL_TO:
|
||||
case OpenLayers.Rule.Comparison.LESS_THAN:
|
||||
case OpenLayers.Rule.Comparison.GREATER_THAN:
|
||||
case OpenLayers.Rule.Comparison.LESS_THAN_OR_EQUAL_TO:
|
||||
case OpenLayers.Rule.Comparison.GREATER_THAN_OR_EQUAL_TO:
|
||||
return this.binaryCompare(context, this.property, this.value);
|
||||
|
||||
case OpenLayers.Rule.Comparison.BETWEEN:
|
||||
var result =
|
||||
context[this.property] > this.lowerBoundary;
|
||||
result = result &&
|
||||
context[this.property] < this.upperBoundary;
|
||||
return result;
|
||||
case OpenLayers.Rule.Comparison.LIKE:
|
||||
var regexp = new RegExp(this.value,
|
||||
"gi");
|
||||
return regexp.test(context[this.property]);
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* APIMethod: value2regex
|
||||
* Converts the value of this rule into a regular expression string,
|
||||
* according to the wildcard characters specified. This method has to
|
||||
* be called after instantiation of this class, if the value is not a
|
||||
* regular expression already.
|
||||
*
|
||||
* Parameters:
|
||||
* wildCard - {<Char>} wildcard character in the above value, default
|
||||
* is "*"
|
||||
* singleChar - {<Char>) single-character wildcard in the above value
|
||||
* default is "."
|
||||
* escape - {<Char>) escape character in the above value, default is
|
||||
* "!"
|
||||
*
|
||||
* Returns:
|
||||
* {String} regular expression string
|
||||
*/
|
||||
value2regex: function(wildCard, singleChar, escapeChar) {
|
||||
if (wildCard == ".") {
|
||||
var msg = "'.' is an unsupported wildCard character for "+
|
||||
"OpenLayers.Rule.Comparison";
|
||||
OpenLayers.Console.error(msg);
|
||||
return null;
|
||||
}
|
||||
|
||||
// set UMN MapServer defaults for unspecified parameters
|
||||
wildCard = wildCard ? wildCard : "*";
|
||||
singleChar = singleChar ? singleChar : ".";
|
||||
escapeChar = escapeChar ? escapeChar : "!";
|
||||
|
||||
this.value = this.value.replace(
|
||||
new RegExp("\\"+escapeChar, "g"), "\\");
|
||||
this.value = this.value.replace(
|
||||
new RegExp("\\"+singleChar, "g"), ".");
|
||||
this.value = this.value.replace(
|
||||
new RegExp("\\"+wildCard, "g"), ".*");
|
||||
this.value = this.value.replace(
|
||||
new RegExp("\\\\.\\*", "g"), "\\"+wildCard);
|
||||
this.value = this.value.replace(
|
||||
new RegExp("\\\\\\.", "g"), "\\"+singleChar);
|
||||
|
||||
return this.value;
|
||||
},
|
||||
|
||||
/**
|
||||
* Function: binaryCompare
|
||||
* Compares a feature property to a rule value
|
||||
*
|
||||
* Parameters:
|
||||
* context - {Object}
|
||||
* property - {String} or {Number}
|
||||
* value - {String} or {Number}, same as property
|
||||
*
|
||||
* Returns:
|
||||
* {boolean}
|
||||
*/
|
||||
binaryCompare: function(context, property, value) {
|
||||
switch (this.type) {
|
||||
case OpenLayers.Rule.Comparison.EQUAL_TO:
|
||||
return context[property] == value;
|
||||
case OpenLayers.Rule.Comparison.NOT_EQUAL_TO:
|
||||
return context[property] != value;
|
||||
case OpenLayers.Rule.Comparison.LESS_THAN:
|
||||
return context[property] < value;
|
||||
case OpenLayers.Rule.Comparison.GREATER_THAN:
|
||||
return context[property] > value;
|
||||
case OpenLayers.Rule.Comparison.LESS_THAN_OR_EQUAL_TO:
|
||||
return context[property] <= value;
|
||||
case OpenLayers.Rule.Comparison.GREATER_THAN_OR_EQUAL_TO:
|
||||
return context[property] >= value;
|
||||
}
|
||||
},
|
||||
|
||||
CLASS_NAME: "OpenLayers.Rule.Comparison"
|
||||
});
|
||||
|
||||
|
||||
OpenLayers.Rule.Comparison.EQUAL_TO = "==";
|
||||
OpenLayers.Rule.Comparison.NOT_EQUAL_TO = "!=";
|
||||
OpenLayers.Rule.Comparison.LESS_THAN = "<";
|
||||
OpenLayers.Rule.Comparison.GREATER_THAN = ">";
|
||||
OpenLayers.Rule.Comparison.LESS_THAN_OR_EQUAL_TO = "<=";
|
||||
OpenLayers.Rule.Comparison.GREATER_THAN_OR_EQUAL_TO = ">=";
|
||||
OpenLayers.Rule.Comparison.BETWEEN = "..";
|
||||
OpenLayers.Rule.Comparison.LIKE = "~";
|
||||
|
||||
@@ -1,69 +1,69 @@
|
||||
/* 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/Rule.js
|
||||
*/
|
||||
|
||||
/**
|
||||
* Class: OpenLayers.Rule.FeatureId
|
||||
* This class represents a ogc:FeatureId Rule, as being used for rule-based SLD
|
||||
* styling
|
||||
*
|
||||
* Inherits from
|
||||
* - <OpenLayers.Rule>
|
||||
*/
|
||||
OpenLayers.Rule.FeatureId = OpenLayers.Class(OpenLayers.Rule, {
|
||||
|
||||
/**
|
||||
* APIProperty: fids
|
||||
* {Array(<String>)} Feature Ids to evaluate this rule against. To be passed
|
||||
* To be passed inside the params object.
|
||||
*/
|
||||
fids: null,
|
||||
|
||||
/**
|
||||
* Constructor: OpenLayers.Rule.FeatureId
|
||||
* Creates an ogc:FeatureId rule.
|
||||
*
|
||||
* Parameters:
|
||||
* options - {Object} An optional object with properties to set on the
|
||||
* rule
|
||||
*
|
||||
* Returns:
|
||||
* {<OpenLayers.Rule.FeatureId>}
|
||||
*/
|
||||
initialize: function(options) {
|
||||
this.fids = [];
|
||||
OpenLayers.Rule.prototype.initialize.apply(this, [options]);
|
||||
},
|
||||
|
||||
/**
|
||||
* APIMethod: evaluate
|
||||
* evaluates this rule for a specific feature
|
||||
*
|
||||
* Parameters:
|
||||
* feature - {<OpenLayers.Feature>} feature to apply the rule to.
|
||||
* For vector features, the check is run against the fid,
|
||||
* for plain features against the id.
|
||||
*
|
||||
* Returns:
|
||||
* {boolean} true if the rule applies, false if it does not
|
||||
*/
|
||||
evaluate: function(feature) {
|
||||
if (!OpenLayers.Rule.prototype.evaluate.apply(this, arguments)) {
|
||||
return false;
|
||||
}
|
||||
for (var i=0; i<this.fids.length; i++) {
|
||||
var fid = feature.fid || feature.id;
|
||||
if (fid == this.fids[i]) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
},
|
||||
|
||||
CLASS_NAME: "OpenLayers.Rule.FeatureId"
|
||||
});
|
||||
/* 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/Rule.js
|
||||
*/
|
||||
|
||||
/**
|
||||
* Class: OpenLayers.Rule.FeatureId
|
||||
* This class represents a ogc:FeatureId Rule, as being used for rule-based SLD
|
||||
* styling
|
||||
*
|
||||
* Inherits from
|
||||
* - <OpenLayers.Rule>
|
||||
*/
|
||||
OpenLayers.Rule.FeatureId = OpenLayers.Class(OpenLayers.Rule, {
|
||||
|
||||
/**
|
||||
* APIProperty: fids
|
||||
* {Array(<String>)} Feature Ids to evaluate this rule against. To be passed
|
||||
* To be passed inside the params object.
|
||||
*/
|
||||
fids: null,
|
||||
|
||||
/**
|
||||
* Constructor: OpenLayers.Rule.FeatureId
|
||||
* Creates an ogc:FeatureId rule.
|
||||
*
|
||||
* Parameters:
|
||||
* options - {Object} An optional object with properties to set on the
|
||||
* rule
|
||||
*
|
||||
* Returns:
|
||||
* {<OpenLayers.Rule.FeatureId>}
|
||||
*/
|
||||
initialize: function(options) {
|
||||
this.fids = [];
|
||||
OpenLayers.Rule.prototype.initialize.apply(this, [options]);
|
||||
},
|
||||
|
||||
/**
|
||||
* APIMethod: evaluate
|
||||
* evaluates this rule for a specific feature
|
||||
*
|
||||
* Parameters:
|
||||
* feature - {<OpenLayers.Feature>} feature to apply the rule to.
|
||||
* For vector features, the check is run against the fid,
|
||||
* for plain features against the id.
|
||||
*
|
||||
* Returns:
|
||||
* {boolean} true if the rule applies, false if it does not
|
||||
*/
|
||||
evaluate: function(feature) {
|
||||
if (!OpenLayers.Rule.prototype.evaluate.apply(this, arguments)) {
|
||||
return false;
|
||||
}
|
||||
for (var i=0; i<this.fids.length; i++) {
|
||||
var fid = feature.fid || feature.id;
|
||||
if (fid == this.fids[i]) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
},
|
||||
|
||||
CLASS_NAME: "OpenLayers.Rule.FeatureId"
|
||||
});
|
||||
|
||||
@@ -1,104 +1,104 @@
|
||||
/* 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/Rule.js
|
||||
*/
|
||||
|
||||
/**
|
||||
* Class: OpenLayers.Rule.Logical
|
||||
* This class represents ogc:And, ogc:Or and ogc:Not rules.
|
||||
*
|
||||
* Inherits from
|
||||
* - <OpenLayers.Rule>
|
||||
*/
|
||||
OpenLayers.Rule.Logical = OpenLayers.Class(OpenLayers.Rule, {
|
||||
|
||||
/**
|
||||
* APIProperty: children
|
||||
* {Array(<OpenLayers.Rule>)} child rules for this rule
|
||||
*/
|
||||
rules: null,
|
||||
|
||||
/**
|
||||
* APIProperty: type
|
||||
* {String} type of logical operator. Available types are:
|
||||
* - OpenLayers.Rule.Locical.AND = "&&";
|
||||
* - OpenLayers.Rule.Logical.OR = "||";
|
||||
* - OpenLayers.Rule.Logical.NOT = "!";
|
||||
*/
|
||||
type: null,
|
||||
|
||||
/**
|
||||
* Constructor: OpenLayers.Rule.Logical
|
||||
* Creates a logical rule (And, Or, Not).
|
||||
*
|
||||
* Parameters:
|
||||
* options - {Object} An optional object with properties to set on the
|
||||
* rule
|
||||
*
|
||||
* Returns:
|
||||
* {<OpenLayers.Rule.Logical>}
|
||||
*/
|
||||
initialize: function(options) {
|
||||
this.rules = [];
|
||||
OpenLayers.Rule.prototype.initialize.apply(this, [options]);
|
||||
},
|
||||
|
||||
/**
|
||||
* APIMethod: destroy
|
||||
* nullify references to prevent circular references and memory leaks
|
||||
*/
|
||||
destroy: function() {
|
||||
for (var i=0; i<this.rules.length; i++) {
|
||||
this.rules[i].destroy();
|
||||
}
|
||||
this.rules = null;
|
||||
OpenLayers.Rule.prototype.destroy.apply(this, arguments);
|
||||
},
|
||||
|
||||
/**
|
||||
* APIMethod: evaluate
|
||||
* evaluates this rule for a specific feature
|
||||
*
|
||||
* Parameters:
|
||||
* feature - {<OpenLayers.Feature>} feature to apply the rule to.
|
||||
*
|
||||
* Returns:
|
||||
* {boolean} true if the rule applies, false if it does not
|
||||
*/
|
||||
evaluate: function(feature) {
|
||||
if (!OpenLayers.Rule.prototype.evaluate.apply(this, arguments)) {
|
||||
return false;
|
||||
}
|
||||
switch(this.type) {
|
||||
case OpenLayers.Rule.Logical.AND:
|
||||
for (var i=0; i<this.rules.length; i++) {
|
||||
if (this.rules[i].evaluate(feature) == false) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
|
||||
case OpenLayers.Rule.Logical.OR:
|
||||
for (var i=0; i<this.rules.length; i++) {
|
||||
if (this.rules[i].evaluate(feature) == true) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
|
||||
case OpenLayers.Rule.Logical.NOT:
|
||||
return (!this.rules[0].evaluate(feature));
|
||||
}
|
||||
},
|
||||
|
||||
CLASS_NAME: "OpenLayers.Rule.Logical"
|
||||
});
|
||||
|
||||
|
||||
OpenLayers.Rule.Logical.AND = "&&";
|
||||
OpenLayers.Rule.Logical.OR = "||";
|
||||
OpenLayers.Rule.Logical.NOT = "!";
|
||||
/* 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/Rule.js
|
||||
*/
|
||||
|
||||
/**
|
||||
* Class: OpenLayers.Rule.Logical
|
||||
* This class represents ogc:And, ogc:Or and ogc:Not rules.
|
||||
*
|
||||
* Inherits from
|
||||
* - <OpenLayers.Rule>
|
||||
*/
|
||||
OpenLayers.Rule.Logical = OpenLayers.Class(OpenLayers.Rule, {
|
||||
|
||||
/**
|
||||
* APIProperty: children
|
||||
* {Array(<OpenLayers.Rule>)} child rules for this rule
|
||||
*/
|
||||
rules: null,
|
||||
|
||||
/**
|
||||
* APIProperty: type
|
||||
* {String} type of logical operator. Available types are:
|
||||
* - OpenLayers.Rule.Locical.AND = "&&";
|
||||
* - OpenLayers.Rule.Logical.OR = "||";
|
||||
* - OpenLayers.Rule.Logical.NOT = "!";
|
||||
*/
|
||||
type: null,
|
||||
|
||||
/**
|
||||
* Constructor: OpenLayers.Rule.Logical
|
||||
* Creates a logical rule (And, Or, Not).
|
||||
*
|
||||
* Parameters:
|
||||
* options - {Object} An optional object with properties to set on the
|
||||
* rule
|
||||
*
|
||||
* Returns:
|
||||
* {<OpenLayers.Rule.Logical>}
|
||||
*/
|
||||
initialize: function(options) {
|
||||
this.rules = [];
|
||||
OpenLayers.Rule.prototype.initialize.apply(this, [options]);
|
||||
},
|
||||
|
||||
/**
|
||||
* APIMethod: destroy
|
||||
* nullify references to prevent circular references and memory leaks
|
||||
*/
|
||||
destroy: function() {
|
||||
for (var i=0; i<this.rules.length; i++) {
|
||||
this.rules[i].destroy();
|
||||
}
|
||||
this.rules = null;
|
||||
OpenLayers.Rule.prototype.destroy.apply(this, arguments);
|
||||
},
|
||||
|
||||
/**
|
||||
* APIMethod: evaluate
|
||||
* evaluates this rule for a specific feature
|
||||
*
|
||||
* Parameters:
|
||||
* feature - {<OpenLayers.Feature>} feature to apply the rule to.
|
||||
*
|
||||
* Returns:
|
||||
* {boolean} true if the rule applies, false if it does not
|
||||
*/
|
||||
evaluate: function(feature) {
|
||||
if (!OpenLayers.Rule.prototype.evaluate.apply(this, arguments)) {
|
||||
return false;
|
||||
}
|
||||
switch(this.type) {
|
||||
case OpenLayers.Rule.Logical.AND:
|
||||
for (var i=0; i<this.rules.length; i++) {
|
||||
if (this.rules[i].evaluate(feature) == false) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
|
||||
case OpenLayers.Rule.Logical.OR:
|
||||
for (var i=0; i<this.rules.length; i++) {
|
||||
if (this.rules[i].evaluate(feature) == true) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
|
||||
case OpenLayers.Rule.Logical.NOT:
|
||||
return (!this.rules[0].evaluate(feature));
|
||||
}
|
||||
},
|
||||
|
||||
CLASS_NAME: "OpenLayers.Rule.Logical"
|
||||
});
|
||||
|
||||
|
||||
OpenLayers.Rule.Logical.AND = "&&";
|
||||
OpenLayers.Rule.Logical.OR = "||";
|
||||
OpenLayers.Rule.Logical.NOT = "!";
|
||||
|
||||
@@ -1,317 +1,317 @@
|
||||
/* 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/Util.js
|
||||
* @requires OpenLayers/Feature/Vector.js
|
||||
*/
|
||||
|
||||
/**
|
||||
* Class: OpenLayers.Style
|
||||
* This class represents a UserStyle obtained
|
||||
* from a SLD, containing styling rules.
|
||||
*/
|
||||
OpenLayers.Style = OpenLayers.Class({
|
||||
|
||||
/**
|
||||
* APIProperty: name
|
||||
* {String}
|
||||
*/
|
||||
name: null,
|
||||
|
||||
/**
|
||||
* APIProperty: layerName
|
||||
* {<String>} name of the layer that this style belongs to, usually
|
||||
* according to the NamedLayer attribute of an SLD document.
|
||||
*/
|
||||
layerName: null,
|
||||
|
||||
/**
|
||||
* APIProperty: isDefault
|
||||
* {Boolean}
|
||||
*/
|
||||
isDefault: false,
|
||||
|
||||
/**
|
||||
* Property: rules
|
||||
* Array({<OpenLayers.Rule>})
|
||||
*/
|
||||
rules: null,
|
||||
|
||||
/**
|
||||
* Property: defaultStyle
|
||||
* {Object} hash of style properties to use as default for merging
|
||||
* rule-based style symbolizers onto. If no rules are defined, createStyle
|
||||
* will return this style.
|
||||
*/
|
||||
defaultStyle: null,
|
||||
|
||||
/**
|
||||
* Property: propertyStyles
|
||||
* {Hash of Boolean} cache of style properties that need to be parsed for
|
||||
* propertyNames. Property names are keys, values won't be used.
|
||||
*/
|
||||
propertyStyles: null,
|
||||
|
||||
|
||||
/**
|
||||
* Constructor: OpenLayers.Style
|
||||
* Creates a UserStyle.
|
||||
*
|
||||
* Parameters:
|
||||
* style - {Object} Optional hash of style properties that will be
|
||||
* used as default style for this style object. This style
|
||||
* applies if no rules are specified. Symbolizers defined in
|
||||
* rules will extend this default style.
|
||||
* options - {Object} An optional object with properties to set on the
|
||||
* userStyle
|
||||
*
|
||||
* Return:
|
||||
* {<OpenLayers.Style>}
|
||||
*/
|
||||
initialize: function(style, options) {
|
||||
this.rules = [];
|
||||
|
||||
// use the default style from OpenLayers.Feature.Vector if no style
|
||||
// was given in the constructor
|
||||
this.setDefaultStyle(style ||
|
||||
OpenLayers.Feature.Vector.style["default"]);
|
||||
|
||||
OpenLayers.Util.extend(this, options);
|
||||
},
|
||||
|
||||
/**
|
||||
* APIMethod: destroy
|
||||
* nullify references to prevent circular references and memory leaks
|
||||
*/
|
||||
destroy: function() {
|
||||
for (var i=0; i<this.rules.length; i++) {
|
||||
this.rules[i].destroy();
|
||||
this.rules[i] = null;
|
||||
}
|
||||
this.rules = null;
|
||||
this.defaultStyle = null;
|
||||
},
|
||||
|
||||
/**
|
||||
* APIMethod: createStyle
|
||||
* creates a style by applying all feature-dependent rules to the base
|
||||
* style.
|
||||
*
|
||||
* Parameters:
|
||||
* feature - {<OpenLayers.Feature>} feature to evaluate rules for
|
||||
* baseStyle - {Object} hash of styles feature styles to extend
|
||||
*
|
||||
* Returns:
|
||||
* {<OpenLayers.Feature.Vector.style>} hash of feature styles
|
||||
*/
|
||||
createStyle: function(feature) {
|
||||
var style = OpenLayers.Util.extend({}, this.defaultStyle);
|
||||
|
||||
var rules = this.rules;
|
||||
|
||||
var rule, context;
|
||||
var elseRules = [];
|
||||
var appliedRules = false;
|
||||
for(var i=0; i<rules.length; i++) {
|
||||
rule = rules[i];
|
||||
context = rule.context;
|
||||
if (!context) {
|
||||
context = feature.attributes || feature.data;
|
||||
}
|
||||
// does the rule apply?
|
||||
var applies = rule.evaluate(feature);
|
||||
|
||||
if(applies) {
|
||||
if(rule instanceof OpenLayers.Rule && rule.elseFilter) {
|
||||
elseRules.push(rule);
|
||||
} else {
|
||||
appliedRules = true;
|
||||
this.applySymbolizer(rule, style, feature, context);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// if no other rules apply, apply the rules with else filters
|
||||
if(appliedRules == false && elseRules.length > 0) {
|
||||
appliedRules = true;
|
||||
for(var i=0; i<elseRules.length; i++) {
|
||||
this.applySymbolizer(elseRules[i], style, feature, context);
|
||||
}
|
||||
}
|
||||
|
||||
// don't display if there were rules but none applied
|
||||
if(rules.length > 0 && appliedRules == false) {
|
||||
style.display = "none";
|
||||
} else {
|
||||
style.display = "";
|
||||
}
|
||||
|
||||
return style;
|
||||
},
|
||||
|
||||
/**
|
||||
* Method: applySymbolizer
|
||||
*
|
||||
* Parameters:
|
||||
* rule - {OpenLayers.Rule}
|
||||
* style - {Object}
|
||||
* feature - {<OpenLayer.Feature.Vector>}
|
||||
* context - {Object}
|
||||
*
|
||||
* Returns:
|
||||
* {Object} A style with new symbolizer applied.
|
||||
*/
|
||||
applySymbolizer: function(rule, style, feature, context) {
|
||||
var symbolizerPrefix = feature.geometry ?
|
||||
this.getSymbolizerPrefix(feature.geometry) :
|
||||
OpenLayers.Style.SYMBOLIZER_PREFIXES[0];
|
||||
|
||||
var symbolizer = rule.symbolizer[symbolizerPrefix];
|
||||
|
||||
// merge the style with the current style
|
||||
return this.createLiterals(
|
||||
OpenLayers.Util.extend(style, symbolizer), context);
|
||||
},
|
||||
|
||||
/**
|
||||
* Method: createLiterals
|
||||
* creates literals for all style properties that have an entry in
|
||||
* <this.propertyStyles>.
|
||||
*
|
||||
* Parameters:
|
||||
* style - {Object} style to create literals for. Will be modified
|
||||
* inline.
|
||||
* context - {Object} context to take property values from. Defaults to
|
||||
* feature.attributes (or feature.data, if attributes are not
|
||||
* available)
|
||||
*
|
||||
* Returns;
|
||||
* {Object} the modified style
|
||||
*/
|
||||
createLiterals: function(style, context) {
|
||||
for (var i in this.propertyStyles) {
|
||||
style[i] = OpenLayers.Style.createLiteral(style[i], context);
|
||||
}
|
||||
return style;
|
||||
},
|
||||
|
||||
/**
|
||||
* Method: findPropertyStyles
|
||||
* Looks into all rules for this style and the defaultStyle to collect
|
||||
* all the style hash property names containing ${...} strings that have
|
||||
* to be replaced using the createLiteral method before returning them.
|
||||
*
|
||||
* Returns:
|
||||
* {Object} hash of property names that need createLiteral parsing. The
|
||||
* name of the property is the key, and the value is true;
|
||||
*/
|
||||
findPropertyStyles: function() {
|
||||
var propertyStyles = {};
|
||||
|
||||
// check the default style
|
||||
var style = this.defaultStyle;
|
||||
for (var i in style) {
|
||||
if (typeof style[i] == "string" && style[i].match(/\$\{\w+\}/)) {
|
||||
propertyStyles[i] = true;
|
||||
}
|
||||
}
|
||||
|
||||
// walk through all rules to check for properties in their symbolizer
|
||||
var rules = this.rules;
|
||||
var prefixes = OpenLayers.Style.SYMBOLIZER_PREFIXES;
|
||||
for (var i in rules) {
|
||||
for (var s=0; s<prefixes.length; s++) {
|
||||
style = rules[i].symbolizer[prefixes[s]];
|
||||
for (var j in style) {
|
||||
if (typeof style[j] == "string" &&
|
||||
style[j].match(/\$\{\w+\}/)) {
|
||||
propertyStyles[j] = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return propertyStyles;
|
||||
},
|
||||
|
||||
/**
|
||||
* APIMethod: addRules
|
||||
* Adds rules to this style.
|
||||
*
|
||||
* Parameters:
|
||||
* rules - {Array(<OpenLayers.Rule>)}
|
||||
*/
|
||||
addRules: function(rules) {
|
||||
this.rules = this.rules.concat(rules);
|
||||
this.propertyStyles = this.findPropertyStyles();
|
||||
},
|
||||
|
||||
/**
|
||||
* APIMethod: setDefaultStyle
|
||||
* Sets the default style for this style object.
|
||||
*
|
||||
* Parameters:
|
||||
* style - {Object} Hash of style properties
|
||||
*/
|
||||
setDefaultStyle: function(style) {
|
||||
this.defaultStyle = style;
|
||||
this.propertyStyles = this.findPropertyStyles();
|
||||
},
|
||||
|
||||
/**
|
||||
* Method: getSymbolizerPrefix
|
||||
* Returns the correct symbolizer prefix according to the
|
||||
* geometry type of the passed geometry
|
||||
*
|
||||
* Parameters:
|
||||
* geometry {<OpenLayers.Geometry>}
|
||||
*
|
||||
* Returns:
|
||||
* {String} key of the according symbolizer
|
||||
*/
|
||||
getSymbolizerPrefix: function(geometry) {
|
||||
var prefixes = OpenLayers.Style.SYMBOLIZER_PREFIXES;
|
||||
for (var i=0; i<prefixes.length; i++) {
|
||||
if (geometry.CLASS_NAME.indexOf(prefixes[i]) != -1) {
|
||||
return prefixes[i];
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
CLASS_NAME: "OpenLayers.Style"
|
||||
});
|
||||
|
||||
|
||||
/**
|
||||
* Function: createLiteral
|
||||
* converts a style value holding a combination of PropertyName and Literal
|
||||
* into a Literal, taking the property values from the passed features.
|
||||
*
|
||||
* Parameters:
|
||||
* value {String} value to parse. If this string contains a construct like
|
||||
* "foo ${bar}", then "foo " will be taken as literal, and "${bar}"
|
||||
* will be replaced by the value of the "bar" attribute of the passed
|
||||
* feature.
|
||||
* context {Object} context to take attribute values from
|
||||
*
|
||||
* Returns:
|
||||
* {String} the parsed value. In the example of the value parameter above, the
|
||||
* result would be "foo valueOfBar", assuming that the passed feature has an
|
||||
* attribute named "bar" with the value "valueOfBar".
|
||||
*/
|
||||
OpenLayers.Style.createLiteral = function(value, context) {
|
||||
if (typeof value == "string" && value.indexOf("${") != -1) {
|
||||
value = OpenLayers.String.format(value, context)
|
||||
value = isNaN(value) ? value : parseFloat(value);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constant: OpenLayers.Style.SYMBOLIZER_PREFIXES
|
||||
* {Array} prefixes of the sld symbolizers. These are the
|
||||
* same as the main geometry types
|
||||
*/
|
||||
OpenLayers.Style.SYMBOLIZER_PREFIXES = ['Point', 'Line', 'Polygon'];
|
||||
/* 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/Util.js
|
||||
* @requires OpenLayers/Feature/Vector.js
|
||||
*/
|
||||
|
||||
/**
|
||||
* Class: OpenLayers.Style
|
||||
* This class represents a UserStyle obtained
|
||||
* from a SLD, containing styling rules.
|
||||
*/
|
||||
OpenLayers.Style = OpenLayers.Class({
|
||||
|
||||
/**
|
||||
* APIProperty: name
|
||||
* {String}
|
||||
*/
|
||||
name: null,
|
||||
|
||||
/**
|
||||
* APIProperty: layerName
|
||||
* {<String>} name of the layer that this style belongs to, usually
|
||||
* according to the NamedLayer attribute of an SLD document.
|
||||
*/
|
||||
layerName: null,
|
||||
|
||||
/**
|
||||
* APIProperty: isDefault
|
||||
* {Boolean}
|
||||
*/
|
||||
isDefault: false,
|
||||
|
||||
/**
|
||||
* Property: rules
|
||||
* Array({<OpenLayers.Rule>})
|
||||
*/
|
||||
rules: null,
|
||||
|
||||
/**
|
||||
* Property: defaultStyle
|
||||
* {Object} hash of style properties to use as default for merging
|
||||
* rule-based style symbolizers onto. If no rules are defined, createStyle
|
||||
* will return this style.
|
||||
*/
|
||||
defaultStyle: null,
|
||||
|
||||
/**
|
||||
* Property: propertyStyles
|
||||
* {Hash of Boolean} cache of style properties that need to be parsed for
|
||||
* propertyNames. Property names are keys, values won't be used.
|
||||
*/
|
||||
propertyStyles: null,
|
||||
|
||||
|
||||
/**
|
||||
* Constructor: OpenLayers.Style
|
||||
* Creates a UserStyle.
|
||||
*
|
||||
* Parameters:
|
||||
* style - {Object} Optional hash of style properties that will be
|
||||
* used as default style for this style object. This style
|
||||
* applies if no rules are specified. Symbolizers defined in
|
||||
* rules will extend this default style.
|
||||
* options - {Object} An optional object with properties to set on the
|
||||
* userStyle
|
||||
*
|
||||
* Return:
|
||||
* {<OpenLayers.Style>}
|
||||
*/
|
||||
initialize: function(style, options) {
|
||||
this.rules = [];
|
||||
|
||||
// use the default style from OpenLayers.Feature.Vector if no style
|
||||
// was given in the constructor
|
||||
this.setDefaultStyle(style ||
|
||||
OpenLayers.Feature.Vector.style["default"]);
|
||||
|
||||
OpenLayers.Util.extend(this, options);
|
||||
},
|
||||
|
||||
/**
|
||||
* APIMethod: destroy
|
||||
* nullify references to prevent circular references and memory leaks
|
||||
*/
|
||||
destroy: function() {
|
||||
for (var i=0; i<this.rules.length; i++) {
|
||||
this.rules[i].destroy();
|
||||
this.rules[i] = null;
|
||||
}
|
||||
this.rules = null;
|
||||
this.defaultStyle = null;
|
||||
},
|
||||
|
||||
/**
|
||||
* APIMethod: createStyle
|
||||
* creates a style by applying all feature-dependent rules to the base
|
||||
* style.
|
||||
*
|
||||
* Parameters:
|
||||
* feature - {<OpenLayers.Feature>} feature to evaluate rules for
|
||||
* baseStyle - {Object} hash of styles feature styles to extend
|
||||
*
|
||||
* Returns:
|
||||
* {<OpenLayers.Feature.Vector.style>} hash of feature styles
|
||||
*/
|
||||
createStyle: function(feature) {
|
||||
var style = OpenLayers.Util.extend({}, this.defaultStyle);
|
||||
|
||||
var rules = this.rules;
|
||||
|
||||
var rule, context;
|
||||
var elseRules = [];
|
||||
var appliedRules = false;
|
||||
for(var i=0; i<rules.length; i++) {
|
||||
rule = rules[i];
|
||||
context = rule.context;
|
||||
if (!context) {
|
||||
context = feature.attributes || feature.data;
|
||||
}
|
||||
// does the rule apply?
|
||||
var applies = rule.evaluate(feature);
|
||||
|
||||
if(applies) {
|
||||
if(rule instanceof OpenLayers.Rule && rule.elseFilter) {
|
||||
elseRules.push(rule);
|
||||
} else {
|
||||
appliedRules = true;
|
||||
this.applySymbolizer(rule, style, feature, context);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// if no other rules apply, apply the rules with else filters
|
||||
if(appliedRules == false && elseRules.length > 0) {
|
||||
appliedRules = true;
|
||||
for(var i=0; i<elseRules.length; i++) {
|
||||
this.applySymbolizer(elseRules[i], style, feature, context);
|
||||
}
|
||||
}
|
||||
|
||||
// don't display if there were rules but none applied
|
||||
if(rules.length > 0 && appliedRules == false) {
|
||||
style.display = "none";
|
||||
} else {
|
||||
style.display = "";
|
||||
}
|
||||
|
||||
return style;
|
||||
},
|
||||
|
||||
/**
|
||||
* Method: applySymbolizer
|
||||
*
|
||||
* Parameters:
|
||||
* rule - {OpenLayers.Rule}
|
||||
* style - {Object}
|
||||
* feature - {<OpenLayer.Feature.Vector>}
|
||||
* context - {Object}
|
||||
*
|
||||
* Returns:
|
||||
* {Object} A style with new symbolizer applied.
|
||||
*/
|
||||
applySymbolizer: function(rule, style, feature, context) {
|
||||
var symbolizerPrefix = feature.geometry ?
|
||||
this.getSymbolizerPrefix(feature.geometry) :
|
||||
OpenLayers.Style.SYMBOLIZER_PREFIXES[0];
|
||||
|
||||
var symbolizer = rule.symbolizer[symbolizerPrefix];
|
||||
|
||||
// merge the style with the current style
|
||||
return this.createLiterals(
|
||||
OpenLayers.Util.extend(style, symbolizer), context);
|
||||
},
|
||||
|
||||
/**
|
||||
* Method: createLiterals
|
||||
* creates literals for all style properties that have an entry in
|
||||
* <this.propertyStyles>.
|
||||
*
|
||||
* Parameters:
|
||||
* style - {Object} style to create literals for. Will be modified
|
||||
* inline.
|
||||
* context - {Object} context to take property values from. Defaults to
|
||||
* feature.attributes (or feature.data, if attributes are not
|
||||
* available)
|
||||
*
|
||||
* Returns;
|
||||
* {Object} the modified style
|
||||
*/
|
||||
createLiterals: function(style, context) {
|
||||
for (var i in this.propertyStyles) {
|
||||
style[i] = OpenLayers.Style.createLiteral(style[i], context);
|
||||
}
|
||||
return style;
|
||||
},
|
||||
|
||||
/**
|
||||
* Method: findPropertyStyles
|
||||
* Looks into all rules for this style and the defaultStyle to collect
|
||||
* all the style hash property names containing ${...} strings that have
|
||||
* to be replaced using the createLiteral method before returning them.
|
||||
*
|
||||
* Returns:
|
||||
* {Object} hash of property names that need createLiteral parsing. The
|
||||
* name of the property is the key, and the value is true;
|
||||
*/
|
||||
findPropertyStyles: function() {
|
||||
var propertyStyles = {};
|
||||
|
||||
// check the default style
|
||||
var style = this.defaultStyle;
|
||||
for (var i in style) {
|
||||
if (typeof style[i] == "string" && style[i].match(/\$\{\w+\}/)) {
|
||||
propertyStyles[i] = true;
|
||||
}
|
||||
}
|
||||
|
||||
// walk through all rules to check for properties in their symbolizer
|
||||
var rules = this.rules;
|
||||
var prefixes = OpenLayers.Style.SYMBOLIZER_PREFIXES;
|
||||
for (var i in rules) {
|
||||
for (var s=0; s<prefixes.length; s++) {
|
||||
style = rules[i].symbolizer[prefixes[s]];
|
||||
for (var j in style) {
|
||||
if (typeof style[j] == "string" &&
|
||||
style[j].match(/\$\{\w+\}/)) {
|
||||
propertyStyles[j] = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return propertyStyles;
|
||||
},
|
||||
|
||||
/**
|
||||
* APIMethod: addRules
|
||||
* Adds rules to this style.
|
||||
*
|
||||
* Parameters:
|
||||
* rules - {Array(<OpenLayers.Rule>)}
|
||||
*/
|
||||
addRules: function(rules) {
|
||||
this.rules = this.rules.concat(rules);
|
||||
this.propertyStyles = this.findPropertyStyles();
|
||||
},
|
||||
|
||||
/**
|
||||
* APIMethod: setDefaultStyle
|
||||
* Sets the default style for this style object.
|
||||
*
|
||||
* Parameters:
|
||||
* style - {Object} Hash of style properties
|
||||
*/
|
||||
setDefaultStyle: function(style) {
|
||||
this.defaultStyle = style;
|
||||
this.propertyStyles = this.findPropertyStyles();
|
||||
},
|
||||
|
||||
/**
|
||||
* Method: getSymbolizerPrefix
|
||||
* Returns the correct symbolizer prefix according to the
|
||||
* geometry type of the passed geometry
|
||||
*
|
||||
* Parameters:
|
||||
* geometry {<OpenLayers.Geometry>}
|
||||
*
|
||||
* Returns:
|
||||
* {String} key of the according symbolizer
|
||||
*/
|
||||
getSymbolizerPrefix: function(geometry) {
|
||||
var prefixes = OpenLayers.Style.SYMBOLIZER_PREFIXES;
|
||||
for (var i=0; i<prefixes.length; i++) {
|
||||
if (geometry.CLASS_NAME.indexOf(prefixes[i]) != -1) {
|
||||
return prefixes[i];
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
CLASS_NAME: "OpenLayers.Style"
|
||||
});
|
||||
|
||||
|
||||
/**
|
||||
* Function: createLiteral
|
||||
* converts a style value holding a combination of PropertyName and Literal
|
||||
* into a Literal, taking the property values from the passed features.
|
||||
*
|
||||
* Parameters:
|
||||
* value {String} value to parse. If this string contains a construct like
|
||||
* "foo ${bar}", then "foo " will be taken as literal, and "${bar}"
|
||||
* will be replaced by the value of the "bar" attribute of the passed
|
||||
* feature.
|
||||
* context {Object} context to take attribute values from
|
||||
*
|
||||
* Returns:
|
||||
* {String} the parsed value. In the example of the value parameter above, the
|
||||
* result would be "foo valueOfBar", assuming that the passed feature has an
|
||||
* attribute named "bar" with the value "valueOfBar".
|
||||
*/
|
||||
OpenLayers.Style.createLiteral = function(value, context) {
|
||||
if (typeof value == "string" && value.indexOf("${") != -1) {
|
||||
value = OpenLayers.String.format(value, context)
|
||||
value = isNaN(value) ? value : parseFloat(value);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constant: OpenLayers.Style.SYMBOLIZER_PREFIXES
|
||||
* {Array} prefixes of the sld symbolizers. These are the
|
||||
* same as the main geometry types
|
||||
*/
|
||||
OpenLayers.Style.SYMBOLIZER_PREFIXES = ['Point', 'Line', 'Polygon'];
|
||||
|
||||
Reference in New Issue
Block a user