Ticket #987: layer.patch
| File layer.patch, 3.8 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(14); 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."); 209 214 210 215 map.destroy(); 211 216 -
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: false, 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 700 var useInRange = false; 684 701 var confProps = {}; 685 702 for(var i=0, len=props.length; i<len; i++) { 686 703 var property = props[i]; 704 705 // If the layer had one of these properties set *and* the property 706 // is not a non-scale property, then the user intended to use 707 // scale-dependant display. 708 if (this.options[property] && OpenLayers.Util.indexOf(notScaleProps, property) == -1) { 709 useInRange = true; 710 } 711 687 712 confProps[property] = this.options[property] || this.map[property]; 688 713 } 714 715 this.alwaysInRange = !useInRange; 689 716 690 717 // Do not use the scales/resolutions at the map level if 691 718 // minScale/minResolution and maxScale/maxResolution are
