Get the mapbox zoom level given bounds and a figure dimension Source: https://stackoverflow.com/questions/6048975/google-maps-v3-how-to-calculate-the-zoom-level-for-a-given-bounds
(lon_min, lon_max, lat_min, lat_max, mapDim)
| 25 | |
| 26 | |
| 27 | def _getBoundsZoomLevel(lon_min, lon_max, lat_min, lat_max, mapDim): |
| 28 | """ |
| 29 | Get the mapbox zoom level given bounds and a figure dimension |
| 30 | Source: https://stackoverflow.com/questions/6048975/google-maps-v3-how-to-calculate-the-zoom-level-for-a-given-bounds |
| 31 | """ |
| 32 | |
| 33 | scale = ( |
| 34 | 2 # adjustment to reflect MapBox base tiles are 512x512 vs. Google's 256x256 |
| 35 | ) |
| 36 | WORLD_DIM = {"height": 256 * scale, "width": 256 * scale} |
| 37 | ZOOM_MAX = 18 |
| 38 | |
| 39 | def latRad(lat): |
| 40 | sin = np.sin(lat * np.pi / 180) |
| 41 | radX2 = np.log((1 + sin) / (1 - sin)) / 2 |
| 42 | return max(min(radX2, np.pi), -np.pi) / 2 |
| 43 | |
| 44 | def zoom(mapPx, worldPx, fraction): |
| 45 | return 0.95 * np.log(mapPx / worldPx / fraction) / np.log(2) |
| 46 | |
| 47 | latFraction = (latRad(lat_max) - latRad(lat_min)) / np.pi |
| 48 | |
| 49 | lngDiff = lon_max - lon_min |
| 50 | lngFraction = ((lngDiff + 360) if lngDiff < 0 else lngDiff) / 360 |
| 51 | |
| 52 | latZoom = zoom(mapDim["height"], WORLD_DIM["height"], latFraction) |
| 53 | lngZoom = zoom(mapDim["width"], WORLD_DIM["width"], lngFraction) |
| 54 | |
| 55 | return min(latZoom, lngZoom, ZOOM_MAX) |
| 56 | |
| 57 | |
| 58 | def _compute_hexbin(x, y, x_range, y_range, color, nx, agg_func, min_count): |
no test coverage detected