Changeset 1302
- Timestamp:
- 08/18/06 22:09:29 (2 years ago)
- Files:
-
- branches/openlayers/2.0/examples/urban.html (modified) (2 diffs)
- branches/openlayers/2.0/examples/zoomLevels.html (added)
- branches/openlayers/2.0/lib/OpenLayers/Control/PanZoomBar.js (modified) (6 diffs)
- branches/openlayers/2.0/lib/OpenLayers/Layer.js (modified) (3 diffs)
- branches/openlayers/2.0/lib/OpenLayers/Layer/Google.js (modified) (1 diff)
- branches/openlayers/2.0/lib/OpenLayers/Layer/Grid.js (modified) (1 diff)
- branches/openlayers/2.0/lib/OpenLayers/Layer/HTTPRequest.js (modified) (2 diffs)
- branches/openlayers/2.0/lib/OpenLayers/Layer/VirtualEarth.js (modified) (2 diffs)
- branches/openlayers/2.0/lib/OpenLayers/Map.js (modified) (10 diffs)
- branches/openlayers/2.0/tests/test_Layer.html (modified) (2 diffs)
- branches/openlayers/2.0/tests/test_Map.html (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/openlayers/2.0/examples/urban.html
r697 r1302 12 12 <!-- 13 13 function init(){ 14 var map = new OpenLayers.Map('map', {'maxResolution': 1.6, maxZoomLevel:20}); 15 14 var mapOptions = { maxResolution: 1.6, numZoomLevels: 21}; 15 var map = new OpenLayers.Map('map', mapOptions); 16 16 17 var ol_wms = new OpenLayers.Layer.WMS( "OpenLayers WMS", 17 18 "http://labs.metacarta.com/wms/vmap0?", {layers: 'basic'} ); … … 19 20 var ww = new OpenLayers.Layer.WorldWind( "Urban", 20 21 "http://worldwind25.arc.nasa.gov/tile/tile.aspx?", .8, 9, 21 {T:"104"}); 22 ww.setTileSize(new OpenLayers.Size(512,512)); 22 {T:"104"}, { tileSize: new OpenLayers.Size(512,512) }); 23 23 24 24 branches/openlayers/2.0/lib/OpenLayers/Control/PanZoomBar.js
r1206 r1302 29 29 // put code here to catch "changebaselayer" event from map, because 30 30 // we are going to have to redraw this thing each time, because 31 // maxZoom will/might change. 32 }, 33 31 // numZoomLevels will/might change. 32 }, 33 34 /** 35 * @param {OpenLayers.Map} map 36 */ 37 setMap: function(map) { 38 OpenLayers.Control.PanZoom.prototype.setMap.apply(this, arguments); 39 40 this.map.events.register("changebaselayer", this, this.redraw); 41 }, 42 43 /** clear the div and start over. 44 * 45 */ 46 redraw: function() { 47 if (this.div != null) { 48 this.div.innerHTML = ""; 49 } 50 this.draw(); 51 }, 52 34 53 /** 35 54 * @param {OpenLayers.Pixel} px … … 66 85 var slider = OpenLayers.Util.createAlphaImageDiv(id, 67 86 centered.add(-1, 68 (this.map.getMaxZoomLevel())*this.zoomStopHeight),87 (this.map.getNumZoomLevels()-1) * this.zoomStopHeight), 69 88 new OpenLayers.Size(20,9), 70 89 imgLocation+"slider.png", … … 80 99 81 100 sz = new OpenLayers.Size(); 82 sz.h = this.zoomStopHeight *(this.map.getMaxZoomLevel()+1);101 sz.h = this.zoomStopHeight * this.map.getNumZoomLevels(); 83 102 sz.w = this.zoomStopWidth; 84 103 var div = null … … 116 135 117 136 centered = centered.add(0, 118 this.zoomStopHeight *(this.map.getMaxZoomLevel()+1));137 this.zoomStopHeight * this.map.getNumZoomLevels()); 119 138 return centered; 120 139 }, … … 137 156 var top = Position.page(evt.object)[1]; 138 157 var levels = Math.floor((y - top)/this.zoomStopHeight); 139 this.map.zoomTo( this.map.getMaxZoomLevel() -levels);158 this.map.zoomTo((this.map.getNumZoomLevels() -1) - levels); 140 159 Event.stop(evt); 141 160 }, … … 199 218 moveZoomBar:function() { 200 219 var newTop = 201 ( this.map.getMaxZoomLevel() - this.map.getZoom()) * this.zoomStopHeight202 + this.startTop + 1;220 ((this.map.getNumZoomLevels()-1) - this.map.getZoom()) * 221 this.zoomStopHeight + this.startTop + 1; 203 222 this.slider.style.top = newTop + "px"; 204 223 }, branches/openlayers/2.0/lib/OpenLayers/Layer.js
r1294 r1302 52 52 53 53 /** @type int */ 54 minZoomLevel: null, 55 56 /** @type int */ 57 maxZoomLevel: null, 54 numZoomLevels: null, 58 55 59 56 /** @type float */ … … 179 176 180 177 var properties = new Array( 181 'projection', 'minExtent', 'maxExtent', 182 'minScale', 'maxScale', 178 'projection', 'units', 179 'scales', 'resolutions', 180 'maxScale', 'minScale', 183 181 'maxResolution', 'minResolution', 184 'minZoomLevel', 'maxZoomLevel', 'units', 185 'scales', 'resolutions' 186 182 'minExtent', 'maxExtent', 183 'numZoomLevels' 187 184 ); 188 185 for(var i=0; i < properties.length; i++) { … … 252 249 253 250 /** 254 * @returns The minimum zoom level that can be reached in this layer251 * @returns The total number of zoom levels this layer can reach 255 252 * @type int 256 253 */ 257 getMinZoomLevel: function() { 258 return this.minZoomLevel; 259 }, 260 261 /** 262 * @returns The maximum zoom level that can be reached in this layer 263 * @type int 264 */ 265 getMaxZoomLevel: function() { 266 return this.maxZoomLevel; 254 getNumZoomLevels: function() { 255 return this.numZoomLevels; 267 256 }, 268 257 branches/openlayers/2.0/lib/OpenLayers/Layer/Google.js
r1275 r1302 50 50 51 51 /** @type int */ 52 minZoomLevel: -1, 53 54 /** @type int */ 55 maxZoomLevel: 16, 52 numZoomLevels: 16, 56 53 57 54 branches/openlayers/2.0/lib/OpenLayers/Layer/Grid.js
r1288 r1302 445 445 var zoom = Math.floor( (Math.log(maxRes/degPerPixel)) / Math.log(2) ); 446 446 447 var maxZoomLevel = this.map.getMaxZoomLevel();448 var minZoomLevel = this.map.getMinZoomLevel();449 450 447 //make sure zoom is within bounds 451 zoom = Math.min( Math.max(zoom, minZoomLevel),452 maxZoomLevel);448 zoom = Math.min( Math.max(zoom, 0), 449 this.getNumZoomLevels() - 1); 453 450 454 451 return zoom; branches/openlayers/2.0/lib/OpenLayers/Layer/HTTPRequest.js
r1296 r1302 37 37 }, 38 38 39 /** When the layer is added to the map, once it has taken all the 40 * relevant properties from the map (in Layer.setMap()), we will 41 * make the call to initialize the layer's resolutions array. 42 * 43 * @param {OpenLayers.Map} map 44 */ 39 45 setMap: function(map) { 40 46 OpenLayers.Layer.prototype.setMap.apply(this, arguments); 41 47 this.initResolutions(); 42 48 }, 49 43 50 /** 44 51 * … … 132 139 }, 133 140 141 /** This method's responsibility is to set up the 'resolutions' array 142 * for the layer -- this array is what the layer will use to interface 143 * between the zoom levels of the map and the resolution display of the 144 * layer. 145 * 146 * The user has several options that determine how the array is set up. 147 * 148 * For a detailed explanation, see the following wiki from the 149 * openlayers.org homepage: 150 * 151 * http://trac.openlayers.org/wiki/SettingZoomLevels 152 * 153 * @private 154 */ 134 155 initResolutions: function() { 135 if (this.scales != null) { 156 157 if ((this.scales != null) || (this.resolutions != null)) { 158 //preset levels 159 if (this.scales != null) { 160 this.resolutions = new Array(); 161 for(var i = 0; i < this.scales.length; i++) { 162 this.resolutions[i] = 163 OpenLayers.Util.getResolutionFromScale(this.scales[i], 164 this.units); 165 } 166 } 167 this.numZoomLevels = this.resolutions.length; 168 169 } else { 170 //maxResolution and numZoomLevels 171 136 172 this.resolutions = new Array(); 137 for(var i = 0; i < this.scales.length; i++) 138 this.resolutions[i] = OpenLayers.Util.getResolutionFromScale(this.scales[i], this.units); 139 this.maxZoomLevel = this.resolutions.length; 140 } else if (this.resolutions != null) { 141 this.maxZoomLevel = this.resolutions.length; 142 } else { 143 this.resolutions = new Array(); 144 if (this.minScale) 145 this.maxResolution = OpenLayers.Util.getResolutionFromScale(this.minScale, this.units); 146 var maxRes = this.getMaxResolution(); 147 if (this.maxScale) { 148 /* This will cause this.map.getMaxZoomLevel() to be set the next time 149 * it is called, which means that the next portion here will succeed. */ 150 var minRes = OpenLayers.Util.getResolutionFromScale(this.maxScale); 151 this.maxZoomLevel = Math.floor(Math.log(maxRes/minRes) / Math.log(2)); 152 } 153 for (var i=this.getMinZoomLevel(); i <= this.getMaxZoomLevel(); i++) { 154 this.resolutions.push(maxRes / Math.pow(2, i)); 173 174 // determine maxResolution 175 if (this.minScale) { 176 this.maxResolution = 177 OpenLayers.Util.getResolutionFromScale(this.minScale, 178 this.units); 179 } else if (this.maxResolution == "auto") { 180 var maxExtent = this.getMaxExtent(); 181 var viewSize = this.map.getSize(); 182 var wRes = maxExtent.getWidth() / viewSize.w; 183 var hRes = maxExtent.getHeight()/ viewSize.h; 184 this.maxResolution = Math.max(wRes, hRes); 185 } 186 187 // determine numZoomLevels 188 189 if (this.maxScale != null) { 190 this.minResolution = 191 OpenLayers.Util.getResolutionFromScale(this.maxScale); 192 } 193 194 if (this.minResolution != null) { 195 var ratio = this.maxResolution / this.minResolution; 196 this.numZoomLevels = 197 Math.floor(Math.log(ratio) / Math.log(2)) + 1; 198 } 199 200 // now we have numZoomLevels and maxResolution, 201 // we can populate the resolutions array 202 for (var i=0; i < this.numZoomLevels; i++) { 203 this.resolutions.push(this.maxResolution / Math.pow(2, i)); 155 204 } 156 205 } 157 206 }, 158 207 208 /** 209 * @returns The currently selected resolution of the map, taken from the 210 * resolutions array, indexed by current zoom level. 211 * @type float 212 */ 159 213 getResolution: function() { 160 214 var zoom = this.map.getZoom(); branches/openlayers/2.0/lib/OpenLayers/Layer/VirtualEarth.js
r1235 r1302 14 14 /** @type VEMap */ 15 15 vemap: null, 16 17 /** @type int */ 18 numZoomLevels: 17, 16 19 17 20 /** … … 212 215 var zoom = Math.floor( (Math.log(maxRes/degPerPixel)) / Math.log(2) ); 213 216 214 var maxZoomLevel = this.map.getMaxZoomLevel();215 var minZoomLevel = this.map.getMinZoomLevel();216 217 217 //make sure zoom is within bounds 218 zoom = Math.min( Math.max(zoom, minZoomLevel),219 maxZoomLevel);218 zoom = Math.min( Math.max(zoom, 0), 219 this.numZoomLevels-1); 220 220 221 221 return zoom; branches/openlayers/2.0/lib/OpenLayers/Map.js
r1296 r1302 79 79 // Options 80 80 81 /** @type OpenLayers.Size */ 82 tileSize: null, 83 81 84 /** @type String */ 82 85 projection: "EPSG:4326", 83 86 87 /** @type String */ 88 units: 'degrees', 89 90 /** default max is 360 deg / 256 px, which corresponds to 91 * zoom level 0 on gmaps 92 * 93 * @type float */ 94 maxResolution: 1.40625, 95 96 /** @type float */ 97 minResolution: null, 98 99 /** @type float */ 100 maxScale: null, 101 102 /** @type float */ 103 minScale: null, 104 84 105 /** @type OpenLayers.Bounds */ 85 106 maxExtent: null, 86 107 87 /** default max is 360 deg / 256 px, which corresponds to 88 * zoom level 0 on gmaps 89 * 90 * @type float */ 91 maxResolution: 1.40625, 92 108 /** @type OpenLayers.Bounds */ 109 minExtent: null, 110 93 111 /** @type int */ 94 minZoomLevel: 0, 95 96 /** @type int */ 97 maxZoomLevel: 16, 98 99 /** @type OpenLayers.Size */ 100 tileSize: null, 101 102 /** @type String */ 103 units: 'degrees', 104 105 /** @type Float */ 106 minScale: null, 107 112 numZoomLevels: 16, 108 113 109 114 … … 208 213 // (these will override defaults) 209 214 Object.extend(this, options); 210 211 // if maxResolution is specified as "auto", calculate it212 // based on the maxExtent and the viewSize213 //214 if (this.maxResolution == "auto" || this.maxResolution == null) {215 var maxExtent = this.getMaxExtent();216 var viewSize = this.getSize();217 this.maxResolution = Math.max(maxExtent.getWidth() / viewSize.w,218 maxExtent.getHeight() / viewSize.h );219 }220 215 }, 221 216 … … 648 643 isValidZoomLevel: function(zoomLevel) { 649 644 return ( (zoomLevel != null) && 650 (zoomLevel >= this.getMinZoomLevel()) &&651 (zoomLevel < = this.getMaxZoomLevel()) );645 (zoomLevel >= 0) && 646 (zoomLevel < this.getNumZoomLevels()) ); 652 647 }, 653 648 … … 685 680 getProjection: function() { 686 681 var projection = null; 687 688 682 if (this.baseLayer != null) { 689 683 projection = this.baseLayer.getProjection(); 690 684 } 691 692 if (projection == null) {693 projection = this.projection;694 }695 696 685 return projection; 697 686 }, … … 703 692 getMaxResolution: function() { 704 693 var maxResolution = null; 705 706 694 if (this.baseLayer != null) { 707 695 maxResolution = this.baseLayer.getMaxResolution(); 708 696 } 709 710 if (maxResolution == null) {711 maxResolution = this.maxResolution;712 }713 714 697 return maxResolution; 715 698 }, … … 720 703 getMaxExtent: function () { 721 704 var maxExtent = null; 722 723 705 if (this.baseLayer != null) { 724 706 maxExtent = this.baseLayer.getMaxExtent(); 725 } 726 727 if (maxExtent == null) { 728 maxExtent = this.maxExtent; 729 } 730 707 } 731 708 return maxExtent; 732 709 }, 733 710 734 711 /** 735 * @returns The maximum zoom level that can be reached in the map 712 * @returns The total number of zoom levels that can be displayed by the 713 * current baseLayer. 736 714 * @type int 737 715 */ 738 getMaxZoomLevel: function() { 739 var maxZoomLevel = null; 740 716 getNumZoomLevels: function() { 717 var numZoomLevels = null; 741 718 if (this.baseLayer != null) { 742 maxZoomLevel = this.baseLayer.getMaxZoomLevel(); 743 } 744 745 if (maxZoomLevel == null) { 746 maxZoomLevel = this.maxZoomLevel; 747 } 748 749 return maxZoomLevel; 750 }, 751 752 /** 753 * @returns The minimum zoom level that can be reached in the map 754 * @type int 755 */ 756 getMinZoomLevel: function() { 757 var minZoomLevel = null; 758 759 if (this.baseLayer != null) { 760 minZoomLevel = this.baseLayer.getMinZoomLevel(); 761 } 762 763 if (minZoomLevel == null) { 764 minZoomLevel = this.minZoomLevel; 765 } 766 767 return minZoomLevel; 768 }, 769 719 numZoomLevels = this.baseLayer.getNumZoomLevels(); 720 } 721 return numZoomLevels; 722 }, 770 723 771 724 /********************************************************/ … … 788 741 getExtent: function () { 789 742 var extent = null; 790 791 743 if (this.baseLayer != null) { 792 744 extent = this.baseLayer.getExtent(); … … 802 754 getResolution: function () { 803 755 var resolution = null; 804 805 756 if (this.baseLayer != null) { 806 757 resolution = this.baseLayer.getResolution(); … … 816 767 getScale: function () { 817 768 var scale = null; 818 819 769 if (this.baseLayer != null) { 820 770 var res = this.getResolution(); … … 836 786 getZoomForExtent: function (bounds) { 837 787 zoom = null; 838 839 788 if (this.baseLayer != null) { 840 789 zoom = this.baseLayer.getZoomForExtent(bounds); branches/openlayers/2.0/tests/test_Layer.html
r1210 r1302 90 90 function test_04_Layer_StandardOptionsAccessors (t) { 91 91 92 t.plan( 5);92 t.plan( 4 ); 93 93 94 94 var projection = "chicken"; 95 95 var maxExtent = new OpenLayers.Bounds(50,50,100,100); 96 96 var maxResolution = 1.5726; 97 var minZoomLevel = 5; 98 var maxZoomLevel = 15; 97 var numZoomLevels = 11; 99 98 100 99 var options = { projection: projection, 101 100 maxExtent: maxExtent, 102 101 maxResolution: maxResolution, 103 minZoomLevel: minZoomLevel, 104 maxZoomLevel: maxZoomLevel 102 numZoomLevels: numZoomLevels, 105 103 }; 106 104 … … 110 108 t.ok(layer.getMaxExtent().equals(maxExtent), "getMaxExtent() works"); 111 109 t.eq(layer.getMaxResolution(), maxResolution, "getMaxResolution() works"); 112 t.eq(layer.getMinZoomLevel(), minZoomLevel, "getMinZoomLevel() works"); 113 t.eq(layer.getMaxZoomLevel(), maxZoomLevel, "getMaxZoomLevel() works"); 110 t.eq(layer.getNumZoomLevels(), numZoomLevels, "getNumZoomLevels() works"); 114 111 } 115 112 branches/openlayers/2.0/tests/test_Map.html
r1244 r1302 28 28 t.ok( map.events instanceof OpenLayers.Events, "map.events is an OpenLayers.Events" ); 29 29 t.ok( map.getMaxExtent() instanceof OpenLayers.Bounds, "map.maxExtent is an OpenLayers.Bounds" ); 30 t.ok( map.get MaxZoomLevel() > 0, "map.maxZoomLevel is set" );30 t.ok( map.getNumZoomLevels() > 0, "map has a default numZoomLevels" ); 31 31 } 32 32 function test_02_Map_center(t) { … … 64 64 function test_04_Map_options(t) { 65 65 t.plan(2); 66 map = new OpenLayers.Map($('map'), { maxZoomLevel: 5, maxResolution: 3.14159});67 t.eq( map. maxZoomLevel, 5, "map.maxZoomLevelset correctly via options hashtable" );66 map = new OpenLayers.Map($('map'), {numZoomLevels: 6, maxResolution: 3.14159}); 67 t.eq( map.numZoomLevels, 6, "map.numZoomLevels set correctly via options hashtable" ); 68 68 t.eq( map.maxResolution, 3.14159, "map.maxResolution set correctly via options hashtable" ); 69 69 } … … 152 152 t.ok(!found, "popup.div successfully removed from the map's viewPort"); 153 153 } 154 function test_10_Map_auto_res(t) {155 t.plan(2);156 map = new OpenLayers.Map($('map'), {maxZoomLevel: 5, maxResolution: 'auto'});157 t.eq( map.maxResolution, 1/3, "map.maxResolution set correctly via auto" );158 map = new OpenLayers.Map($('map'), {maxZoomLevel: 5, maxResolution: null});159 t.eq( map.maxResolution, 1/3, "map.maxResolution set correctly via null" );160 }161 162 154 /*** THIS IS A GOOD TEST, BUT IT SHOULD BE MOVED TO WMS. 163 155 * Also, it won't work until we figure out the viewSize bug
