Ticket #987: layer.2.patch
| File layer.2.patch, 4.2 kB (added by crschmidt, 4 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 should not use scale-based display properties, 43 * this should be set to true. This will cause the layer, as an 44 * overlay, to always be 'active'. By default, this is set to 45 * true on overlays which do not pass any explicit scale-based options 46 * in the options of the layer. 47 */ 48 alwaysInRange: null, 49 50 /** 41 51 * Constant: EVENT_TYPES 42 52 * {Array(String)} Supported application event types. Register a listener 43 53 * for a particular event with the following syntax: … … 618 628 * resolution. 619 629 */ 620 630 calculateInRange: function() { 631 if (this.alwaysInRange) { 632 return true; 633 } 621 634 var inRange = false; 622 635 if (this.map) { 623 636 var resolution = this.map.getResolution(); … … 677 690 'numZoomLevels', 'maxZoomLevel' 678 691 ); 679 692 693 var notScaleProps = ['projection', 'units']; 694 680 695 // First we create a new object where we will store all of the 681 696 // resolution-related properties that we find in either the layer's 682 697 // 'options' array or from the map. 683 // 698 699 var useInRange = false; 684 700 var confProps = {}; 685 701 for(var i=0, len=props.length; i<len; i++) { 686 702 var property = props[i]; 703 704 // If the layer had one of these properties set *and* the property 705 // is not a non-scale property, then the user intended to use 706 // scale-dependant display. 707 if (this.options[property] && OpenLayers.Util.indexOf(notScaleProps, property) == -1) { 708 useInRange = true; 709 } 710 687 711 confProps[property] = this.options[property] || this.map[property]; 688 712 } 713 714 this.alwaysInRange = (this.alwaysInRange == null) ? !useInRange : this.alwaysInRange; 689 715 690 716 // Do not use the scales/resolutions at the map level if 691 717 // minScale/minResolution and maxScale/maxResolution are
