Centers the map view on a given object. Args: ee_object: An Earth Engine object to center on a geometry, image or feature. zoom: The zoom level, from 1 to 24. max_error: The maximum error for the geometry.
(
self,
ee_object: ee.ComputedObject,
zoom: int | None = None,
max_error: float = 0.001,
)
| 355 | self.zoom_to_bounds(bounds) |
| 356 | |
| 357 | def center_object( |
| 358 | self, |
| 359 | ee_object: ee.ComputedObject, |
| 360 | zoom: int | None = None, |
| 361 | max_error: float = 0.001, |
| 362 | ) -> None: |
| 363 | """Centers the map view on a given object. |
| 364 | |
| 365 | Args: |
| 366 | ee_object: An Earth Engine object to center on a geometry, image or feature. |
| 367 | zoom: The zoom level, from 1 to 24. |
| 368 | max_error: The maximum error for the geometry. |
| 369 | """ |
| 370 | if isinstance(ee_object, ee.Geometry): |
| 371 | geometry = ee_object.transform(maxError=max_error) |
| 372 | else: |
| 373 | try: |
| 374 | geometry = ee_object.geometry(maxError=max_error).transform( |
| 375 | maxError=max_error |
| 376 | ) |
| 377 | except Exception: |
| 378 | raise Exception( |
| 379 | "ee_object must be an instance of one of ee.Geometry, " |
| 380 | "ee.FeatureCollection, ee.Image, or ee.ImageCollection." |
| 381 | ) |
| 382 | |
| 383 | if zoom is not None: |
| 384 | if not isinstance(zoom, int): |
| 385 | raise Exception("Zoom must be an integer.") |
| 386 | |
| 387 | centroid = geometry.centroid(maxError=max_error).getInfo()["coordinates"] |
| 388 | lat = centroid[1] |
| 389 | lon = centroid[0] |
| 390 | self.set_center(lon, lat, zoom) |
| 391 | |
| 392 | if is_arcpy(): |
| 393 | arc_zoom_to_extent(lon, lat, lon, lat) |
| 394 | |
| 395 | else: |
| 396 | coordinates = geometry.bounds(maxError=max_error).getInfo()["coordinates"][ |
| 397 | 0 |
| 398 | ] |
| 399 | x = [c[0] for c in coordinates] |
| 400 | y = [c[1] for c in coordinates] |
| 401 | xmin = min(x) |
| 402 | xmax = max(x) |
| 403 | ymin = min(y) |
| 404 | ymax = max(y) |
| 405 | bounds = [[ymin, xmin], [ymax, xmax]] |
| 406 | self.fit_bounds(bounds) |
| 407 | |
| 408 | if is_arcpy(): |
| 409 | arc_zoom_to_extent(xmin, ymin, xmax, ymax) |
| 410 | |
| 411 | centerObject = center_object |
| 412 |
nothing calls this directly
no test coverage detected