Skip to content

Commit

Permalink
Fixed vis_param palette validation (gee-community#1613)
Browse files Browse the repository at this point in the history
* Use validated palette in EELeafletTileLayer

* Make dict copy; don't modify original
  • Loading branch information
jdbcode authored Jul 7, 2023
1 parent 161c961 commit 3deafea
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions geemap/ee_tile_layers.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,16 @@ def _get_tile_url_format(ee_object, vis_params):
def _validate_vis_params(vis_params):
if vis_params is None:
return {}
if "palette" in vis_params:
vis_params["palette"] = _validate_palette(vis_params["palette"])
return vis_params

if not isinstance(vis_params, dict):
raise TypeError("vis_params must be a dictionary")

valid_dict = vis_params.copy()

if "palette" in valid_dict:
valid_dict["palette"] = _validate_palette(valid_dict["palette"])

return valid_dict


def _ee_object_to_image(ee_object, vis_params):
Expand Down Expand Up @@ -56,7 +63,7 @@ def _validate_palette(palette):
if isinstance(palette, box.Box):
if "default" not in palette:
raise ValueError("The provided palette Box object is invalid.")
return palette["default"]
return list(palette["default"])
if isinstance(palette, str):
return common.check_cmap(palette)
if isinstance(palette, list):
Expand Down Expand Up @@ -128,7 +135,7 @@ def __init__(
opacity (float, optional): The layer's opacity represented as a number between 0 and 1. Defaults to 1.
"""
self.vis_params = _validate_vis_params(vis_params)
self.url_format = _get_tile_url_format(ee_object, vis_params)
self.url_format = _get_tile_url_format(ee_object, self.vis_params)
super().__init__(
url=self.url_format,
attribution="Google Earth Engine",
Expand Down

0 comments on commit 3deafea

Please sign in to comment.