* extentZoom * Returns the maximum zoom that will fit the given extent in the map viewport. * @param extent Extent Object to fit * @param dimensions? Array [width, height] to fit it in (defaults to viewport) * @return zoom
(extent, dimensions)
| 900 | * @return zoom |
| 901 | */ |
| 902 | extentZoom(extent, dimensions) { |
| 903 | const viewport = this.context.viewport; |
| 904 | const [w, h] = dimensions || viewport.dimensions; |
| 905 | |
| 906 | const tl = viewport.project([extent.min[0], extent.max[1]]); |
| 907 | const br = viewport.project([extent.max[0], extent.min[1]]); |
| 908 | |
| 909 | // Calculate maximum zoom that fits extent |
| 910 | const hFactor = (br[0] - tl[0]) / w; |
| 911 | const vFactor = (br[1] - tl[1]) / h; |
| 912 | const hZoomDiff = Math.log(Math.abs(hFactor)) / Math.LN2; |
| 913 | const vZoomDiff = Math.log(Math.abs(vFactor)) / Math.LN2; |
| 914 | const zoomDiff = Math.max(hZoomDiff, vZoomDiff); |
| 915 | |
| 916 | const currZoom = viewport.transform.zoom; |
| 917 | const defaultZoom = Math.max(currZoom, 19); |
| 918 | |
| 919 | return isFinite(zoomDiff) ? (currZoom - zoomDiff) : defaultZoom; |
| 920 | } |
| 921 | |
| 922 | |
| 923 | /** |
no outgoing calls
no test coverage detected