| 209 | | var properties = new Array( |
|---|
| 210 | | 'projection', 'units', |
|---|
| 211 | | 'scales', 'resolutions', |
|---|
| 212 | | 'maxScale', 'minScale', |
|---|
| 213 | | 'maxResolution', 'minResolution', |
|---|
| 214 | | 'minExtent', 'maxExtent', |
|---|
| 215 | | 'numZoomLevels' |
|---|
| 216 | | ); |
|---|
| 217 | | if (this.map.maxZoomLevel && !this.numZoomLevels) { |
|---|
| 218 | | this.numZoomLevels = this.map.maxZoomLevel + 1; |
|---|
| 219 | | } |
|---|
| 220 | | for(var i=0; i < properties.length; i++) { |
|---|
| 221 | | if (this[properties[i]] == null) { |
|---|
| 222 | | this[properties[i]] = this.map[properties[i]]; |
|---|
| 223 | | } |
|---|
| 224 | | } |
|---|
| 325 | | |
|---|
| 326 | | if ((this.scales != null) || (this.resolutions != null)) { |
|---|
| | 309 | |
|---|
| | 310 | // These are the relevant options which are used for calculating |
|---|
| | 311 | // resolutions information. |
|---|
| | 312 | // |
|---|
| | 313 | var props = new Array( |
|---|
| | 314 | 'projection', 'units', |
|---|
| | 315 | 'scales', 'resolutions', |
|---|
| | 316 | 'maxScale', 'minScale', |
|---|
| | 317 | 'maxResolution', 'minResolution', |
|---|
| | 318 | 'minExtent', 'maxExtent', |
|---|
| | 319 | 'numZoomLevels', 'maxZoomLevel' |
|---|
| | 320 | ); |
|---|
| | 321 | |
|---|
| | 322 | // First we create a new object where we will store all of the |
|---|
| | 323 | // resolution-related properties that we find in either the layer's |
|---|
| | 324 | // 'options' array or from the map. |
|---|
| | 325 | // |
|---|
| | 326 | var confProps = new Object(); |
|---|
| | 327 | for(var i=0; i < props.length; i++) { |
|---|
| | 328 | var property = props[i]; |
|---|
| | 329 | confProps[property] = this.options[property] || this.map[property]; |
|---|
| | 330 | } |
|---|
| | 331 | |
|---|
| | 332 | // If numZoomLevels hasn't been set and the maxZoomLevel *has*, |
|---|
| | 333 | // then use maxZoomLevel to calculate numZoomLevels |
|---|
| | 334 | // |
|---|
| | 335 | if ( (!confProps.numZoomLevels) && (confProps.maxZoomLevel) ) { |
|---|
| | 336 | confProps.numZoomLevels = confProps.maxZoomLevel + 1; |
|---|
| | 337 | } |
|---|
| | 338 | |
|---|
| | 339 | // First off, we take whatever hodge-podge of values we have and |
|---|
| | 340 | // calculate/distill them down into a resolutions[] array |
|---|
| | 341 | // |
|---|
| | 342 | if ((confProps.scales != null) || (confProps.resolutions != null)) { |
|---|
| 328 | | if (this.scales != null) { |
|---|
| 329 | | this.resolutions = new Array(); |
|---|
| 330 | | for(var i = 0; i < this.scales.length; i++) { |
|---|
| 331 | | this.resolutions[i] = |
|---|
| 332 | | OpenLayers.Util.getResolutionFromScale(this.scales[i], |
|---|
| 333 | | this.units); |
|---|
| | 344 | if (confProps.scales != null) { |
|---|
| | 345 | confProps.resolutions = new Array(); |
|---|
| | 346 | for(var i = 0; i < confProps.scales.length; i++) { |
|---|
| | 347 | var scale = confProps.scales[i]; |
|---|
| | 348 | confProps.resolutions[i] = |
|---|
| | 349 | OpenLayers.Util.getResolutionFromScale(scale, |
|---|
| | 350 | confProps.units); |
|---|
| 356 | | if (this.maxScale != null) { |
|---|
| 357 | | this.minResolution = |
|---|
| 358 | | OpenLayers.Util.getResolutionFromScale(this.maxScale); |
|---|
| 359 | | } else if ((this.minResolution == "auto") && |
|---|
| 360 | | (this.minExtent != null)){ |
|---|
| | 373 | if (confProps.maxScale != null) { |
|---|
| | 374 | confProps.minResolution = |
|---|
| | 375 | OpenLayers.Util.getResolutionFromScale(confProps.maxScale); |
|---|
| | 376 | } else if ( (confProps.minResolution == "auto") && |
|---|
| | 377 | (confProps.minExtent != null) ) { |
|---|
| 380 | | |
|---|
| 381 | | this.resolutions.sort( function(a,b) { |
|---|
| 382 | | return(b-a); |
|---|
| 383 | | }); |
|---|
| 384 | | |
|---|
| 385 | | this.minResolution = this.resolutions[this.resolutions.length - 1]; |
|---|
| 386 | | this.maxResolution = this.resolutions[0]; |
|---|
| 387 | | |
|---|
| 388 | | this.minScale = |
|---|
| 389 | | OpenLayers.Util.getScaleFromResolution(this.maxResolution, |
|---|
| 390 | | this.units); |
|---|
| 391 | | this.maxScale = |
|---|
| 392 | | OpenLayers.Util.getScaleFromResolution(this.minResolution, |
|---|
| 393 | | this.units); |
|---|
| | 398 | |
|---|
| | 399 | //sort resolutions array ascendingly |
|---|
| | 400 | // |
|---|
| | 401 | confProps.resolutions.sort( function(a, b) { return(b-a); } ); |
|---|
| | 402 | |
|---|
| | 403 | // now set our newly calculated values back to the layer |
|---|
| | 404 | // Note: We specifically do *not* set them to layer.options, which we |
|---|
| | 405 | // will preserve as it was when we added this layer to the map. |
|---|
| | 406 | // this way cloned layers reset themselves to new map div |
|---|
| | 407 | // dimensions) |
|---|
| | 408 | // |
|---|
| | 409 | this.projection = confProps.projection; |
|---|
| | 410 | this.units = confProps.units; |
|---|
| | 411 | |
|---|
| | 412 | this.resolutions = confProps.resolutions; |
|---|
| | 413 | this.maxResolution = confProps.resolutions[0]; |
|---|
| | 414 | var lastIndex = confProps.resolutions.length - 1; |
|---|
| | 415 | this.minResolution = confProps.resolutions[lastIndex]; |
|---|
| | 416 | |
|---|
| | 417 | this.scales = new Array(); |
|---|
| | 418 | for(var i = 0; i < confProps.resolutions.length; i++) { |
|---|
| | 419 | this.scales[i] = |
|---|
| | 420 | OpenLayers.Util.getScaleFromResolution(confProps.resolutions[i], |
|---|
| | 421 | confProps.units); |
|---|
| | 422 | } |
|---|
| | 423 | this.minScale = this.scales[0]; |
|---|
| | 424 | this.maxScale = this.scales[this.scales.length - 1]; |
|---|
| | 425 | |
|---|
| | 426 | this.minExtent = confProps.minExtent; |
|---|
| | 427 | this.maxExtent = confProps.maxExtent; |
|---|
| | 428 | |
|---|
| | 429 | this.numZoomLevels = confProps.numZoomLevels; |
|---|