| 9 | | |
|---|
| 10 | | /** |
|---|
| 11 | | * Namespace: OpenLayers.Class |
|---|
| 12 | | * Contains functions to create OpenLayers style classes. |
|---|
| 13 | | */ |
|---|
| 14 | | OpenLayers.Class = { |
|---|
| 15 | | isPrototype: function () {}, // magic anonymous value |
|---|
| 16 | | |
|---|
| 17 | | /** |
|---|
| 18 | | * APIFunction: create |
|---|
| 19 | | * Create an OpenLayers style class |
|---|
| 20 | | * |
|---|
| 21 | | * Return: |
|---|
| 22 | | * An OpenLayers class |
|---|
| 23 | | */ |
|---|
| 24 | | create: function() { |
|---|
| 25 | | return function() { |
|---|
| 26 | | if (arguments && arguments[0] != OpenLayers.Class.isPrototype) |
|---|
| 27 | | this.initialize.apply(this, arguments); |
|---|
| 28 | | } |
|---|
| 29 | | }, |
|---|
| 30 | | |
|---|
| 31 | | /** |
|---|
| 32 | | * APIFunction: inherit |
|---|
| 33 | | * Inherit from one or more OpenLayers style classes |
|---|
| 34 | | * |
|---|
| 35 | | * Parameters: |
|---|
| 36 | | * class - One or more classes can be provided as arguments |
|---|
| 37 | | * |
|---|
| 38 | | * Return: |
|---|
| 39 | | * An object prototype |
|---|
| 40 | | */ |
|---|
| 41 | | inherit: function () { |
|---|
| 42 | | var superClass = arguments[0]; |
|---|
| 43 | | var proto = new superClass(OpenLayers.Class.isPrototype); |
|---|
| 44 | | for (var i = 1; i < arguments.length; i++) { |
|---|
| 45 | | if (typeof arguments[i] == "function") { |
|---|
| 46 | | var mixin = arguments[i]; |
|---|
| 47 | | arguments[i] = new mixin(OpenLayers.Class.isPrototype); |
|---|
| 48 | | } |
|---|
| 49 | | OpenLayers.Util.extend(proto, arguments[i]); |
|---|
| 50 | | |
|---|
| 51 | | // This is a hack for IE see |
|---|
| 52 | | // http://trac.openlayers.org/attachment/ticket/552 |
|---|
| 53 | | // |
|---|
| 54 | | // The problem is that ie doesnt recognize toString as a property |
|---|
| 55 | | // so the util.extend() doesnt copy it over. we do it manually. |
|---|
| 56 | | // |
|---|
| 57 | | // to be revisited in 3.0 |
|---|
| 58 | | // |
|---|
| 59 | | if((arguments[i].hasOwnProperty && arguments[i].hasOwnProperty('toString')) || |
|---|
| 60 | | (!arguments[i].hasOwnProperty && arguments[i].toString)) { |
|---|
| 61 | | proto.toString = arguments[i].toString; |
|---|
| 62 | | } |
|---|
| 63 | | } |
|---|
| 64 | | return proto; |
|---|
| 65 | | } |
|---|
| 66 | | }; |
|---|
| 67 | | |
|---|
| 68 | | /* |
|---|
| 69 | | OpenLayers.Class.inherit( OpenLayers.Layer.Grid, OpenLayers.Layer.HTTPRequest, { |
|---|
| 70 | | some stuff |
|---|
| 71 | | }); |
|---|
| 72 | | */ |
|---|
| 73 | | |
|---|
| 74 | | /********************* |
|---|
| 75 | | * * |
|---|
| 76 | | * PIXEL * |
|---|
| 77 | | * * |
|---|
| 78 | | *********************/ |
|---|
| 79 | | |
|---|
| 80 | | /** |
|---|
| 81 | | * Class: OpenLayers.Pixel |
|---|
| 82 | | * This class represents a screen coordinate, in x and y coordinates |
|---|
| 83 | | */ |
|---|
| 84 | | OpenLayers.Pixel = OpenLayers.Class.create(); |
|---|
| 85 | | OpenLayers.Pixel.prototype = { |
|---|
| 86 | | |
|---|
| 87 | | /** |
|---|
| 88 | | * APIProperty: x |
|---|
| 89 | | * {Number} The x coordinate |
|---|
| 90 | | */ |
|---|
| 91 | | x: 0.0, |
|---|
| 92 | | |
|---|
| 93 | | /** |
|---|
| 94 | | * APIProperty: y |
|---|
| 95 | | * {Number} The y coordinate |
|---|
| 96 | | */ |
|---|
| 97 | | y: 0.0, |
|---|
| 98 | | |
|---|
| 99 | | /** |
|---|
| 100 | | * Constructor: OpenLayers.Pixel |
|---|
| 101 | | * Create a new OpenLayers.Pixel instance |
|---|
| 102 | | * |
|---|
| 103 | | * Parameters: |
|---|
| 104 | | * x - {Number} The x coordinate |
|---|
| 105 | | * y - {Number} The y coordinate |
|---|
| 106 | | * |
|---|
| 107 | | * Return: |
|---|
| 108 | | * An instance of OpenLayers.Pixel |
|---|
| 109 | | */ |
|---|
| 110 | | initialize: function(x, y) { |
|---|
| 111 | | this.x = parseFloat(x); |
|---|
| 112 | | this.y = parseFloat(y); |
|---|
| 113 | | }, |
|---|
| 114 | | |
|---|
| 115 | | /** |
|---|
| 116 | | * Method: toString |
|---|
| 117 | | * Cast this object into a string |
|---|
| 118 | | * |
|---|
| 119 | | * Return: |
|---|
| 120 | | * {String} The string representation of Pixel. ex: "x=200.4,y=242.2" |
|---|
| 121 | | */ |
|---|
| 122 | | toString:function() { |
|---|
| 123 | | return ("x=" + this.x + ",y=" + this.y); |
|---|
| 124 | | }, |
|---|
| 125 | | |
|---|
| 126 | | /** |
|---|
| 127 | | * APIMethod: clone |
|---|
| 128 | | * Return a clone of this pixel object |
|---|
| 129 | | * |
|---|
| 130 | | * Return: |
|---|
| 131 | | * {<OpenLayers.Pixel>} A clone pixel |
|---|
| 132 | | */ |
|---|
| 133 | | clone:function() { |
|---|
| 134 | | return new OpenLayers.Pixel(this.x, this.y); |
|---|
| 135 | | }, |
|---|
| 136 | | |
|---|
| 137 | | /** |
|---|
| 138 | | * APIMethod: equals |
|---|
| 139 | | * Determine whether one pixel is equivalent to another |
|---|
| 140 | | * |
|---|
| 141 | | * Parameters: |
|---|
| 142 | | * px - {<OpenLayers.Pixel>} |
|---|
| 143 | | * |
|---|
| 144 | | * Return: |
|---|
| 145 | | * {Boolean} The point passed in as parameter is equal to this. Note that |
|---|
| 146 | | * if px passed in is null, returns false. |
|---|
| 147 | | */ |
|---|
| 148 | | equals:function(px) { |
|---|
| 149 | | var equals = false; |
|---|
| 150 | | if (px != null) { |
|---|
| 151 | | equals = ((this.x == px.x && this.y == px.y) || |
|---|
| 152 | | (isNaN(this.x) && isNaN(this.y) && isNaN(px.x) && isNaN(px.y))); |
|---|
| 153 | | } |
|---|
| 154 | | return equals; |
|---|
| 155 | | }, |
|---|
| 156 | | |
|---|
| 157 | | /** |
|---|
| 158 | | * APIMethod: add |
|---|
| 159 | | * |
|---|
| 160 | | * Parameters: |
|---|
| 161 | | * x - {Integer} |
|---|
| 162 | | * y - {Integer} |
|---|
| 163 | | * |
|---|
| 164 | | * Return: |
|---|
| 165 | | * {<OpenLayers.Pixel>} A new Pixel with this pixel's x&y augmented by the |
|---|
| 166 | | * values passed in. |
|---|
| 167 | | */ |
|---|
| 168 | | add:function(x, y) { |
|---|
| 169 | | return new OpenLayers.Pixel(this.x + x, this.y + y); |
|---|
| 170 | | }, |
|---|
| 171 | | |
|---|
| 172 | | /** |
|---|
| 173 | | * APIMethod: offset |
|---|
| 174 | | * |
|---|
| 175 | | * Parameters |
|---|
| 176 | | * px - {<OpenLayers.Pixel>} |
|---|
| 177 | | * |
|---|
| 178 | | * Return: |
|---|
| 179 | | * {<OpenLayers.Pixel>} A new Pixel with this pixel's x&y augmented by the |
|---|
| 180 | | * x&y values of the pixel passed in. |
|---|
| 181 | | */ |
|---|
| 182 | | offset:function(px) { |
|---|
| 183 | | var newPx = this.clone(); |
|---|
| 184 | | if (px) { |
|---|
| 185 | | newPx = this.add(px.x, px.y); |
|---|
| 186 | | } |
|---|
| 187 | | return newPx; |
|---|
| 188 | | }, |
|---|
| 189 | | |
|---|
| 190 | | /** @final @type str */ |
|---|
| 191 | | CLASS_NAME: "OpenLayers.Pixel" |
|---|
| 192 | | }; |
|---|
| 193 | | |
|---|
| 194 | | |
|---|
| 195 | | /********************* |
|---|
| 196 | | * * |
|---|
| 197 | | * SIZE * |
|---|
| 198 | | * * |
|---|
| 199 | | *********************/ |
|---|
| 200 | | |
|---|
| 201 | | |
|---|
| 202 | | /** |
|---|
| 203 | | * Class: OpenLayers.Size |
|---|
| 204 | | * Instances of this class represent a width/height pair |
|---|
| 205 | | */ |
|---|
| 206 | | OpenLayers.Size = OpenLayers.Class.create(); |
|---|
| 207 | | OpenLayers.Size.prototype = { |
|---|
| 208 | | |
|---|
| 209 | | /** |
|---|
| 210 | | * APIProperty: w |
|---|
| 211 | | * {Number} width |
|---|
| 212 | | */ |
|---|
| 213 | | w: 0.0, |
|---|
| 214 | | |
|---|
| 215 | | /** |
|---|
| 216 | | * APIProperty: h |
|---|
| 217 | | * {Number} height |
|---|
| 218 | | */ |
|---|
| 219 | | h: 0.0, |
|---|
| 220 | | |
|---|
| 221 | | |
|---|
| 222 | | /** |
|---|
| 223 | | * Constructor: OpenLayers.Size |
|---|
| 224 | | * Create an instance of OpenLayers.Size |
|---|
| 225 | | * |
|---|
| 226 | | * Parameters: |
|---|
| 227 | | * w - {Number} width |
|---|
| 228 | | * h - {Number} height |
|---|
| 229 | | */ |
|---|
| 230 | | initialize: function(w, h) { |
|---|
| 231 | | this.w = parseFloat(w); |
|---|
| 232 | | this.h = parseFloat(h); |
|---|
| 233 | | }, |
|---|
| 234 | | |
|---|
| 235 | | /** |
|---|
| 236 | | * Method: toString |
|---|
| 237 | | * Return the string representation of a size object |
|---|
| 238 | | * |
|---|
| 239 | | * Return: |
|---|
| 240 | | * {String} The string representation of OpenLayers.Size object. |
|---|
| 241 | | * (ex. <i>"w=55,h=66"</i>) |
|---|
| 242 | | */ |
|---|
| 243 | | toString:function() { |
|---|
| 244 | | return ("w=" + this.w + ",h=" + this.h); |
|---|
| 245 | | }, |
|---|
| 246 | | |
|---|
| 247 | | /** |
|---|
| 248 | | * APIMethod: clone |
|---|
| 249 | | * Create a clone of this size object |
|---|
| 250 | | * |
|---|
| 251 | | * Return: |
|---|
| 252 | | * {<OpenLayers.Size>} A new OpenLayers.Size object with the same w and h |
|---|
| 253 | | * values |
|---|
| 254 | | */ |
|---|
| 255 | | clone:function() { |
|---|
| 256 | | return new OpenLayers.Size(this.w, this.h); |
|---|
| 257 | | }, |
|---|
| 258 | | |
|---|
| 259 | | /** |
|---|
| 260 | | * |
|---|
| 261 | | * APIMethod: equals |
|---|
| 262 | | * Determine where this size is equal to another |
|---|
| 263 | | * |
|---|
| 264 | | * Parameters: |
|---|
| 265 | | * sz - {<OpenLayers.Size>} |
|---|
| 266 | | * |
|---|
| 267 | | * Return: |
|---|
| 268 | | * {Boolean} The passed in size has the same h and w properties as this one. |
|---|
| 269 | | * Note that if sz passed in is null, returns false. |
|---|
| 270 | | * |
|---|
| 271 | | */ |
|---|
| 272 | | equals:function(sz) { |
|---|
| 273 | | var equals = false; |
|---|
| 274 | | if (sz != null) { |
|---|
| 275 | | equals = ((this.w == sz.w && this.h == sz.h) || |
|---|
| 276 | | (isNaN(this.w) && isNaN(this.h) && isNaN(sz.w) && isNaN(sz.h))); |
|---|
| 277 | | } |
|---|
| 278 | | return equals; |
|---|
| 279 | | }, |
|---|
| 280 | | |
|---|
| 281 | | /** @final @type String */ |
|---|
| 282 | | CLASS_NAME: "OpenLayers.Size" |
|---|
| 283 | | }; |
|---|
| 284 | | |
|---|
| 285 | | /********************* |
|---|
| 286 | | * * |
|---|
| 287 | | * LONLAT * |
|---|
| 288 | | * * |
|---|
| 289 | | *********************/ |
|---|
| 290 | | |
|---|
| 291 | | |
|---|
| 292 | | /** |
|---|
| 293 | | * Class: OpenLayers.LonLat |
|---|
| 294 | | * This class represents a longitude and latitude pair |
|---|
| 295 | | */ |
|---|
| 296 | | OpenLayers.LonLat = OpenLayers.Class.create(); |
|---|
| 297 | | OpenLayers.LonLat.prototype = { |
|---|
| 298 | | |
|---|
| 299 | | /** |
|---|
| 300 | | * APIProperty: lon |
|---|
| 301 | | * {Float} |
|---|
| 302 | | */ |
|---|
| 303 | | lon: 0.0, |
|---|
| 304 | | |
|---|
| 305 | | /** |
|---|
| 306 | | * APIProperty: lat |
|---|
| 307 | | * {Float} |
|---|
| 308 | | */ |
|---|
| 309 | | lat: 0.0, |
|---|
| 310 | | |
|---|
| 311 | | /** |
|---|
| 312 | | * Constructor: OpenLayers.LonLat |
|---|
| 313 | | * Create a new OpenLayers.LonLat instance |
|---|
| 314 | | * |
|---|
| 315 | | * Parameters: |
|---|
| 316 | | * lon - {Number} The lon coordinate |
|---|
| 317 | | * lat - {Number} The lat coordinate |
|---|
| 318 | | */ |
|---|
| 319 | | initialize: function(lon, lat) { |
|---|
| 320 | | this.lon = parseFloat(lon); |
|---|
| 321 | | this.lat = parseFloat(lat); |
|---|
| 322 | | }, |
|---|
| 323 | | |
|---|
| 324 | | /** |
|---|
| 325 | | * Method: toString |
|---|
| 326 | | * Return a readable string version of the lonlat |
|---|
| 327 | | * |
|---|
| 328 | | * Return: |
|---|
| 329 | | * {String} String representation of OpenLayers.LonLat object. |
|---|
| 330 | | * (ex. <i>"lon=5,lat=42"</i>) |
|---|
| 331 | | */ |
|---|
| 332 | | toString:function() { |
|---|
| 333 | | return ("lon=" + this.lon + ",lat=" + this.lat); |
|---|
| 334 | | }, |
|---|
| 335 | | |
|---|
| 336 | | /** |
|---|
| 337 | | * APIMethod: toShortString |
|---|
| 338 | | * |
|---|
| 339 | | * Return: |
|---|
| 340 | | * {String} Shortened String representation of OpenLayers.LonLat object. |
|---|
| 341 | | * (ex. <i>"5, 42"</i>) |
|---|
| 342 | | */ |
|---|
| 343 | | toShortString:function() { |
|---|
| 344 | | return (this.lon + ", " + this.lat); |
|---|
| 345 | | }, |
|---|
| 346 | | |
|---|
| 347 | | /** |
|---|
| 348 | | * APIMethod: clone |
|---|
| 349 | | * |
|---|
| 350 | | * Return: |
|---|
| 351 | | * {<OpenLayers.LonLat>} New OpenLayers.LonLat object with the same lon |
|---|
| 352 | | * and lat values |
|---|
| 353 | | */ |
|---|
| 354 | | clone:function() { |
|---|
| 355 | | return new OpenLayers.LonLat(this.lon, this.lat); |
|---|
| 356 | | }, |
|---|
| 357 | | |
|---|
| 358 | | /** |
|---|
| 359 | | * APIMethod: add |
|---|
| 360 | | * |
|---|
| 361 | | * Parameters: |
|---|
| 362 | | * lon - {Float} |
|---|
| 363 | | * lat - {Float} |
|---|
| 364 | | * |
|---|
| 365 | | * Return: |
|---|
| 366 | | * {<OpenLayers.LonLat>} A new OpenLayers.LonLat object with the lon and |
|---|
| 367 | | * lat passed-in added to this's. |
|---|
| 368 | | */ |
|---|
| 369 | | add:function(lon, lat) { |
|---|
| 370 | | return new OpenLayers.LonLat(this.lon + lon, this.lat + lat); |
|---|
| 371 | | }, |
|---|
| 372 | | |
|---|
| 373 | | /** |
|---|
| 374 | | * APIMethod: equals |
|---|
| 375 | | * |
|---|
| 376 | | * Parameters: |
|---|
| 377 | | * ll - {<OpenLayers.LonLat>} |
|---|
| 378 | | * |
|---|
| 379 | | * Return: |
|---|
| 380 | | * {Boolean} Boolean value indicating whether the passed-in |
|---|
| 381 | | * <OpenLayers.LonLat> object has the same lon and lat |
|---|
| 382 | | * components as this. |
|---|
| 383 | | * Note: if ll passed in is null, returns false |
|---|
| 384 | | */ |
|---|
| 385 | | equals:function(ll) { |
|---|
| 386 | | var equals = false; |
|---|
| 387 | | if (ll != null) { |
|---|
| 388 | | equals = ((this.lon == ll.lon && this.lat == ll.lat) || |
|---|
| 389 | | (isNaN(this.lon) && isNaN(this.lat) && isNaN(ll.lon) && isNaN(ll.lat))); |
|---|
| 390 | | } |
|---|
| 391 | | return equals; |
|---|
| 392 | | }, |
|---|
| 393 | | |
|---|
| 394 | | /** |
|---|
| 395 | | * APIMethod: wrapDateLine |
|---|
| 396 | | * |
|---|
| 397 | | * Parameters: |
|---|
| 398 | | * maxExtent - {<OpenLayers.Bounds>} |
|---|
| 399 | | * |
|---|
| 400 | | * Return: |
|---|
| 401 | | * {<OpenLayers.LonLat>} A copy of this lonlat, but wrapped around the |
|---|
| 402 | | * "dateline" (as specified by the borders of |
|---|
| 403 | | * maxExtent) |
|---|
| 404 | | */ |
|---|
| 405 | | wrapDateLine: function(maxExtent) { |
|---|
| 406 | | |
|---|
| 407 | | var newLonLat = this.clone(); |
|---|
| 408 | | |
|---|
| 409 | | if (maxExtent) { |
|---|
| 410 | | //shift right? |
|---|
| 411 | | while (newLonLat.lon < maxExtent.left) { |
|---|
| 412 | | newLonLat.lon += maxExtent.getWidth(); |
|---|
| 413 | | } |
|---|
| 414 | | |
|---|
| 415 | | //shift left? |
|---|
| 416 | | while (newLonLat.lon > maxExtent.right) { |
|---|
| 417 | | newLonLat.lon -= maxExtent.getWidth(); |
|---|
| 418 | | } |
|---|
| 419 | | } |
|---|
| 420 | | |
|---|
| 421 | | return newLonLat; |
|---|
| 422 | | }, |
|---|
| 423 | | |
|---|
| 424 | | /** @final @type String */ |
|---|
| 425 | | CLASS_NAME: "OpenLayers.LonLat" |
|---|
| 426 | | }; |
|---|
| 427 | | |
|---|
| 428 | | /** |
|---|
| 429 | | * Function: fromString |
|---|
| 430 | | * Alternative constructor that builds a new <OpenLayers.LonLat> from a |
|---|
| 431 | | * parameter string |
|---|
| 432 | | * |
|---|
| 433 | | * Parameters: |
|---|
| 434 | | * str - {String} Comma-separated Lon,Lat coordinate string. |
|---|
| 435 | | * (ex. <i>"5,40"</i>) |
|---|
| 436 | | * |
|---|
| 437 | | * Return: |
|---|
| 438 | | * {<OpenLayers.LonLat>} New <OpenLayers.LonLat> object built from the |
|---|
| 439 | | * passed-in String. |
|---|
| 440 | | */ |
|---|
| 441 | | OpenLayers.LonLat.fromString = function(str) { |
|---|
| 442 | | var pair = str.split(","); |
|---|
| 443 | | return new OpenLayers.LonLat(parseFloat(pair[0]), |
|---|
| 444 | | parseFloat(pair[1])); |
|---|
| 445 | | }; |
|---|
| 446 | | |
|---|
| 447 | | |
|---|
| 448 | | |
|---|
| 449 | | /********************* |
|---|
| 450 | | * * |
|---|
| 451 | | * BOUNDS * |
|---|
| 452 | | * * |
|---|
| 453 | | *********************/ |
|---|
| 454 | | |
|---|
| 455 | | |
|---|
| 456 | | |
|---|
| 457 | | |
|---|
| 458 | | /** |
|---|
| 459 | | * Class: OpenLayers.Bounds |
|---|
| 460 | | * Instances of this class represent bounding boxes. Data stored as left, |
|---|
| 461 | | * bottom, right, top floats |
|---|
| 462 | | */ |
|---|
| 463 | | OpenLayers.Bounds = OpenLayers.Class.create(); |
|---|
| 464 | | OpenLayers.Bounds.prototype = { |
|---|
| 465 | | |
|---|
| 466 | | /** |
|---|
| 467 | | * Property: left |
|---|
| 468 | | * {Number} |
|---|
| 469 | | */ |
|---|
| 470 | | left: 0.0, |
|---|
| 471 | | |
|---|
| 472 | | /** |
|---|
| 473 | | * Property: bottom |
|---|
| 474 | | * {Number} |
|---|
| 475 | | */ |
|---|
| 476 | | bottom: 0.0, |
|---|
| 477 | | |
|---|
| 478 | | /** |
|---|
| 479 | | * Property: right |
|---|
| 480 | | * {Number} |
|---|
| 481 | | */ |
|---|
| 482 | | right: 0.0, |
|---|
| 483 | | |
|---|
| 484 | | /** |
|---|
| 485 | | * Property: top |
|---|
| 486 | | * {Number} |
|---|
| 487 | | */ |
|---|
| 488 | | top: 0.0, |
|---|
| 489 | | |
|---|
| 490 | | /** |
|---|
| 491 | | * Constructor: OpenLayers.Bounds |
|---|
| 492 | | * Construct a new bounds object. |
|---|
| 493 | | * |
|---|
| 494 | | * Parameters: |
|---|
| 495 | | * left - {Number} The left bounds of the box. Note that for width |
|---|
| 496 | | * calculations, this is assumed to be less than the right value. |
|---|
| 497 | | * bottom - {Number} The bottom bounds of the box. Note that for height |
|---|
| 498 | | * calculations, this is assumed to be more than the top value. |
|---|
| 499 | | * right - {Number} The right bounds. |
|---|
| 500 | | * top - {Number} The top bounds. |
|---|
| 501 | | */ |
|---|
| 502 | | initialize: function(left, bottom, right, top) { |
|---|
| 503 | | this.left = parseFloat(left); |
|---|
| 504 | | this.bottom = parseFloat(bottom); |
|---|
| 505 | | this.right = parseFloat(right); |
|---|
| 506 | | this.top = parseFloat(top); |
|---|
| 507 | | }, |
|---|
| 508 | | |
|---|
| 509 | | /** |
|---|
| 510 | | * Method: clone |
|---|
| 511 | | * Create a cloned instance of this bounds. |
|---|
| 512 | | * |
|---|
| 513 | | * Return: |
|---|
| 514 | | * {<OpenLayers.Bounds>} A fresh copy of the bounds |
|---|
| 515 | | */ |
|---|
| 516 | | clone:function() { |
|---|
| 517 | | return new OpenLayers.Bounds(this.left, this.bottom, |
|---|
| 518 | | this.right, this.top); |
|---|
| 519 | | }, |
|---|
| 520 | | |
|---|
| 521 | | /** |
|---|
| 522 | | * Method: equals |
|---|
| 523 | | * Test a two bounds for equivalence |
|---|
| 524 | | * |
|---|
| 525 | | * Parameters: |
|---|
| 526 | | * bounds - {<OpenLayers.Bounds>} |
|---|
| 527 | | * |
|---|
| 528 | | * Return: |
|---|
| 529 | | * {Boolean} The passed-in OpenLayers.Bounds object has the same left, |
|---|
| 530 | | * right, top, bottom components as this. Note that if bounds |
|---|
| 531 | | * passed in is null, returns false. |
|---|
| 532 | | */ |
|---|
| 533 | | equals:function(bounds) { |
|---|
| 534 | | var equals = false; |
|---|
| 535 | | if (bounds != null) { |
|---|
| 536 | | equals = ((this.left == bounds.left) && |
|---|
| 537 | | (this.right == bounds.right) && |
|---|
| 538 | | (this.top == bounds.top) && |
|---|
| 539 | | (this.bottom == bounds.bottom)); |
|---|
| 540 | | } |
|---|
| 541 | | return equals; |
|---|
| 542 | | }, |
|---|
| 543 | | |
|---|
| 544 | | /** |
|---|
| 545 | | * APIMethod: toString |
|---|
| 546 | | * |
|---|
| 547 | | * Return: |
|---|
| 548 | | * {String} String representation of OpenLayers.Bounds object. |
|---|
| 549 | | * (ex.<i>"left-bottom=(5,42) right-top=(10,45)"</i>) |
|---|
| 550 | | */ |
|---|
| 551 | | toString:function() { |
|---|
| 552 | | return ( "left-bottom=(" + this.left + "," + this.bottom + ")" |
|---|
| 553 | | + " right-top=(" + this.right + "," + this.top + ")" ); |
|---|
| 554 | | }, |
|---|
| 555 | | |
|---|
| 556 | | /** |
|---|
| 557 | | * APIMethod: toBBOX |
|---|
| 558 | | * |
|---|
| 559 | | * Parameters: |
|---|
| 560 | | * decimal - {Integer} How many significant digits in the bbox coords? |
|---|
| 561 | | * Default is 6 |
|---|
| 562 | | * |
|---|
| 563 | | * Return: |
|---|
| 564 | | * {String} Simple String representation of OpenLayers.Bounds object. |
|---|
| 565 | | * (ex. <i>"5,42,10,45"</i>) |
|---|
| 566 | | */ |
|---|
| 567 | | toBBOX:function(decimal) { |
|---|
| 568 | | if (decimal== null) { |
|---|
| 569 | | decimal = 6; |
|---|
| 570 | | } |
|---|
| 571 | | var mult = Math.pow(10, decimal); |
|---|
| 572 | | var bbox = Math.round(this.left * mult) / mult + "," + |
|---|
| 573 | | Math.round(this.bottom * mult) / mult + "," + |
|---|
| 574 | | Math.round(this.right * mult) / mult + "," + |
|---|
| 575 | | Math.round(this.top * mult) / mult; |
|---|
| 576 | | |
|---|
| 577 | | return bbox; |
|---|
| 578 | | }, |
|---|
| 579 | | |
|---|
| 580 | | /** |
|---|
| 581 | | * APIMethod: getWidth |
|---|
| 582 | | * |
|---|
| 583 | | * Return: |
|---|
| 584 | | * {Float} The width of the bounds |
|---|
| 585 | | */ |
|---|
| 586 | | getWidth:function() { |
|---|
| 587 | | return (this.right - this.left); |
|---|
| 588 | | }, |
|---|
| 589 | | |
|---|
| 590 | | /** |
|---|
| 591 | | * APIMethod: getHeight |
|---|
| 592 | | * |
|---|
| 593 | | * Return: |
|---|
| 594 | | * {Float} The height of the bounds |
|---|
| 595 | | */ |
|---|
| 596 | | getHeight:function() { |
|---|
| 597 | | return (this.top - this.bottom); |
|---|
| 598 | | }, |
|---|
| 599 | | |
|---|
| 600 | | /** |
|---|
| 601 | | * APIMethod: getSize |
|---|
| 602 | | * |
|---|
| 603 | | * Return: |
|---|
| 604 | | * {<OpenLayers.Size>} An <OpenLayers.Size> which represents the size of the box |
|---|
| 605 | | */ |
|---|
| 606 | | getSize:function() { |
|---|
| 607 | | return new OpenLayers.Size(this.getWidth(), this.getHeight()); |
|---|
| 608 | | }, |
|---|
| 609 | | |
|---|
| 610 | | /** |
|---|
| 611 | | * APIMethod: getCenterPixel |
|---|
| 612 | | * |
|---|
| 613 | | * Return: |
|---|
| 614 | | * {<OpenLayers.Pixel>} An <OpenLayers.Pixel> which represents the center |
|---|
| 615 | | * of the bounds |
|---|
| 616 | | */ |
|---|
| 617 | | getCenterPixel:function() { |
|---|
| 618 | | return new OpenLayers.Pixel( (this.left + this.right) / 2, |
|---|
| 619 | | (this.bottom + this.top) / 2); |
|---|
| 620 | | }, |
|---|
| 621 | | |
|---|
| 622 | | /** |
|---|
| 623 | | * APIMethod: getCenterLonLat |
|---|
| 624 | | * |
|---|
| 625 | | * Return: |
|---|
| 626 | | * {<OpenLayers.LonLat>} An <OpenLayers.LonLat> which represents the center |
|---|
| 627 | | * of the bounds |
|---|
| 628 | | */ |
|---|
| 629 | | getCenterLonLat:function() { |
|---|
| 630 | | return new OpenLayers.LonLat( (this.left + this.right) / 2, |
|---|
| 631 | | (this.bottom + this.top) / 2); |
|---|
| 632 | | }, |
|---|
| 633 | | |
|---|
| 634 | | /** |
|---|
| 635 | | * APIMethod: add |
|---|
| 636 | | * |
|---|
| 637 | | * Parameters: |
|---|
| 638 | | * x - {Float} |
|---|
| 639 | | * y - {Float} |
|---|
| 640 | | * |
|---|
| 641 | | * Return: |
|---|
| 642 | | * {<OpenLayers.Bounds>} A new <OpenLayers.Bounds> whose coordinates are |
|---|
| 643 | | * the same as this, but shifted by the passed-in |
|---|
| 644 | | * x and y values |
|---|
| 645 | | */ |
|---|
| 646 | | add:function(x, y) { |
|---|
| 647 | | return new OpenLayers.Bounds(this.left + x, this.bottom + y, |
|---|
| 648 | | this.right + x, this.top + y); |
|---|
| 649 | | }, |
|---|
| 650 | | |
|---|
| 651 | | /** |
|---|
| 652 | | * APIMethod: extend |
|---|
| 653 | | * Extend the bounds to include the point, lonlat, or bounds specified. |
|---|
| 654 | | * Note: This function assumes that left<right and bottom<top. |
|---|
| 655 | | * |
|---|
| 656 | | * |
|---|
| 657 | | * Parameters: |
|---|
| 658 | | * object - {Object} Can be LonLat, Point, or Bounds |
|---|
| 659 | | */ |
|---|
| 660 | | extend:function(object) { |
|---|
| 661 | | var bounds = null; |
|---|
| 662 | | if (object) { |
|---|
| 663 | | switch(object.CLASS_NAME) { |
|---|
| 664 | | case "OpenLayers.LonLat": |
|---|
| 665 | | bounds = new OpenLayers.Bounds(object.lon, object.lat, |
|---|
| 666 | | object.lon, object.lat); |
|---|
| 667 | | break; |
|---|
| 668 | | case "OpenLayers.Geometry.Point": |
|---|
| 669 | | bounds = new OpenLayers.Bounds(object.x, object.y, |
|---|
| 670 | | object.x, object.y); |
|---|
| 671 | | break; |
|---|
| 672 | | |
|---|
| 673 | | case "OpenLayers.Bounds": |
|---|
| 674 | | bounds = object; |
|---|
| 675 | | break; |
|---|
| 676 | | } |
|---|
| 677 | | |
|---|
| 678 | | if (bounds) { |
|---|
| 679 | | this.left = (bounds.left < this.left) ? bounds.left |
|---|
| 680 | | : this.left; |
|---|
| 681 | | this.bottom = (bounds.bottom < this.bottom) ? bounds.bottom |
|---|
| 682 | | : this.bottom; |
|---|
| 683 | | this.right = (bounds.right > this.right) ? bounds.right |
|---|
| 684 | | : this.right; |
|---|
| 685 | | this.top = (bounds.top > this.top) ? bounds.top |
|---|
| 686 | | : this.top; |
|---|
| 687 | | } |
|---|
| 688 | | } |
|---|
| 689 | | }, |
|---|
| 690 | | |
|---|
| 691 | | /** |
|---|
| 692 | | * APIMethod: containsLonLat |
|---|
| 693 | | * |
|---|
| 694 | | * Parameters: |
|---|
| 695 | | * ll - {<OpenLayers.LonLat>} |
|---|
| 696 | | * inclusive - {Boolean} Whether or not to include the border. |
|---|
| 697 | | * Default is true. |
|---|
| 698 | | * |
|---|
| 699 | | * Return: |
|---|
| 700 | | * {Boolean} Whether or not the passed-in lonlat is within this bounds. |
|---|
| 701 | | */ |
|---|
| 702 | | containsLonLat:function(ll, inclusive) { |
|---|
| 703 | | return this.contains(ll.lon, ll.lat, inclusive); |
|---|
| 704 | | }, |
|---|
| 705 | | |
|---|
| 706 | | /** |
|---|
| 707 | | * APIMethod: containsPixel |
|---|
| 708 | | * |
|---|
| 709 | | * Parameters: |
|---|
| 710 | | * px - {<OpenLayers.Pixel>} |
|---|
| 711 | | * inclusive - {Boolean} Whether or not to include the border. |
|---|
| 712 | | * Default is true. |
|---|
| 713 | | * |
|---|
| 714 | | * Return: |
|---|
| 715 | | * {Boolean} Whether or not the passed-in pixel is within this bounds. |
|---|
| 716 | | */ |
|---|
| 717 | | containsPixel:function(px, inclusive) { |
|---|
| 718 | | return this.contains(px.x, px.y, inclusive); |
|---|
| 719 | | }, |
|---|
| 720 | | |
|---|
| 721 | | /** |
|---|
| 722 | | * APIMethod: contains |
|---|
| 723 | | * |
|---|
| 724 | | * Parameters: |
|---|
| 725 | | * x - {Float} |
|---|
| 726 | | * y - {Float} |
|---|
| 727 | | * inclusive - {Boolean} Whether or not to include the border. |
|---|
| 728 | | * Default is true. |
|---|
| 729 | | * |
|---|
| 730 | | * Return: |
|---|
| 731 | | * {Boolean} Whether or not the passed-in coordinates are within this |
|---|
| 732 | | * bounds. |
|---|
| 733 | | */ |
|---|
| 734 | | contains:function(x, y, inclusive) { |
|---|
| 735 | | |
|---|
| 736 | | //set default |
|---|
| 737 | | if (inclusive == null) { |
|---|
| 738 | | inclusive = true; |
|---|
| 739 | | } |
|---|
| 740 | | |
|---|
| 741 | | var contains = false; |
|---|
| 742 | | if (inclusive) { |
|---|
| 743 | | contains = ((x >= this.left) && (x <= this.right) && |
|---|
| 744 | | (y >= this.bottom) && (y <= this.top)); |
|---|
| 745 | | } else { |
|---|
| 746 | | contains = ((x > this.left) && (x < this.right) && |
|---|
| 747 | | (y > this.bottom) && (y < this.top)); |
|---|
| 748 | | } |
|---|
| 749 | | return contains; |
|---|
| 750 | | }, |
|---|
| 751 | | |
|---|
| 752 | | /** |
|---|
| 753 | | * APIMethod: intersectsBounds |
|---|
| 754 | | * |
|---|
| 755 | | * Parameters: |
|---|
| 756 | | * bounds - {<OpenLayers.Bounds>} |
|---|
| 757 | | * inclusive - {<Boolean>} Whether or not to include the border. |
|---|
| 758 | | * Default is true. |
|---|
| 759 | | * |
|---|
| 760 | | * Return: |
|---|
| 761 | | * {Boolean} Whether or not the passed-in OpenLayers.Bounds object |
|---|
| 762 | | * intersects this bounds. Simple math just check if either |
|---|
| 763 | | * contains the other, allowing for partial. |
|---|
| 764 | | */ |
|---|
| 765 | | intersectsBounds:function(bounds, inclusive) { |
|---|
| 766 | | |
|---|
| 767 | | if (inclusive == null) { |
|---|
| 768 | | inclusive = true; |
|---|
| 769 | | } |
|---|
| 770 | | var inBottom = (bounds.bottom == this.bottom && bounds.top == this.top) ? |
|---|
| 771 | | true : (((bounds.bottom > this.bottom) && (bounds.bottom < this.top)) || |
|---|
| 772 | | ((this.bottom > bounds.bottom) && (this.bottom < bounds.top))); |
|---|
| 773 | | var inTop = (bounds.bottom == this.bottom && bounds.top == this.top) ? |
|---|
| 774 | | true : (((bounds.top > this.bottom) && (bounds.top < this.top)) || |
|---|
| 775 | | ((this.top > bounds.bottom) && (this.top < bounds.top))); |
|---|
| 776 | | var inRight = (bounds.right == this.right && bounds.left == this.left) ? |
|---|
| 777 | | true : (((bounds.right > this.left) && (bounds.right < this.right)) || |
|---|
| 778 | | ((this.right > bounds.left) && (this.right < bounds.right))); |
|---|
| 779 | | var inLeft = (bounds.right == this.right && bounds.left == this.left) ? |
|---|
| 780 | | true : (((bounds.left > this.left) && (bounds.left < this.right)) || |
|---|
| 781 | | ((this.left > bounds.left) && (this.left < bounds.right))); |
|---|
| 782 | | |
|---|
| 783 | | return (this.containsBounds(bounds, true, inclusive) || |
|---|
| 784 | | bounds.containsBounds(this, true, inclusive) || |
|---|
| 785 | | ((inTop || inBottom ) && (inLeft || inRight ))); |
|---|
| 786 | | }, |
|---|
| 787 | | |
|---|
| 788 | | /** |
|---|
| 789 | | * APIMethod: containsBounds |
|---|
| 790 | | * |
|---|
| 791 | | * bounds - {<OpenLayers.Bounds>} |
|---|
| 792 | | * partial - {<Boolean>} If true, only part of passed-in |
|---|
| 793 | | * <OpenLayers.Bounds> needs be within this bounds. |
|---|
| 794 | | * If false, the entire passed-in bounds must be |
|---|
| 795 | | * within. Default is false |
|---|
| 796 | | * inclusive - {<Boolean>} Whether or not to include the border. |
|---|
| 797 | | * Default is true. |
|---|
| 798 | | * |
|---|
| 799 | | * Return: |
|---|
| 800 | | * {Boolean} Whether or not the passed-in OpenLayers.Bounds object is |
|---|
| 801 | | * contained within this bounds. |
|---|
| 802 | | */ |
|---|
| 803 | | containsBounds:function(bounds, partial, inclusive) { |
|---|
| 804 | | |
|---|
| 805 | | //set defaults |
|---|
| 806 | | if (partial == null) { |
|---|
| 807 | | partial = false; |
|---|
| 808 | | } |
|---|
| 809 | | if (inclusive == null) { |
|---|
| 810 | | inclusive = true; |
|---|
| 811 | | } |
|---|
| 812 | | |
|---|
| 813 | | var inLeft; |
|---|
| 814 | | var inTop; |
|---|
| 815 | | var inRight; |
|---|
| 816 | | var inBottom; |
|---|
| 817 | | |
|---|
| 818 | | if (inclusive) { |
|---|
| 819 | | inLeft = (bounds.left >= this.left) && (bounds.left <= this.right); |
|---|
| 820 | | inTop = (bounds.top >= this.bottom) && (bounds.top <= this.top); |
|---|
| 821 | | inRight= (bounds.right >= this.left) && (bounds.right <= this.right); |
|---|
| 822 | | inBottom = (bounds.bottom >= this.bottom) && (bounds.bottom <= this.top); |
|---|
| 823 | | } else { |
|---|
| 824 | | inLeft = (bounds.left > this.left) && (bounds.left < this.right); |
|---|
| 825 | | inTop = (bounds.top > this.bottom) && (bounds.top < this.top); |
|---|
| 826 | | inRight= (bounds.right > this.left) && (bounds.right < this.right); |
|---|
| 827 | | inBottom = (bounds.bottom > this.bottom) && (bounds.bottom < this.top); |
|---|
| 828 | | } |
|---|
| 829 | | |
|---|
| 830 | | return (partial) ? (inTop || inBottom ) && (inLeft || inRight ) |
|---|
| 831 | | : (inTop && inLeft && inBottom && inRight); |
|---|
| 832 | | }, |
|---|
| 833 | | |
|---|
| 834 | | /** |
|---|
| 835 | | * APIMethod: determineQuadrant |
|---|
| 836 | | * |
|---|
| 837 | | * Parameters: |
|---|
| 838 | | * lonlat - {<OpenLayers.LonLat>} |
|---|
| 839 | | * |
|---|
| 840 | | * Return: |
|---|
| 841 | | * {String} The quadrant ("br" "tr" "tl" "bl") of the bounds in which |
|---|
| 842 | | * the coordinate lies. |
|---|
| 843 | | */ |
|---|
| 844 | | determineQuadrant: function(lonlat) { |
|---|
| 845 | | |
|---|
| 846 | | var quadrant = ""; |
|---|
| 847 | | var center = this.getCenterLonLat(); |
|---|
| 848 | | |
|---|
| 849 | | quadrant += (lonlat.lat < center.lat) ? "b" : "t"; |
|---|
| 850 | | quadrant += (lonlat.lon < center.lon) ? "l" : "r"; |
|---|
| 851 | | |
|---|
| 852 | | return quadrant; |
|---|
| 853 | | }, |
|---|
| 854 | | |
|---|
| 855 | | /** |
|---|
| 856 | | * APIMethod: wrapDateLine |
|---|
| 857 | | * |
|---|
| 858 | | * Parameters: |
|---|
| 859 | | * maxExtent - {<OpenLayers.Bounds>} |
|---|
| 860 | | * options - {Object} Some possible options are: |
|---|
| 861 | | * leftTolerance - {float} Allow for a margin of error |
|---|
| 862 | | * with the 'left' value of this |
|---|
| 863 | | * bound. |
|---|
| 864 | | * Default is 0. |
|---|
| 865 | | * rightTolerance - {float} Allow for a margin of error |
|---|
| 866 | | * with the 'right' value of |
|---|
| 867 | | * this bound. |
|---|
| 868 | | * Default is 0. |
|---|
| 869 | | * |
|---|
| 870 | | * Return: |
|---|
| 871 | | * {<OpenLayers.Bounds>} A copy of this bounds, but wrapped around the |
|---|
| 872 | | * "dateline" (as specified by the borders of |
|---|
| 873 | | * maxExtent). Note that this function only returns |
|---|
| 874 | | * a different bounds value if this bounds is |
|---|
| 875 | | * *entirely* outside of the maxExtent. If this |
|---|
| 876 | | * bounds straddles the dateline (is part in/part |
|---|
| 877 | | * out of maxExtent), the returned bounds will be |
|---|
| 878 | | * merely a copy of this one. |
|---|
| 879 | | */ |
|---|
| 880 | | wrapDateLine: function(maxExtent, options) { |
|---|
| 881 | | options = options || new Object(); |
|---|
| 882 | | |
|---|
| 883 | | var leftTolerance = options.leftTolerance || 0; |
|---|
| 884 | | var rightTolerance = options.rightTolerance || 0; |
|---|
| 885 | | |
|---|
| 886 | | var newBounds = this.clone(); |
|---|
| 887 | | |
|---|
| 888 | | if (maxExtent) { |
|---|
| 889 | | |
|---|
| 890 | | //shift right? |
|---|
| 891 | | while ( newBounds.left < maxExtent.left && |
|---|
| 892 | | (newBounds.right - rightTolerance) <= maxExtent.left ) { |
|---|
| 893 | | newBounds = newBounds.add(maxExtent.getWidth(), 0); |
|---|
| 894 | | } |
|---|
| 895 | | |
|---|
| 896 | | //shift left? |
|---|
| 897 | | while ( (newBounds.left + leftTolerance) >= maxExtent.right && |
|---|
| 898 | | newBounds.right > maxExtent.right ) { |
|---|
| 899 | | newBounds = newBounds.add(-maxExtent.getWidth(), 0); |
|---|
| 900 | | } |
|---|
| 901 | | } |
|---|
| 902 | | |
|---|
| 903 | | return newBounds; |
|---|
| 904 | | }, |
|---|
| 905 | | |
|---|
| 906 | | /** @final @type String */ |
|---|
| 907 | | CLASS_NAME: "OpenLayers.Bounds" |
|---|
| 908 | | }; |
|---|
| 909 | | |
|---|
| 910 | | /** |
|---|
| 911 | | * APIFunction: fromString |
|---|
| 912 | | * Alternative constructor that builds a new OpenLayers.Bounds from a |
|---|
| 913 | | * parameter string |
|---|
| 914 | | * |
|---|
| 915 | | * Parameters: |
|---|
| 916 | | * str - {String}Comma-separated bounds string. (ex. <i>"5,42,10,45"</i>) |
|---|
| 917 | | * |
|---|
| 918 | | * Return: |
|---|
| 919 | | * {<OpenLayers.Bounds>} New <OpenLayers.Bounds> object built from the |
|---|
| 920 | | * passed-in String. |
|---|
| 921 | | */ |
|---|
| 922 | | OpenLayers.Bounds.fromString = function(str) { |
|---|
| 923 | | var bounds = str.split(","); |
|---|
| 924 | | return OpenLayers.Bounds.fromArray(bounds); |
|---|
| 925 | | }; |
|---|
| 926 | | |
|---|
| 927 | | /** |
|---|
| 928 | | * APIFunction: fromArray |
|---|
| 929 | | * Alternative constructor that builds a new OpenLayers.Bounds |
|---|
| 930 | | * from an array |
|---|
| 931 | | * |
|---|
| 932 | | * Parameters: |
|---|
| 933 | | * bbox - {Array} Array of bounds values (ex. <i>[5,42,10,45]</i>) |
|---|
| 934 | | * |
|---|
| 935 | | * Return: |
|---|
| 936 | | * {<OpenLayers.Bounds>} New <OpenLayers.Bounds> object built from the |
|---|
| 937 | | * passed-in Array. |
|---|
| 938 | | */ |
|---|
| 939 | | OpenLayers.Bounds.fromArray = function(bbox) { |
|---|
| 940 | | return new OpenLayers.Bounds(parseFloat(bbox[0]), |
|---|
| 941 | | parseFloat(bbox[1]), |
|---|
| 942 | | parseFloat(bbox[2]), |
|---|
| 943 | | parseFloat(bbox[3])); |
|---|
| 944 | | }; |
|---|
| 945 | | |
|---|
| 946 | | /** |
|---|
| 947 | | * APIFunction: fromSize |
|---|
| 948 | | * Alternative constructor that builds a new OpenLayers.Bounds |
|---|
| 949 | | * from a size |
|---|
| 950 | | * |
|---|
| 951 | | * Parameters: |
|---|
| 952 | | * size - {<OpenLayers.Size>} |
|---|
| 953 | | * |
|---|
| 954 | | * Return: |
|---|
| 955 | | * {<OpenLayers.Bounds>} New <OpenLayers.Bounds> object built from the |
|---|
| 956 | | * & |
|---|