Centers the map view on a given object. Args: ee_object: The Earth Engine object to center on. zoom: Zoom level to set. max_error: The maximum error for the geometry.
(
self,
ee_object: ee.ComputedObject,
zoom: int | None = None,
max_error: float = 0.001,
)
| 754 | ) from exc |
| 755 | |
| 756 | def center_object( |
| 757 | self, |
| 758 | ee_object: ee.ComputedObject, |
| 759 | zoom: int | None = None, |
| 760 | max_error: float = 0.001, |
| 761 | ) -> None: |
| 762 | """Centers the map view on a given object. |
| 763 | |
| 764 | Args: |
| 765 | ee_object: The Earth Engine object to center on. |
| 766 | zoom: Zoom level to set. |
| 767 | max_error: The maximum error for the geometry. |
| 768 | """ |
| 769 | geometry = self._get_geometry(ee_object, max_error).transform( |
| 770 | maxError=max_error |
| 771 | ) |
| 772 | if zoom is None: |
| 773 | coordinates = geometry.bounds(maxError=max_error).getInfo()["coordinates"][ |
| 774 | 0 |
| 775 | ] |
| 776 | x_vals = [c[0] for c in coordinates] |
| 777 | y_vals = [c[1] for c in coordinates] |
| 778 | self.fit_bounds([[min(y_vals), min(x_vals)], [max(y_vals), max(x_vals)]]) |
| 779 | else: |
| 780 | if not isinstance(zoom, int): |
| 781 | raise ValueError("Zoom must be an integer.") |
| 782 | centroid = geometry.centroid(maxError=max_error).getInfo()["coordinates"] |
| 783 | self.set_center(centroid[0], centroid[1], zoom) |
| 784 | |
| 785 | def _find_widget_of_type( |
| 786 | self, widget_type: type[ipywidgets.Widget], return_control: bool = False |