geemap/geemap.py
def center_object(self, ee_object, zoom=None):
        """Centers the map view on a given object.

        Args:
            ee_object (Element|Geometry): An Earth Engine object to center on a geometry, image or feature.
            zoom (int, optional): The zoom level, from 1 to 24. Defaults to None.
        """
        maxError = 0.001
        if isinstance(ee_object, ee.Geometry):
            geometry = ee_object.transform(maxError=maxError)
        else:
            try:
                geometry = ee_object.geometry(maxError=maxError).transform(
                    maxError=maxError
                )
            except Exception:
                raise Exception(
                    "ee_object must be an instance of one of ee.Geometry, ee.FeatureCollection, ee.Image, or ee.ImageCollection."
                )

        if zoom is not None:
            if not isinstance(zoom, int):
                raise Exception("Zoom must be an integer.")
            else:
                centroid = geometry.centroid(maxError=maxError).getInfo()["coordinates"]
                lat = centroid[1]
                lon = centroid[0]
                self.set_center(lon, lat, zoom)
        else:
            coordinates = geometry.bounds(maxError).getInfo()["coordinates"][0]
            x = [c[0] for c in coordinates]
            y = [c[1] for c in coordinates]
            xmin = min(x)
            xmax = max(x)
            ymin = min(y)
            ymax = max(y)
            bounds = [[ymin, xmin], [ymax, xmax]]
            self.fit_bounds(bounds)
Centers the map view on a given object.

        Args:
            ee_object (Element|Geometry): An Earth Engine object to center on a geometry, image or feature.
            zoom (int, optional): The zoom level, from 1 to 24. Defaults to None.
        
Centers the map view on a given object.
Centers the map view on a given object .
def center_object(self, ee_object, zoom=None):
        maxError = 0.001
        if isinstance(ee_object, ee.Geometry):
            geometry = ee_object.transform(maxError=maxError)
        else:
            try:
                geometry = ee_object.geometry(maxError=maxError).transform(
                    maxError=maxError
                )
            except Exception:
                raise Exception(
                    "ee_object must be an instance of one of ee.Geometry, ee.FeatureCollection, ee.Image, or ee.ImageCollection."
                )
        if zoom is not None:
            if not isinstance(zoom, int):
                raise Exception("Zoom must be an integer.")
            else:
                centroid = geometry.centroid(maxError=maxError).getInfo()["coordinates"]
                lat = centroid[1]
                lon = centroid[0]
                self.set_center(lon, lat, zoom)
        else:
            coordinates = geometry.bounds(maxError).getInfo()["coordinates"][0]
            x = [c[0] for c in coordinates]
            y = [c[1] for c in coordinates]
            xmin = min(x)
            xmax = max(x)
            ymin = min(y)
            ymax = max(y)
            bounds = [[ymin, xmin], [ymax, xmax]]
            self.fit_bounds(bounds)
def center_object ( self , ee_object , zoom = None ) : maxError = 0.001 if isinstance ( ee_object , ee . Geometry ) : geometry = ee_object . transform ( maxError = maxError ) else : try : geometry = ee_object . geometry ( maxError = maxError ) . transform ( maxError = maxError ) except Exception : raise Exception ( "ee_object must be an instance of one of ee.Geometry, ee.FeatureCollection, ee.Image, or ee.ImageCollection." ) if zoom is not None : if not isinstance ( zoom , int ) : raise Exception ( "Zoom must be an integer." ) else : centroid = geometry . centroid ( maxError = maxError ) . getInfo ( ) [ "coordinates" ] lat = centroid [ 1 ] lon = centroid [ 0 ] self . set_center ( lon , lat , zoom ) else : coordinates = geometry . bounds ( maxError ) . getInfo ( ) [ "coordinates" ] [ 0 ] x = [ c [ 0 ] for c in coordinates ] y = [ c [ 1 ] for c in coordinates ] xmin = min ( x ) xmax = max ( x ) ymin = min ( y ) ymax = max ( y ) bounds = [ [ ymin , xmin ] , [ ymax , xmax ] ] self . fit_bounds ( bounds )
Centers the map view on a given object.
Centers the map view on a given object .
"""Centers the map view on a given object.

        Args:
            ee_object (Element|Geometry): An Earth Engine object to center on a geometry, image or feature.
            zoom (int, optional): The zoom level, from 1 to 24. Defaults to None.
        """
self
ee_object
An Earth Engine object to center on a geometry, image or feature.
An Earth Engine object to center on a geometry image or feature .
zoom
The zoom level, from 1 to 24. Defaults to None.
The zoom level from 1 to 24 . Defaults to None .
None