Ticket #987: layer.3.patch
| File layer.3.patch, 6.0 kB (added by euzuro, 3 months ago) |
|---|
-
tests/Layer.html
old new 145 145 } 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, 155 155 maxResolution: 10.5, … … 163 163 t.eq(layer.maxResolution.toPrecision(6), (10.5).toPrecision(6), 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 = { 169 170 minResolution: 1.5, … … 206 207 t.eq(layer.maxScale.toPrecision(6), (155).toPrecision(6), 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(); 211 222 -
lib/OpenLayers/Layer.js
old new 38 38 opacity: null, 39 39 40 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, 56 57 /** 41 58 * Constant: EVENT_TYPES 42 59 * {Array(String)} Supported application event types. Register a listener 43 60 * for a particular event with the following syntax: … … 615 632 * 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; 628 651 }, … … 677 700 'numZoomLevels', 'maxZoomLevel' 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 682 714 // 'options' array or from the map. … … 684 716 var confProps = {}; 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]; 688 729 } 689 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; 739 } 740 690 741 // Do not use the scales array set at the map level if 691 742 // either minScale or maxScale or both are set at the 692 743 // layer level
