Ticket #1043: zoomer.patch
| File zoomer.patch, 4.7 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 * Default is false. 766 773 * 767 774 * Returns: 768 775 * {Integer} The index of the zoomLevel (entry in the resolutions array) 769 776 * that is the smallest resolution that is greater than the passed-in 770 777 * resolution. 771 778 */ 772 getZoomForResolution: function(resolution) { 773 774 for(var i=1; i < this.resolutions.length; i++) { 775 if ( this.resolutions[i] < resolution) { 776 break; 779 getZoomForResolution: function(resolution, closest) { 780 var diff; 781 var minDiff = Number.POSITIVE_INFINITY; 782 for(var i=0; i < this.resolutions.length; i++) { 783 if (closest) { 784 diff = Math.abs(this.resolutions[i] - resolution); 785 if (diff > minDiff) { 786 break; 787 } 788 minDiff = diff; 789 } else { 790 if (this.resolutions[i] < resolution) { 791 break; 792 } 777 793 } 778 794 } 779 return (i -1);795 return Math.max(0, i-1); 780 796 }, 781 797 782 798 /** -
lib/OpenLayers/Map.js
old new 707 707 //redraw all layers 708 708 var center = this.getCenter(); 709 709 if (center != null) { 710 if (oldExtent == null) { 711 // simply set center but force zoom change 712 this.setCenter( 713 center, 714 this.getZoomForResolution(this.resolution), 715 false, true 716 ); 717 } else { 718 // zoom to oldExtent *and* force zoom change 719 this.setCenter(oldExtent.getCenterLonLat(), 720 this.getZoomForExtent(oldExtent), 721 false, true); 722 } 710 //either get the center from the old Extent or just from 711 // the current center of the map. 712 var newCenter = (oldExtent) 713 ? oldExtent.getCenterLonLat() 714 : center; 715 716 //the new zoom will either come from the old Extent or 717 // from the current resolution of the map 718 var newZoom = (oldExtent) 719 ? this.getZoomForExtent(oldExtent, true) 720 : this.getZoomForResolution(this.resolution, true); 721 722 // zoom and force zoom change 723 this.setCenter(newCenter, newZoom, false, true); 723 724 } 724 725 725 726 this.events.triggerEvent("changebaselayer");
