geemap/plotlymap.py
def add_ee_layer(
        self, ee_object, vis_params={}, name=None, shown=True, opacity=1.0, **kwargs
    ):
        """Adds a given EE object to the map as a layer.

        Args:
            ee_object (Collection|Feature|Image|MapId): The object to add to the map.
            vis_params (dict, optional): The visualization parameters. Defaults to {}.
            name (str, optional): The name of the layer. Defaults to 'Layer N'.
            shown (bool, optional): A flag indicating whether the layer should be on by default. Defaults to True.
            opacity (float, optional): The layer's opacity represented as a number between 0 and 1. Defaults to 1.
        """
        from box import Box

        image = None

        if vis_params is None:
            vis_params = {}

        if name is None:
            layer_count = len(self.layout.mapbox.layers)
            name = "Layer " + str(layer_count + 1)

        if (
            not isinstance(ee_object, ee.Image)
            and not isinstance(ee_object, ee.ImageCollection)
            and not isinstance(ee_object, ee.FeatureCollection)
            and not isinstance(ee_object, ee.Feature)
            and not isinstance(ee_object, ee.Geometry)
        ):
            err_str = "\n\nThe image argument in 'addLayer' function must be an instance of one of ee.Image, ee.Geometry, ee.Feature or ee.FeatureCollection."
            raise AttributeError(err_str)

        if (
            isinstance(ee_object, ee.geometry.Geometry)
            or isinstance(ee_object, ee.feature.Feature)
            or isinstance(ee_object, ee.featurecollection.FeatureCollection)
        ):
            features = ee.FeatureCollection(ee_object)

            width = 2

            if "width" in vis_params:
                width = vis_params["width"]

            color = "000000"

            if "color" in vis_params:
                color = vis_params["color"]

            image_fill = features.style(**{"fillColor": color}).updateMask(
                ee.Image.constant(0.5)
            )
            image_outline = features.style(
                **{"color": color, "fillColor": "00000000", "width": width}
            )

            image = image_fill.blend(image_outline)
        elif isinstance(ee_object, ee.image.Image):
            image = ee_object
        elif isinstance(ee_object, ee.imagecollection.ImageCollection):
            image = ee_object.mosaic()

        if "palette" in vis_params and isinstance(vis_params["palette"], Box):
            try:
                vis_params["palette"] = vis_params["palette"]["default"]
            except Exception as e:
                print("The provided palette is invalid.")
                raise Exception(e)

        map_id_dict = ee.Image(image).getMapId(vis_params)
        url = map_id_dict["tile_fetcher"].url_format
        self.add_tile_layer(
            url, name=name, attribution="Google Earth Engine", opacity=opacity, **kwargs
        )
        self.set_layer_visibility(name=name, show=shown)
Adds a given EE object to the map as a layer.

        Args:
            ee_object (Collection|Feature|Image|MapId): The object to add to the map.
            vis_params (dict, optional): The visualization parameters. Defaults to {}.
            name (str, optional): The name of the layer. Defaults to 'Layer N'.
            shown (bool, optional): A flag indicating whether the layer should be on by default. Defaults to True.
            opacity (float, optional): The layer's opacity represented as a number between 0 and 1. Defaults to 1.
        
Adds a given EE object to the map as a layer.
Adds a given EE object to the map as a layer .
def add_ee_layer(
        self, ee_object, vis_params={}, name=None, shown=True, opacity=1.0, **kwargs
    ):
        from box import Box
        image = None
        if vis_params is None:
            vis_params = {}
        if name is None:
            layer_count = len(self.layout.mapbox.layers)
            name = "Layer " + str(layer_count + 1)
        if (
            not isinstance(ee_object, ee.Image)
            and not isinstance(ee_object, ee.ImageCollection)
            and not isinstance(ee_object, ee.FeatureCollection)
            and not isinstance(ee_object, ee.Feature)
            and not isinstance(ee_object, ee.Geometry)
        ):
            err_str = "\n\nThe image argument in 'addLayer' function must be an instance of one of ee.Image, ee.Geometry, ee.Feature or ee.FeatureCollection."
            raise AttributeError(err_str)
        if (
            isinstance(ee_object, ee.geometry.Geometry)
            or isinstance(ee_object, ee.feature.Feature)
            or isinstance(ee_object, ee.featurecollection.FeatureCollection)
        ):
            features = ee.FeatureCollection(ee_object)
            width = 2
            if "width" in vis_params:
                width = vis_params["width"]
            color = "000000"
            if "color" in vis_params:
                color = vis_params["color"]
            image_fill = features.style(**{"fillColor": color}).updateMask(
                ee.Image.constant(0.5)
            )
            image_outline = features.style(
                **{"color": color, "fillColor": "00000000", "width": width}
            )
            image = image_fill.blend(image_outline)
        elif isinstance(ee_object, ee.image.Image):
            image = ee_object
        elif isinstance(ee_object, ee.imagecollection.ImageCollection):
            image = ee_object.mosaic()
        if "palette" in vis_params and isinstance(vis_params["palette"], Box):
            try:
                vis_params["palette"] = vis_params["palette"]["default"]
            except Exception as e:
                print("The provided palette is invalid.")
                raise Exception(e)
        map_id_dict = ee.Image(image).getMapId(vis_params)
        url = map_id_dict["tile_fetcher"].url_format
        self.add_tile_layer(
            url, name=name, attribution="Google Earth Engine", opacity=opacity, **kwargs
        )
        self.set_layer_visibility(name=name, show=shown)
def add_ee_layer ( self , ee_object , vis_params = { } , name = None , shown = True , opacity = 1.0 , ** kwargs ) : from box import Box image = None if vis_params is None : vis_params = { } if name is None : layer_count = len ( self . layout . mapbox . layers ) name = "Layer " + str ( layer_count + 1 ) if ( not isinstance ( ee_object , ee . Image ) and not isinstance ( ee_object , ee . ImageCollection ) and not isinstance ( ee_object , ee . FeatureCollection ) and not isinstance ( ee_object , ee . Feature ) and not isinstance ( ee_object , ee . Geometry ) ) : err_str = "\n\nThe image argument in 'addLayer' function must be an instance of one of ee.Image, ee.Geometry, ee.Feature or ee.FeatureCollection." raise AttributeError ( err_str ) if ( isinstance ( ee_object , ee . geometry . Geometry ) or isinstance ( ee_object , ee . feature . Feature ) or isinstance ( ee_object , ee . featurecollection . FeatureCollection ) ) : features = ee . FeatureCollection ( ee_object ) width = 2 if "width" in vis_params : width = vis_params [ "width" ] color = "000000" if "color" in vis_params : color = vis_params [ "color" ] image_fill = features . style ( ** { "fillColor" : color } ) . updateMask ( ee . Image . constant ( 0.5 ) ) image_outline = features . style ( ** { "color" : color , "fillColor" : "00000000" , "width" : width } ) image = image_fill . blend ( image_outline ) elif isinstance ( ee_object , ee . image . Image ) : image = ee_object elif isinstance ( ee_object , ee . imagecollection . ImageCollection ) : image = ee_object . mosaic ( ) if "palette" in vis_params and isinstance ( vis_params [ "palette" ] , Box ) : try : vis_params [ "palette" ] = vis_params [ "palette" ] [ "default" ] except Exception as e : print ( "The provided palette is invalid." ) raise Exception ( e ) map_id_dict = ee . Image ( image ) . getMapId ( vis_params ) url = map_id_dict [ "tile_fetcher" ] . url_format self . add_tile_layer ( url , name = name , attribution = "Google Earth Engine" , opacity = opacity , ** kwargs ) self . set_layer_visibility ( name = name , show = shown )
Adds a given EE object to the map as a layer.
Adds a given EE object to the map as a layer .
"""Adds a given EE object to the map as a layer.

        Args:
            ee_object (Collection|Feature|Image|MapId): The object to add to the map.
            vis_params (dict, optional): The visualization parameters. Defaults to {}.
            name (str, optional): The name of the layer. Defaults to 'Layer N'.
            shown (bool, optional): A flag indicating whether the layer should be on by default. Defaults to True.
            opacity (float, optional): The layer's opacity represented as a number between 0 and 1. Defaults to 1.
        """
self
ee_object
The object to add to the map.
The object to add to the map .
vis_params
The visualization parameters. Defaults to {}.
The visualization parameters . Defaults to {} .
{}
name
The name of the layer. Defaults to 'Layer N'.
The name of the layer . Defaults to ' Layer N ' .
'Layer N'
shown
A flag indicating whether the layer should be on by default. Defaults to True.
A flag indicating whether the layer should be on by default . Defaults to True .
True
opacity
The layer's opacity represented as a number between 0 and 1. Defaults to 1.
The layer ' s opacity represented as a number between 0 and 1 . Defaults to 1 .
1