Changeset 7863
- Timestamp:
- 08/26/08 10:27:36 (3 months ago)
- Files:
-
- trunk/openlayers/lib/OpenLayers/Layer.js (modified) (4 diffs)
- trunk/openlayers/tests/Layer.html (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/openlayers/lib/OpenLayers/Layer.js
r7688 r7863 37 37 */ 38 38 opacity: null, 39 40 /** 41 * APIProperty: alwaysInRange 42 * {Boolean} If a layer's display should not be scale-based, this should 43 * be set to true. This will cause the layer, as an overlay, to always 44 * be 'active', by always returning true from the calculateInRange() 45 * function. 46 * 47 * If not explicitly specified for a layer, its value will be 48 * determined on startup in initResolutions() based on whether or not 49 * any scale-specific properties have been set as options on the 50 * layer. If no scale-specific options have been set on the layer, we 51 * assume that it should always be in range. 52 * 53 * See #987 for more info. 54 */ 55 alwaysInRange: null, 39 56 40 57 /** … … 616 633 * Returns: 617 634 * {Boolean} The layer is displayable at the current map's current 618 * resolution. 635 * resolution. Note that if 'alwaysInRange' is true for the layer, 636 * this function will always return true. 619 637 */ 620 638 calculateInRange: function() { 621 639 var inRange = false; 622 if (this.map) { 623 var resolution = this.map.getResolution(); 624 inRange = ( (resolution >= this.minResolution) && 625 (resolution <= this.maxResolution) ); 640 641 if (this.alwaysInRange) { 642 inRange = true; 643 } else { 644 if (this.map) { 645 var resolution = this.map.getResolution(); 646 inRange = ( (resolution >= this.minResolution) && 647 (resolution <= this.maxResolution) ); 648 } 626 649 } 627 650 return inRange; … … 678 701 ); 679 702 703 //these are the properties which do *not* imply that user wishes 704 // this layer to be scale-dependant 705 var notScaleProps = ['projection', 'units']; 706 707 //should the layer be scale-dependant? default is false -- this will 708 // only be set true if we find that the user has specified a property 709 // from the 'props' array that is not in 'notScaleProps' 710 var useInRange = false; 711 680 712 // First we create a new object where we will store all of the 681 713 // resolution-related properties that we find in either the layer's … … 685 717 for(var i=0, len=props.length; i<len; i++) { 686 718 var property = props[i]; 719 720 // If the layer had one of these properties set *and* it is 721 // a scale property (is not a non-scale property), then we assume 722 // the user did intend to use scale-dependant display (useInRange). 723 if (this.options[property] && 724 OpenLayers.Util.indexOf(notScaleProps, property) == -1) { 725 useInRange = true; 726 } 727 687 728 confProps[property] = this.options[property] || this.map[property]; 729 } 730 731 //only automatically set 'alwaysInRange' if the user hasn't already 732 // set it (to true or false, since the default is null). If user did 733 // not intend to use scale-dependant display then we set they layer 734 // as alwaysInRange. This means calculateInRange() will always return 735 // true and the layer will never be turned off due to scale changes. 736 // 737 if (this.alwaysInRange == null) { 738 this.alwaysInRange = !useInRange; 688 739 } 689 740 trunk/openlayers/tests/Layer.html
r6724 r7863 146 146 147 147 function test_Layer_initResolutions(t) { 148 t.plan(1 2);148 t.plan(15); 149 149 var map = new OpenLayers.Map("map"); 150 150 var options, layer; 151 151 152 // t hree tests for minResolution, maxResolution, and numZoomLevels152 // tests for minResolution, maxResolution, and numZoomLevels 153 153 options = { 154 154 minResolution: 1.5, … … 164 164 "(with numZoomLevels) layer maxResolution preserved"); 165 165 t.eq(layer.numZoomLevels, 5, "(with numZoomLevels) layer numZoomLevels preserved"); 166 166 t.eq(layer.alwaysInRange, false, "Always in range is set to false due to passed options.") 167 167 168 // three tests for minResolution, and maxResolution 168 169 options = { … … 207 208 "(without numZoomLevels) layer maxScale preserved"); 208 209 t.eq(layer.numZoomLevels, 4, "(without numZoomLevels) layer numZoomLevels calculated"); 210 211 layer = new OpenLayers.Layer("test", {'projection': 'EPSG:4326', 'map': map}); 212 layer.initResolutions(); 213 t.eq(layer.alwaysInRange, true, "always in range true if only get projection."); 214 215 OpenLayers.Layer.prototype.alwaysInRange = false; 216 layer = new OpenLayers.Layer("test", {'projection': 'EPSG:4326', 'map': map}); 217 layer.initResolutions(); 218 t.eq(layer.alwaysInRange, false, "always in range true if overridden on prototype."); 219 OpenLayers.Layer.prototype.alwaysInRange = null; 209 220 210 221 map.destroy();
