| 55 | | /* ====================================================================== |
|---|
| 56 | | OpenLayers/SingleFile.js |
|---|
| 57 | | ====================================================================== */ |
|---|
| 58 | | |
|---|
| 59 | | /* Copyright (c) 2006-2008 MetaCarta, Inc., published under the Clear BSD |
|---|
| 60 | | * license. See http://svn.openlayers.org/trunk/openlayers/license.txt for the |
|---|
| 61 | | * full text of the license. */ |
|---|
| 62 | | |
|---|
| 63 | | var OpenLayers = { |
|---|
| 64 | | singleFile: true |
|---|
| 65 | | }; |
|---|
| 66 | | |
|---|
| 67 | | |
|---|
| 68 | | /* ====================================================================== |
|---|
| 69 | | OpenLayers.js |
|---|
| 70 | | ====================================================================== */ |
|---|
| 71 | | |
|---|
| 72 | | /* Copyright (c) 2006-2008 MetaCarta, Inc., published under the Clear BSD |
|---|
| 73 | | * license. See http://svn.openlayers.org/trunk/openlayers/license.txt for the |
|---|
| 74 | | * full text of the license. */ |
|---|
| 75 | | |
|---|
| 76 | | /* |
|---|
| 77 | | * @requires OpenLayers/BaseTypes.js |
|---|
| 78 | | * @requires OpenLayers/Lang/en.js |
|---|
| 79 | | */ |
|---|
| 80 | | |
|---|
| 81 | | (function() { |
|---|
| 82 | | /** |
|---|
| 83 | | * Before creating the OpenLayers namespace, check to see if |
|---|
| 84 | | * OpenLayers.singleFile is true. This occurs if the |
|---|
| 85 | | * OpenLayers/SingleFile.js script is included before this one - as is the |
|---|
| 86 | | * case with single file builds. |
|---|
| 87 | | */ |
|---|
| 88 | | var singleFile = (typeof OpenLayers == "object" && OpenLayers.singleFile); |
|---|
| 89 | | |
|---|
| 90 | | /** |
|---|
| 91 | | * Namespace: OpenLayers |
|---|
| 92 | | * The OpenLayers object provides a namespace for all things OpenLayers |
|---|
| 93 | | */ |
|---|
| 94 | | window.OpenLayers = { |
|---|
| 95 | | |
|---|
| 96 | | /** |
|---|
| 97 | | * Property: _scriptName |
|---|
| 98 | | * {String} Relative path of this script. |
|---|
| 99 | | */ |
|---|
| 100 | | _scriptName: (!singleFile) ? "lib/OpenLayers.js" : "OpenLayers.js", |
|---|
| 101 | | |
|---|
| 102 | | /** |
|---|
| 103 | | * Function: _getScriptLocation |
|---|
| 104 | | * Return the path to this script. |
|---|
| 105 | | * |
|---|
| 106 | | * Returns: |
|---|
| 107 | | * {String} Path to this script |
|---|
| 108 | | */ |
|---|
| 109 | | _getScriptLocation: function () { |
|---|
| 110 | | var scriptLocation = ""; |
|---|
| 111 | | var scriptName = OpenLayers._scriptName; |
|---|
| 112 | | |
|---|
| 113 | | var scripts = document.getElementsByTagName('script'); |
|---|
| 114 | | for (var i = 0; i < scripts.length; i++) { |
|---|
| 115 | | var src = scripts[i].getAttribute('src'); |
|---|
| 116 | | if (src) { |
|---|
| 117 | | var index = src.lastIndexOf(scriptName); |
|---|
| 118 | | // set path length for src up to a query string |
|---|
| 119 | | var pathLength = src.lastIndexOf('?'); |
|---|
| 120 | | if (pathLength < 0) { |
|---|
| 121 | | pathLength = src.length; |
|---|
| 122 | | } |
|---|
| 123 | | // is it found, at the end of the URL? |
|---|
| 124 | | if ((index > -1) && (index + scriptName.length == pathLength)) { |
|---|
| 125 | | scriptLocation = src.slice(0, pathLength - scriptName.length); |
|---|
| 126 | | break; |
|---|
| 127 | | } |
|---|
| 128 | | } |
|---|
| 129 | | } |
|---|
| 130 | | return scriptLocation; |
|---|
| 131 | | } |
|---|
| 132 | | }; |
|---|
| 133 | | /** |
|---|
| 134 | | * OpenLayers.singleFile is a flag indicating this file is being included |
|---|
| 135 | | * in a Single File Library build of the OpenLayers Library. |
|---|
| 136 | | * |
|---|
| 137 | | * When we are *not* part of a SFL build we dynamically include the |
|---|
| 138 | | * OpenLayers library code. |
|---|
| 139 | | * |
|---|
| 140 | | * When we *are* part of a SFL build we do not dynamically include the |
|---|
| 141 | | * OpenLayers library code as it will be appended at the end of this file. |
|---|
| 142 | | */ |
|---|
| 143 | | if(!singleFile) { |
|---|
| 144 | | var jsfiles = new Array( |
|---|
| 145 | | "OpenLayers/Util.js", |
|---|
| 146 | | "OpenLayers/BaseTypes.js", |
|---|
| 147 | | "OpenLayers/BaseTypes/Class.js", |
|---|
| 148 | | "OpenLayers/BaseTypes/Bounds.js", |
|---|
| 149 | | "OpenLayers/BaseTypes/Element.js", |
|---|
| 150 | | "OpenLayers/BaseTypes/LonLat.js", |
|---|
| 151 | | "OpenLayers/BaseTypes/Pixel.js", |
|---|
| 152 | | "OpenLayers/BaseTypes/Size.js", |
|---|
| 153 | | "OpenLayers/Console.js", |
|---|
| 154 | | "OpenLayers/Tween.js", |
|---|
| 155 | | "Rico/Corner.js", |
|---|
| 156 | | "Rico/Color.js", |
|---|
| 157 | | "OpenLayers/Ajax.js", |
|---|
| 158 | | "OpenLayers/Request.js", |
|---|
| 159 | | "OpenLayers/Request/XMLHttpRequest.js", |
|---|
| 160 | | "OpenLayers/Events.js", |
|---|
| 161 | | "OpenLayers/Projection.js", |
|---|
| 162 | | "OpenLayers/Map.js", |
|---|
| 163 | | "OpenLayers/Layer.js", |
|---|
| 164 | | "OpenLayers/Icon.js", |
|---|
| 165 | | "OpenLayers/Marker.js", |
|---|
| 166 | | "OpenLayers/Marker/Box.js", |
|---|
| 167 | | "OpenLayers/Popup.js", |
|---|
| 168 | | "OpenLayers/Tile.js", |
|---|
| 169 | | "OpenLayers/Tile/Image.js", |
|---|
| 170 | | "OpenLayers/Tile/WFS.js", |
|---|
| 171 | | "OpenLayers/Layer/Image.js", |
|---|
| 172 | | "OpenLayers/Layer/SphericalMercator.js", |
|---|
| 173 | | "OpenLayers/Layer/EventPane.js", |
|---|
| 174 | | "OpenLayers/Layer/FixedZoomLevels.js", |
|---|
| 175 | | "OpenLayers/Layer/Google.js", |
|---|
| 176 | | "OpenLayers/Layer/VirtualEarth.js", |
|---|
| 177 | | "OpenLayers/Layer/Yahoo.js", |
|---|
| 178 | | "OpenLayers/Layer/HTTPRequest.js", |
|---|
| 179 | | "OpenLayers/Layer/Grid.js", |
|---|
| 180 | | "OpenLayers/Layer/MapGuide.js", |
|---|
| 181 | | "OpenLayers/Layer/MapServer.js", |
|---|
| 182 | | "OpenLayers/Layer/MapServer/Untiled.js", |
|---|
| 183 | | "OpenLayers/Layer/KaMap.js", |
|---|
| 184 | | "OpenLayers/Layer/MultiMap.js", |
|---|
| 185 | | "OpenLayers/Layer/Markers.js", |
|---|
| 186 | | "OpenLayers/Layer/Text.js", |
|---|
| 187 | | "OpenLayers/Layer/WorldWind.js", |
|---|
| 188 | | "OpenLayers/Layer/WMS.js", |
|---|
| 189 | | "OpenLayers/Layer/WMS/Untiled.js", |
|---|
| 190 | | "OpenLayers/Layer/GeoRSS.js", |
|---|
| 191 | | "OpenLayers/Layer/Boxes.js", |
|---|
| 192 | | "OpenLayers/Layer/TMS.js", |
|---|
| 193 | | "OpenLayers/Layer/TileCache.js", |
|---|
| 194 | | "OpenLayers/Popup/Anchored.js", |
|---|
| 195 | | "OpenLayers/Popup/AnchoredBubble.js", |
|---|
| 196 | | "OpenLayers/Popup/Framed.js", |
|---|
| 197 | | "OpenLayers/Popup/FramedCloud.js", |
|---|
| 198 | | "OpenLayers/Feature.js", |
|---|
| 199 | | "OpenLayers/Feature/Vector.js", |
|---|
| 200 | | "OpenLayers/Feature/WFS.js", |
|---|
| 201 | | "OpenLayers/Handler.js", |
|---|
| 202 | | "OpenLayers/Handler/Click.js", |
|---|
| 203 | | "OpenLayers/Handler/Hover.js", |
|---|
| 204 | | "OpenLayers/Handler/Point.js", |
|---|
| 205 | | "OpenLayers/Handler/Path.js", |
|---|
| 206 | | "OpenLayers/Handler/Polygon.js", |
|---|
| 207 | | "OpenLayers/Handler/Feature.js", |
|---|
| 208 | | "OpenLayers/Handler/Drag.js", |
|---|
| 209 | | "OpenLayers/Handler/RegularPolygon.js", |
|---|
| 210 | | "OpenLayers/Handler/Box.js", |
|---|
| 211 | | "OpenLayers/Handler/MouseWheel.js", |
|---|
| 212 | | "OpenLayers/Handler/Keyboard.js", |
|---|
| 213 | | "OpenLayers/Control.js", |
|---|
| 214 | | "OpenLayers/Control/Attribution.js", |
|---|
| 215 | | "OpenLayers/Control/Button.js", |
|---|
| 216 | | "OpenLayers/Control/ZoomBox.js", |
|---|
| 217 | | "OpenLayers/Control/ZoomToMaxExtent.js", |
|---|
| 218 | | "OpenLayers/Control/DragPan.js", |
|---|
| 219 | | "OpenLayers/Control/Navigation.js", |
|---|
| 220 | | "OpenLayers/Control/MouseDefaults.js", |
|---|
| 221 | | "OpenLayers/Control/MousePosition.js", |
|---|
| 222 | | "OpenLayers/Control/OverviewMap.js", |
|---|
| 223 | | "OpenLayers/Control/KeyboardDefaults.js", |
|---|
| 224 | | "OpenLayers/Control/PanZoom.js", |
|---|
| 225 | | "OpenLayers/Control/PanZoomBar.js", |
|---|
| 226 | | "OpenLayers/Control/ArgParser.js", |
|---|
| 227 | | "OpenLayers/Control/Permalink.js", |
|---|
| 228 | | "OpenLayers/Control/Scale.js", |
|---|
| 229 | | "OpenLayers/Control/ScaleLine.js", |
|---|
| 230 | | "OpenLayers/Control/LayerSwitcher.js", |
|---|
| 231 | | "OpenLayers/Control/DrawFeature.js", |
|---|
| 232 | | "OpenLayers/Control/DragFeature.js", |
|---|
| 233 | | "OpenLayers/Control/ModifyFeature.js", |
|---|
| 234 | | "OpenLayers/Control/Panel.js", |
|---|
| 235 | | "OpenLayers/Control/SelectFeature.js", |
|---|
| 236 | | "OpenLayers/Control/NavigationHistory.js", |
|---|
| 237 | | "OpenLayers/Geometry.js", |
|---|
| 238 | | "OpenLayers/Geometry/Rectangle.js", |
|---|
| 239 | | "OpenLayers/Geometry/Collection.js", |
|---|
| 240 | | "OpenLayers/Geometry/Point.js", |
|---|
| 241 | | "OpenLayers/Geometry/MultiPoint.js", |
|---|
| 242 | | "OpenLayers/Geometry/Curve.js", |
|---|
| 243 | | "OpenLayers/Geometry/LineString.js", |
|---|
| 244 | | "OpenLayers/Geometry/LinearRing.js", |
|---|
| 245 | | "OpenLayers/Geometry/Polygon.js", |
|---|
| 246 | | "OpenLayers/Geometry/MultiLineString.js", |
|---|
| 247 | | "OpenLayers/Geometry/MultiPolygon.js", |
|---|
| 248 | | "OpenLayers/Geometry/Surface.js", |
|---|
| 249 | | "OpenLayers/Renderer.js", |
|---|
| 250 | | "OpenLayers/Renderer/Elements.js", |
|---|
| 251 | | "OpenLayers/Renderer/SVG.js", |
|---|
| 252 | | "OpenLayers/Renderer/VML.js", |
|---|
| 253 | | "OpenLayers/Layer/Vector.js", |
|---|
| 254 | | "OpenLayers/Layer/PointTrack.js", |
|---|
| 255 | | "OpenLayers/Layer/GML.js", |
|---|
| 256 | | "OpenLayers/Style.js", |
|---|
| 257 | | "OpenLayers/StyleMap.js", |
|---|
| 258 | | "OpenLayers/Rule.js", |
|---|
| 259 | | "OpenLayers/Filter.js", |
|---|
| 260 | | "OpenLayers/Filter/FeatureId.js", |
|---|
| 261 | | "OpenLayers/Filter/Logical.js", |
|---|
| 262 | | "OpenLayers/Filter/Comparison.js", |
|---|
| 263 | | "OpenLayers/Format.js", |
|---|
| 264 | | "OpenLayers/Format/XML.js", |
|---|
| 265 | | "OpenLayers/Format/GML.js", |
|---|
| 266 | | "OpenLayers/Format/KML.js", |
|---|
| 267 | | "OpenLayers/Format/GeoRSS.js", |
|---|
| 268 | | "OpenLayers/Format/WFS.js", |
|---|
| 269 | | "OpenLayers/Format/WKT.js", |
|---|
| 270 | | "OpenLayers/Format/OSM.js", |
|---|
| 271 | | "OpenLayers/Format/SLD.js", |
|---|
| 272 | | "OpenLayers/Format/SLD/v1.js", |
|---|
| 273 | | "OpenLayers/Format/SLD/v1_0_0.js", |
|---|
| 274 | | "OpenLayers/Format/Text.js", |
|---|
| 275 | | "OpenLayers/Format/JSON.js", |
|---|
| 276 | | "OpenLayers/Format/GeoJSON.js", |
|---|
| 277 | | "OpenLayers/Format/WMC.js", |
|---|
| 278 | | "OpenLayers/Format/WMC/v1.js", |
|---|
| 279 | | "OpenLayers/Format/WMC/v1_0_0.js", |
|---|
| 280 | | "OpenLayers/Format/WMC/v1_1_0.js", |
|---|
| 281 | | "OpenLayers/Layer/WFS.js", |
|---|
| 282 | | "OpenLayers/Control/MouseToolbar.js", |
|---|
| 283 | | "OpenLayers/Control/NavToolbar.js", |
|---|
| 284 | | "OpenLayers/Control/EditingToolbar.js", |
|---|
| 285 | | "OpenLayers/Lang.js", |
|---|
| 286 | | "OpenLayers/Lang/en.js" |
|---|
| 287 | | ); // etc. |
|---|
| 288 | | |
|---|
| 289 | | var agent = navigator.userAgent; |
|---|
| 290 | | var docWrite = (agent.match("MSIE") || agent.match("Safari")); |
|---|
| 291 | | if(docWrite) { |
|---|
| 292 | | var allScriptTags = new Array(jsfiles.length); |
|---|
| 293 | | } |
|---|
| 294 | | var host = OpenLayers._getScriptLocation() + "lib/"; |
|---|
| 295 | | for (var i = 0; i < jsfiles.length; i++) { |
|---|
| 296 | | if (docWrite) { |
|---|
| 297 | | allScriptTags[i] = "<script src='" + host + jsfiles[i] + |
|---|
| 298 | | "'></script>"; |
|---|
| 299 | | } else { |
|---|
| 300 | | var s = document.createElement("script"); |
|---|
| 301 | | s.src = host + jsfiles[i]; |
|---|
| 302 | | var h = document.getElementsByTagName("head").length ? |
|---|
| 303 | | document.getElementsByTagName("head")[0] : |
|---|
| 304 | | document.body; |
|---|
| 305 | | h.appendChild(s); |
|---|
| 306 | | } |
|---|
| 307 | | } |
|---|
| 308 | | if (docWrite) { |
|---|
| 309 | | document.write(allScriptTags.join("")); |
|---|
| 310 | | } |
|---|
| 311 | | } |
|---|
| 312 | | })(); |
|---|
| 313 | | |
|---|
| 314 | | /** |
|---|
| 315 | | * Constant: VERSION_NUMBER |
|---|
| 316 | | */ |
|---|
| 317 | | OpenLayers.VERSION_NUMBER="$Revision: 7335 $"; |
|---|
| 318 | | /* ====================================================================== |
|---|
| 319 | | OpenLayers/BaseTypes.js |
|---|
| 320 | | ====================================================================== */ |
|---|
| 321 | | |
|---|
| 322 | | /* Copyright (c) 2006-2008 MetaCarta, Inc., published under the Clear BSD |
|---|
| 323 | | * license. See http://svn.openlayers.org/trunk/openlayers/license.txt for the |
|---|
| 324 | | * full text of the license. */ |
|---|
| 325 | | |
|---|
| 326 | | /** |
|---|
| 327 | | * @requires OpenLayers/BaseTypes/Class.js |
|---|
| 328 | | * @requires OpenLayers/BaseTypes/LonLat.js |
|---|
| 329 | | * @requires OpenLayers/BaseTypes/Size.js |
|---|
| 330 | | * @requires OpenLayers/BaseTypes/Pixel.js |
|---|
| 331 | | * @requires OpenLayers/BaseTypes/Bounds.js |
|---|
| 332 | | * @requires OpenLayers/BaseTypes/Element.js |
|---|
| 333 | | * @requires OpenLayers/Lang/en.js |
|---|
| 334 | | */ |
|---|
| 335 | | |
|---|
| 336 | | /** |
|---|
| 337 | | * Header: OpenLayers Base Types |
|---|
| 338 | | * OpenLayers custom string, number and function functions are described here. |
|---|
| 339 | | */ |
|---|
| 340 | | |
|---|
| 341 | | /** |
|---|
| 342 | | * Namespace: OpenLayers.String |
|---|
| 343 | | * Contains convenience functions for string manipulation. |
|---|
| 344 | | */ |
|---|
| 345 | | OpenLayers.String = { |
|---|
| 346 | | |
|---|
| 347 | | /** |
|---|
| 348 | | * APIFunction: startsWith |
|---|
| 349 | | * Test whether a string starts with another string. |
|---|
| 350 | | * |
|---|
| 351 | | * Parameters: |
|---|
| 352 | | * str - {String} The string to test. |
|---|
| 353 | | * sub - {Sring} The substring to look for. |
|---|
| 354 | | * |
|---|
| 355 | | * Returns: |
|---|
| 356 | | * {Boolean} The first string starts with the second. |
|---|
| 357 | | */ |
|---|
| 358 | | startsWith: function(str, sub) { |
|---|
| 359 | | return (str.indexOf(sub) == 0); |
|---|
| 360 | | }, |
|---|
| 361 | | |
|---|
| 362 | | /** |
|---|
| 363 | | * APIFunction: contains |
|---|
| 364 | | * Test whether a string contains another string. |
|---|
| 365 | | * |
|---|
| 366 | | * Parameters: |
|---|
| 367 | | * str - {String} The string to test. |
|---|
| 368 | | * sub - {String} The substring to look for. |
|---|
| 369 | | * |
|---|
| 370 | | * Returns: |
|---|
| 371 | | * {Boolean} The first string contains the second. |
|---|
| 372 | | */ |
|---|
| 373 | | contains: function(str, sub) { |
|---|
| 374 | | return (str.indexOf(sub) != -1); |
|---|
| 375 | | }, |
|---|
| 376 | | |
|---|
| 377 | | /** |
|---|
| 378 | | * APIFunction: trim |
|---|
| 379 | | * Removes leading and trailing whitespace characters from a string. |
|---|
| 380 | | * |
|---|
| 381 | | * Parameters: |
|---|
| 382 | | * str - {String} The (potentially) space padded string. This string is not |
|---|
| 383 | | * modified. |
|---|
| 384 | | * |
|---|
| 385 | | * Returns: |
|---|
| 386 | | * {String} A trimmed version of the string with all leading and |
|---|
| 387 | | * trailing spaces removed. |
|---|
| 388 | | */ |
|---|
| 389 | | trim: function(str) { |
|---|
| 390 | | return str.replace(/^\s*(.*?)\s*$/, "$1"); |
|---|
| 391 | | }, |
|---|
| 392 | | |
|---|
| 393 | | /** |
|---|
| 394 | | * APIFunction: camelize |
|---|
| 395 | | * Camel-case a hyphenated string. |
|---|
| 396 | | * Ex. "chicken-head" becomes "chickenHead", and |
|---|
| 397 | | * "-chicken-head" becomes "ChickenHead". |
|---|
| 398 | | * |
|---|
| 399 | | * Parameters: |
|---|
| 400 | | * str - {String} The string to be camelized. The original is not modified. |
|---|
| 401 | | * |
|---|
| 402 | | * Returns: |
|---|
| 403 | | * {String} The string, camelized |
|---|
| 404 | | */ |
|---|
| 405 | | camelize: function(str) { |
|---|
| 406 | | var oStringList = str.split('-'); |
|---|
| 407 | | var camelizedString = oStringList[0]; |
|---|
| 408 | | for (var i = 1; i < oStringList.length; i++) { |
|---|
| 409 | | var s = oStringList[i]; |
|---|
| 410 | | camelizedString += s.charAt(0).toUpperCase() + s.substring(1); |
|---|
| 411 | | } |
|---|
| 412 | | return camelizedString; |
|---|
| 413 | | }, |
|---|
| 414 | | |
|---|
| 415 | | /** |
|---|
| 416 | | * APIFunction: format |
|---|
| 417 | | * Given a string with tokens in the form ${token}, return a string |
|---|
| 418 | | * with tokens replaced with properties from the given context |
|---|
| 419 | | * object. Represent a literal "${" by doubling it, e.g. "${${". |
|---|
| 420 | | * |
|---|
| 421 | | * Parameters: |
|---|
| 422 | | * template - {String} A string with tokens to be replaced. A template |
|---|
| 423 | | * has the form "literal ${token}" where the token will be replaced |
|---|
| 424 | | * by the value of context["token"]. |
|---|
| 425 | | * context - {Object} An optional object with properties corresponding |
|---|
| 426 | | * to the tokens in the format string. If no context is sent, the |
|---|
| 427 | | * window object will be used. |
|---|
| 428 | | * args - {Array} Optional arguments to pass to any functions found in |
|---|
| 429 | | * the context. If a context property is a function, the token |
|---|
| 430 | | * will be replaced by the return from the function called with |
|---|
| 431 | | * these arguments. |
|---|
| 432 | | * |
|---|
| 433 | | * Returns: |
|---|
| 434 | | * {String} A string with tokens replaced from the context object. |
|---|
| 435 | | */ |
|---|
| 436 | | format: function(template, context, args) { |
|---|
| 437 | | if(!context) { |
|---|
| 438 | | context = window; |
|---|
| 439 | | } |
|---|
| 440 | | var tokens = template.split("${"); |
|---|
| 441 | | var item, last, replacement; |
|---|
| 442 | | for(var i=1; i<tokens.length; i++) { |
|---|
| 443 | | item = tokens[i]; |
|---|
| 444 | | last = item.indexOf("}"); |
|---|
| 445 | | if(last > 0) { |
|---|
| 446 | | replacement = context[item.substring(0, last)]; |
|---|
| 447 | | if(typeof replacement == "function") { |
|---|
| 448 | | replacement = args ? |
|---|
| 449 | | replacement.apply(null, args) : |
|---|
| 450 | | replacement(); |
|---|
| 451 | | } |
|---|
| 452 | | tokens[i] = replacement + item.substring(++last); |
|---|
| 453 | | } else { |
|---|
| 454 | | tokens[i] = "${" + item; |
|---|
| 455 | | } |
|---|
| 456 | | } |
|---|
| 457 | | return tokens.join(""); |
|---|
| 458 | | }, |
|---|
| 459 | | |
|---|
| 460 | | /** |
|---|
| 461 | | * Property: OpenLayers.String.numberRegEx |
|---|
| 462 | | * Used to test strings as numbers. |
|---|
| 463 | | */ |
|---|
| 464 | | numberRegEx: /^([+-]?)(?=\d|\.\d)\d*(\.\d*)?([Ee]([+-]?\d+))?$/, |
|---|
| 465 | | |
|---|
| 466 | | /** |
|---|
| 467 | | * APIFunction: OpenLayers.String.isNumeric |
|---|
| 468 | | * Determine whether a string contains only a numeric value. |
|---|
| 469 | | * |
|---|
| 470 | | * Examples: |
|---|
| 471 | | * (code) |
|---|
| 472 | | * OpenLayers.String.isNumeric("6.02e23") // true |
|---|
| 473 | | * OpenLayers.String.isNumeric("12 dozen") // false |
|---|
| 474 | | * OpenLayers.String.isNumeric("4") // true |
|---|
| 475 | | * OpenLayers.String.isNumeric(" 4 ") // false |
|---|
| 476 | | * (end) |
|---|
| 477 | | * |
|---|
| 478 | | * Returns: |
|---|
| 479 | | * {Boolean} String contains only a number. |
|---|
| 480 | | */ |
|---|
| 481 | | isNumeric: function(value) { |
|---|
| 482 | | return OpenLayers.String.numberRegEx.test(value); |
|---|
| 483 | | } |
|---|
| 484 | | |
|---|
| 485 | | }; |
|---|
| 486 | | |
|---|
| 487 | | if (!String.prototype.startsWith) { |
|---|
| 488 | | /** |
|---|
| 489 | | * APIMethod: String.startsWith |
|---|
| 490 | | * *Deprecated*. Whether or not a string starts with another string. |
|---|
| 491 | | * |
|---|
| 492 | | * Parameters: |
|---|
| 493 | | * sStart - {Sring} The string we're testing for. |
|---|
| 494 | | * |
|---|
| 495 | | * Returns: |
|---|
| 496 | | * {Boolean} Whether or not this string starts with the string passed in. |
|---|
| 497 | | */ |
|---|
| 498 | | String.prototype.startsWith = function(sStart) { |
|---|
| 499 | | OpenLayers.Console.warn(OpenLayers.i18n("methodDeprecated", |
|---|
| 500 | | {'newMethod':'OpenLayers.String.startsWith'})); |
|---|
| 501 | | return OpenLayers.String.startsWith(this, sStart); |
|---|
| 502 | | }; |
|---|
| 503 | | } |
|---|
| 504 | | |
|---|
| 505 | | if (!String.prototype.contains) { |
|---|
| 506 | | /** |
|---|
| 507 | | * APIMethod: String.contains |
|---|
| 508 | | * *Deprecated*. Whether or not a string contains another string. |
|---|
| 509 | | * |
|---|
| 510 | | * Parameters: |
|---|
| 511 | | * str - {String} The string that we're testing for. |
|---|
| 512 | | * |
|---|
| 513 | | * Returns: |
|---|
| 514 | | * {Boolean} Whether or not this string contains with the string passed in. |
|---|
| 515 | | */ |
|---|
| 516 | | String.prototype.contains = function(str) { |
|---|
| 517 | | OpenLayers.Console.warn(OpenLayers.i18n("methodDeprecated", |
|---|
| 518 | | {'newMethod':'OpenLayers.String.contains'})); |
|---|
| 519 | | return OpenLayers.String.contains(this, str); |
|---|
| 520 | | }; |
|---|
| 521 | | } |
|---|
| 522 | | |
|---|
| 523 | | if (!String.prototype.trim) { |
|---|
| 524 | | /** |
|---|
| 525 | | * APIMethod: String.trim |
|---|
| 526 | | * *Deprecated*. Removes leading and trailing whitespace characters from a string. |
|---|
| 527 | | * |
|---|
| 528 | | * Returns: |
|---|
| 529 | | * {String} A trimmed version of the string - all leading and |
|---|
| 530 | | * trailing spaces removed |
|---|
| 531 | | */ |
|---|
| 532 | | String.prototype.trim = function() { |
|---|
| 533 | | OpenLayers.Console.warn(OpenLayers.i18n("methodDeprecated", |
|---|
| 534 | | {'newMethod':'OpenLayers.String.trim'})); |
|---|
| 535 | | return OpenLayers.String.trim(this); |
|---|
| 536 | | }; |
|---|
| 537 | | } |
|---|
| 538 | | |
|---|
| 539 | | if (!String.prototype.camelize) { |
|---|
| 540 | | /** |
|---|
| 541 | | * APIMethod: String.camelize |
|---|
| 542 | | * *Deprecated*. Camel-case a hyphenated string. |
|---|
| 543 | | * Ex. "chicken-head" becomes "chickenHead", and |
|---|
| 544 | | * "-chicken-head" becomes "ChickenHead". |
|---|
| 545 | | * |
|---|
| 546 | | * Returns: |
|---|
| 547 | | * {String} The string, camelized |
|---|
| 548 | | */ |
|---|
| 549 | | String.prototype.camelize = function() { |
|---|
| 550 | | OpenLayers.Console.warn(OpenLayers.i18n("methodDeprecated", |
|---|
| 551 | | {'newMethod':'OpenLayers.String.camelize'})); |
|---|
| 552 | | return OpenLayers.String.camelize(this); |
|---|
| 553 | | }; |
|---|
| 554 | | } |
|---|
| 555 | | |
|---|
| 556 | | /** |
|---|
| 557 | | * Namespace: OpenLayers.Number |
|---|
| 558 | | * Contains convenience functions for manipulating numbers. |
|---|
| 559 | | */ |
|---|
| 560 | | OpenLayers.Number = { |
|---|
| 561 | | |
|---|
| 562 | | /** |
|---|
| 563 | | * Property: decimalSeparator |
|---|
| 564 | | * Decimal separator to use when formatting numbers. |
|---|
| 565 | | */ |
|---|
| 566 | | decimalSeparator: ".", |
|---|
| 567 | | |
|---|
| 568 | | /** |
|---|
| 569 | | * Property: thousandsSeparator |
|---|
| 570 | | * Thousands separator to use when formatting numbers. |
|---|
| 571 | | */ |
|---|
| 572 | | thousandsSeparator: ",", |
|---|
| 573 | | |
|---|
| 574 | | /** |
|---|
| 575 | | * APIFunction: limitSigDigs |
|---|
| 576 | | * Limit the number of significant digits on a float. |
|---|
| 577 | | * |
|---|
| 578 | | * Parameters: |
|---|
| 579 | | * num - {Float} |
|---|
| 580 | | * sig - {Integer} |
|---|
| 581 | | * |
|---|
| 582 | | * Returns: |
|---|
| 583 | | * {Float} The number, rounded to the specified number of significant |
|---|
| 584 | | * digits. |
|---|
| 585 | | */ |
|---|
| 586 | | limitSigDigs: function(num, sig) { |
|---|
| 587 | | var fig = 0; |
|---|
| 588 | | if (sig > 0) { |
|---|
| 589 | | fig = parseFloat(num.toPrecision(sig)); |
|---|
| 590 | | } |
|---|
| 591 | | return fig; |
|---|
| 592 | | }, |
|---|
| 593 | | |
|---|
| 594 | | /** |
|---|
| 595 | | * APIFunction: format |
|---|
| 596 | | * Formats a number for output. |
|---|
| 597 | | * |
|---|
| 598 | | * Parameters: |
|---|
| 599 | | * num - {Float} |
|---|
| 600 | | * dec - {Integer} Number of decimal places to round to. |
|---|
| 601 | | * Defaults to 0. Set to null to leave decimal places unchanged. |
|---|
| 602 | | * tsep - {String} Thousands separator. |
|---|
| 603 | | * Default is ",". |
|---|
| 604 | | * dsep - {String} Decimal separator. |
|---|
| 605 | | * Default is ".". |
|---|
| 606 | | * |
|---|
| 607 | | * Returns: |
|---|
| 608 | | * {String} A string representing the formatted number. |
|---|
| 609 | | */ |
|---|
| 610 | | format: function(num, dec, tsep, dsep) { |
|---|
| 611 | | dec = (typeof dec != "undefined") ? dec : 0; |
|---|
| 612 | | tsep = (typeof tsep != "undefined") ? tsep : |
|---|
| 613 | | OpenLayers.Number.thousandsSeparator; |
|---|
| 614 | | dsep = (typeof dsep != "undefined") ? dsep : |
|---|
| 615 | | OpenLayers.Number.decimalSeparator; |
|---|
| 616 | | |
|---|
| 617 | | if (dec != null) { |
|---|
| 618 | | num = parseFloat(num.toFixed(dec)); |
|---|
| 619 | | } |
|---|
| 620 | | |
|---|
| 621 | | var parts = num.toString().split("."); |
|---|
| 622 | | if (parts.length == 1 && dec == null) { |
|---|
| 623 | | // integer where we do not want to touch the decimals |
|---|
| 624 | | dec = 0; |
|---|
| 625 | | } |
|---|
| 626 | | |
|---|
| 627 | | var integer = parts[0]; |
|---|
| 628 | | if (tsep) { |
|---|
| 629 | | var thousands = /(-?[0-9]+)([0-9]{3})/; |
|---|
| 630 | | while(thousands.test(integer)) { |
|---|
| 631 | | integer = integer.replace(thousands, "$1" + tsep + "$2"); |
|---|
| 632 | | } |
|---|
| 633 | | } |
|---|
| 634 | | |
|---|
| 635 | | var str; |
|---|
| 636 | | if (dec == 0) { |
|---|
| 637 | | str = integer; |
|---|
| 638 | | } else { |
|---|
| 639 | | var rem = parts.length > 1 ? parts[1] : "0"; |
|---|
| 640 | | if (dec != null) { |
|---|
| 641 | | rem = rem + new Array(dec - rem.length + 1).join("0"); |
|---|
| 642 | | } |
|---|
| 643 | | str = integer + dsep + rem; |
|---|
| 644 | | } |
|---|
| 645 | | return str; |
|---|
| 646 | | } |
|---|
| 647 | | }; |
|---|
| 648 | | |
|---|
| 649 | | if (!Number.prototype.limitSigDigs) { |
|---|
| 650 | | /** |
|---|
| 651 | | * APIMethod: Number.limitSigDigs |
|---|
| 652 | | * *Deprecated*. Limit the number of significant digits on an integer. Does *not* |
|---|
| 653 | | * work with floats! |
|---|
| 654 | | * |
|---|
| 655 | | * Parameters: |
|---|
| 656 | | * sig - {Integer} |
|---|
| 657 | | * |
|---|
| 658 | | * Returns: |
|---|
| 659 | | * {Integer} The number, rounded to the specified number of significant digits. |
|---|
| 660 | | * If null, 0, or negative value passed in, returns 0 |
|---|
| 661 | | */ |
|---|
| 662 | | Number.prototype.limitSigDigs = function(sig) { |
|---|
| 663 | | OpenLayers.Console.warn(OpenLayers.i18n("methodDeprecated", |
|---|
| 664 | | {'newMethod':'OpenLayers.String.limitSigDigs'})); |
|---|
| 665 | | return OpenLayers.Number.limitSigDigs(this, sig); |
|---|
| 666 | | }; |
|---|
| 667 | | } |
|---|
| 668 | | |
|---|
| 669 | | /** |
|---|
| 670 | | * Namespace: OpenLayers.Function |
|---|
| 671 | | * Contains convenience functions for function manipulation. |
|---|
| 672 | | */ |
|---|
| 673 | | OpenLayers.Function = { |
|---|
| 674 | | /** |
|---|
| 675 | | * APIFunction: bind |
|---|
| 676 | | * Bind a function to an object. Method to easily create closures with |
|---|
| 677 | | * 'this' altered. |
|---|
| 678 | | * |
|---|
| 679 | | * Parameters: |
|---|
| 680 | | * func - {Function} Input function. |
|---|
| 681 | | * object - {Object} The object to bind to the input function (as this). |
|---|
| 682 | | * |
|---|
| 683 | | * Returns: |
|---|
| 684 | | * {Function} A closure with 'this' set to the passed in object. |
|---|
| 685 | | */ |
|---|
| 686 | | bind: function(func, object) { |
|---|
| 687 | | // create a reference to all arguments past the second one |
|---|
| 688 | | var args = Array.prototype.slice.apply(arguments, [2]); |
|---|
| 689 | | return function() { |
|---|
| 690 | | // Push on any additional arguments from the actual function call. |
|---|
| 691 | | // These will come after those sent to the bind call. |
|---|
| 692 | | var newArgs = args.concat( |
|---|
| 693 | | Array.prototype.slice.apply(arguments, [0]) |
|---|
| 694 | | ); |
|---|
| 695 | | return func.apply(object, newArgs); |
|---|
| 696 | | }; |
|---|
| 697 | | }, |
|---|
| 698 | | |
|---|
| 699 | | /** |
|---|
| 700 | | * APIFunction: bindAsEventListener |
|---|
| 701 | | * Bind a function to an object, and configure it to receive the event |
|---|
| 702 | | * object as first parameter when called. |
|---|
| 703 | | * |
|---|
| 704 | | * Parameters: |
|---|
| 705 | | * func - {Function} Input function to serve as an event listener. |
|---|
| 706 | | * object - {Object} A reference to this. |
|---|
| 707 | | * |
|---|
| 708 | | * Returns: |
|---|
| 709 | | * {Function} |
|---|
| 710 | | */ |
|---|
| 711 | | bindAsEventListener: function(func, object) { |
|---|
| 712 | | return function(event) { |
|---|
| 713 | | return func.call(object, event || window.event); |
|---|
| 714 | | }; |
|---|
| 715 | | } |
|---|
| 716 | | }; |
|---|
| 717 | | |
|---|
| 718 | | if (!Function.prototype.bind) { |
|---|
| 719 | | /** |
|---|
| 720 | | * APIMethod: Function.bind |
|---|
| 721 | | * *Deprecated*. Bind a function to an object. |
|---|
| 722 | | * Method to easily create closures with 'this' altered. |
|---|
| 723 | | * |
|---|
| 724 | | * Parameters: |
|---|
| 725 | | * object - {Object} the this parameter |
|---|
| 726 | | * |
|---|
| 727 | | * Returns: |
|---|
| 728 | | * {Function} A closure with 'this' altered to the first |
|---|
| 729 | | * argument. |
|---|
| 730 | | */ |
|---|
| 731 | | Function.prototype.bind = function() { |
|---|
| 732 | | OpenLayers.Console.warn(OpenLayers.i18n("methodDeprecated", |
|---|
| 733 | | {'newMethod':'OpenLayers.String.bind'})); |
|---|
| 734 | | // new function takes the same arguments with this function up front |
|---|
| 735 | | Array.prototype.unshift.apply(arguments, [this]); |
|---|
| 736 | | return OpenLayers.Function.bind.apply(null, arguments); |
|---|
| 737 | | }; |
|---|
| 738 | | } |
|---|
| 739 | | |
|---|
| 740 | | if (!Function.prototype.bindAsEventListener) { |
|---|
| 741 | | /** |
|---|
| 742 | | * APIMethod: Function.bindAsEventListener |
|---|
| 743 | | * *Deprecated*. Bind a function to an object, and configure it to receive the |
|---|
| 744 | | * event object as first parameter when called. |
|---|
| 745 | | * |
|---|
| 746 | | * Parameters: |
|---|
| 747 | | * object - {Object} A reference to this. |
|---|
| 748 | | * |
|---|
| 749 | | * Returns: |
|---|
| 750 | | * {Function} |
|---|
| 751 | | */ |
|---|
| 752 | | Function.prototype.bindAsEventListener = function(object) { |
|---|
| 753 | | OpenLayers.Console.warn(OpenLayers.i18n("methodDeprecated", |
|---|
| 754 | | {'newMethod':'OpenLayers.String.bindAsEventListener'})); |
|---|
| 755 | | return OpenLayers.Function.bindAsEventListener(this, object); |
|---|
| 756 | | }; |
|---|
| 757 | | } |
|---|
| 758 | | |
|---|
| 759 | | /** |
|---|
| 760 | | * Namespace: OpenLayers.Array |
|---|
| 761 | | * Contains convenience functions for array manipulation. |
|---|
| 762 | | */ |
|---|
| 763 | | OpenLayers.Array = { |
|---|
| 764 | | |
|---|
| 765 | | /** |
|---|
| 766 | | * APIMethod: filter |
|---|
| 767 | | * Filter an array. Provides the functionality of the |
|---|
| 768 | | * Array.prototype.filter extension to the ECMA-262 standard. Where |
|---|
| 769 | | * available, Array.prototype.filter will be used. |
|---|
| 770 | | * |
|---|
| 771 | | * Based on well known example from http://developer.mozilla.org/en/docs/Core_JavaScript_1.5_Reference:Objects:Array:filter |
|---|
| 772 | | * |
|---|
| 773 | | * Parameters: |
|---|
| 774 | | * array - {Array} The array to be filtered. This array is not mutated. |
|---|
| 775 | | * Elements added to this array by the callback will not be visited. |
|---|
| 776 | | * callback - {Function} A function that is called for each element in |
|---|
| 777 | | * the array. If this function returns true, the element will be |
|---|
| 778 | | * included in the return. The function will be called with three |
|---|
| 779 | | * arguments: the element in the array, the index of that element, and |
|---|
| 780 | | * the array itself. If the optional caller parameter is specified |
|---|
| 781 | | * the callback will be called with this set to caller. |
|---|
| 782 | | * caller - {Object} Optional object to be set as this when the callback |
|---|
| 783 | | * is called. |
|---|
| 784 | | * |
|---|
| 785 | | * Returns: |
|---|
| 786 | | * {Array} An array of elements from the passed in array for which the |
|---|
| 787 | | * callback returns true. |
|---|
| 788 | | */ |
|---|
| 789 | | filter: function(array, callback, caller) { |
|---|
| 790 | | var selected = []; |
|---|
| 791 | | if (Array.prototype.filter) { |
|---|
| 792 | | selected = array.filter(callback, caller); |
|---|
| 793 | | } else { |
|---|
| 794 | | var len = array.length; |
|---|
| 795 | | if (typeof callback != "function") { |
|---|
| 796 | | throw new TypeError(); |
|---|
| 797 | | } |
|---|
| 798 | | for(var i=0; i<len; i++) { |
|---|
| 799 | | if (i in array) { |
|---|
| 800 | | var val = array[i]; |
|---|
| 801 | | if (callback.call(caller, val, i, array)) { |
|---|
| 802 | | selected.push(val); |
|---|
| 803 | | } |
|---|
| 804 | | } |
|---|
| 805 | | } |
|---|
| 806 | | } |
|---|
| 807 | | return selected; |
|---|
| 808 | | } |
|---|
| 809 | | |
|---|
| 810 | | }; |
|---|
| 811 | | /* ====================================================================== |
|---|
| 812 | | OpenLayers/BaseTypes/Class.js |
|---|
| 813 | | ====================================================================== */ |
|---|
| 814 | | |
|---|
| 815 | | /* Copyright (c) 2006-2008 MetaCarta, Inc., published under the Clear BSD |
|---|
| 816 | | * license. See http://svn.openlayers.org/trunk/openlayers/license.txt for the |
|---|
| 817 | | * full text of the license. */ |
|---|
| 818 | | |
|---|
| 819 | | /** |
|---|
| 820 | | * Constructor: OpenLayers.Class |
|---|
| 821 | | * Base class used to construct all other classes. Includes support for |
|---|
| 822 | | * multiple inheritance. |
|---|
| 823 | | * |
|---|
| 824 | | * This constructor is new in OpenLayers 2.5. At OpenLayers 3.0, the old |
|---|
| 825 | | * syntax for creating classes and dealing with inheritance |
|---|
| 826 | | * will be removed. |
|---|
| 827 | | * |
|---|
| 828 | | * To create a new OpenLayers-style class, use the following syntax: |
|---|
| 829 | | * > var MyClass = OpenLayers.Class(prototype); |
|---|
| 830 | | * |
|---|
| 831 | | * To create a new OpenLayers-style class with multiple inheritance, use the |
|---|
| 832 | | * following syntax: |
|---|
| 833 | | * > var MyClass = OpenLayers.Class(Class1, Class2, prototype); |
|---|
| 834 | | * |
|---|
| 835 | | */ |
|---|
| 836 | | OpenLayers.Class = function() { |
|---|
| 837 | | var Class = function() { |
|---|
| 838 | | /** |
|---|
| 839 | | * This following condition can be removed at 3.0 - this is only for |
|---|
| 840 | | * backwards compatibility while the Class.inherit method is still |
|---|
| 841 | | * in use. So at 3.0, the following three lines would be replaced with |
|---|
| 842 | | * simply: |
|---|
| 843 | | * this.initialize.apply(this, arguments); |
|---|
| 844 | | */ |
|---|
| 845 | | if (arguments && arguments[0] != OpenLayers.Class.isPrototype) { |
|---|
| 846 | | this.initialize.apply(this, arguments); |
|---|
| 847 | | } |
|---|
| 848 | | }; |
|---|
| 849 | | var extended = {}; |
|---|
| 850 | | var parent; |
|---|
| 851 | | for(var i=0; i<arguments.length; ++i) { |
|---|
| 852 | | if(typeof arguments[i] == "function") { |
|---|
| 853 | | // get the prototype of the superclass |
|---|
| 854 | | parent = arguments[i].prototype; |
|---|
| 855 | | } else { |
|---|
| 856 | | // in this case we're extending with the prototype |
|---|
| 857 | | parent = arguments[i]; |
|---|
| 858 | | } |
|---|
| 859 | | OpenLayers.Util.extend(extended, parent); |
|---|
| 860 | | } |
|---|
| 861 | | Class.prototype = extended; |
|---|
| 862 | | return Class; |
|---|
| 863 | | }; |
|---|
| 864 | | |
|---|
| 865 | | /** |
|---|
| 866 | | * Property: isPrototype |
|---|
| 867 | | * *Deprecated*. This is no longer needed and will be removed at 3.0. |
|---|
| 868 | | */ |
|---|
| 869 | | OpenLayers.Class.isPrototype = function () {}; |
|---|
| 870 | | |
|---|
| 871 | | /** |
|---|
| 872 | | * APIFunction: OpenLayers.create |
|---|
| 873 | | * *Deprecated*. Old method to create an OpenLayers style class. Use the |
|---|
| 874 | | * <OpenLayers.Class> constructor instead. |
|---|
| 875 | | * |
|---|
| 876 | | * Returns: |
|---|
| 877 | | * An OpenLayers class |
|---|
| 878 | | */ |
|---|
| 879 | | OpenLayers.Class.create = function() { |
|---|
| 880 | | return function() { |
|---|
| 881 | | if (arguments && arguments[0] != OpenLayers.Class.isPrototype) { |
|---|
| 882 | | this.initialize.apply(this, arguments); |
|---|
| 883 | | } |
|---|
| 884 | | }; |
|---|
| 885 | | }; |
|---|
| 886 | | |
|---|
| 887 | | |
|---|
| 888 | | /** |
|---|
| 889 | | * APIFunction: inherit |
|---|
| 890 | | * *Deprecated*. Old method to inherit from one or more OpenLayers style |
|---|
| 891 | | * classes. Use the <OpenLayers.Class> constructor instead. |
|---|
| 892 | | * |
|---|
| 893 | | * Parameters: |
|---|
| 894 | | * class - One or more classes can be provided as arguments |
|---|
| 895 | | * |
|---|
| 896 | | * Returns: |
|---|
| 897 | | * An object prototype |
|---|
| 898 | | */ |
|---|
| 899 | | OpenLayers.Class.inherit = function () { |
|---|
| 900 | | var superClass = arguments[0]; |
|---|
| 901 | | var proto = new superClass(OpenLayers.Class.isPrototype); |
|---|
| 902 | | for (var i = 1; i < arguments.length; i++) { |
|---|
| 903 | | if (typeof arguments[i] == "function") { |
|---|
| 904 | | var mixin = arguments[i]; |
|---|
| 905 | | arguments[i] = new mixin(OpenLayers.Class.isPrototype); |
|---|
| 906 | | } |
|---|
| 907 | | OpenLayers.Util.extend(proto, arguments[i]); |
|---|
| 908 | | } |
|---|
| 909 | | return proto; |
|---|
| 910 | | }; |
|---|
| 911 | | /* ====================================================================== |
|---|
| 912 | | OpenLayers/Util.js |
|---|
| 913 | | ====================================================================== */ |
|---|
| 914 | | |
|---|
| 915 | | /* Copyright (c) 2006-2008 MetaCarta, Inc., published under the Clear BSD |
|---|
| 916 | | * license. See http://svn.openlayers.org/trunk/openlayers/license.txt for the |
|---|
| 917 | | * full text of the license. */ |
|---|
| 918 | | |
|---|
| 919 | | |
|---|
| 920 | | /** |
|---|
| 921 | | * Namespace: Util |
|---|
| 922 | | */ |
|---|
| 923 | | OpenLayers.Util = {}; |
|---|
| 924 | | |
|---|
| 925 | | /** |
|---|
| 926 | | * Function: getElement |
|---|
| 927 | | * This is the old $() from prototype |
|---|
| 928 | | */ |
|---|
| 929 | | OpenLayers.Util.getElement = function() { |
|---|
| 930 | | var elements = []; |
|---|
| 931 | | |
|---|
| 932 | | for (var i = 0; i < arguments.length; i++) { |
|---|
| 933 | | var element = arguments[i]; |
|---|
| 934 | | if (typeof element == 'string') { |
|---|
| 935 | | element = document.getElementById(element); |
|---|
| 936 | | } |
|---|
| 937 | | if (arguments.length == 1) { |
|---|
| 938 | | return element; |
|---|
| 939 | | } |
|---|
| 940 | | elements.push(element); |
|---|
| 941 | | } |
|---|
| 942 | | return elements; |
|---|
| 943 | | }; |
|---|
| 944 | | |
|---|
| 945 | | /** |
|---|
| 946 | | * Maintain $() from prototype |
|---|
| 947 | | */ |
|---|
| 948 | | if ($ == null) { |
|---|
| 949 | | var $ = OpenLayers.Util.getElement; |
|---|
| 950 | | } |
|---|
| 951 | | |
|---|
| 952 | | /** |
|---|
| 953 | | * APIFunction: extend |
|---|
| 954 | | * Copy all properties of a source object to a destination object. Modifies |
|---|
| 955 | | * the passed in destination object. Any properties on the source object |
|---|
| 956 | | * that are set to undefined will not be (re)set on the destination object. |
|---|
| 957 | | * |
|---|
| 958 | | * Parameters: |
|---|
| 959 | | * destination - {Object} The object that will be modified |
|---|
| 960 | | * source - {Object} The object with properties to be set on the destination |
|---|
| 961 | | * |
|---|
| 962 | | * Returns: |
|---|
| 963 | | * {Object} The destination object. |
|---|
| 964 | | */ |
|---|
| 965 | | OpenLayers.Util.extend = function(destination, source) { |
|---|
| 966 | | destination = destination || {}; |
|---|
| 967 | | if(source) { |
|---|
| 968 | | for(var property in source) { |
|---|
| 969 | | var value = source[property]; |
|---|
| 970 | | if(value !== undefined) { |
|---|
| 971 | | destination[property] = value; |
|---|
| 972 | | } |
|---|
| 973 | | } |
|---|
| 974 | | |
|---|
| 975 | | /** |
|---|
| 976 | | * IE doesn't include the toString property when iterating over an object's |
|---|
| 977 | | * properties with the for(property in object) syntax. Explicitly check if |
|---|
| 978 | | * the source has its own toString property. |
|---|
| 979 | | */ |
|---|
| 980 | | |
|---|
| 981 | | /* |
|---|
| 982 | | * FF/Windows < 2.0.0.13 reports "Illegal operation on WrappedNative |
|---|
| 983 | | * prototype object" when calling hawOwnProperty if the source object |
|---|
| 984 | | * is an instance of window.Event. |
|---|
| 985 | | */ |
|---|
| 986 | | |
|---|
| 987 | | var sourceIsEvt = typeof window.Event == "function" |
|---|
| 988 | | && source instanceof window.Event; |
|---|
| 989 | | |
|---|
| 990 | | if(!sourceIsEvt |
|---|
| 991 | | && source.hasOwnProperty && source.hasOwnProperty('toString')) { |
|---|
| 992 | | destination.toString = source.toString; |
|---|
| 993 | | } |
|---|
| 994 | | } |
|---|
| 995 | | return destination; |
|---|
| 996 | | }; |
|---|
| 997 | | |
|---|
| 998 | | |
|---|
| 999 | | /** |
|---|
| 1000 | | * Function: removeItem |
|---|
| 1001 | | * Remove an object from an array. Iterates through the array |
|---|
| 1002 | | * to find the item, then removes it. |
|---|
| 1003 | | * |
|---|
| 1004 | | * Parameters: |
|---|
| 1005 | | * array - {Array} |
|---|
| 1006 | | * item - {Object} |
|---|
| 1007 | | * |
|---|
| 1008 | | * Return |
|---|
| 1009 | | * {Array} A reference to the array |
|---|
| 1010 | | */ |
|---|
| 1011 | | OpenLayers.Util.removeItem = function(array, item) { |
|---|
| 1012 | | for(var i = array.length - 1; i >= 0; i--) { |
|---|
| 1013 | | if(array[i] == item) { |
|---|
| 1014 | | array.splice(i,1); |
|---|
| 1015 | | //break;more than once?? |
|---|
| 1016 | | } |
|---|
| 1017 | | } |
|---|
| 1018 | | return array; |
|---|
| 1019 | | }; |
|---|
| 1020 | | |
|---|
| 1021 | | /** |
|---|
| 1022 | | * Function: clearArray |
|---|
| 1023 | | * *Deprecated*. This function will disappear in 3.0. |
|---|
| 1024 | | * Please use "array.length = 0" instead. |
|---|
| 1025 | | * |
|---|
| 1026 | | * Parameters: |
|---|
| 1027 | | * array - {Array} |
|---|
| 1028 | | */ |
|---|
| 1029 | | OpenLayers.Util.clearArray = function(array) { |
|---|
| 1030 | | OpenLayers.Console.warn( |
|---|
| 1031 | | OpenLayers.i18n( |
|---|
| 1032 | | "methodDeprecated", {'newMethod': 'array = []'} |
|---|
| 1033 | | ) |
|---|
| 1034 | | ); |
|---|
| 1035 | | array.length = 0; |
|---|
| 1036 | | }; |
|---|
| 1037 | | |
|---|
| 1038 | | /** |
|---|
| 1039 | | * Function: indexOf |
|---|
| 1040 | | * Seems to exist already in FF, but not in MOZ. |
|---|
| 1041 | | * |
|---|
| 1042 | | * Parameters: |
|---|
| 1043 | | * array - {Array} |
|---|
| 1044 | | * obj - {Object} |
|---|
| 1045 | | * |
|---|
| 1046 | | * Returns: |
|---|
| 1047 | | * {Integer} The index at, which the object was found in the array. |
|---|
| 1048 | | * If not found, returns -1. |
|---|
| 1049 | | */ |
|---|
| 1050 | | OpenLayers.Util.indexOf = function(array, obj) { |
|---|
| 1051 | | |
|---|
| 1052 | | for(var i=0; i < array.length; i++) { |
|---|
| 1053 | | if (array[i] == obj) { |
|---|
| 1054 | | return i; |
|---|
| 1055 | | } |
|---|
| 1056 | | } |
|---|
| 1057 | | return -1; |
|---|
| 1058 | | }; |
|---|
| 1059 | | |
|---|
| 1060 | | |
|---|
| 1061 | | |
|---|
| 1062 | | /** |
|---|
| 1063 | | * Function: modifyDOMElement |
|---|
| 1064 | | * |
|---|
| 1065 | | * Modifies many properties of a DOM element all at once. Passing in |
|---|
| 1066 | | * null to an individual parameter will avoid setting the attribute. |
|---|
| 1067 | | * |
|---|
| 1068 | | * Parameters: |
|---|
| 1069 | | * id - {String} The element id attribute to set. |
|---|
| 1070 | | * px - {<OpenLayers.Pixel>} The left and top style position. |
|---|
| 1071 | | * sz - {<OpenLayers.Size>} The width and height style attributes. |
|---|
| 1072 | | * position - {String} The position attribute. eg: absolute, |
|---|
| 1073 | | * relative, etc. |
|---|
| 1074 | | * border - {String} The style.border attribute. eg: |
|---|
| 1075 | | * solid black 2px |
|---|
| 1076 | | * overflow - {String} The style.overview attribute. |
|---|
| 1077 | | * opacity - {Float} Fractional value (0.0 - 1.0) |
|---|
| 1078 | | */ |
|---|
| 1079 | | OpenLayers.Util.modifyDOMElement = function(element, id, px, sz, position, |
|---|
| 1080 | | border, overflow, opacity) { |
|---|
| 1081 | | |
|---|
| 1082 | | if (id) { |
|---|
| 1083 | | element.id = id; |
|---|
| 1084 | | } |
|---|
| 1085 | | if (px) { |
|---|
| 1086 | | element.style.left = px.x + "px"; |
|---|
| 1087 | | element.style.top = px.y + "px"; |
|---|
| 1088 | | } |
|---|
| 1089 | | if (sz) { |
|---|
| 1090 | | element.style.width = sz.w + "px"; |
|---|
| 1091 | | element.style.height = sz.h + "px"; |
|---|
| 1092 | | } |
|---|
| 1093 | | if (position) { |
|---|
| 1094 | | element.style.position = position; |
|---|
| 1095 | | } |
|---|
| 1096 | | if (border) { |
|---|
| 1097 | | element.style.border = border; |
|---|
| 1098 | | } |
|---|
| 1099 | | if (overflow) { |
|---|
| 1100 | | element.style.overflow = overflow; |
|---|
| 1101 | | } |
|---|
| 1102 | | if (parseFloat(opacity) >= 0.0 && parseFloat(opacity) < 1.0) { |
|---|
| 1103 | | element.style.filter = 'alpha(opacity=' + (opacity * 100) + ')'; |
|---|
| 1104 | | element.style.opacity = opacity; |
|---|
| 1105 | | } else if (parseFloat(opacity) == 1.0) { |
|---|
| 1106 | | element.style.filter = ''; |
|---|
| 1107 | | element.style.opacity = ''; |
|---|
| 1108 | | } |
|---|
| 1109 | | }; |
|---|
| 1110 | | |
|---|
| 1111 | | /** |
|---|
| 1112 | | * Function: createDiv |
|---|
| 1113 | | * Creates a new div and optionally set some standard attributes. |
|---|
| 1114 | | * Null may be passed to each parameter if you do not wish to |
|---|
| 1115 | | * set a particular attribute. |
|---|
| 1116 | | * Note - zIndex is NOT set on the resulting div. |
|---|
| 1117 | | * |
|---|
| 1118 | | * Parameters: |
|---|
| 1119 | | * id - {String} An identifier for this element. If no id is |
|---|
| 1120 | | * passed an identifier will be created |
|---|
| 1121 | | * automatically. |
|---|
| 1122 | | * px - {<OpenLayers.Pixel>} The element left and top position. |
|---|
| 1123 | | * sz - {<OpenLayers.Size>} The element width and height. |
|---|
| 1124 | | * imgURL - {String} A url pointing to an image to use as a |
|---|
| 1125 | | * background image. |
|---|
| 1126 | | * position - {String} The style.position value. eg: absolute, |
|---|
| 1127 | | * relative etc. |
|---|
| 1128 | | * border - {String} The the style.border value. |
|---|
| 1129 | | * eg: 2px solid black |
|---|
| 1130 | | * overflow - {String} The style.overflow value. Eg. hidden |
|---|
| 1131 | | * opacity - {Float} Fractional value (0.0 - 1.0) |
|---|
| 1132 | | * |
|---|
| 1133 | | * Returns: |
|---|
| 1134 | | * {DOMElement} A DOM Div created with the specified attributes. |
|---|
| 1135 | | */ |
|---|
| 1136 | | OpenLayers.Util.createDiv = function(id, px, sz, imgURL, position, |
|---|
| 1137 | | border, overflow, opacity) { |
|---|
| 1138 | | |
|---|
| 1139 | | var dom = document.createElement('div'); |
|---|
| 1140 | | |
|---|
| 1141 | | if (imgURL) { |
|---|
| 1142 | | dom.style.backgroundImage = 'url(' + imgURL + ')'; |
|---|
| 1143 | | } |
|---|
| 1144 | | |
|---|
| 1145 | | //set generic properties |
|---|
| 1146 | | if (!id) { |
|---|
| 1147 | | id = OpenLayers.Util.createUniqueID("OpenLayersDiv"); |
|---|
| 1148 | | } |
|---|
| 1149 | | if (!position) { |
|---|
| 1150 | | position = "absolute"; |
|---|
| 1151 | | } |
|---|
| 1152 | | OpenLayers.Util.modifyDOMElement(dom, id, px, sz, position, |
|---|
| 1153 | | border, overflow, opacity); |
|---|
| 1154 | | |
|---|
| 1155 | | return dom; |
|---|
| 1156 | | }; |
|---|
| 1157 | | |
|---|
| 1158 | | /** |
|---|
| 1159 | | * Function: createImage |
|---|
| 1160 | | * Creates an img element with specific attribute values. |
|---|
| 1161 | | * |
|---|
| 1162 | | * Parameters: |
|---|
| 1163 | | * id - {String} The id field for the img. If none assigned one will be |
|---|
| 1164 | | * automatically generated. |
|---|
| 1165 | | * px - {<OpenLayers.Pixel>} The left and top positions. |
|---|
| 1166 | | * sz - {<OpenLayers.Size>} The style.width and style.height values. |
|---|
| 1167 | | * imgURL - {String} The url to use as the image source. |
|---|
| 1168 | | * position - {String} |
|---|