Ticket #1043: zoomer.2.patch
| File zoomer.2.patch, 4.2 kB (added by euzuro, 1 year ago) |
|---|
-
lib/OpenLayers/Layer.js
old new 730 730 * 731 731 * Parameters: 732 732 * bounds - {<OpenLayers.Bounds>} 733 * closest - {Boolean} Find the zoom level that corresponds to the absolute 734 * closest for the given extent, which may result in a zoom whose 735 * that does not exactly contain the entire extent. 736 * Default is false. 733 737 * 734 738 * Returns: 735 739 * {Integer} The index of the zoomLevel (entry in the resolutions array) 736 * that still contains the passed-in extent. We do this by calculating737 * the ideal resolution for the given exteng (based on the map size)738 * and then find the smallest resolution that is greater than this739 * ideal resolution.740 * for the passed-in extent. We do this by calculating the ideal 741 * resolution for the given extent (based on the map size) and then 742 * calling getZoomForResolution(), passing along the 'closest' 743 * parameter. 740 744 */ 741 getZoomForExtent: function(extent ) {745 getZoomForExtent: function(extent, closest) { 742 746 var viewSize = this.map.getSize(); 743 747 var idealResolution = Math.max( extent.getWidth() / viewSize.w, 744 748 extent.getHeight() / viewSize.h ); 745 749 746 return this.getZoomForResolution(idealResolution );750 return this.getZoomForResolution(idealResolution, closest); 747 751 }, 748 752 749 753 /** … … 763 767 * 764 768 * Parameters: 765 769 * resolution - {Float} 770 * closest - {Boolean} Find the zoom level that corresponds to the absolute 771 * closest resolution, which may result in a zoom whose corresponding 772 * resolution is actually smaller than we would have desired (if this 773 * is being called from a getZoomForExtent() call, then this means that 774 * the returned zoom index might not actually contain the entire 775 * extent specified... but it'll be close). 776 * Default is false. 766 777 * 767 778 * Returns: 768 779 * {Integer} The index of the zoomLevel (entry in the resolutions array) 769 * that is the smallest resolution that is greater than the passed-in770 * resolution.780 * that corresponds to the best fit resolution given the passed in 781 * value and the 'closest' specification. 771 782 */ 772 getZoomForResolution: function(resolution) { 773 774 for(var i=1; i < this.resolutions.length; i++) { 775 if ( this.resolutions[i] < resolution) { 776 break; 783 getZoomForResolution: function(resolution, closest) { 784 var diff; 785 var minDiff = Number.POSITIVE_INFINITY; 786 for(var i=0; i < this.resolutions.length; i++) { 787 if (closest) { 788 diff = Math.abs(this.resolutions[i] - resolution); 789 if (diff > minDiff) { 790 break; 791 } 792 minDiff = diff; 793 } else { 794 if (this.resolutions[i] < resolution) { 795 break; 796 } 777 797 } 778 798 } 779 return (i -1);799 return Math.max(0, i-1); 780 800 }, 781 801 782 802 /** -
lib/OpenLayers/Map.js
old new 711 711 // simply set center but force zoom change 712 712 this.setCenter( 713 713 center, 714 this.getZoomForResolution(this.resolution ),714 this.getZoomForResolution(this.resolution, true), 715 715 false, true 716 716 ); 717 717 } else { 718 718 // zoom to oldExtent *and* force zoom change 719 719 this.setCenter(oldExtent.getCenterLonLat(), 720 this.getZoomForExtent(oldExtent ),720 this.getZoomForExtent(oldExtent, true), 721 721 false, true); 722 722 } 723 723 }
