Commit d649bc4f7a3b4b8b3a76dd53a2bca6314098348e
1 parent
73e4c672
Exists in
master
and in
7 other branches
--no commit message
Showing
5 changed files
with
0 additions
and
2863 deletions
Show diff stats
ferramentas/ol3panel/Class.js
| ... | ... | @@ -1,163 +0,0 @@ |
| 1 | -/* Copyright (c) 2006-2011 by OpenLayers Contributors (see authors.txt for | |
| 2 | - * full list of contributors). Published under the Clear BSD license. | |
| 3 | - * See http://svn.openlayers.org/trunk/openlayers/license.txt for the | |
| 4 | - * full text of the license. */ | |
| 5 | - | |
| 6 | -/** | |
| 7 | - * @requires OpenLayers/SingleFile.js | |
| 8 | - */ | |
| 9 | - | |
| 10 | -/** | |
| 11 | - * Constructor: OpenLayers.Class | |
| 12 | - * Base class used to construct all other classes. Includes support for | |
| 13 | - * multiple inheritance. | |
| 14 | - * | |
| 15 | - * This constructor is new in OpenLayers 2.5. At OpenLayers 3.0, the old | |
| 16 | - * syntax for creating classes and dealing with inheritance | |
| 17 | - * will be removed. | |
| 18 | - * | |
| 19 | - * To create a new OpenLayers-style class, use the following syntax: | |
| 20 | - * (code) | |
| 21 | - * var MyClass = OpenLayers.Class(prototype); | |
| 22 | - * (end) | |
| 23 | - * | |
| 24 | - * To create a new OpenLayers-style class with multiple inheritance, use the | |
| 25 | - * following syntax: | |
| 26 | - * (code) | |
| 27 | - * var MyClass = OpenLayers.Class(Class1, Class2, prototype); | |
| 28 | - * (end) | |
| 29 | - * | |
| 30 | - * Note that instanceof reflection will only reveal Class1 as superclass. | |
| 31 | - * | |
| 32 | - */ | |
| 33 | -OpenLayers.Class = function() { | |
| 34 | - var len = arguments.length; | |
| 35 | - var P = arguments[0]; | |
| 36 | - var F = arguments[len-1]; | |
| 37 | - | |
| 38 | - var C = typeof F.initialize == "function" ? | |
| 39 | - F.initialize : | |
| 40 | - function(){ P.prototype.initialize.apply(this, arguments); }; | |
| 41 | - | |
| 42 | - if (len > 1) { | |
| 43 | - var newArgs = [C, P].concat( | |
| 44 | - Array.prototype.slice.call(arguments).slice(1, len-1), F); | |
| 45 | - OpenLayers.inherit.apply(null, newArgs); | |
| 46 | - } else { | |
| 47 | - C.prototype = F; | |
| 48 | - } | |
| 49 | - return C; | |
| 50 | -}; | |
| 51 | - | |
| 52 | -/** | |
| 53 | - * Property: isPrototype | |
| 54 | - * *Deprecated*. This is no longer needed and will be removed at 3.0. | |
| 55 | - */ | |
| 56 | -OpenLayers.Class.isPrototype = function () {}; | |
| 57 | - | |
| 58 | -/** | |
| 59 | - * APIFunction: OpenLayers.create | |
| 60 | - * *Deprecated*. Old method to create an OpenLayers style class. Use the | |
| 61 | - * <OpenLayers.Class> constructor instead. | |
| 62 | - * | |
| 63 | - * Returns: | |
| 64 | - * An OpenLayers class | |
| 65 | - */ | |
| 66 | -OpenLayers.Class.create = function() { | |
| 67 | - return function() { | |
| 68 | - if (arguments && arguments[0] != OpenLayers.Class.isPrototype) { | |
| 69 | - this.initialize.apply(this, arguments); | |
| 70 | - } | |
| 71 | - }; | |
| 72 | -}; | |
| 73 | - | |
| 74 | -/** | |
| 75 | - * APIFunction: inherit | |
| 76 | - * *Deprecated*. Old method to inherit from one or more OpenLayers style | |
| 77 | - * classes. Use the <OpenLayers.Class> constructor instead. | |
| 78 | - * | |
| 79 | - * Parameters: | |
| 80 | - * class - One or more classes can be provided as arguments | |
| 81 | - * | |
| 82 | - * Returns: | |
| 83 | - * An object prototype | |
| 84 | - */ | |
| 85 | -OpenLayers.Class.inherit = function (P) { | |
| 86 | - var C = function() { | |
| 87 | - P.call(this); | |
| 88 | - }; | |
| 89 | - var newArgs = [C].concat(Array.prototype.slice.call(arguments)); | |
| 90 | - OpenLayers.inherit.apply(null, newArgs); | |
| 91 | - return C.prototype; | |
| 92 | -}; | |
| 93 | - | |
| 94 | -/** | |
| 95 | - * Function: OpenLayers.inherit | |
| 96 | - * | |
| 97 | - * Parameters: | |
| 98 | - * C - {Object} the class that inherits | |
| 99 | - * P - {Object} the superclass to inherit from | |
| 100 | - * | |
| 101 | - * In addition to the mandatory C and P parameters, an arbitrary number of | |
| 102 | - * objects can be passed, which will extend C. | |
| 103 | - */ | |
| 104 | -OpenLayers.inherit = function(C, P) { | |
| 105 | - var F = function() {}; | |
| 106 | - F.prototype = P.prototype; | |
| 107 | - C.prototype = new F; | |
| 108 | - var i, l, o; | |
| 109 | - for(i=2, l=arguments.length; i<l; i++) { | |
| 110 | - o = arguments[i]; | |
| 111 | - if(typeof o === "function") { | |
| 112 | - o = o.prototype; | |
| 113 | - } | |
| 114 | - OpenLayers.Util.extend(C.prototype, o); | |
| 115 | - } | |
| 116 | -}; | |
| 117 | - | |
| 118 | -/** | |
| 119 | - * APIFunction: extend | |
| 120 | - * Copy all properties of a source object to a destination object. Modifies | |
| 121 | - * the passed in destination object. Any properties on the source object | |
| 122 | - * that are set to undefined will not be (re)set on the destination object. | |
| 123 | - * | |
| 124 | - * Parameters: | |
| 125 | - * destination - {Object} The object that will be modified | |
| 126 | - * source - {Object} The object with properties to be set on the destination | |
| 127 | - * | |
| 128 | - * Returns: | |
| 129 | - * {Object} The destination object. | |
| 130 | - */ | |
| 131 | -OpenLayers.Util = OpenLayers.Util || {}; | |
| 132 | -OpenLayers.Util.extend = function(destination, source) { | |
| 133 | - destination = destination || {}; | |
| 134 | - if (source) { | |
| 135 | - for (var property in source) { | |
| 136 | - var value = source[property]; | |
| 137 | - if (value !== undefined) { | |
| 138 | - destination[property] = value; | |
| 139 | - } | |
| 140 | - } | |
| 141 | - | |
| 142 | - /** | |
| 143 | - * IE doesn't include the toString property when iterating over an object's | |
| 144 | - * properties with the for(property in object) syntax. Explicitly check if | |
| 145 | - * the source has its own toString property. | |
| 146 | - */ | |
| 147 | - | |
| 148 | - /* | |
| 149 | - * FF/Windows < 2.0.0.13 reports "Illegal operation on WrappedNative | |
| 150 | - * prototype object" when calling hawOwnProperty if the source object | |
| 151 | - * is an instance of window.Event. | |
| 152 | - */ | |
| 153 | - | |
| 154 | - var sourceIsEvt = typeof window.Event == "function" | |
| 155 | - && source instanceof window.Event; | |
| 156 | - | |
| 157 | - if (!sourceIsEvt | |
| 158 | - && source.hasOwnProperty && source.hasOwnProperty("toString")) { | |
| 159 | - destination.toString = source.toString; | |
| 160 | - } | |
| 161 | - } | |
| 162 | - return destination; | |
| 163 | -}; |
ferramentas/ol3panel/Control.js
| ... | ... | @@ -1,372 +0,0 @@ |
| 1 | -/* Copyright (c) 2006-2011 by OpenLayers Contributors (see authors.txt for | |
| 2 | - * full list of contributors). Published under the Clear BSD license. | |
| 3 | - * See http://svn.openlayers.org/trunk/openlayers/license.txt for the | |
| 4 | - * full text of the license. */ | |
| 5 | - | |
| 6 | -/** | |
| 7 | - * @requires OpenLayers/BaseTypes/Class.js | |
| 8 | - * @requires OpenLayers/Console.js | |
| 9 | - */ | |
| 10 | - | |
| 11 | -/** | |
| 12 | - * Class: OpenLayers.Control | |
| 13 | - * Controls affect the display or behavior of the map. They allow everything | |
| 14 | - * from panning and zooming to displaying a scale indicator. Controls by | |
| 15 | - * default are added to the map they are contained within however it is | |
| 16 | - * possible to add a control to an external div by passing the div in the | |
| 17 | - * options parameter. | |
| 18 | - * | |
| 19 | - * Example: | |
| 20 | - * The following example shows how to add many of the common controls | |
| 21 | - * to a map. | |
| 22 | - * | |
| 23 | - * > var map = new OpenLayers.Map('map', { controls: [] }); | |
| 24 | - * > | |
| 25 | - * > map.addControl(new OpenLayers.Control.PanZoomBar()); | |
| 26 | - * > map.addControl(new OpenLayers.Control.MouseToolbar()); | |
| 27 | - * > map.addControl(new OpenLayers.Control.LayerSwitcher({'ascending':false})); | |
| 28 | - * > map.addControl(new OpenLayers.Control.Permalink()); | |
| 29 | - * > map.addControl(new OpenLayers.Control.Permalink('permalink')); | |
| 30 | - * > map.addControl(new OpenLayers.Control.MousePosition()); | |
| 31 | - * > map.addControl(new OpenLayers.Control.OverviewMap()); | |
| 32 | - * > map.addControl(new OpenLayers.Control.KeyboardDefaults()); | |
| 33 | - * | |
| 34 | - * The next code fragment is a quick example of how to intercept | |
| 35 | - * shift-mouse click to display the extent of the bounding box | |
| 36 | - * dragged out by the user. Usually controls are not created | |
| 37 | - * in exactly this manner. See the source for a more complete | |
| 38 | - * example: | |
| 39 | - * | |
| 40 | - * > var control = new OpenLayers.Control(); | |
| 41 | - * > OpenLayers.Util.extend(control, { | |
| 42 | - * > draw: function () { | |
| 43 | - * > // this Handler.Box will intercept the shift-mousedown | |
| 44 | - * > // before Control.MouseDefault gets to see it | |
| 45 | - * > this.box = new OpenLayers.Handler.Box( control, | |
| 46 | - * > {"done": this.notice}, | |
| 47 | - * > {keyMask: OpenLayers.Handler.MOD_SHIFT}); | |
| 48 | - * > this.box.activate(); | |
| 49 | - * > }, | |
| 50 | - * > | |
| 51 | - * > notice: function (bounds) { | |
| 52 | - * > OpenLayers.Console.userError(bounds); | |
| 53 | - * > } | |
| 54 | - * > }); | |
| 55 | - * > map.addControl(control); | |
| 56 | - * | |
| 57 | - */ | |
| 58 | -OpenLayers.Control = OpenLayers.Class({ | |
| 59 | - | |
| 60 | - /** | |
| 61 | - * Property: id | |
| 62 | - * {String} | |
| 63 | - */ | |
| 64 | - id: null, | |
| 65 | - | |
| 66 | - /** | |
| 67 | - * Property: map | |
| 68 | - * {<OpenLayers.Map>} this gets set in the addControl() function in | |
| 69 | - * OpenLayers.Map | |
| 70 | - */ | |
| 71 | - map: null, | |
| 72 | - | |
| 73 | - /** | |
| 74 | - * APIProperty: div | |
| 75 | - * {DOMElement} The element that contains the control, if not present the | |
| 76 | - * control is placed inside the map. | |
| 77 | - */ | |
| 78 | - div: null, | |
| 79 | - | |
| 80 | - /** | |
| 81 | - * APIProperty: type | |
| 82 | - * {Number} Controls can have a 'type'. The type determines the type of | |
| 83 | - * interactions which are possible with them when they are placed in an | |
| 84 | - * <OpenLayers.Control.Panel>. | |
| 85 | - */ | |
| 86 | - type: null, | |
| 87 | - | |
| 88 | - /** | |
| 89 | - * Property: allowSelection | |
| 90 | - * {Boolean} By deafault, controls do not allow selection, because | |
| 91 | - * it may interfere with map dragging. If this is true, OpenLayers | |
| 92 | - * will not prevent selection of the control. | |
| 93 | - * Default is false. | |
| 94 | - */ | |
| 95 | - allowSelection: false, | |
| 96 | - | |
| 97 | - /** | |
| 98 | - * Property: displayClass | |
| 99 | - * {string} This property is used for CSS related to the drawing of the | |
| 100 | - * Control. | |
| 101 | - */ | |
| 102 | - displayClass: "", | |
| 103 | - | |
| 104 | - /** | |
| 105 | - * APIProperty: title | |
| 106 | - * {string} This property is used for showing a tooltip over the | |
| 107 | - * Control. | |
| 108 | - */ | |
| 109 | - title: "", | |
| 110 | - | |
| 111 | - /** | |
| 112 | - * APIProperty: autoActivate | |
| 113 | - * {Boolean} Activate the control when it is added to a map. Default is | |
| 114 | - * false. | |
| 115 | - */ | |
| 116 | - autoActivate: false, | |
| 117 | - | |
| 118 | - /** | |
| 119 | - * APIProperty: active | |
| 120 | - * {Boolean} The control is active (read-only). Use <activate> and | |
| 121 | - * <deactivate> to change control state. | |
| 122 | - */ | |
| 123 | - active: null, | |
| 124 | - | |
| 125 | - /** | |
| 126 | - * Property: handler | |
| 127 | - * {<OpenLayers.Handler>} null | |
| 128 | - */ | |
| 129 | - handler: null, | |
| 130 | - | |
| 131 | - /** | |
| 132 | - * APIProperty: eventListeners | |
| 133 | - * {Object} If set as an option at construction, the eventListeners | |
| 134 | - * object will be registered with <OpenLayers.Events.on>. Object | |
| 135 | - * structure must be a listeners object as shown in the example for | |
| 136 | - * the events.on method. | |
| 137 | - */ | |
| 138 | - eventListeners: null, | |
| 139 | - | |
| 140 | - /** | |
| 141 | - * APIProperty: events | |
| 142 | - * {<OpenLayers.Events>} Events instance for listeners and triggering | |
| 143 | - * control specific events. | |
| 144 | - */ | |
| 145 | - events: null, | |
| 146 | - | |
| 147 | - /** | |
| 148 | - * Constant: EVENT_TYPES | |
| 149 | - * {Array(String)} Supported application event types. Register a listener | |
| 150 | - * for a particular event with the following syntax: | |
| 151 | - * (code) | |
| 152 | - * control.events.register(type, obj, listener); | |
| 153 | - * (end) | |
| 154 | - * | |
| 155 | - * Listeners will be called with a reference to an event object. The | |
| 156 | - * properties of this event depends on exactly what happened. | |
| 157 | - * | |
| 158 | - * All event objects have at least the following properties: | |
| 159 | - * object - {Object} A reference to control.events.object (a reference | |
| 160 | - * to the control). | |
| 161 | - * element - {DOMElement} A reference to control.events.element (which | |
| 162 | - * will be null unless documented otherwise). | |
| 163 | - * | |
| 164 | - * Supported map event types: | |
| 165 | - * activate - Triggered when activated. | |
| 166 | - * deactivate - Triggered when deactivated. | |
| 167 | - */ | |
| 168 | - EVENT_TYPES: ["activate", "deactivate"], | |
| 169 | - | |
| 170 | - /** | |
| 171 | - * Constructor: OpenLayers.Control | |
| 172 | - * Create an OpenLayers Control. The options passed as a parameter | |
| 173 | - * directly extend the control. For example passing the following: | |
| 174 | - * | |
| 175 | - * > var control = new OpenLayers.Control({div: myDiv}); | |
| 176 | - * | |
| 177 | - * Overrides the default div attribute value of null. | |
| 178 | - * | |
| 179 | - * Parameters: | |
| 180 | - * options - {Object} | |
| 181 | - */ | |
| 182 | - initialize: function (options) { | |
| 183 | - // We do this before the extend so that instances can override | |
| 184 | - // className in options. | |
| 185 | - this.displayClass = | |
| 186 | - this.CLASS_NAME.replace("OpenLayers.", "ol").replace(/\./g, ""); | |
| 187 | - | |
| 188 | - OpenLayers.Util.extend(this, options); | |
| 189 | - | |
| 190 | - this.events = new OpenLayers.Events(this, null, this.EVENT_TYPES); | |
| 191 | - if(this.eventListeners instanceof Object) { | |
| 192 | - this.events.on(this.eventListeners); | |
| 193 | - } | |
| 194 | - if (this.id == null) { | |
| 195 | - this.id = OpenLayers.Util.createUniqueID(this.CLASS_NAME + "_"); | |
| 196 | - } | |
| 197 | - }, | |
| 198 | - | |
| 199 | - /** | |
| 200 | - * Method: destroy | |
| 201 | - * The destroy method is used to perform any clean up before the control | |
| 202 | - * is dereferenced. Typically this is where event listeners are removed | |
| 203 | - * to prevent memory leaks. | |
| 204 | - */ | |
| 205 | - destroy: function () { | |
| 206 | - if(this.events) { | |
| 207 | - if(this.eventListeners) { | |
| 208 | - this.events.un(this.eventListeners); | |
| 209 | - } | |
| 210 | - this.events.destroy(); | |
| 211 | - this.events = null; | |
| 212 | - } | |
| 213 | - this.eventListeners = null; | |
| 214 | - | |
| 215 | - // eliminate circular references | |
| 216 | - if (this.handler) { | |
| 217 | - this.handler.destroy(); | |
| 218 | - this.handler = null; | |
| 219 | - } | |
| 220 | - if(this.handlers) { | |
| 221 | - for(var key in this.handlers) { | |
| 222 | - if(this.handlers.hasOwnProperty(key) && | |
| 223 | - typeof this.handlers[key].destroy == "function") { | |
| 224 | - this.handlers[key].destroy(); | |
| 225 | - } | |
| 226 | - } | |
| 227 | - this.handlers = null; | |
| 228 | - } | |
| 229 | - if (this.map) { | |
| 230 | - this.map.removeControl(this); | |
| 231 | - this.map = null; | |
| 232 | - } | |
| 233 | - this.div = null; | |
| 234 | - }, | |
| 235 | - | |
| 236 | - /** | |
| 237 | - * Method: setMap | |
| 238 | - * Set the map property for the control. This is done through an accessor | |
| 239 | - * so that subclasses can override this and take special action once | |
| 240 | - * they have their map variable set. | |
| 241 | - * | |
| 242 | - * Parameters: | |
| 243 | - * map - {<OpenLayers.Map>} | |
| 244 | - */ | |
| 245 | - setMap: function(map) { | |
| 246 | - this.map = map; | |
| 247 | - if (this.handler) { | |
| 248 | - this.handler.setMap(map); | |
| 249 | - } | |
| 250 | - }, | |
| 251 | - | |
| 252 | - /** | |
| 253 | - * Method: draw | |
| 254 | - * The draw method is called when the control is ready to be displayed | |
| 255 | - * on the page. If a div has not been created one is created. Controls | |
| 256 | - * with a visual component will almost always want to override this method | |
| 257 | - * to customize the look of control. | |
| 258 | - * | |
| 259 | - * Parameters: | |
| 260 | - * px - {<OpenLayers.Pixel>} The top-left pixel position of the control | |
| 261 | - * or null. | |
| 262 | - * | |
| 263 | - * Returns: | |
| 264 | - * {DOMElement} A reference to the DIV DOMElement containing the control | |
| 265 | - */ | |
| 266 | - draw: function (px) { | |
| 267 | - if (this.div == null) { | |
| 268 | - this.div = OpenLayers.Util.createDiv(this.id); | |
| 269 | - this.div.className = this.displayClass; | |
| 270 | - if (!this.allowSelection) { | |
| 271 | - this.div.className += " olControlNoSelect"; | |
| 272 | - this.div.setAttribute("unselectable", "on", 0); | |
| 273 | - this.div.onselectstart = OpenLayers.Function.False; | |
| 274 | - } | |
| 275 | - if (this.title != "") { | |
| 276 | - this.div.title = this.title; | |
| 277 | - } | |
| 278 | - } | |
| 279 | - if (px != null) { | |
| 280 | - this.position = px.clone(); | |
| 281 | - } | |
| 282 | - this.moveTo(this.position); | |
| 283 | - return this.div; | |
| 284 | - }, | |
| 285 | - | |
| 286 | - /** | |
| 287 | - * Method: moveTo | |
| 288 | - * Sets the left and top style attributes to the passed in pixel | |
| 289 | - * coordinates. | |
| 290 | - * | |
| 291 | - * Parameters: | |
| 292 | - * px - {<OpenLayers.Pixel>} | |
| 293 | - */ | |
| 294 | - moveTo: function (px) { | |
| 295 | - if ((px != null) && (this.div != null)) { | |
| 296 | - this.div.style.left = px.x + "px"; | |
| 297 | - this.div.style.top = px.y + "px"; | |
| 298 | - } | |
| 299 | - }, | |
| 300 | - | |
| 301 | - /** | |
| 302 | - * APIMethod: activate | |
| 303 | - * Explicitly activates a control and it's associated | |
| 304 | - * handler if one has been set. Controls can be | |
| 305 | - * deactivated by calling the deactivate() method. | |
| 306 | - * | |
| 307 | - * Returns: | |
| 308 | - * {Boolean} True if the control was successfully activated or | |
| 309 | - * false if the control was already active. | |
| 310 | - */ | |
| 311 | - activate: function () { | |
| 312 | - if (this.active) { | |
| 313 | - return false; | |
| 314 | - } | |
| 315 | - if (this.handler) { | |
| 316 | - this.handler.activate(); | |
| 317 | - } | |
| 318 | - this.active = true; | |
| 319 | - if(this.map) { | |
| 320 | - OpenLayers.Element.addClass( | |
| 321 | - this.map.viewPortDiv, | |
| 322 | - this.displayClass.replace(/ /g, "") + "Active" | |
| 323 | - ); | |
| 324 | - } | |
| 325 | - this.events.triggerEvent("activate"); | |
| 326 | - return true; | |
| 327 | - }, | |
| 328 | - | |
| 329 | - /** | |
| 330 | - * APIMethod: deactivate | |
| 331 | - * Deactivates a control and it's associated handler if any. The exact | |
| 332 | - * effect of this depends on the control itself. | |
| 333 | - * | |
| 334 | - * Returns: | |
| 335 | - * {Boolean} True if the control was effectively deactivated or false | |
| 336 | - * if the control was already inactive. | |
| 337 | - */ | |
| 338 | - deactivate: function () { | |
| 339 | - if (this.active) { | |
| 340 | - if (this.handler) { | |
| 341 | - this.handler.deactivate(); | |
| 342 | - } | |
| 343 | - this.active = false; | |
| 344 | - if(this.map) { | |
| 345 | - OpenLayers.Element.removeClass( | |
| 346 | - this.map.viewPortDiv, | |
| 347 | - this.displayClass.replace(/ /g, "") + "Active" | |
| 348 | - ); | |
| 349 | - } | |
| 350 | - this.events.triggerEvent("deactivate"); | |
| 351 | - return true; | |
| 352 | - } | |
| 353 | - return false; | |
| 354 | - }, | |
| 355 | - | |
| 356 | - CLASS_NAME: "OpenLayers.Control" | |
| 357 | -}); | |
| 358 | - | |
| 359 | -/** | |
| 360 | - * Constant: OpenLayers.Control.TYPE_BUTTON | |
| 361 | - */ | |
| 362 | -OpenLayers.Control.TYPE_BUTTON = 1; | |
| 363 | - | |
| 364 | -/** | |
| 365 | - * Constant: OpenLayers.Control.TYPE_TOGGLE | |
| 366 | - */ | |
| 367 | -OpenLayers.Control.TYPE_TOGGLE = 2; | |
| 368 | - | |
| 369 | -/** | |
| 370 | - * Constant: OpenLayers.Control.TYPE_TOOL | |
| 371 | - */ | |
| 372 | -OpenLayers.Control.TYPE_TOOL = 3; |
ferramentas/ol3panel/Panel.js
| ... | ... | @@ -1,392 +0,0 @@ |
| 1 | -/* Copyright (c) 2006-2011 by OpenLayers Contributors (see authors.txt for | |
| 2 | - * full list of contributors). Published under the Clear BSD license. | |
| 3 | - * See http://svn.openlayers.org/trunk/openlayers/license.txt for the | |
| 4 | - * full text of the license. */ | |
| 5 | - | |
| 6 | -/** | |
| 7 | - * @requires OpenLayers/Control.js | |
| 8 | - */ | |
| 9 | - | |
| 10 | -/** | |
| 11 | - * Class: OpenLayers.Control.Panel | |
| 12 | - * The Panel control is a container for other controls. With it toolbars | |
| 13 | - * may be composed. | |
| 14 | - * | |
| 15 | - * Inherits from: | |
| 16 | - * - <OpenLayers.Control> | |
| 17 | - */ | |
| 18 | -OpenLayers.Control.Panel = OpenLayers.Class(OpenLayers.Control, { | |
| 19 | - /** | |
| 20 | - * Property: controls | |
| 21 | - * {Array(<OpenLayers.Control>)} | |
| 22 | - */ | |
| 23 | - controls: null, | |
| 24 | - | |
| 25 | - /** | |
| 26 | - * APIProperty: autoActivate | |
| 27 | - * {Boolean} Activate the control when it is added to a map. Default is | |
| 28 | - * true. | |
| 29 | - */ | |
| 30 | - autoActivate: true, | |
| 31 | - | |
| 32 | - /** | |
| 33 | - * APIProperty: defaultControl | |
| 34 | - * {<OpenLayers.Control>} The control which is activated when the control is | |
| 35 | - * activated (turned on), which also happens at instantiation. | |
| 36 | - * If <saveState> is true, <defaultControl> will be nullified after the | |
| 37 | - * first activation of the panel. | |
| 38 | - */ | |
| 39 | - defaultControl: null, | |
| 40 | - | |
| 41 | - /** | |
| 42 | - * APIProperty: saveState | |
| 43 | - * {Boolean} If set to true, the active state of this panel's controls will | |
| 44 | - * be stored on panel deactivation, and restored on reactivation. Default | |
| 45 | - * is false. | |
| 46 | - */ | |
| 47 | - saveState: false, | |
| 48 | - | |
| 49 | - /** | |
| 50 | - * APIProperty: allowDepress | |
| 51 | - * {Boolean} If is true the <OpenLayers.Control.TYPE_TOOL> controls can | |
| 52 | - * be deactivated by clicking the icon that represents them. Default | |
| 53 | - * is false. | |
| 54 | - */ | |
| 55 | - allowDepress: false, | |
| 56 | - | |
| 57 | - /** | |
| 58 | - * Property: activeState | |
| 59 | - * {Object} stores the active state of this panel's controls. | |
| 60 | - */ | |
| 61 | - activeState: null, | |
| 62 | - | |
| 63 | - /** | |
| 64 | - * Constructor: OpenLayers.Control.Panel | |
| 65 | - * Create a new control panel. | |
| 66 | - * | |
| 67 | - * Each control in the panel is represented by an icon. When clicking | |
| 68 | - * on an icon, the <activateControl> method is called. | |
| 69 | - * | |
| 70 | - * Specific properties for controls on a panel: | |
| 71 | - * type - {Number} One of <OpenLayers.Control.TYPE_TOOL>, | |
| 72 | - * <OpenLayers.Control.TYPE_TOGGLE>, <OpenLayers.Control.TYPE_BUTTON>. | |
| 73 | - * If not provided, <OpenLayers.Control.TYPE_TOOL> is assumed. | |
| 74 | - * title - {string} Text displayed when mouse is over the icon that | |
| 75 | - * represents the control. | |
| 76 | - * | |
| 77 | - * The <OpenLayers.Control.type> of a control determines the behavior when | |
| 78 | - * clicking its icon: | |
| 79 | - * <OpenLayers.Control.TYPE_TOOL> - The control is activated and other | |
| 80 | - * controls of this type in the same panel are deactivated. This is | |
| 81 | - * the default type. | |
| 82 | - * <OpenLayers.Control.TYPE_TOGGLE> - The active state of the control is | |
| 83 | - * toggled. | |
| 84 | - * <OpenLayers.Control.TYPE_BUTTON> - The | |
| 85 | - * <OpenLayers.Control.Button.trigger> method of the control is called, | |
| 86 | - * but its active state is not changed. | |
| 87 | - * | |
| 88 | - * If a control is <OpenLayers.Control.active>, it will be drawn with the | |
| 89 | - * olControl[Name]ItemActive class, otherwise with the | |
| 90 | - * olControl[Name]ItemInactive class. | |
| 91 | - * | |
| 92 | - * Parameters: | |
| 93 | - * options - {Object} An optional object whose properties will be used | |
| 94 | - * to extend the control. | |
| 95 | - */ | |
| 96 | - initialize: function(options) { | |
| 97 | - OpenLayers.Control.prototype.initialize.apply(this, [options]); | |
| 98 | - this.controls = []; | |
| 99 | - this.activeState = {}; | |
| 100 | - }, | |
| 101 | - | |
| 102 | - /** | |
| 103 | - * APIMethod: destroy | |
| 104 | - */ | |
| 105 | - destroy: function() { | |
| 106 | - OpenLayers.Control.prototype.destroy.apply(this, arguments); | |
| 107 | - for (var ctl, i = this.controls.length - 1; i >= 0; i--) { | |
| 108 | - ctl = this.controls[i]; | |
| 109 | - if (ctl.events) { | |
| 110 | - ctl.events.un({ | |
| 111 | - activate: this.iconOn, | |
| 112 | - deactivate: this.iconOff | |
| 113 | - }); | |
| 114 | - } | |
| 115 | - OpenLayers.Event.stopObservingElement(ctl.panel_div); | |
| 116 | - ctl.panel_div = null; | |
| 117 | - } | |
| 118 | - this.activeState = null; | |
| 119 | - }, | |
| 120 | - | |
| 121 | - /** | |
| 122 | - * APIMethod: activate | |
| 123 | - */ | |
| 124 | - activate: function() { | |
| 125 | - if (OpenLayers.Control.prototype.activate.apply(this, arguments)) { | |
| 126 | - var control; | |
| 127 | - for (var i=0, len=this.controls.length; i<len; i++) { | |
| 128 | - control = this.controls[i]; | |
| 129 | - if (control === this.defaultControl || | |
| 130 | - (this.saveState && this.activeState[control.id])) { | |
| 131 | - control.activate(); | |
| 132 | - } | |
| 133 | - } | |
| 134 | - if (this.saveState === true) { | |
| 135 | - this.defaultControl = null; | |
| 136 | - } | |
| 137 | - this.redraw(); | |
| 138 | - return true; | |
| 139 | - } else { | |
| 140 | - return false; | |
| 141 | - } | |
| 142 | - }, | |
| 143 | - | |
| 144 | - /** | |
| 145 | - * APIMethod: deactivate | |
| 146 | - */ | |
| 147 | - deactivate: function() { | |
| 148 | - if (OpenLayers.Control.prototype.deactivate.apply(this, arguments)) { | |
| 149 | - var control; | |
| 150 | - for (var i=0, len=this.controls.length; i<len; i++) { | |
| 151 | - control = this.controls[i]; | |
| 152 | - this.activeState[control.id] = control.deactivate(); | |
| 153 | - } | |
| 154 | - this.redraw(); | |
| 155 | - return true; | |
| 156 | - } else { | |
| 157 | - return false; | |
| 158 | - } | |
| 159 | - }, | |
| 160 | - | |
| 161 | - /** | |
| 162 | - * Method: draw | |
| 163 | - * | |
| 164 | - * Returns: | |
| 165 | - * {DOMElement} | |
| 166 | - */ | |
| 167 | - draw: function() { | |
| 168 | - OpenLayers.Control.prototype.draw.apply(this, arguments); | |
| 169 | - this.addControlsToMap(this.controls); | |
| 170 | - return this.div; | |
| 171 | - }, | |
| 172 | - | |
| 173 | - /** | |
| 174 | - * Method: redraw | |
| 175 | - */ | |
| 176 | - redraw: function() { | |
| 177 | - for (var l=this.div.childNodes.length, i=l-1; i>=0; i--) { | |
| 178 | - this.div.removeChild(this.div.childNodes[i]); | |
| 179 | - } | |
| 180 | - this.div.innerHTML = ""; | |
| 181 | - if (this.active) { | |
| 182 | - for (var i=0, len=this.controls.length; i<len; i++) { | |
| 183 | - this.div.appendChild(this.controls[i].panel_div); | |
| 184 | - } | |
| 185 | - } | |
| 186 | - }, | |
| 187 | - | |
| 188 | - /** | |
| 189 | - * APIMethod: activateControl | |
| 190 | - * This method is called when the user click on the icon representing a | |
| 191 | - * control in the panel. | |
| 192 | - * | |
| 193 | - * Parameters: | |
| 194 | - * control - {<OpenLayers.Control>} | |
| 195 | - */ | |
| 196 | - activateControl: function (control) { | |
| 197 | - if (!this.active) { return false; } | |
| 198 | - if (control.type == OpenLayers.Control.TYPE_BUTTON) { | |
| 199 | - control.trigger(); | |
| 200 | - return; | |
| 201 | - } | |
| 202 | - if (control.type == OpenLayers.Control.TYPE_TOGGLE) { | |
| 203 | - if (control.active) { | |
| 204 | - control.deactivate(); | |
| 205 | - } else { | |
| 206 | - control.activate(); | |
| 207 | - } | |
| 208 | - return; | |
| 209 | - } | |
| 210 | - if (this.allowDepress && control.active) { | |
| 211 | - control.deactivate(); | |
| 212 | - } else { | |
| 213 | - var c; | |
| 214 | - for (var i=0, len=this.controls.length; i<len; i++) { | |
| 215 | - c = this.controls[i]; | |
| 216 | - if (c != control && | |
| 217 | - (c.type === OpenLayers.Control.TYPE_TOOL || c.type == null)) { | |
| 218 | - c.deactivate(); | |
| 219 | - } | |
| 220 | - } | |
| 221 | - control.activate(); | |
| 222 | - } | |
| 223 | - }, | |
| 224 | - | |
| 225 | - /** | |
| 226 | - * APIMethod: addControls | |
| 227 | - * To build a toolbar, you add a set of controls to it. addControls | |
| 228 | - * lets you add a single control or a list of controls to the | |
| 229 | - * Control Panel. | |
| 230 | - * | |
| 231 | - * Parameters: | |
| 232 | - * controls - {<OpenLayers.Control>} Controls to add in the panel. | |
| 233 | - */ | |
| 234 | - addControls: function(controls) { | |
| 235 | - if (!(OpenLayers.Util.isArray(controls))) { | |
| 236 | - controls = [controls]; | |
| 237 | - } | |
| 238 | - this.controls = this.controls.concat(controls); | |
| 239 | - | |
| 240 | - // Give each control a panel_div which will be used later. | |
| 241 | - // Access to this div is via the panel_div attribute of the | |
| 242 | - // control added to the panel. | |
| 243 | - // Also, stop mousedowns and clicks, but don't stop mouseup, | |
| 244 | - // since they need to pass through. | |
| 245 | - for (var i=0, len=controls.length; i<len; i++) { | |
| 246 | - var element = document.createElement("div"); | |
| 247 | - element.className = controls[i].displayClass + "ItemInactive"; | |
| 248 | - controls[i].panel_div = element; | |
| 249 | - if (controls[i].title != "") { | |
| 250 | - controls[i].panel_div.title = controls[i].title; | |
| 251 | - } | |
| 252 | - OpenLayers.Event.observe(controls[i].panel_div, "click", | |
| 253 | - OpenLayers.Function.bind(this.onClick, this, controls[i])); | |
| 254 | - OpenLayers.Event.observe(controls[i].panel_div, "dblclick", | |
| 255 | - OpenLayers.Function.bind(this.onDoubleClick, this, controls[i])); | |
| 256 | - OpenLayers.Event.observe(controls[i].panel_div, "mousedown", | |
| 257 | - OpenLayers.Function.bindAsEventListener(OpenLayers.Event.stop)); | |
| 258 | - } | |
| 259 | - | |
| 260 | - if (this.map) { // map.addControl() has already been called on the panel | |
| 261 | - this.addControlsToMap(controls); | |
| 262 | - this.redraw(); | |
| 263 | - } | |
| 264 | - }, | |
| 265 | - | |
| 266 | - /** | |
| 267 | - * Method: addControlsToMap | |
| 268 | - * Only for internal use in draw() and addControls() methods. | |
| 269 | - * | |
| 270 | - * Parameters: | |
| 271 | - * controls - {Array(<OpenLayers.Control>)} Controls to add into map. | |
| 272 | - */ | |
| 273 | - addControlsToMap: function (controls) { | |
| 274 | - var control; | |
| 275 | - for (var i=0, len=controls.length; i<len; i++) { | |
| 276 | - control = controls[i]; | |
| 277 | - if (control.autoActivate === true) { | |
| 278 | - control.autoActivate = false; | |
| 279 | - this.map.addControl(control); | |
| 280 | - control.autoActivate = true; | |
| 281 | - } else { | |
| 282 | - this.map.addControl(control); | |
| 283 | - control.deactivate(); | |
| 284 | - } | |
| 285 | - control.events.on({ | |
| 286 | - activate: this.iconOn, | |
| 287 | - deactivate: this.iconOff | |
| 288 | - }); | |
| 289 | - } | |
| 290 | - }, | |
| 291 | - | |
| 292 | - /** | |
| 293 | - * Method: iconOn | |
| 294 | - * Internal use, for use only with "controls[i].events.on/un". | |
| 295 | - */ | |
| 296 | - iconOn: function() { | |
| 297 | - var d = this.panel_div; // "this" refers to a control on panel! | |
| 298 | - d.className = d.className.replace(/ItemInactive$/, "ItemActive"); | |
| 299 | - }, | |
| 300 | - | |
| 301 | - /** | |
| 302 | - * Method: iconOff | |
| 303 | - * Internal use, for use only with "controls[i].events.on/un". | |
| 304 | - */ | |
| 305 | - iconOff: function() { | |
| 306 | - var d = this.panel_div; // "this" refers to a control on panel! | |
| 307 | - d.className = d.className.replace(/ItemActive$/, "ItemInactive"); | |
| 308 | - }, | |
| 309 | - | |
| 310 | - /** | |
| 311 | - * Method: onClick | |
| 312 | - */ | |
| 313 | - onClick: function (ctrl, evt) { | |
| 314 | - OpenLayers.Event.stop(evt ? evt : window.event); | |
| 315 | - this.activateControl(ctrl); | |
| 316 | - }, | |
| 317 | - | |
| 318 | - /** | |
| 319 | - * Method: onDoubleClick | |
| 320 | - */ | |
| 321 | - onDoubleClick: function(ctrl, evt) { | |
| 322 | - OpenLayers.Event.stop(evt ? evt : window.event); | |
| 323 | - }, | |
| 324 | - | |
| 325 | - /** | |
| 326 | - * APIMethod: getControlsBy | |
| 327 | - * Get a list of controls with properties matching the given criteria. | |
| 328 | - * | |
| 329 | - * Parameter: | |
| 330 | - * property - {String} A control property to be matched. | |
| 331 | - * match - {String | Object} A string to match. Can also be a regular | |
| 332 | - * expression literal or object. In addition, it can be any object | |
| 333 | - * with a method named test. For reqular expressions or other, if | |
| 334 | - * match.test(control[property]) evaluates to true, the control will be | |
| 335 | - * included in the array returned. If no controls are found, an empty | |
| 336 | - * array is returned. | |
| 337 | - * | |
| 338 | - * Returns: | |
| 339 | - * {Array(<OpenLayers.Control>)} A list of controls matching the given criteria. | |
| 340 | - * An empty array is returned if no matches are found. | |
| 341 | - */ | |
| 342 | - getControlsBy: function(property, match) { | |
| 343 | - var test = (typeof match.test == "function"); | |
| 344 | - var found = OpenLayers.Array.filter(this.controls, function(item) { | |
| 345 | - return item[property] == match || (test && match.test(item[property])); | |
| 346 | - }); | |
| 347 | - return found; | |
| 348 | - }, | |
| 349 | - | |
| 350 | - /** | |
| 351 | - * APIMethod: getControlsByName | |
| 352 | - * Get a list of contorls with names matching the given name. | |
| 353 | - * | |
| 354 | - * Parameter: | |
| 355 | - * match - {String | Object} A control name. The name can also be a regular | |
| 356 | - * expression literal or object. In addition, it can be any object | |
| 357 | - * with a method named test. For reqular expressions or other, if | |
| 358 | - * name.test(control.name) evaluates to true, the control will be included | |
| 359 | - * in the list of controls returned. If no controls are found, an empty | |
| 360 | - * array is returned. | |
| 361 | - * | |
| 362 | - * Returns: | |
| 363 | - * {Array(<OpenLayers.Control>)} A list of controls matching the given name. | |
| 364 | - * An empty array is returned if no matches are found. | |
| 365 | - */ | |
| 366 | - getControlsByName: function(match) { | |
| 367 | - return this.getControlsBy("name", match); | |
| 368 | - }, | |
| 369 | - | |
| 370 | - /** | |
| 371 | - * APIMethod: getControlsByClass | |
| 372 | - * Get a list of controls of a given type (CLASS_NAME). | |
| 373 | - * | |
| 374 | - * Parameter: | |
| 375 | - * match - {String | Object} A control class name. The type can also be a | |
| 376 | - * regular expression literal or object. In addition, it can be any | |
| 377 | - * object with a method named test. For reqular expressions or other, | |
| 378 | - * if type.test(control.CLASS_NAME) evaluates to true, the control will | |
| 379 | - * be included in the list of controls returned. If no controls are | |
| 380 | - * found, an empty array is returned. | |
| 381 | - * | |
| 382 | - * Returns: | |
| 383 | - * {Array(<OpenLayers.Control>)} A list of controls matching the given type. | |
| 384 | - * An empty array is returned if no matches are found. | |
| 385 | - */ | |
| 386 | - getControlsByClass: function(match) { | |
| 387 | - return this.getControlsBy("CLASS_NAME", match); | |
| 388 | - }, | |
| 389 | - | |
| 390 | - CLASS_NAME: "OpenLayers.Control.Panel" | |
| 391 | -}); | |
| 392 | - |
ferramentas/ol3panel/Util.js
| ... | ... | @@ -1,1839 +0,0 @@ |
| 1 | -/* Copyright (c) 2006-2011 by OpenLayers Contributors (see authors.txt for | |
| 2 | - * full list of contributors). Published under the Clear BSD license. | |
| 3 | - * See http://svn.openlayers.org/trunk/openlayers/license.txt for the | |
| 4 | - * full text of the license. */ | |
| 5 | - | |
| 6 | -/** | |
| 7 | - * @requires OpenLayers/BaseTypes.js | |
| 8 | - * @requires OpenLayers/BaseTypes/Bounds.js | |
| 9 | - * @requires OpenLayers/BaseTypes/Element.js | |
| 10 | - * @requires OpenLayers/BaseTypes/LonLat.js | |
| 11 | - * @requires OpenLayers/BaseTypes/Pixel.js | |
| 12 | - * @requires OpenLayers/BaseTypes/Size.js | |
| 13 | - * @requires OpenLayers/Console.js | |
| 14 | - * @requires OpenLayers/Lang.js | |
| 15 | - */ | |
| 16 | - | |
| 17 | -/** | |
| 18 | - * Namespace: Util | |
| 19 | - */ | |
| 20 | -OpenLayers.Util = OpenLayers.Util || {}; | |
| 21 | - | |
| 22 | -/** | |
| 23 | - * Function: getElement | |
| 24 | - * This is the old $() from prototype | |
| 25 | - * | |
| 26 | - * Parameters: | |
| 27 | - * e - {String or DOMElement or Window} | |
| 28 | - * Return: | |
| 29 | - * {Array(DOMElement)} | |
| 30 | - */ | |
| 31 | -OpenLayers.Util.getElement = function() { | |
| 32 | - var elements = []; | |
| 33 | - | |
| 34 | - for (var i=0, len=arguments.length; i<len; i++) { | |
| 35 | - var element = arguments[i]; | |
| 36 | - if (typeof element == 'string') { | |
| 37 | - element = document.getElementById(element); | |
| 38 | - } | |
| 39 | - if (arguments.length == 1) { | |
| 40 | - return element; | |
| 41 | - } | |
| 42 | - elements.push(element); | |
| 43 | - } | |
| 44 | - return elements; | |
| 45 | -}; | |
| 46 | - | |
| 47 | -/** | |
| 48 | - * Function: isElement | |
| 49 | - * A cross-browser implementation of "e instanceof Element". | |
| 50 | - * | |
| 51 | - * Parameters: | |
| 52 | - * o - {Object} The object to test. | |
| 53 | - * | |
| 54 | - * Returns: | |
| 55 | - * {Boolean} | |
| 56 | - */ | |
| 57 | -OpenLayers.Util.isElement = function(o) { | |
| 58 | - return !!(o && o.nodeType === 1); | |
| 59 | -}; | |
| 60 | - | |
| 61 | -/** | |
| 62 | - * Function: isArray | |
| 63 | - * Tests that the provided object is an array. | |
| 64 | - * This test handles the cross-IFRAME case not caught | |
| 65 | - * by "a instanceof Array" and should be used instead. | |
| 66 | - * | |
| 67 | - * Parameters: | |
| 68 | - * a - {Object} the object test. | |
| 69 | - * | |
| 70 | - * Returns | |
| 71 | - * {Boolean} true if the object is an array. | |
| 72 | - */ | |
| 73 | -OpenLayers.Util.isArray = function(a) { | |
| 74 | - return (Object.prototype.toString.call(a) === '[object Array]'); | |
| 75 | -}; | |
| 76 | - | |
| 77 | -/** | |
| 78 | - * Maintain existing definition of $. | |
| 79 | - */ | |
| 80 | -if(typeof window.$ === "undefined") { | |
| 81 | - window.$ = OpenLayers.Util.getElement; | |
| 82 | -} | |
| 83 | - | |
| 84 | -/** | |
| 85 | - * Function: removeItem | |
| 86 | - * Remove an object from an array. Iterates through the array | |
| 87 | - * to find the item, then removes it. | |
| 88 | - * | |
| 89 | - * Parameters: | |
| 90 | - * array - {Array} | |
| 91 | - * item - {Object} | |
| 92 | - * | |
| 93 | - * Return | |
| 94 | - * {Array} A reference to the array | |
| 95 | - */ | |
| 96 | -OpenLayers.Util.removeItem = function(array, item) { | |
| 97 | - for(var i = array.length - 1; i >= 0; i--) { | |
| 98 | - if(array[i] == item) { | |
| 99 | - array.splice(i,1); | |
| 100 | - //break;more than once?? | |
| 101 | - } | |
| 102 | - } | |
| 103 | - return array; | |
| 104 | -}; | |
| 105 | - | |
| 106 | -/** | |
| 107 | - * Function: clearArray | |
| 108 | - * *Deprecated*. This function will disappear in 3.0. | |
| 109 | - * Please use "array.length = 0" instead. | |
| 110 | - * | |
| 111 | - * Parameters: | |
| 112 | - * array - {Array} | |
| 113 | - */ | |
| 114 | -OpenLayers.Util.clearArray = function(array) { | |
| 115 | - OpenLayers.Console.warn( | |
| 116 | - OpenLayers.i18n( | |
| 117 | - "methodDeprecated", {'newMethod': 'array = []'} | |
| 118 | - ) | |
| 119 | - ); | |
| 120 | - array.length = 0; | |
| 121 | -}; | |
| 122 | - | |
| 123 | -/** | |
| 124 | - * Function: indexOf | |
| 125 | - * Seems to exist already in FF, but not in MOZ. | |
| 126 | - * | |
| 127 | - * Parameters: | |
| 128 | - * array - {Array} | |
| 129 | - * obj - {*} | |
| 130 | - * | |
| 131 | - * Returns: | |
| 132 | - * {Integer} The index at, which the first object was found in the array. | |
| 133 | - * If not found, returns -1. | |
| 134 | - */ | |
| 135 | -OpenLayers.Util.indexOf = function(array, obj) { | |
| 136 | - // use the build-in function if available. | |
| 137 | - if (typeof array.indexOf == "function") { | |
| 138 | - return array.indexOf(obj); | |
| 139 | - } else { | |
| 140 | - for (var i = 0, len = array.length; i < len; i++) { | |
| 141 | - if (array[i] == obj) { | |
| 142 | - return i; | |
| 143 | - } | |
| 144 | - } | |
| 145 | - return -1; | |
| 146 | - } | |
| 147 | -}; | |
| 148 | - | |
| 149 | - | |
| 150 | - | |
| 151 | -/** | |
| 152 | - * Function: modifyDOMElement | |
| 153 | - * | |
| 154 | - * Modifies many properties of a DOM element all at once. Passing in | |
| 155 | - * null to an individual parameter will avoid setting the attribute. | |
| 156 | - * | |
| 157 | - * Parameters: | |
| 158 | - * element - {DOMElement} DOM element to modify. | |
| 159 | - * id - {String} The element id attribute to set. | |
| 160 | - * px - {<OpenLayers.Pixel>} The left and top style position. | |
| 161 | - * sz - {<OpenLayers.Size>} The width and height style attributes. | |
| 162 | - * position - {String} The position attribute. eg: absolute, | |
| 163 | - * relative, etc. | |
| 164 | - * border - {String} The style.border attribute. eg: | |
| 165 | - * solid black 2px | |
| 166 | - * overflow - {String} The style.overview attribute. | |
| 167 | - * opacity - {Float} Fractional value (0.0 - 1.0) | |
| 168 | - */ | |
| 169 | -OpenLayers.Util.modifyDOMElement = function(element, id, px, sz, position, | |
| 170 | - border, overflow, opacity) { | |
| 171 | - | |
| 172 | - if (id) { | |
| 173 | - element.id = id; | |
| 174 | - } | |
| 175 | - if (px) { | |
| 176 | - element.style.left = px.x + "px"; | |
| 177 | - element.style.top = px.y + "px"; | |
| 178 | - } | |
| 179 | - if (sz) { | |
| 180 | - element.style.width = sz.w + "px"; | |
| 181 | - element.style.height = sz.h + "px"; | |
| 182 | - } | |
| 183 | - if (position) { | |
| 184 | - element.style.position = position; | |
| 185 | - } | |
| 186 | - if (border) { | |
| 187 | - element.style.border = border; | |
| 188 | - } | |
| 189 | - if (overflow) { | |
| 190 | - element.style.overflow = overflow; | |
| 191 | - } | |
| 192 | - if (parseFloat(opacity) >= 0.0 && parseFloat(opacity) < 1.0) { | |
| 193 | - element.style.filter = 'alpha(opacity=' + (opacity * 100) + ')'; | |
| 194 | - element.style.opacity = opacity; | |
| 195 | - } else if (parseFloat(opacity) == 1.0) { | |
| 196 | - element.style.filter = ''; | |
| 197 | - element.style.opacity = ''; | |
| 198 | - } | |
| 199 | -}; | |
| 200 | - | |
| 201 | -/** | |
| 202 | - * Function: createDiv | |
| 203 | - * Creates a new div and optionally set some standard attributes. | |
| 204 | - * Null may be passed to each parameter if you do not wish to | |
| 205 | - * set a particular attribute. | |
| 206 | - * Note - zIndex is NOT set on the resulting div. | |
| 207 | - * | |
| 208 | - * Parameters: | |
| 209 | - * id - {String} An identifier for this element. If no id is | |
| 210 | - * passed an identifier will be created | |
| 211 | - * automatically. | |
| 212 | - * px - {<OpenLayers.Pixel>} The element left and top position. | |
| 213 | - * sz - {<OpenLayers.Size>} The element width and height. | |
| 214 | - * imgURL - {String} A url pointing to an image to use as a | |
| 215 | - * background image. | |
| 216 | - * position - {String} The style.position value. eg: absolute, | |
| 217 | - * relative etc. | |
| 218 | - * border - {String} The the style.border value. | |
| 219 | - * eg: 2px solid black | |
| 220 | - * overflow - {String} The style.overflow value. Eg. hidden | |
| 221 | - * opacity - {Float} Fractional value (0.0 - 1.0) | |
| 222 | - * | |
| 223 | - * Returns: | |
| 224 | - * {DOMElement} A DOM Div created with the specified attributes. | |
| 225 | - */ | |
| 226 | -OpenLayers.Util.createDiv = function(id, px, sz, imgURL, position, | |
| 227 | - border, overflow, opacity) { | |
| 228 | - | |
| 229 | - var dom = document.createElement('div'); | |
| 230 | - | |
| 231 | - if (imgURL) { | |
| 232 | - dom.style.backgroundImage = 'url(' + imgURL + ')'; | |
| 233 | - } | |
| 234 | - | |
| 235 | - //set generic properties | |
| 236 | - if (!id) { | |
| 237 | - id = OpenLayers.Util.createUniqueID("OpenLayersDiv"); | |
| 238 | - } | |
| 239 | - if (!position) { | |
| 240 | - position = "absolute"; | |
| 241 | - } | |
| 242 | - OpenLayers.Util.modifyDOMElement(dom, id, px, sz, position, | |
| 243 | - border, overflow, opacity); | |
| 244 | - | |
| 245 | - return dom; | |
| 246 | -}; | |
| 247 | - | |
| 248 | -/** | |
| 249 | - * Function: createImage | |
| 250 | - * Creates an img element with specific attribute values. | |
| 251 | - * | |
| 252 | - * Parameters: | |
| 253 | - * id - {String} The id field for the img. If none assigned one will be | |
| 254 | - * automatically generated. | |
| 255 | - * px - {<OpenLayers.Pixel>} The left and top positions. | |
| 256 | - * sz - {<OpenLayers.Size>} The style.width and style.height values. | |
| 257 | - * imgURL - {String} The url to use as the image source. | |
| 258 | - * position - {String} The style.position value. | |
| 259 | - * border - {String} The border to place around the image. | |
| 260 | - * opacity - {Float} Fractional value (0.0 - 1.0) | |
| 261 | - * delayDisplay - {Boolean} If true waits until the image has been | |
| 262 | - * loaded. | |
| 263 | - * | |
| 264 | - * Returns: | |
| 265 | - * {DOMElement} A DOM Image created with the specified attributes. | |
| 266 | - */ | |
| 267 | -OpenLayers.Util.createImage = function(id, px, sz, imgURL, position, border, | |
| 268 | - opacity, delayDisplay) { | |
| 269 | - | |
| 270 | - var image = document.createElement("img"); | |
| 271 | - | |
| 272 | - //set generic properties | |
| 273 | - if (!id) { | |
| 274 | - id = OpenLayers.Util.createUniqueID("OpenLayersDiv"); | |
| 275 | - } | |
| 276 | - if (!position) { | |
| 277 | - position = "relative"; | |
| 278 | - } | |
| 279 | - OpenLayers.Util.modifyDOMElement(image, id, px, sz, position, | |
| 280 | - border, null, opacity); | |
| 281 | - | |
| 282 | - if(delayDisplay) { | |
| 283 | - image.style.display = "none"; | |
| 284 | - OpenLayers.Event.observe(image, "load", | |
| 285 | - OpenLayers.Function.bind(OpenLayers.Util.onImageLoad, image)); | |
| 286 | - OpenLayers.Event.observe(image, "error", | |
| 287 | - OpenLayers.Function.bind(OpenLayers.Util.onImageLoadError, image)); | |
| 288 | - | |
| 289 | - } | |
| 290 | - | |
| 291 | - //set special properties | |
| 292 | - image.style.alt = id; | |
| 293 | - image.galleryImg = "no"; | |
| 294 | - if (imgURL) { | |
| 295 | - image.src = imgURL; | |
| 296 | - } | |
| 297 | - | |
| 298 | - | |
| 299 | - | |
| 300 | - return image; | |
| 301 | -}; | |
| 302 | - | |
| 303 | -/** | |
| 304 | - * Function: setOpacity | |
| 305 | - * *Deprecated*. This function has been deprecated. Instead, please use | |
| 306 | - * <OpenLayers.Util.modifyDOMElement> | |
| 307 | - * or | |
| 308 | - * <OpenLayers.Util.modifyAlphaImageDiv> | |
| 309 | - * | |
| 310 | - * Set the opacity of a DOM Element | |
| 311 | - * Note that for this function to work in IE, elements must "have layout" | |
| 312 | - * according to: | |
| 313 | - * http://msdn.microsoft.com/workshop/author/dhtml/reference/properties/haslayout.asp | |
| 314 | - * | |
| 315 | - * Parameters: | |
| 316 | - * element - {DOMElement} Set the opacity on this DOM element | |
| 317 | - * opacity - {Float} Opacity value (0.0 - 1.0) | |
| 318 | - */ | |
| 319 | -OpenLayers.Util.setOpacity = function(element, opacity) { | |
| 320 | - OpenLayers.Util.modifyDOMElement(element, null, null, null, | |
| 321 | - null, null, null, opacity); | |
| 322 | -}; | |
| 323 | - | |
| 324 | -/** | |
| 325 | - * Function: onImageLoad | |
| 326 | - * Bound to image load events. For all images created with <createImage> or | |
| 327 | - * <createAlphaImageDiv>, this function will be bound to the load event. | |
| 328 | - */ | |
| 329 | -OpenLayers.Util.onImageLoad = function() { | |
| 330 | - // The complex check here is to solve issues described in #480. | |
| 331 | - // Every time a map view changes, it increments the 'viewRequestID' | |
| 332 | - // property. As the requests for the images for the new map view are sent | |
| 333 | - // out, they are tagged with this unique viewRequestID. | |
| 334 | - // | |
| 335 | - // If an image has no viewRequestID property set, we display it regardless, | |
| 336 | - // but if it does have a viewRequestID property, we check that it matches | |
| 337 | - // the viewRequestID set on the map. | |
| 338 | - // | |
| 339 | - // If the viewRequestID on the map has changed, that means that the user | |
| 340 | - // has changed the map view since this specific request was sent out, and | |
| 341 | - // therefore this tile does not need to be displayed (so we do not execute | |
| 342 | - // this code that turns its display on). | |
| 343 | - // | |
| 344 | - if (!this.viewRequestID || | |
| 345 | - (this.map && this.viewRequestID == this.map.viewRequestID)) { | |
| 346 | - this.style.display = ""; | |
| 347 | - } | |
| 348 | - OpenLayers.Element.removeClass(this, "olImageLoadError"); | |
| 349 | -}; | |
| 350 | - | |
| 351 | -/** | |
| 352 | - * Property: IMAGE_RELOAD_ATTEMPTS | |
| 353 | - * {Integer} How many times should we try to reload an image before giving up? | |
| 354 | - * Default is 0 | |
| 355 | - */ | |
| 356 | -OpenLayers.IMAGE_RELOAD_ATTEMPTS = 0; | |
| 357 | - | |
| 358 | -/** | |
| 359 | - * Function: onImageLoadError | |
| 360 | - */ | |
| 361 | -OpenLayers.Util.onImageLoadError = function() { | |
| 362 | - this._attempts = (this._attempts) ? (this._attempts + 1) : 1; | |
| 363 | - if (this._attempts <= OpenLayers.IMAGE_RELOAD_ATTEMPTS) { | |
| 364 | - var urls = this.urls; | |
| 365 | - if (urls && OpenLayers.Util.isArray(urls) && urls.length > 1){ | |
| 366 | - var src = this.src.toString(); | |
| 367 | - var current_url, k; | |
| 368 | - for (k = 0; current_url = urls[k]; k++){ | |
| 369 | - if(src.indexOf(current_url) != -1){ | |
| 370 | - break; | |
| 371 | - } | |
| 372 | - } | |
| 373 | - var guess = Math.floor(urls.length * Math.random()); | |
| 374 | - var new_url = urls[guess]; | |
| 375 | - k = 0; | |
| 376 | - while(new_url == current_url && k++ < 4){ | |
| 377 | - guess = Math.floor(urls.length * Math.random()); | |
| 378 | - new_url = urls[guess]; | |
| 379 | - } | |
| 380 | - this.src = src.replace(current_url, new_url); | |
| 381 | - } else { | |
| 382 | - this.src = this.src; | |
| 383 | - } | |
| 384 | - } else { | |
| 385 | - OpenLayers.Element.addClass(this, "olImageLoadError"); | |
| 386 | - } | |
| 387 | - this.style.display = ""; | |
| 388 | -}; | |
| 389 | - | |
| 390 | -/** | |
| 391 | - * Property: alphaHackNeeded | |
| 392 | - * {Boolean} true if the png alpha hack is necessary and possible, false otherwise. | |
| 393 | - */ | |
| 394 | -OpenLayers.Util.alphaHackNeeded = null; | |
| 395 | - | |
| 396 | -/** | |
| 397 | - * Function: alphaHack | |
| 398 | - * Checks whether it's necessary (and possible) to use the png alpha | |
| 399 | - * hack which allows alpha transparency for png images under Internet | |
| 400 | - * Explorer. | |
| 401 | - * | |
| 402 | - * Returns: | |
| 403 | - * {Boolean} true if the png alpha hack is necessary and possible, false otherwise. | |
| 404 | - */ | |
| 405 | -OpenLayers.Util.alphaHack = function() { | |
| 406 | - if (OpenLayers.Util.alphaHackNeeded == null) { | |
| 407 | - var arVersion = navigator.appVersion.split("MSIE"); | |
| 408 | - var version = parseFloat(arVersion[1]); | |
| 409 | - var filter = false; | |
| 410 | - | |
| 411 | - // IEs4Lin dies when trying to access document.body.filters, because | |
| 412 | - // the property is there, but requires a DLL that can't be provided. This | |
| 413 | - // means that we need to wrap this in a try/catch so that this can | |
| 414 | - // continue. | |
| 415 | - | |
| 416 | - try { | |
| 417 | - filter = !!(document.body.filters); | |
| 418 | - } catch (e) {} | |
| 419 | - | |
| 420 | - OpenLayers.Util.alphaHackNeeded = (filter && | |
| 421 | - (version >= 5.5) && (version < 7)); | |
| 422 | - } | |
| 423 | - return OpenLayers.Util.alphaHackNeeded; | |
| 424 | -}; | |
| 425 | - | |
| 426 | -/** | |
| 427 | - * Function: modifyAlphaImageDiv | |
| 428 | - * | |
| 429 | - * Parameters: | |
| 430 | - * div - {DOMElement} Div containing Alpha-adjusted Image | |
| 431 | - * id - {String} | |
| 432 | - * px - {<OpenLayers.Pixel>} | |
| 433 | - * sz - {<OpenLayers.Size>} | |
| 434 | - * imgURL - {String} | |
| 435 | - * position - {String} | |
| 436 | - * border - {String} | |
| 437 | - * sizing - {String} 'crop', 'scale', or 'image'. Default is "scale" | |
| 438 | - * opacity - {Float} Fractional value (0.0 - 1.0) | |
| 439 | - */ | |
| 440 | -OpenLayers.Util.modifyAlphaImageDiv = function(div, id, px, sz, imgURL, | |
| 441 | - position, border, sizing, | |
| 442 | - opacity) { | |
| 443 | - | |
| 444 | - OpenLayers.Util.modifyDOMElement(div, id, px, sz, position, | |
| 445 | - null, null, opacity); | |
| 446 | - | |
| 447 | - var img = div.childNodes[0]; | |
| 448 | - | |
| 449 | - if (imgURL) { | |
| 450 | - img.src = imgURL; | |
| 451 | - } | |
| 452 | - OpenLayers.Util.modifyDOMElement(img, div.id + "_innerImage", null, sz, | |
| 453 | - "relative", border); | |
| 454 | - | |
| 455 | - if (OpenLayers.Util.alphaHack()) { | |
| 456 | - if(div.style.display != "none") { | |
| 457 | - div.style.display = "inline-block"; | |
| 458 | - } | |
| 459 | - if (sizing == null) { | |
| 460 | - sizing = "scale"; | |
| 461 | - } | |
| 462 | - | |
| 463 | - div.style.filter = "progid:DXImageTransform.Microsoft" + | |
| 464 | - ".AlphaImageLoader(src='" + img.src + "', " + | |
| 465 | - "sizingMethod='" + sizing + "')"; | |
| 466 | - if (parseFloat(div.style.opacity) >= 0.0 && | |
| 467 | - parseFloat(div.style.opacity) < 1.0) { | |
| 468 | - div.style.filter += " alpha(opacity=" + div.style.opacity * 100 + ")"; | |
| 469 | - } | |
| 470 | - | |
| 471 | - img.style.filter = "alpha(opacity=0)"; | |
| 472 | - } | |
| 473 | -}; | |
| 474 | - | |
| 475 | -/** | |
| 476 | - * Function: createAlphaImageDiv | |
| 477 | - * | |
| 478 | - * Parameters: | |
| 479 | - * id - {String} | |
| 480 | - * px - {<OpenLayers.Pixel>} | |
| 481 | - * sz - {<OpenLayers.Size>} | |
| 482 | - * imgURL - {String} | |
| 483 | - * position - {String} | |
| 484 | - * border - {String} | |
| 485 | - * sizing - {String} 'crop', 'scale', or 'image'. Default is "scale" | |
| 486 | - * opacity - {Float} Fractional value (0.0 - 1.0) | |
| 487 | - * delayDisplay - {Boolean} If true waits until the image has been | |
| 488 | - * loaded. | |
| 489 | - * | |
| 490 | - * Returns: | |
| 491 | - * {DOMElement} A DOM Div created with a DOM Image inside it. If the hack is | |
| 492 | - * needed for transparency in IE, it is added. | |
| 493 | - */ | |
| 494 | -OpenLayers.Util.createAlphaImageDiv = function(id, px, sz, imgURL, | |
| 495 | - position, border, sizing, | |
| 496 | - opacity, delayDisplay) { | |
| 497 | - | |
| 498 | - var div = OpenLayers.Util.createDiv(); | |
| 499 | - var img = OpenLayers.Util.createImage(null, null, null, null, null, null, | |
| 500 | - null, false); | |
| 501 | - div.appendChild(img); | |
| 502 | - | |
| 503 | - if (delayDisplay) { | |
| 504 | - img.style.display = "none"; | |
| 505 | - OpenLayers.Event.observe(img, "load", | |
| 506 | - OpenLayers.Function.bind(OpenLayers.Util.onImageLoad, div)); | |
| 507 | - OpenLayers.Event.observe(img, "error", | |
| 508 | - OpenLayers.Function.bind(OpenLayers.Util.onImageLoadError, div)); | |
| 509 | - } | |
| 510 | - | |
| 511 | - OpenLayers.Util.modifyAlphaImageDiv(div, id, px, sz, imgURL, position, | |
| 512 | - border, sizing, opacity); | |
| 513 | - | |
| 514 | - return div; | |
| 515 | -}; | |
| 516 | - | |
| 517 | - | |
| 518 | -/** | |
| 519 | - * Function: upperCaseObject | |
| 520 | - * Creates a new hashtable and copies over all the keys from the | |
| 521 | - * passed-in object, but storing them under an uppercased | |
| 522 | - * version of the key at which they were stored. | |
| 523 | - * | |
| 524 | - * Parameters: | |
| 525 | - * object - {Object} | |
| 526 | - * | |
| 527 | - * Returns: | |
| 528 | - * {Object} A new Object with all the same keys but uppercased | |
| 529 | - */ | |
| 530 | -OpenLayers.Util.upperCaseObject = function (object) { | |
| 531 | - var uObject = {}; | |
| 532 | - for (var key in object) { | |
| 533 | - uObject[key.toUpperCase()] = object[key]; | |
| 534 | - } | |
| 535 | - return uObject; | |
| 536 | -}; | |
| 537 | - | |
| 538 | -/** | |
| 539 | - * Function: applyDefaults | |
| 540 | - * Takes an object and copies any properties that don't exist from | |
| 541 | - * another properties, by analogy with OpenLayers.Util.extend() from | |
| 542 | - * Prototype.js. | |
| 543 | - * | |
| 544 | - * Parameters: | |
| 545 | - * to - {Object} The destination object. | |
| 546 | - * from - {Object} The source object. Any properties of this object that | |
| 547 | - * are undefined in the to object will be set on the to object. | |
| 548 | - * | |
| 549 | - * Returns: | |
| 550 | - * {Object} A reference to the to object. Note that the to argument is modified | |
| 551 | - * in place and returned by this function. | |
| 552 | - */ | |
| 553 | -OpenLayers.Util.applyDefaults = function (to, from) { | |
| 554 | - to = to || {}; | |
| 555 | - /* | |
| 556 | - * FF/Windows < 2.0.0.13 reports "Illegal operation on WrappedNative | |
| 557 | - * prototype object" when calling hawOwnProperty if the source object is an | |
| 558 | - * instance of window.Event. | |
| 559 | - */ | |
| 560 | - var fromIsEvt = typeof window.Event == "function" | |
| 561 | - && from instanceof window.Event; | |
| 562 | - | |
| 563 | - for (var key in from) { | |
| 564 | - if (to[key] === undefined || | |
| 565 | - (!fromIsEvt && from.hasOwnProperty | |
| 566 | - && from.hasOwnProperty(key) && !to.hasOwnProperty(key))) { | |
| 567 | - to[key] = from[key]; | |
| 568 | - } | |
| 569 | - } | |
| 570 | - /** | |
| 571 | - * IE doesn't include the toString property when iterating over an object's | |
| 572 | - * properties with the for(property in object) syntax. Explicitly check if | |
| 573 | - * the source has its own toString property. | |
| 574 | - */ | |
| 575 | - if(!fromIsEvt && from && from.hasOwnProperty | |
| 576 | - && from.hasOwnProperty('toString') && !to.hasOwnProperty('toString')) { | |
| 577 | - to.toString = from.toString; | |
| 578 | - } | |
| 579 | - | |
| 580 | - return to; | |
| 581 | -}; | |
| 582 | - | |
| 583 | -/** | |
| 584 | - * Function: getParameterString | |
| 585 | - * | |
| 586 | - * Parameters: | |
| 587 | - * params - {Object} | |
| 588 | - * | |
| 589 | - * Returns: | |
| 590 | - * {String} A concatenation of the properties of an object in | |
| 591 | - * http parameter notation. | |
| 592 | - * (ex. <i>"key1=value1&key2=value2&key3=value3"</i>) | |
| 593 | - * If a parameter is actually a list, that parameter will then | |
| 594 | - * be set to a comma-seperated list of values (foo,bar) instead | |
| 595 | - * of being URL escaped (foo%3Abar). | |
| 596 | - */ | |
| 597 | -OpenLayers.Util.getParameterString = function(params) { | |
| 598 | - var paramsArray = []; | |
| 599 | - | |
| 600 | - for (var key in params) { | |
| 601 | - var value = params[key]; | |
| 602 | - if ((value != null) && (typeof value != 'function')) { | |
| 603 | - var encodedValue; | |
| 604 | - if (typeof value == 'object' && value.constructor == Array) { | |
| 605 | - /* value is an array; encode items and separate with "," */ | |
| 606 | - var encodedItemArray = []; | |
| 607 | - var item; | |
| 608 | - for (var itemIndex=0, len=value.length; itemIndex<len; itemIndex++) { | |
| 609 | - item = value[itemIndex]; | |
| 610 | - encodedItemArray.push(encodeURIComponent( | |
| 611 | - (item === null || item === undefined) ? "" : item) | |
| 612 | - ); | |
| 613 | - } | |
| 614 | - encodedValue = encodedItemArray.join(","); | |
| 615 | - } | |
| 616 | - else { | |
| 617 | - /* value is a string; simply encode */ | |
| 618 | - encodedValue = encodeURIComponent(value); | |
| 619 | - } | |
| 620 | - paramsArray.push(encodeURIComponent(key) + "=" + encodedValue); | |
| 621 | - } | |
| 622 | - } | |
| 623 | - | |
| 624 | - return paramsArray.join("&"); | |
| 625 | -}; | |
| 626 | - | |
| 627 | -/** | |
| 628 | - * Function: urlAppend | |
| 629 | - * Appends a parameter string to a url. This function includes the logic for | |
| 630 | - * using the appropriate character (none, & or ?) to append to the url before | |
| 631 | - * appending the param string. | |
| 632 | - * | |
| 633 | - * Parameters: | |
| 634 | - * url - {String} The url to append to | |
| 635 | - * paramStr - {String} The param string to append | |
| 636 | - * | |
| 637 | - * Returns: | |
| 638 | - * {String} The new url | |
| 639 | - */ | |
| 640 | -OpenLayers.Util.urlAppend = function(url, paramStr) { | |
| 641 | - var newUrl = url; | |
| 642 | - if(paramStr) { | |
| 643 | - var parts = (url + " ").split(/[?&]/); | |
| 644 | - newUrl += (parts.pop() === " " ? | |
| 645 | - paramStr : | |
| 646 | - parts.length ? "&" + paramStr : "?" + paramStr); | |
| 647 | - } | |
| 648 | - return newUrl; | |
| 649 | -}; | |
| 650 | - | |
| 651 | -/** | |
| 652 | - * Property: ImgPath | |
| 653 | - * {String} Default is ''. | |
| 654 | - */ | |
| 655 | -OpenLayers.ImgPath = ''; | |
| 656 | - | |
| 657 | -/** | |
| 658 | - * Function: getImagesLocation | |
| 659 | - * | |
| 660 | - * Returns: | |
| 661 | - * {String} The fully formatted image location string | |
| 662 | - */ | |
| 663 | -OpenLayers.Util.getImagesLocation = function() { | |
| 664 | - return OpenLayers.ImgPath || (OpenLayers._getScriptLocation() + "img/"); | |
| 665 | -}; | |
| 666 | - | |
| 667 | - | |
| 668 | -/** | |
| 669 | - * Function: Try | |
| 670 | - * Execute functions until one of them doesn't throw an error. | |
| 671 | - * Capitalized because "try" is a reserved word in JavaScript. | |
| 672 | - * Taken directly from OpenLayers.Util.Try() | |
| 673 | - * | |
| 674 | - * Parameters: | |
| 675 | - * [*] - {Function} Any number of parameters may be passed to Try() | |
| 676 | - * It will attempt to execute each of them until one of them | |
| 677 | - * successfully executes. | |
| 678 | - * If none executes successfully, returns null. | |
| 679 | - * | |
| 680 | - * Returns: | |
| 681 | - * {*} The value returned by the first successfully executed function. | |
| 682 | - */ | |
| 683 | -OpenLayers.Util.Try = function() { | |
| 684 | - var returnValue = null; | |
| 685 | - | |
| 686 | - for (var i=0, len=arguments.length; i<len; i++) { | |
| 687 | - var lambda = arguments[i]; | |
| 688 | - try { | |
| 689 | - returnValue = lambda(); | |
| 690 | - break; | |
| 691 | - } catch (e) {} | |
| 692 | - } | |
| 693 | - | |
| 694 | - return returnValue; | |
| 695 | -}; | |
| 696 | - | |
| 697 | -/** | |
| 698 | - * Function: getXmlNodeValue | |
| 699 | - * | |
| 700 | - * Parameters: | |
| 701 | - * node - {XMLNode} | |
| 702 | - * | |
| 703 | - * Returns: | |
| 704 | - * {String} The text value of the given node, without breaking in firefox or IE | |
| 705 | - */ | |
| 706 | -OpenLayers.Util.getXmlNodeValue = function(node) { | |
| 707 | - var val = null; | |
| 708 | - OpenLayers.Util.Try( | |
| 709 | - function() { | |
| 710 | - val = node.text; | |
| 711 | - if (!val) { | |
| 712 | - val = node.textContent; | |
| 713 | - } | |
| 714 | - if (!val) { | |
| 715 | - val = node.firstChild.nodeValue; | |
| 716 | - } | |
| 717 | - }, | |
| 718 | - function() { | |
| 719 | - val = node.textContent; | |
| 720 | - }); | |
| 721 | - return val; | |
| 722 | -}; | |
| 723 | - | |
| 724 | -/** | |
| 725 | - * Function: mouseLeft | |
| 726 | - * | |
| 727 | - * Parameters: | |
| 728 | - * evt - {Event} | |
| 729 | - * div - {HTMLDivElement} | |
| 730 | - * | |
| 731 | - * Returns: | |
| 732 | - * {Boolean} | |
| 733 | - */ | |
| 734 | -OpenLayers.Util.mouseLeft = function (evt, div) { | |
| 735 | - // start with the element to which the mouse has moved | |
| 736 | - var target = (evt.relatedTarget) ? evt.relatedTarget : evt.toElement; | |
| 737 | - // walk up the DOM tree. | |
| 738 | - while (target != div && target != null) { | |
| 739 | - target = target.parentNode; | |
| 740 | - } | |
| 741 | - // if the target we stop at isn't the div, then we've left the div. | |
| 742 | - return (target != div); | |
| 743 | -}; | |
| 744 | - | |
| 745 | -/** | |
| 746 | - * Property: precision | |
| 747 | - * {Number} The number of significant digits to retain to avoid | |
| 748 | - * floating point precision errors. | |
| 749 | - * | |
| 750 | - * We use 14 as a "safe" default because, although IEEE 754 double floats | |
| 751 | - * (standard on most modern operating systems) support up to about 16 | |
| 752 | - * significant digits, 14 significant digits are sufficient to represent | |
| 753 | - * sub-millimeter accuracy in any coordinate system that anyone is likely to | |
| 754 | - * use with OpenLayers. | |
| 755 | - * | |
| 756 | - * If DEFAULT_PRECISION is set to 0, the original non-truncating behavior | |
| 757 | - * of OpenLayers <2.8 is preserved. Be aware that this will cause problems | |
| 758 | - * with certain projections, e.g. spherical Mercator. | |
| 759 | - * | |
| 760 | - */ | |
| 761 | -OpenLayers.Util.DEFAULT_PRECISION = 14; | |
| 762 | - | |
| 763 | -/** | |
| 764 | - * Function: toFloat | |
| 765 | - * Convenience method to cast an object to a Number, rounded to the | |
| 766 | - * desired floating point precision. | |
| 767 | - * | |
| 768 | - * Parameters: | |
| 769 | - * number - {Number} The number to cast and round. | |
| 770 | - * precision - {Number} An integer suitable for use with | |
| 771 | - * Number.toPrecision(). Defaults to OpenLayers.Util.DEFAULT_PRECISION. | |
| 772 | - * If set to 0, no rounding is performed. | |
| 773 | - * | |
| 774 | - * Returns: | |
| 775 | - * {Number} The cast, rounded number. | |
| 776 | - */ | |
| 777 | -OpenLayers.Util.toFloat = function (number, precision) { | |
| 778 | - if (precision == null) { | |
| 779 | - precision = OpenLayers.Util.DEFAULT_PRECISION; | |
| 780 | - } | |
| 781 | - if (typeof number !== "number") { | |
| 782 | - number = parseFloat(number); | |
| 783 | - } | |
| 784 | - return precision === 0 ? number : | |
| 785 | - parseFloat(number.toPrecision(precision)); | |
| 786 | -}; | |
| 787 | - | |
| 788 | -/** | |
| 789 | - * Function: rad | |
| 790 | - * | |
| 791 | - * Parameters: | |
| 792 | - * x - {Float} | |
| 793 | - * | |
| 794 | - * Returns: | |
| 795 | - * {Float} | |
| 796 | - */ | |
| 797 | -OpenLayers.Util.rad = function(x) {return x*Math.PI/180;}; | |
| 798 | - | |
| 799 | -/** | |
| 800 | - * Function: deg | |
| 801 | - * | |
| 802 | - * Parameters: | |
| 803 | - * x - {Float} | |
| 804 | - * | |
| 805 | - * Returns: | |
| 806 | - * {Float} | |
| 807 | - */ | |
| 808 | -OpenLayers.Util.deg = function(x) {return x*180/Math.PI;}; | |
| 809 | - | |
| 810 | -/** | |
| 811 | - * Property: VincentyConstants | |
| 812 | - * {Object} Constants for Vincenty functions. | |
| 813 | - */ | |
| 814 | -OpenLayers.Util.VincentyConstants = { | |
| 815 | - a: 6378137, | |
| 816 | - b: 6356752.3142, | |
| 817 | - f: 1/298.257223563 | |
| 818 | -}; | |
| 819 | - | |
| 820 | -/** | |
| 821 | - * APIFunction: distVincenty | |
| 822 | - * Given two objects representing points with geographic coordinates, this | |
| 823 | - * calculates the distance between those points on the surface of an | |
| 824 | - * ellipsoid. | |
| 825 | - * | |
| 826 | - * Parameters: | |
| 827 | - * p1 - {<OpenLayers.LonLat>} (or any object with both .lat, .lon properties) | |
| 828 | - * p2 - {<OpenLayers.LonLat>} (or any object with both .lat, .lon properties) | |
| 829 | - * | |
| 830 | - * Returns: | |
| 831 | - * {Float} The distance (in km) between the two input points as measured on an | |
| 832 | - * ellipsoid. Note that the input point objects must be in geographic | |
| 833 | - * coordinates (decimal degrees) and the return distance is in kilometers. | |
| 834 | - */ | |
| 835 | -OpenLayers.Util.distVincenty = function(p1, p2) { | |
| 836 | - var ct = OpenLayers.Util.VincentyConstants; | |
| 837 | - var a = ct.a, b = ct.b, f = ct.f; | |
| 838 | - | |
| 839 | - var L = OpenLayers.Util.rad(p2.lon - p1.lon); | |
| 840 | - var U1 = Math.atan((1-f) * Math.tan(OpenLayers.Util.rad(p1.lat))); | |
| 841 | - var U2 = Math.atan((1-f) * Math.tan(OpenLayers.Util.rad(p2.lat))); | |
| 842 | - var sinU1 = Math.sin(U1), cosU1 = Math.cos(U1); | |
| 843 | - var sinU2 = Math.sin(U2), cosU2 = Math.cos(U2); | |
| 844 | - var lambda = L, lambdaP = 2*Math.PI; | |
| 845 | - var iterLimit = 20; | |
| 846 | - while (Math.abs(lambda-lambdaP) > 1e-12 && --iterLimit>0) { | |
| 847 | - var sinLambda = Math.sin(lambda), cosLambda = Math.cos(lambda); | |
| 848 | - var sinSigma = Math.sqrt((cosU2*sinLambda) * (cosU2*sinLambda) + | |
| 849 | - (cosU1*sinU2-sinU1*cosU2*cosLambda) * (cosU1*sinU2-sinU1*cosU2*cosLambda)); | |
| 850 | - if (sinSigma==0) { | |
| 851 | - return 0; // co-incident points | |
| 852 | - } | |
| 853 | - var cosSigma = sinU1*sinU2 + cosU1*cosU2*cosLambda; | |
| 854 | - var sigma = Math.atan2(sinSigma, cosSigma); | |
| 855 | - var alpha = Math.asin(cosU1 * cosU2 * sinLambda / sinSigma); | |
| 856 | - var cosSqAlpha = Math.cos(alpha) * Math.cos(alpha); | |
| 857 | - var cos2SigmaM = cosSigma - 2*sinU1*sinU2/cosSqAlpha; | |
| 858 | - var C = f/16*cosSqAlpha*(4+f*(4-3*cosSqAlpha)); | |
| 859 | - lambdaP = lambda; | |
| 860 | - lambda = L + (1-C) * f * Math.sin(alpha) * | |
| 861 | - (sigma + C*sinSigma*(cos2SigmaM+C*cosSigma*(-1+2*cos2SigmaM*cos2SigmaM))); | |
| 862 | - } | |
| 863 | - if (iterLimit==0) { | |
| 864 | - return NaN; // formula failed to converge | |
| 865 | - } | |
| 866 | - var uSq = cosSqAlpha * (a*a - b*b) / (b*b); | |
| 867 | - var A = 1 + uSq/16384*(4096+uSq*(-768+uSq*(320-175*uSq))); | |
| 868 | - var B = uSq/1024 * (256+uSq*(-128+uSq*(74-47*uSq))); | |
| 869 | - var deltaSigma = B*sinSigma*(cos2SigmaM+B/4*(cosSigma*(-1+2*cos2SigmaM*cos2SigmaM)- | |
| 870 | - B/6*cos2SigmaM*(-3+4*sinSigma*sinSigma)*(-3+4*cos2SigmaM*cos2SigmaM))); | |
| 871 | - var s = b*A*(sigma-deltaSigma); | |
| 872 | - var d = s.toFixed(3)/1000; // round to 1mm precision | |
| 873 | - return d; | |
| 874 | -}; | |
| 875 | - | |
| 876 | -/** | |
| 877 | - * APIFunction: destinationVincenty | |
| 878 | - * Calculate destination point given start point lat/long (numeric degrees), | |
| 879 | - * bearing (numeric degrees) & distance (in m). | |
| 880 | - * Adapted from Chris Veness work, see | |
| 881 | - * http://www.movable-type.co.uk/scripts/latlong-vincenty-direct.html | |
| 882 | - * | |
| 883 | - * Parameters: | |
| 884 | - * lonlat - {<OpenLayers.LonLat>} (or any object with both .lat, .lon | |
| 885 | - * properties) The start point. | |
| 886 | - * brng - {Float} The bearing (degrees). | |
| 887 | - * dist - {Float} The ground distance (meters). | |
| 888 | - * | |
| 889 | - * Returns: | |
| 890 | - * {<OpenLayers.LonLat>} The destination point. | |
| 891 | - */ | |
| 892 | -OpenLayers.Util.destinationVincenty = function(lonlat, brng, dist) { | |
| 893 | - var u = OpenLayers.Util; | |
| 894 | - var ct = u.VincentyConstants; | |
| 895 | - var a = ct.a, b = ct.b, f = ct.f; | |
| 896 | - | |
| 897 | - var lon1 = lonlat.lon; | |
| 898 | - var lat1 = lonlat.lat; | |
| 899 | - | |
| 900 | - var s = dist; | |
| 901 | - var alpha1 = u.rad(brng); | |
| 902 | - var sinAlpha1 = Math.sin(alpha1); | |
| 903 | - var cosAlpha1 = Math.cos(alpha1); | |
| 904 | - | |
| 905 | - var tanU1 = (1-f) * Math.tan(u.rad(lat1)); | |
| 906 | - var cosU1 = 1 / Math.sqrt((1 + tanU1*tanU1)), sinU1 = tanU1*cosU1; | |
| 907 | - var sigma1 = Math.atan2(tanU1, cosAlpha1); | |
| 908 | - var sinAlpha = cosU1 * sinAlpha1; | |
| 909 | - var cosSqAlpha = 1 - sinAlpha*sinAlpha; | |
| 910 | - var uSq = cosSqAlpha * (a*a - b*b) / (b*b); | |
| 911 | - var A = 1 + uSq/16384*(4096+uSq*(-768+uSq*(320-175*uSq))); | |
| 912 | - var B = uSq/1024 * (256+uSq*(-128+uSq*(74-47*uSq))); | |
| 913 | - | |
| 914 | - var sigma = s / (b*A), sigmaP = 2*Math.PI; | |
| 915 | - while (Math.abs(sigma-sigmaP) > 1e-12) { | |
| 916 | - var cos2SigmaM = Math.cos(2*sigma1 + sigma); | |
| 917 | - var sinSigma = Math.sin(sigma); | |
| 918 | - var cosSigma = Math.cos(sigma); | |
| 919 | - var deltaSigma = B*sinSigma*(cos2SigmaM+B/4*(cosSigma*(-1+2*cos2SigmaM*cos2SigmaM)- | |
| 920 | - B/6*cos2SigmaM*(-3+4*sinSigma*sinSigma)*(-3+4*cos2SigmaM*cos2SigmaM))); | |
| 921 | - sigmaP = sigma; | |
| 922 | - sigma = s / (b*A) + deltaSigma; | |
| 923 | - } | |
| 924 | - | |
| 925 | - var tmp = sinU1*sinSigma - cosU1*cosSigma*cosAlpha1; | |
| 926 | - var lat2 = Math.atan2(sinU1*cosSigma + cosU1*sinSigma*cosAlpha1, | |
| 927 | - (1-f)*Math.sqrt(sinAlpha*sinAlpha + tmp*tmp)); | |
| 928 | - var lambda = Math.atan2(sinSigma*sinAlpha1, cosU1*cosSigma - sinU1*sinSigma*cosAlpha1); | |
| 929 | - var C = f/16*cosSqAlpha*(4+f*(4-3*cosSqAlpha)); | |
| 930 | - var L = lambda - (1-C) * f * sinAlpha * | |
| 931 | - (sigma + C*sinSigma*(cos2SigmaM+C*cosSigma*(-1+2*cos2SigmaM*cos2SigmaM))); | |
| 932 | - | |
| 933 | - var revAz = Math.atan2(sinAlpha, -tmp); // final bearing | |
| 934 | - | |
| 935 | - return new OpenLayers.LonLat(lon1+u.deg(L), u.deg(lat2)); | |
| 936 | -}; | |
| 937 | - | |
| 938 | -/** | |
| 939 | - * Function: getParameters | |
| 940 | - * Parse the parameters from a URL or from the current page itself into a | |
| 941 | - * JavaScript Object. Note that parameter values with commas are separated | |
| 942 | - * out into an Array. | |
| 943 | - * | |
| 944 | - * Parameters: | |
| 945 | - * url - {String} Optional url used to extract the query string. | |
| 946 | - * If url is null or is not supplied, query string is taken | |
| 947 | - * from the page location. | |
| 948 | - * | |
| 949 | - * Returns: | |
| 950 | - * {Object} An object of key/value pairs from the query string. | |
| 951 | - */ | |
| 952 | -OpenLayers.Util.getParameters = function(url) { | |
| 953 | - // if no url specified, take it from the location bar | |
| 954 | - url = (url === null || url === undefined) ? window.location.href : url; | |
| 955 | - | |
| 956 | - //parse out parameters portion of url string | |
| 957 | - var paramsString = ""; | |
| 958 | - if (OpenLayers.String.contains(url, '?')) { | |
| 959 | - var start = url.indexOf('?') + 1; | |
| 960 | - var end = OpenLayers.String.contains(url, "#") ? | |
| 961 | - url.indexOf('#') : url.length; | |
| 962 | - paramsString = url.substring(start, end); | |
| 963 | - } | |
| 964 | - | |
| 965 | - var parameters = {}; | |
| 966 | - var pairs = paramsString.split(/[&;]/); | |
| 967 | - for(var i=0, len=pairs.length; i<len; ++i) { | |
| 968 | - var keyValue = pairs[i].split('='); | |
| 969 | - if (keyValue[0]) { | |
| 970 | - | |
| 971 | - var key = keyValue[0]; | |
| 972 | - try { | |
| 973 | - key = decodeURIComponent(key); | |
| 974 | - } catch (err) { | |
| 975 | - key = unescape(key); | |
| 976 | - } | |
| 977 | - | |
| 978 | - // being liberal by replacing "+" with " " | |
| 979 | - var value = (keyValue[1] || '').replace(/\+/g, " "); | |
| 980 | - | |
| 981 | - try { | |
| 982 | - value = decodeURIComponent(value); | |
| 983 | - } catch (err) { | |
| 984 | - value = unescape(value); | |
| 985 | - } | |
| 986 | - | |
| 987 | - // follow OGC convention of comma delimited values | |
| 988 | - value = value.split(","); | |
| 989 | - | |
| 990 | - //if there's only one value, do not return as array | |
| 991 | - if (value.length == 1) { | |
| 992 | - value = value[0]; | |
| 993 | - } | |
| 994 | - | |
| 995 | - parameters[key] = value; | |
| 996 | - } | |
| 997 | - } | |
| 998 | - return parameters; | |
| 999 | -}; | |
| 1000 | - | |
| 1001 | -/** | |
| 1002 | - * Function: getArgs | |
| 1003 | - * *Deprecated*. Will be removed in 3.0. Please use instead | |
| 1004 | - * <OpenLayers.Util.getParameters> | |
| 1005 | - * | |
| 1006 | - * Parameters: | |
| 1007 | - * url - {String} Optional url used to extract the query string. | |
| 1008 | - * If null, query string is taken from page location. | |
| 1009 | - * | |
| 1010 | - * Returns: | |
| 1011 | - * {Object} An object of key/value pairs from the query string. | |
| 1012 | - */ | |
| 1013 | -OpenLayers.Util.getArgs = function(url) { | |
| 1014 | - OpenLayers.Console.warn( | |
| 1015 | - OpenLayers.i18n( | |
| 1016 | - "methodDeprecated", {'newMethod': 'OpenLayers.Util.getParameters'} | |
| 1017 | - ) | |
| 1018 | - ); | |
| 1019 | - return OpenLayers.Util.getParameters(url); | |
| 1020 | -}; | |
| 1021 | - | |
| 1022 | -/** | |
| 1023 | - * Property: lastSeqID | |
| 1024 | - * {Integer} The ever-incrementing count variable. | |
| 1025 | - * Used for generating unique ids. | |
| 1026 | - */ | |
| 1027 | -OpenLayers.Util.lastSeqID = 0; | |
| 1028 | - | |
| 1029 | -/** | |
| 1030 | - * Function: createUniqueID | |
| 1031 | - * Create a unique identifier for this session. Each time this function | |
| 1032 | - * is called, a counter is incremented. The return will be the optional | |
| 1033 | - * prefix (defaults to "id_") appended with the counter value. | |
| 1034 | - * | |
| 1035 | - * Parameters: | |
| 1036 | - * prefix {String} Optionsal string to prefix unique id. Default is "id_". | |
| 1037 | - * | |
| 1038 | - * Returns: | |
| 1039 | - * {String} A unique id string, built on the passed in prefix. | |
| 1040 | - */ | |
| 1041 | -OpenLayers.Util.createUniqueID = function(prefix) { | |
| 1042 | - if (prefix == null) { | |
| 1043 | - prefix = "id_"; | |
| 1044 | - } | |
| 1045 | - OpenLayers.Util.lastSeqID += 1; | |
| 1046 | - return prefix + OpenLayers.Util.lastSeqID; | |
| 1047 | -}; | |
| 1048 | - | |
| 1049 | -/** | |
| 1050 | - * Constant: INCHES_PER_UNIT | |
| 1051 | - * {Object} Constant inches per unit -- borrowed from MapServer mapscale.c | |
| 1052 | - * derivation of nautical miles from http://en.wikipedia.org/wiki/Nautical_mile | |
| 1053 | - * Includes the full set of units supported by CS-MAP (http://trac.osgeo.org/csmap/) | |
| 1054 | - * and PROJ.4 (http://trac.osgeo.org/proj/) | |
| 1055 | - * The hardcoded table is maintain in a CS-MAP source code module named CSdataU.c | |
| 1056 | - * The hardcoded table of PROJ.4 units are in pj_units.c. | |
| 1057 | - */ | |
| 1058 | -OpenLayers.INCHES_PER_UNIT = { | |
| 1059 | - 'inches': 1.0, | |
| 1060 | - 'ft': 12.0, | |
| 1061 | - 'mi': 63360.0, | |
| 1062 | - 'm': 39.3701, | |
| 1063 | - 'km': 39370.1, | |
| 1064 | - 'dd': 4374754, | |
| 1065 | - 'yd': 36 | |
| 1066 | -}; | |
| 1067 | -OpenLayers.INCHES_PER_UNIT["in"]= OpenLayers.INCHES_PER_UNIT.inches; | |
| 1068 | -OpenLayers.INCHES_PER_UNIT["degrees"] = OpenLayers.INCHES_PER_UNIT.dd; | |
| 1069 | -OpenLayers.INCHES_PER_UNIT["nmi"] = 1852 * OpenLayers.INCHES_PER_UNIT.m; | |
| 1070 | - | |
| 1071 | -// Units from CS-Map | |
| 1072 | -OpenLayers.METERS_PER_INCH = 0.02540005080010160020; | |
| 1073 | -OpenLayers.Util.extend(OpenLayers.INCHES_PER_UNIT, { | |
| 1074 | - "Inch": OpenLayers.INCHES_PER_UNIT.inches, | |
| 1075 | - "Meter": 1.0 / OpenLayers.METERS_PER_INCH, //EPSG:9001 | |
| 1076 | - "Foot": 0.30480060960121920243 / OpenLayers.METERS_PER_INCH, //EPSG:9003 | |
| 1077 | - "IFoot": 0.30480000000000000000 / OpenLayers.METERS_PER_INCH, //EPSG:9002 | |
| 1078 | - "ClarkeFoot": 0.3047972651151 / OpenLayers.METERS_PER_INCH, //EPSG:9005 | |
| 1079 | - "SearsFoot": 0.30479947153867624624 / OpenLayers.METERS_PER_INCH, //EPSG:9041 | |
| 1080 | - "GoldCoastFoot": 0.30479971018150881758 / OpenLayers.METERS_PER_INCH, //EPSG:9094 | |
| 1081 | - "IInch": 0.02540000000000000000 / OpenLayers.METERS_PER_INCH, | |
| 1082 | - "MicroInch": 0.00002540000000000000 / OpenLayers.METERS_PER_INCH, | |
| 1083 | - "Mil": 0.00000002540000000000 / OpenLayers.METERS_PER_INCH, | |
| 1084 | - "Centimeter": 0.01000000000000000000 / OpenLayers.METERS_PER_INCH, | |
| 1085 | - "Kilometer": 1000.00000000000000000000 / OpenLayers.METERS_PER_INCH, //EPSG:9036 | |
| 1086 | - "Yard": 0.91440182880365760731 / OpenLayers.METERS_PER_INCH, | |
| 1087 | - "SearsYard": 0.914398414616029 / OpenLayers.METERS_PER_INCH, //EPSG:9040 | |
| 1088 | - "IndianYard": 0.91439853074444079983 / OpenLayers.METERS_PER_INCH, //EPSG:9084 | |
| 1089 | - "IndianYd37": 0.91439523 / OpenLayers.METERS_PER_INCH, //EPSG:9085 | |
| 1090 | - "IndianYd62": 0.9143988 / OpenLayers.METERS_PER_INCH, //EPSG:9086 | |
| 1091 | - "IndianYd75": 0.9143985 / OpenLayers.METERS_PER_INCH, //EPSG:9087 | |
| 1092 | - "IndianFoot": 0.30479951 / OpenLayers.METERS_PER_INCH, //EPSG:9080 | |
| 1093 | - "IndianFt37": 0.30479841 / OpenLayers.METERS_PER_INCH, //EPSG:9081 | |
| 1094 | - "IndianFt62": 0.3047996 / OpenLayers.METERS_PER_INCH, //EPSG:9082 | |
| 1095 | - "IndianFt75": 0.3047995 / OpenLayers.METERS_PER_INCH, //EPSG:9083 | |
| 1096 | - "Mile": 1609.34721869443738887477 / OpenLayers.METERS_PER_INCH, | |
| 1097 | - "IYard": 0.91440000000000000000 / OpenLayers.METERS_PER_INCH, //EPSG:9096 | |
| 1098 | - "IMile": 1609.34400000000000000000 / OpenLayers.METERS_PER_INCH, //EPSG:9093 | |
| 1099 | - "NautM": 1852.00000000000000000000 / OpenLayers.METERS_PER_INCH, //EPSG:9030 | |
| 1100 | - "Lat-66": 110943.316488932731 / OpenLayers.METERS_PER_INCH, | |
| 1101 | - "Lat-83": 110946.25736872234125 / OpenLayers.METERS_PER_INCH, | |
| 1102 | - "Decimeter": 0.10000000000000000000 / OpenLayers.METERS_PER_INCH, | |
| 1103 | - "Millimeter": 0.00100000000000000000 / OpenLayers.METERS_PER_INCH, | |
| 1104 | - "Dekameter": 10.00000000000000000000 / OpenLayers.METERS_PER_INCH, | |
| 1105 | - "Decameter": 10.00000000000000000000 / OpenLayers.METERS_PER_INCH, | |
| 1106 | - "Hectometer": 100.00000000000000000000 / OpenLayers.METERS_PER_INCH, | |
| 1107 | - "GermanMeter": 1.0000135965 / OpenLayers.METERS_PER_INCH, //EPSG:9031 | |
| 1108 | - "CaGrid": 0.999738 / OpenLayers.METERS_PER_INCH, | |
| 1109 | - "ClarkeChain": 20.1166194976 / OpenLayers.METERS_PER_INCH, //EPSG:9038 | |
| 1110 | - "GunterChain": 20.11684023368047 / OpenLayers.METERS_PER_INCH, //EPSG:9033 | |
| 1111 | - "BenoitChain": 20.116782494375872 / OpenLayers.METERS_PER_INCH, //EPSG:9062 | |
| 1112 | - "SearsChain": 20.11676512155 / OpenLayers.METERS_PER_INCH, //EPSG:9042 | |
| 1113 | - "ClarkeLink": 0.201166194976 / OpenLayers.METERS_PER_INCH, //EPSG:9039 | |
| 1114 | - "GunterLink": 0.2011684023368047 / OpenLayers.METERS_PER_INCH, //EPSG:9034 | |
| 1115 | - "BenoitLink": 0.20116782494375872 / OpenLayers.METERS_PER_INCH, //EPSG:9063 | |
| 1116 | - "SearsLink": 0.2011676512155 / OpenLayers.METERS_PER_INCH, //EPSG:9043 | |
| 1117 | - "Rod": 5.02921005842012 / OpenLayers.METERS_PER_INCH, | |
| 1118 | - "IntnlChain": 20.1168 / OpenLayers.METERS_PER_INCH, //EPSG:9097 | |
| 1119 | - "IntnlLink": 0.201168 / OpenLayers.METERS_PER_INCH, //EPSG:9098 | |
| 1120 | - "Perch": 5.02921005842012 / OpenLayers.METERS_PER_INCH, | |
| 1121 | - "Pole": 5.02921005842012 / OpenLayers.METERS_PER_INCH, | |
| 1122 | - "Furlong": 201.1684023368046 / OpenLayers.METERS_PER_INCH, | |
| 1123 | - "Rood": 3.778266898 / OpenLayers.METERS_PER_INCH, | |
| 1124 | - "CapeFoot": 0.3047972615 / OpenLayers.METERS_PER_INCH, | |
| 1125 | - "Brealey": 375.00000000000000000000 / OpenLayers.METERS_PER_INCH, | |
| 1126 | - "ModAmFt": 0.304812252984505969011938 / OpenLayers.METERS_PER_INCH, | |
| 1127 | - "Fathom": 1.8288 / OpenLayers.METERS_PER_INCH, | |
| 1128 | - "NautM-UK": 1853.184 / OpenLayers.METERS_PER_INCH, | |
| 1129 | - "50kilometers": 50000.0 / OpenLayers.METERS_PER_INCH, | |
| 1130 | - "150kilometers": 150000.0 / OpenLayers.METERS_PER_INCH | |
| 1131 | -}); | |
| 1132 | - | |
| 1133 | -//unit abbreviations supported by PROJ.4 | |
| 1134 | -OpenLayers.Util.extend(OpenLayers.INCHES_PER_UNIT, { | |
| 1135 | - "mm": OpenLayers.INCHES_PER_UNIT["Meter"] / 1000.0, | |
| 1136 | - "cm": OpenLayers.INCHES_PER_UNIT["Meter"] / 100.0, | |
| 1137 | - "dm": OpenLayers.INCHES_PER_UNIT["Meter"] * 100.0, | |
| 1138 | - "km": OpenLayers.INCHES_PER_UNIT["Meter"] * 1000.0, | |
| 1139 | - "kmi": OpenLayers.INCHES_PER_UNIT["nmi"], //International Nautical Mile | |
| 1140 | - "fath": OpenLayers.INCHES_PER_UNIT["Fathom"], //International Fathom | |
| 1141 | - "ch": OpenLayers.INCHES_PER_UNIT["IntnlChain"], //International Chain | |
| 1142 | - "link": OpenLayers.INCHES_PER_UNIT["IntnlLink"], //International Link | |
| 1143 | - "us-in": OpenLayers.INCHES_PER_UNIT["inches"], //U.S. Surveyor's Inch | |
| 1144 | - "us-ft": OpenLayers.INCHES_PER_UNIT["Foot"], //U.S. Surveyor's Foot | |
| 1145 | - "us-yd": OpenLayers.INCHES_PER_UNIT["Yard"], //U.S. Surveyor's Yard | |
| 1146 | - "us-ch": OpenLayers.INCHES_PER_UNIT["GunterChain"], //U.S. Surveyor's Chain | |
| 1147 | - "us-mi": OpenLayers.INCHES_PER_UNIT["Mile"], //U.S. Surveyor's Statute Mile | |
| 1148 | - "ind-yd": OpenLayers.INCHES_PER_UNIT["IndianYd37"], //Indian Yard | |
| 1149 | - "ind-ft": OpenLayers.INCHES_PER_UNIT["IndianFt37"], //Indian Foot | |
| 1150 | - "ind-ch": 20.11669506 / OpenLayers.METERS_PER_INCH //Indian Chain | |
| 1151 | -}); | |
| 1152 | - | |
| 1153 | -/** | |
| 1154 | - * Constant: DOTS_PER_INCH | |
| 1155 | - * {Integer} 72 (A sensible default) | |
| 1156 | - */ | |
| 1157 | -OpenLayers.DOTS_PER_INCH = 72; | |
| 1158 | - | |
| 1159 | -/** | |
| 1160 | - * Function: normalizeScale | |
| 1161 | - * | |
| 1162 | - * Parameters: | |
| 1163 | - * scale - {float} | |
| 1164 | - * | |
| 1165 | - * Returns: | |
| 1166 | - * {Float} A normalized scale value, in 1 / X format. | |
| 1167 | - * This means that if a value less than one ( already 1/x) is passed | |
| 1168 | - * in, it just returns scale directly. Otherwise, it returns | |
| 1169 | - * 1 / scale | |
| 1170 | - */ | |
| 1171 | -OpenLayers.Util.normalizeScale = function (scale) { | |
| 1172 | - var normScale = (scale > 1.0) ? (1.0 / scale) | |
| 1173 | - : scale; | |
| 1174 | - return normScale; | |
| 1175 | -}; | |
| 1176 | - | |
| 1177 | -/** | |
| 1178 | - * Function: getResolutionFromScale | |
| 1179 | - * | |
| 1180 | - * Parameters: | |
| 1181 | - * scale - {Float} | |
| 1182 | - * units - {String} Index into OpenLayers.INCHES_PER_UNIT hashtable. | |
| 1183 | - * Default is degrees | |
| 1184 | - * | |
| 1185 | - * Returns: | |
| 1186 | - * {Float} The corresponding resolution given passed-in scale and unit | |
| 1187 | - * parameters. If the given scale is falsey, the returned resolution will | |
| 1188 | - * be undefined. | |
| 1189 | - */ | |
| 1190 | -OpenLayers.Util.getResolutionFromScale = function (scale, units) { | |
| 1191 | - var resolution; | |
| 1192 | - if (scale) { | |
| 1193 | - if (units == null) { | |
| 1194 | - units = "degrees"; | |
| 1195 | - } | |
| 1196 | - var normScale = OpenLayers.Util.normalizeScale(scale); | |
| 1197 | - resolution = 1 / (normScale * OpenLayers.INCHES_PER_UNIT[units] | |
| 1198 | - * OpenLayers.DOTS_PER_INCH); | |
| 1199 | - } | |
| 1200 | - return resolution; | |
| 1201 | -}; | |
| 1202 | - | |
| 1203 | -/** | |
| 1204 | - * Function: getScaleFromResolution | |
| 1205 | - * | |
| 1206 | - * Parameters: | |
| 1207 | - * resolution - {Float} | |
| 1208 | - * units - {String} Index into OpenLayers.INCHES_PER_UNIT hashtable. | |
| 1209 | - * Default is degrees | |
| 1210 | - * | |
| 1211 | - * Returns: | |
| 1212 | - * {Float} The corresponding scale given passed-in resolution and unit | |
| 1213 | - * parameters. | |
| 1214 | - */ | |
| 1215 | -OpenLayers.Util.getScaleFromResolution = function (resolution, units) { | |
| 1216 | - | |
| 1217 | - if (units == null) { | |
| 1218 | - units = "degrees"; | |
| 1219 | - } | |
| 1220 | - | |
| 1221 | - var scale = resolution * OpenLayers.INCHES_PER_UNIT[units] * | |
| 1222 | - OpenLayers.DOTS_PER_INCH; | |
| 1223 | - return scale; | |
| 1224 | -}; | |
| 1225 | - | |
| 1226 | -/** | |
| 1227 | - * Function: safeStopPropagation | |
| 1228 | - * *Deprecated*. This function has been deprecated. Please use directly | |
| 1229 | - * <OpenLayers.Event.stop> passing 'true' as the 2nd | |
| 1230 | - * argument (preventDefault) | |
| 1231 | - * | |
| 1232 | - * Safely stop the propagation of an event *without* preventing | |
| 1233 | - * the default browser action from occurring. | |
| 1234 | - * | |
| 1235 | - * Parameter: | |
| 1236 | - * evt - {Event} | |
| 1237 | - */ | |
| 1238 | -OpenLayers.Util.safeStopPropagation = function(evt) { | |
| 1239 | - OpenLayers.Event.stop(evt, true); | |
| 1240 | -}; | |
| 1241 | - | |
| 1242 | -/** | |
| 1243 | - * Function: pagePosition | |
| 1244 | - * Calculates the position of an element on the page (see | |
| 1245 | - * http://code.google.com/p/doctype/wiki/ArticlePageOffset) | |
| 1246 | - * | |
| 1247 | - * OpenLayers.Util.pagePosition is based on Yahoo's getXY method, which is | |
| 1248 | - * Copyright (c) 2006, Yahoo! Inc. | |
| 1249 | - * All rights reserved. | |
| 1250 | - * | |
| 1251 | - * Redistribution and use of this software in source and binary forms, with or | |
| 1252 | - * without modification, are permitted provided that the following conditions | |
| 1253 | - * are met: | |
| 1254 | - * | |
| 1255 | - * * Redistributions of source code must retain the above copyright notice, | |
| 1256 | - * this list of conditions and the following disclaimer. | |
| 1257 | - * | |
| 1258 | - * * Redistributions in binary form must reproduce the above copyright notice, | |
| 1259 | - * this list of conditions and the following disclaimer in the documentation | |
| 1260 | - * and/or other materials provided with the distribution. | |
| 1261 | - * | |
| 1262 | - * * Neither the name of Yahoo! Inc. nor the names of its contributors may be | |
| 1263 | - * used to endorse or promote products derived from this software without | |
| 1264 | - * specific prior written permission of Yahoo! Inc. | |
| 1265 | - * | |
| 1266 | - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | |
| 1267 | - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
| 1268 | - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
| 1269 | - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE | |
| 1270 | - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | |
| 1271 | - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | |
| 1272 | - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | |
| 1273 | - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | |
| 1274 | - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | |
| 1275 | - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | |
| 1276 | - * POSSIBILITY OF SUCH DAMAGE. | |
| 1277 | - * | |
| 1278 | - * Parameters: | |
| 1279 | - * forElement - {DOMElement} | |
| 1280 | - * | |
| 1281 | - * Returns: | |
| 1282 | - * {Array} two item array, Left value then Top value. | |
| 1283 | - */ | |
| 1284 | -OpenLayers.Util.pagePosition = function(forElement) { | |
| 1285 | - // NOTE: If element is hidden (display none or disconnected or any the | |
| 1286 | - // ancestors are hidden) we get (0,0) by default but we still do the | |
| 1287 | - // accumulation of scroll position. | |
| 1288 | - | |
| 1289 | - var pos = [0, 0]; | |
| 1290 | - var viewportElement = OpenLayers.Util.getViewportElement(); | |
| 1291 | - if (!forElement || forElement == window || forElement == viewportElement) { | |
| 1292 | - // viewport is always at 0,0 as that defined the coordinate system for | |
| 1293 | - // this function - this avoids special case checks in the code below | |
| 1294 | - return pos; | |
| 1295 | - } | |
| 1296 | - | |
| 1297 | - // Gecko browsers normally use getBoxObjectFor to calculate the position. | |
| 1298 | - // When invoked for an element with an implicit absolute position though it | |
| 1299 | - // can be off by one. Therefore the recursive implementation is used in | |
| 1300 | - // those (relatively rare) cases. | |
| 1301 | - var BUGGY_GECKO_BOX_OBJECT = | |
| 1302 | - OpenLayers.IS_GECKO && document.getBoxObjectFor && | |
| 1303 | - OpenLayers.Element.getStyle(forElement, 'position') == 'absolute' && | |
| 1304 | - (forElement.style.top == '' || forElement.style.left == ''); | |
| 1305 | - | |
| 1306 | - var parent = null; | |
| 1307 | - var box; | |
| 1308 | - | |
| 1309 | - if (forElement.getBoundingClientRect) { // IE | |
| 1310 | - box = forElement.getBoundingClientRect(); | |
| 1311 | - var scrollTop = viewportElement.scrollTop; | |
| 1312 | - var scrollLeft = viewportElement.scrollLeft; | |
| 1313 | - | |
| 1314 | - pos[0] = box.left + scrollLeft; | |
| 1315 | - pos[1] = box.top + scrollTop; | |
| 1316 | - | |
| 1317 | - } else if (document.getBoxObjectFor && !BUGGY_GECKO_BOX_OBJECT) { // gecko | |
| 1318 | - // Gecko ignores the scroll values for ancestors, up to 1.9. See: | |
| 1319 | - // https://bugzilla.mozilla.org/show_bug.cgi?id=328881 and | |
| 1320 | - // https://bugzilla.mozilla.org/show_bug.cgi?id=330619 | |
| 1321 | - | |
| 1322 | - box = document.getBoxObjectFor(forElement); | |
| 1323 | - var vpBox = document.getBoxObjectFor(viewportElement); | |
| 1324 | - pos[0] = box.screenX - vpBox.screenX; | |
| 1325 | - pos[1] = box.screenY - vpBox.screenY; | |
| 1326 | - | |
| 1327 | - } else { // safari/opera | |
| 1328 | - pos[0] = forElement.offsetLeft; | |
| 1329 | - pos[1] = forElement.offsetTop; | |
| 1330 | - parent = forElement.offsetParent; | |
| 1331 | - if (parent != forElement) { | |
| 1332 | - while (parent) { | |
| 1333 | - pos[0] += parent.offsetLeft; | |
| 1334 | - pos[1] += parent.offsetTop; | |
| 1335 | - parent = parent.offsetParent; | |
| 1336 | - } | |
| 1337 | - } | |
| 1338 | - | |
| 1339 | - var browser = OpenLayers.BROWSER_NAME; | |
| 1340 | - | |
| 1341 | - // opera & (safari absolute) incorrectly account for body offsetTop | |
| 1342 | - if (browser == "opera" || (browser == "safari" && | |
| 1343 | - OpenLayers.Element.getStyle(forElement, 'position') == 'absolute')) { | |
| 1344 | - pos[1] -= document.body.offsetTop; | |
| 1345 | - } | |
| 1346 | - | |
| 1347 | - // accumulate the scroll positions for everything but the body element | |
| 1348 | - parent = forElement.offsetParent; | |
| 1349 | - while (parent && parent != document.body) { | |
| 1350 | - pos[0] -= parent.scrollLeft; | |
| 1351 | - // see https://bugs.opera.com/show_bug.cgi?id=249965 | |
| 1352 | - if (browser != "opera" || parent.tagName != 'TR') { | |
| 1353 | - pos[1] -= parent.scrollTop; | |
| 1354 | - } | |
| 1355 | - parent = parent.offsetParent; | |
| 1356 | - } | |
| 1357 | - } | |
| 1358 | - | |
| 1359 | - return pos; | |
| 1360 | -}; | |
| 1361 | - | |
| 1362 | -/** | |
| 1363 | - * Function: getViewportElement | |
| 1364 | - * Returns die viewport element of the document. The viewport element is | |
| 1365 | - * usually document.documentElement, except in IE,where it is either | |
| 1366 | - * document.body or document.documentElement, depending on the document's | |
| 1367 | - * compatibility mode (see | |
| 1368 | - * http://code.google.com/p/doctype/wiki/ArticleClientViewportElement) | |
| 1369 | - */ | |
| 1370 | -OpenLayers.Util.getViewportElement = function() { | |
| 1371 | - var viewportElement = arguments.callee.viewportElement; | |
| 1372 | - if (viewportElement == undefined) { | |
| 1373 | - viewportElement = (OpenLayers.BROWSER_NAME == "msie" && | |
| 1374 | - document.compatMode != 'CSS1Compat') ? document.body : | |
| 1375 | - document.documentElement; | |
| 1376 | - arguments.callee.viewportElement = viewportElement; | |
| 1377 | - } | |
| 1378 | - return viewportElement; | |
| 1379 | -}; | |
| 1380 | - | |
| 1381 | -/** | |
| 1382 | - * Function: isEquivalentUrl | |
| 1383 | - * Test two URLs for equivalence. | |
| 1384 | - * | |
| 1385 | - * Setting 'ignoreCase' allows for case-independent comparison. | |
| 1386 | - * | |
| 1387 | - * Comparison is based on: | |
| 1388 | - * - Protocol | |
| 1389 | - * - Host (evaluated without the port) | |
| 1390 | - * - Port (set 'ignorePort80' to ignore "80" values) | |
| 1391 | - * - Hash ( set 'ignoreHash' to disable) | |
| 1392 | - * - Pathname (for relative <-> absolute comparison) | |
| 1393 | - * - Arguments (so they can be out of order) | |
| 1394 | - * | |
| 1395 | - * Parameters: | |
| 1396 | - * url1 - {String} | |
| 1397 | - * url2 - {String} | |
| 1398 | - * options - {Object} Allows for customization of comparison: | |
| 1399 | - * 'ignoreCase' - Default is True | |
| 1400 | - * 'ignorePort80' - Default is True | |
| 1401 | - * 'ignoreHash' - Default is True | |
| 1402 | - * | |
| 1403 | - * Returns: | |
| 1404 | - * {Boolean} Whether or not the two URLs are equivalent | |
| 1405 | - */ | |
| 1406 | -OpenLayers.Util.isEquivalentUrl = function(url1, url2, options) { | |
| 1407 | - options = options || {}; | |
| 1408 | - | |
| 1409 | - OpenLayers.Util.applyDefaults(options, { | |
| 1410 | - ignoreCase: true, | |
| 1411 | - ignorePort80: true, | |
| 1412 | - ignoreHash: true | |
| 1413 | - }); | |
| 1414 | - | |
| 1415 | - var urlObj1 = OpenLayers.Util.createUrlObject(url1, options); | |
| 1416 | - var urlObj2 = OpenLayers.Util.createUrlObject(url2, options); | |
| 1417 | - | |
| 1418 | - //compare all keys except for "args" (treated below) | |
| 1419 | - for(var key in urlObj1) { | |
| 1420 | - if(key !== "args") { | |
| 1421 | - if(urlObj1[key] != urlObj2[key]) { | |
| 1422 | - return false; | |
| 1423 | - } | |
| 1424 | - } | |
| 1425 | - } | |
| 1426 | - | |
| 1427 | - // compare search args - irrespective of order | |
| 1428 | - for(var key in urlObj1.args) { | |
| 1429 | - if(urlObj1.args[key] != urlObj2.args[key]) { | |
| 1430 | - return false; | |
| 1431 | - } | |
| 1432 | - delete urlObj2.args[key]; | |
| 1433 | - } | |
| 1434 | - // urlObj2 shouldn't have any args left | |
| 1435 | - for(var key in urlObj2.args) { | |
| 1436 | - return false; | |
| 1437 | - } | |
| 1438 | - | |
| 1439 | - return true; | |
| 1440 | -}; | |
| 1441 | - | |
| 1442 | -/** | |
| 1443 | - * Function: createUrlObject | |
| 1444 | - * | |
| 1445 | - * Parameters: | |
| 1446 | - * url - {String} | |
| 1447 | - * options - {Object} A hash of options. Can be one of: | |
| 1448 | - * ignoreCase: lowercase url, | |
| 1449 | - * ignorePort80: don't include explicit port if port is 80, | |
| 1450 | - * ignoreHash: Don't include part of url after the hash (#). | |
| 1451 | - * | |
| 1452 | - * Returns: | |
| 1453 | - * {Object} An object with separate url, a, port, host, and args parsed out | |
| 1454 | - * and ready for comparison | |
| 1455 | - */ | |
| 1456 | -OpenLayers.Util.createUrlObject = function(url, options) { | |
| 1457 | - options = options || {}; | |
| 1458 | - | |
| 1459 | - // deal with relative urls first | |
| 1460 | - if(!(/^\w+:\/\//).test(url)) { | |
| 1461 | - var loc = window.location; | |
| 1462 | - var port = loc.port ? ":" + loc.port : ""; | |
| 1463 | - var fullUrl = loc.protocol + "//" + loc.host.split(":").shift() + port; | |
| 1464 | - if(url.indexOf("/") === 0) { | |
| 1465 | - // full pathname | |
| 1466 | - url = fullUrl + url; | |
| 1467 | - } else { | |
| 1468 | - // relative to current path | |
| 1469 | - var parts = loc.pathname.split("/"); | |
| 1470 | - parts.pop(); | |
| 1471 | - url = fullUrl + parts.join("/") + "/" + url; | |
| 1472 | - } | |
| 1473 | - } | |
| 1474 | - | |
| 1475 | - if (options.ignoreCase) { | |
| 1476 | - url = url.toLowerCase(); | |
| 1477 | - } | |
| 1478 | - | |
| 1479 | - var a = document.createElement('a'); | |
| 1480 | - a.href = url; | |
| 1481 | - | |
| 1482 | - var urlObject = {}; | |
| 1483 | - | |
| 1484 | - //host (without port) | |
| 1485 | - urlObject.host = a.host.split(":").shift(); | |
| 1486 | - | |
| 1487 | - //protocol | |
| 1488 | - urlObject.protocol = a.protocol; | |
| 1489 | - | |
| 1490 | - //port (get uniform browser behavior with port 80 here) | |
| 1491 | - if(options.ignorePort80) { | |
| 1492 | - urlObject.port = (a.port == "80" || a.port == "0") ? "" : a.port; | |
| 1493 | - } else { | |
| 1494 | - urlObject.port = (a.port == "" || a.port == "0") ? "80" : a.port; | |
| 1495 | - } | |
| 1496 | - | |
| 1497 | - //hash | |
| 1498 | - urlObject.hash = (options.ignoreHash || a.hash === "#") ? "" : a.hash; | |
| 1499 | - | |
| 1500 | - //args | |
| 1501 | - var queryString = a.search; | |
| 1502 | - if (!queryString) { | |
| 1503 | - var qMark = url.indexOf("?"); | |
| 1504 | - queryString = (qMark != -1) ? url.substr(qMark) : ""; | |
| 1505 | - } | |
| 1506 | - urlObject.args = OpenLayers.Util.getParameters(queryString); | |
| 1507 | - | |
| 1508 | - //pathname (uniform browser behavior with leading "/") | |
| 1509 | - urlObject.pathname = (a.pathname.charAt(0) == "/") ? a.pathname : "/" + a.pathname; | |
| 1510 | - | |
| 1511 | - return urlObject; | |
| 1512 | -}; | |
| 1513 | - | |
| 1514 | -/** | |
| 1515 | - * Function: removeTail | |
| 1516 | - * Takes a url and removes everything after the ? and # | |
| 1517 | - * | |
| 1518 | - * Parameters: | |
| 1519 | - * url - {String} The url to process | |
| 1520 | - * | |
| 1521 | - * Returns: | |
| 1522 | - * {String} The string with all queryString and Hash removed | |
| 1523 | - */ | |
| 1524 | -OpenLayers.Util.removeTail = function(url) { | |
| 1525 | - var head = null; | |
| 1526 | - | |
| 1527 | - var qMark = url.indexOf("?"); | |
| 1528 | - var hashMark = url.indexOf("#"); | |
| 1529 | - | |
| 1530 | - if (qMark == -1) { | |
| 1531 | - head = (hashMark != -1) ? url.substr(0,hashMark) : url; | |
| 1532 | - } else { | |
| 1533 | - head = (hashMark != -1) ? url.substr(0,Math.min(qMark, hashMark)) | |
| 1534 | - : url.substr(0, qMark); | |
| 1535 | - } | |
| 1536 | - return head; | |
| 1537 | -}; | |
| 1538 | - | |
| 1539 | -/** | |
| 1540 | - * Constant: IS_GECKO | |
| 1541 | - * {Boolean} True if the userAgent reports the browser to use the Gecko engine | |
| 1542 | - */ | |
| 1543 | -OpenLayers.IS_GECKO = (function() { | |
| 1544 | - var ua = navigator.userAgent.toLowerCase(); | |
| 1545 | - return ua.indexOf("webkit") == -1 && ua.indexOf("gecko") != -1; | |
| 1546 | -})(); | |
| 1547 | - | |
| 1548 | -/** | |
| 1549 | - * Constant: BROWSER_NAME | |
| 1550 | - * {String} | |
| 1551 | - * A substring of the navigator.userAgent property. Depending on the userAgent | |
| 1552 | - * property, this will be the empty string or one of the following: | |
| 1553 | - * * "opera" -- Opera | |
| 1554 | - * * "msie" -- Internet Explorer | |
| 1555 | - * * "safari" -- Safari | |
| 1556 | - * * "firefox" -- Firefox | |
| 1557 | - * * "mozilla" -- Mozilla | |
| 1558 | - */ | |
| 1559 | -OpenLayers.BROWSER_NAME = (function() { | |
| 1560 | - var name = ""; | |
| 1561 | - var ua = navigator.userAgent.toLowerCase(); | |
| 1562 | - if (ua.indexOf("opera") != -1) { | |
| 1563 | - name = "opera"; | |
| 1564 | - } else if (ua.indexOf("msie") != -1) { | |
| 1565 | - name = "msie"; | |
| 1566 | - } else if (ua.indexOf("safari") != -1) { | |
| 1567 | - name = "safari"; | |
| 1568 | - } else if (ua.indexOf("mozilla") != -1) { | |
| 1569 | - if (ua.indexOf("firefox") != -1) { | |
| 1570 | - name = "firefox"; | |
| 1571 | - } else { | |
| 1572 | - name = "mozilla"; | |
| 1573 | - } | |
| 1574 | - } | |
| 1575 | - return name; | |
| 1576 | -})(); | |
| 1577 | - | |
| 1578 | -/** | |
| 1579 | - * Function: getBrowserName | |
| 1580 | - * | |
| 1581 | - * Returns: | |
| 1582 | - * {String} A string which specifies which is the current | |
| 1583 | - * browser in which we are running. | |
| 1584 | - * | |
| 1585 | - * Currently-supported browser detection and codes: | |
| 1586 | - * * 'opera' -- Opera | |
| 1587 | - * * 'msie' -- Internet Explorer | |
| 1588 | - * * 'safari' -- Safari | |
| 1589 | - * * 'firefox' -- Firefox | |
| 1590 | - * * 'mozilla' -- Mozilla | |
| 1591 | - * | |
| 1592 | - * If we are unable to property identify the browser, we | |
| 1593 | - * return an empty string. | |
| 1594 | - */ | |
| 1595 | -OpenLayers.Util.getBrowserName = function() { | |
| 1596 | - return OpenLayers.BROWSER_NAME; | |
| 1597 | -}; | |
| 1598 | - | |
| 1599 | -/** | |
| 1600 | - * Method: getRenderedDimensions | |
| 1601 | - * Renders the contentHTML offscreen to determine actual dimensions for | |
| 1602 | - * popup sizing. As we need layout to determine dimensions the content | |
| 1603 | - * is rendered -9999px to the left and absolute to ensure the | |
| 1604 | - * scrollbars do not flicker | |
| 1605 | - * | |
| 1606 | - * Parameters: | |
| 1607 | - * contentHTML | |
| 1608 | - * size - {<OpenLayers.Size>} If either the 'w' or 'h' properties is | |
| 1609 | - * specified, we fix that dimension of the div to be measured. This is | |
| 1610 | - * useful in the case where we have a limit in one dimension and must | |
| 1611 | - * therefore meaure the flow in the other dimension. | |
| 1612 | - * options - {Object} | |
| 1613 | - * | |
| 1614 | - * Allowed Options: | |
| 1615 | - * displayClass - {String} Optional parameter. A CSS class name(s) string | |
| 1616 | - * to provide the CSS context of the rendered content. | |
| 1617 | - * containerElement - {DOMElement} Optional parameter. Insert the HTML to | |
| 1618 | - * this node instead of the body root when calculating dimensions. | |
| 1619 | - * | |
| 1620 | - * Returns: | |
| 1621 | - * {OpenLayers.Size} | |
| 1622 | - */ | |
| 1623 | -OpenLayers.Util.getRenderedDimensions = function(contentHTML, size, options) { | |
| 1624 | - | |
| 1625 | - var w, h; | |
| 1626 | - | |
| 1627 | - // create temp container div with restricted size | |
| 1628 | - var container = document.createElement("div"); | |
| 1629 | - container.style.visibility = "hidden"; | |
| 1630 | - | |
| 1631 | - var containerElement = (options && options.containerElement) | |
| 1632 | - ? options.containerElement : document.body; | |
| 1633 | - | |
| 1634 | - //fix a dimension, if specified. | |
| 1635 | - if (size) { | |
| 1636 | - if (size.w) { | |
| 1637 | - w = size.w; | |
| 1638 | - container.style.width = w + "px"; | |
| 1639 | - } else if (size.h) { | |
| 1640 | - h = size.h; | |
| 1641 | - container.style.height = h + "px"; | |
| 1642 | - } | |
| 1643 | - } | |
| 1644 | - | |
| 1645 | - //add css classes, if specified | |
| 1646 | - if (options && options.displayClass) { | |
| 1647 | - container.className = options.displayClass; | |
| 1648 | - } | |
| 1649 | - | |
| 1650 | - // create temp content div and assign content | |
| 1651 | - var content = document.createElement("div"); | |
| 1652 | - content.innerHTML = contentHTML; | |
| 1653 | - | |
| 1654 | - // we need overflow visible when calculating the size | |
| 1655 | - content.style.overflow = "visible"; | |
| 1656 | - if (content.childNodes) { | |
| 1657 | - for (var i=0, l=content.childNodes.length; i<l; i++) { | |
| 1658 | - if (!content.childNodes[i].style) continue; | |
| 1659 | - content.childNodes[i].style.overflow = "visible"; | |
| 1660 | - } | |
| 1661 | - } | |
| 1662 | - | |
| 1663 | - // add content to restricted container | |
| 1664 | - container.appendChild(content); | |
| 1665 | - | |
| 1666 | - // append container to body for rendering | |
| 1667 | - containerElement.appendChild(container); | |
| 1668 | - | |
| 1669 | - // Opera and IE7 can't handle a node with position:aboslute if it inherits | |
| 1670 | - // position:absolute from a parent. | |
| 1671 | - var parentHasPositionAbsolute = false; | |
| 1672 | - var parent = container.parentNode; | |
| 1673 | - while (parent && parent.tagName.toLowerCase()!="body") { | |
| 1674 | - var parentPosition = OpenLayers.Element.getStyle(parent, "position"); | |
| 1675 | - if(parentPosition == "absolute") { | |
| 1676 | - parentHasPositionAbsolute = true; | |
| 1677 | - break; | |
| 1678 | - } else if (parentPosition && parentPosition != "static") { | |
| 1679 | - break; | |
| 1680 | - } | |
| 1681 | - parent = parent.parentNode; | |
| 1682 | - } | |
| 1683 | - | |
| 1684 | - if(!parentHasPositionAbsolute) { | |
| 1685 | - container.style.position = "absolute"; | |
| 1686 | - } | |
| 1687 | - | |
| 1688 | - // calculate scroll width of content and add corners and shadow width | |
| 1689 | - if (!w) { | |
| 1690 | - w = parseInt(content.scrollWidth); | |
| 1691 | - | |
| 1692 | - // update container width to allow height to adjust | |
| 1693 | - container.style.width = w + "px"; | |
| 1694 | - } | |
| 1695 | - // capture height and add shadow and corner image widths | |
| 1696 | - if (!h) { | |
| 1697 | - h = parseInt(content.scrollHeight); | |
| 1698 | - } | |
| 1699 | - | |
| 1700 | - // remove elements | |
| 1701 | - container.removeChild(content); | |
| 1702 | - containerElement.removeChild(container); | |
| 1703 | - | |
| 1704 | - return new OpenLayers.Size(w, h); | |
| 1705 | -}; | |
| 1706 | - | |
| 1707 | -/** | |
| 1708 | - * APIFunction: getScrollbarWidth | |
| 1709 | - * This function has been modified by the OpenLayers from the original version, | |
| 1710 | - * written by Matthew Eernisse and released under the Apache 2 | |
| 1711 | - * license here: | |
| 1712 | - * | |
| 1713 | - * http://www.fleegix.org/articles/2006/05/30/getting-the-scrollbar-width-in-pixels | |
| 1714 | - * | |
| 1715 | - * It has been modified simply to cache its value, since it is physically | |
| 1716 | - * impossible that this code could ever run in more than one browser at | |
| 1717 | - * once. | |
| 1718 | - * | |
| 1719 | - * Returns: | |
| 1720 | - * {Integer} | |
| 1721 | - */ | |
| 1722 | -OpenLayers.Util.getScrollbarWidth = function() { | |
| 1723 | - | |
| 1724 | - var scrollbarWidth = OpenLayers.Util._scrollbarWidth; | |
| 1725 | - | |
| 1726 | - if (scrollbarWidth == null) { | |
| 1727 | - var scr = null; | |
| 1728 | - var inn = null; | |
| 1729 | - var wNoScroll = 0; | |
| 1730 | - var wScroll = 0; | |
| 1731 | - | |
| 1732 | - // Outer scrolling div | |
| 1733 | - scr = document.createElement('div'); | |
| 1734 | - scr.style.position = 'absolute'; | |
| 1735 | - scr.style.top = '-1000px'; | |
| 1736 | - scr.style.left = '-1000px'; | |
| 1737 | - scr.style.width = '100px'; | |
| 1738 | - scr.style.height = '50px'; | |
| 1739 | - // Start with no scrollbar | |
| 1740 | - scr.style.overflow = 'hidden'; | |
| 1741 | - | |
| 1742 | - // Inner content div | |
| 1743 | - inn = document.createElement('div'); | |
| 1744 | - inn.style.width = '100%'; | |
| 1745 | - inn.style.height = '200px'; | |
| 1746 | - | |
| 1747 | - // Put the inner div in the scrolling div | |
| 1748 | - scr.appendChild(inn); | |
| 1749 | - // Append the scrolling div to the doc | |
| 1750 | - document.body.appendChild(scr); | |
| 1751 | - | |
| 1752 | - // Width of the inner div sans scrollbar | |
| 1753 | - wNoScroll = inn.offsetWidth; | |
| 1754 | - | |
| 1755 | - // Add the scrollbar | |
| 1756 | - scr.style.overflow = 'scroll'; | |
| 1757 | - // Width of the inner div width scrollbar | |
| 1758 | - wScroll = inn.offsetWidth; | |
| 1759 | - | |
| 1760 | - // Remove the scrolling div from the doc | |
| 1761 | - document.body.removeChild(document.body.lastChild); | |
| 1762 | - | |
| 1763 | - // Pixel width of the scroller | |
| 1764 | - OpenLayers.Util._scrollbarWidth = (wNoScroll - wScroll); | |
| 1765 | - scrollbarWidth = OpenLayers.Util._scrollbarWidth; | |
| 1766 | - } | |
| 1767 | - | |
| 1768 | - return scrollbarWidth; | |
| 1769 | -}; | |
| 1770 | - | |
| 1771 | -/** | |
| 1772 | - * APIFunction: getFormattedLonLat | |
| 1773 | - * This function will return latitude or longitude value formatted as | |
| 1774 | - * | |
| 1775 | - * Parameters: | |
| 1776 | - * coordinate - {Float} the coordinate value to be formatted | |
| 1777 | - * axis - {String} value of either 'lat' or 'lon' to indicate which axis is to | |
| 1778 | - * to be formatted (default = lat) | |
| 1779 | - * dmsOption - {String} specify the precision of the output can be one of: | |
| 1780 | - * 'dms' show degrees minutes and seconds | |
| 1781 | - * 'dm' show only degrees and minutes | |
| 1782 | - * 'd' show only degrees | |
| 1783 | - * | |
| 1784 | - * Returns: | |
| 1785 | - * {String} the coordinate value formatted as a string | |
| 1786 | - */ | |
| 1787 | -OpenLayers.Util.getFormattedLonLat = function(coordinate, axis, dmsOption) { | |
| 1788 | - if (!dmsOption) { | |
| 1789 | - dmsOption = 'dms'; //default to show degree, minutes, seconds | |
| 1790 | - } | |
| 1791 | - | |
| 1792 | - coordinate = (coordinate+540)%360 - 180; // normalize for sphere being round | |
| 1793 | - | |
| 1794 | - var abscoordinate = Math.abs(coordinate); | |
| 1795 | - var coordinatedegrees = Math.floor(abscoordinate); | |
| 1796 | - | |
| 1797 | - var coordinateminutes = (abscoordinate - coordinatedegrees)/(1/60); | |
| 1798 | - var tempcoordinateminutes = coordinateminutes; | |
| 1799 | - coordinateminutes = Math.floor(coordinateminutes); | |
| 1800 | - var coordinateseconds = (tempcoordinateminutes - coordinateminutes)/(1/60); | |
| 1801 | - coordinateseconds = Math.round(coordinateseconds*10); | |
| 1802 | - coordinateseconds /= 10; | |
| 1803 | - | |
| 1804 | - if( coordinateseconds >= 60) { | |
| 1805 | - coordinateseconds -= 60; | |
| 1806 | - coordinateminutes += 1; | |
| 1807 | - if( coordinateminutes >= 60) { | |
| 1808 | - coordinateminutes -= 60; | |
| 1809 | - coordinatedegrees += 1; | |
| 1810 | - } | |
| 1811 | - } | |
| 1812 | - | |
| 1813 | - if( coordinatedegrees < 10 ) { | |
| 1814 | - coordinatedegrees = "0" + coordinatedegrees; | |
| 1815 | - } | |
| 1816 | - var str = coordinatedegrees + "\u00B0"; | |
| 1817 | - | |
| 1818 | - if (dmsOption.indexOf('dm') >= 0) { | |
| 1819 | - if( coordinateminutes < 10 ) { | |
| 1820 | - coordinateminutes = "0" + coordinateminutes; | |
| 1821 | - } | |
| 1822 | - str += coordinateminutes + "'"; | |
| 1823 | - | |
| 1824 | - if (dmsOption.indexOf('dms') >= 0) { | |
| 1825 | - if( coordinateseconds < 10 ) { | |
| 1826 | - coordinateseconds = "0" + coordinateseconds; | |
| 1827 | - } | |
| 1828 | - str += coordinateseconds + '"'; | |
| 1829 | - } | |
| 1830 | - } | |
| 1831 | - | |
| 1832 | - if (axis == "lon") { | |
| 1833 | - str += coordinate < 0 ? OpenLayers.i18n("W") : OpenLayers.i18n("E"); | |
| 1834 | - } else { | |
| 1835 | - str += coordinate < 0 ? OpenLayers.i18n("S") : OpenLayers.i18n("N"); | |
| 1836 | - } | |
| 1837 | - return str; | |
| 1838 | -}; | |
| 1839 | - |
ferramentas/ol3panel/ol3Panel.php
| ... | ... | @@ -1,97 +0,0 @@ |
| 1 | -var OpenLayers={ | |
| 2 | - VERSION_NUMBER:"Release 2.11", | |
| 3 | - singleFile:true, | |
| 4 | - _getScriptLocation:( | |
| 5 | - function(){ | |
| 6 | - var r=new RegExp("(^|(.*?\\/))(OpenLayers\.js)(\\?|$)"), | |
| 7 | - s=document.getElementsByTagName('script'), | |
| 8 | - src, | |
| 9 | - m, | |
| 10 | - l=""; | |
| 11 | - for(var i=0,len=s.length;i<len;i++){ | |
| 12 | - src=s[i].getAttribute('src'); | |
| 13 | - if(src){ | |
| 14 | - var m=src.match(r); | |
| 15 | - if(m){ | |
| 16 | - l=m[1]; | |
| 17 | - break; | |
| 18 | - } | |
| 19 | - } | |
| 20 | - } | |
| 21 | - return( | |
| 22 | - function(){ | |
| 23 | - return l; | |
| 24 | - } | |
| 25 | - ); | |
| 26 | - } | |
| 27 | - )() | |
| 28 | -}; | |
| 29 | -OpenLayers.Util = OpenLayers.Util || {}; | |
| 30 | -OpenLayers.Util.lastSeqID = 0; | |
| 31 | -OpenLayers.Util.isArray = function(a) { | |
| 32 | - return (Object.prototype.toString.call(a) === '[object Array]'); | |
| 33 | -}; | |
| 34 | -OpenLayers.Util.createUniqueID = function(prefix) { | |
| 35 | - if (prefix == null) { | |
| 36 | - prefix = "id_"; | |
| 37 | - } | |
| 38 | - OpenLayers.Util.lastSeqID += 1; | |
| 39 | - return prefix + OpenLayers.Util.lastSeqID; | |
| 40 | -}; | |
| 41 | -OpenLayers.Util.createDiv = function(id, px, sz, imgURL, position, | |
| 42 | - border, overflow, opacity) { | |
| 43 | - | |
| 44 | - var dom = document.createElement('div'); | |
| 45 | - | |
| 46 | - if (imgURL) { | |
| 47 | - dom.style.backgroundImage = 'url(' + imgURL + ')'; | |
| 48 | - } | |
| 49 | - | |
| 50 | - //set generic properties | |
| 51 | - if (!id) { | |
| 52 | - id = OpenLayers.Util.createUniqueID("OpenLayersDiv"); | |
| 53 | - } | |
| 54 | - if (!position) { | |
| 55 | - position = "absolute"; | |
| 56 | - } | |
| 57 | - OpenLayers.Util.modifyDOMElement(dom, id, px, sz, position, | |
| 58 | - border, overflow, opacity); | |
| 59 | - | |
| 60 | - return dom; | |
| 61 | -}; | |
| 62 | -OpenLayers.Util.modifyDOMElement = function(element, id, px, sz, position, | |
| 63 | - border, overflow, opacity) { | |
| 64 | - | |
| 65 | - if (id) { | |
| 66 | - element.id = id; | |
| 67 | - } | |
| 68 | - if (px) { | |
| 69 | - element.style.left = px.x + "px"; | |
| 70 | - element.style.top = px.y + "px"; | |
| 71 | - } | |
| 72 | - if (sz) { | |
| 73 | - element.style.width = sz.w + "px"; | |
| 74 | - element.style.height = sz.h + "px"; | |
| 75 | - } | |
| 76 | - if (position) { | |
| 77 | - element.style.position = position; | |
| 78 | - } | |
| 79 | - if (border) { | |
| 80 | - element.style.border = border; | |
| 81 | - } | |
| 82 | - if (overflow) { | |
| 83 | - element.style.overflow = overflow; | |
| 84 | - } | |
| 85 | - if (parseFloat(opacity) >= 0.0 && parseFloat(opacity) < 1.0) { | |
| 86 | - element.style.filter = 'alpha(opacity=' + (opacity * 100) + ')'; | |
| 87 | - element.style.opacity = opacity; | |
| 88 | - } else if (parseFloat(opacity) == 1.0) { | |
| 89 | - element.style.filter = ''; | |
| 90 | - element.style.opacity = ''; | |
| 91 | - } | |
| 92 | -}; | |
| 93 | -<?php | |
| 94 | -include("Class.js"); | |
| 95 | -include("Panel.js"); | |
| 96 | -include("Control.js"); | |
| 97 | -?> |