Skip to content

Commit

Permalink
Improved to_html function gee-community#361
Browse files Browse the repository at this point in the history
  • Loading branch information
giswqs committed Mar 14, 2021
1 parent aacc6ca commit 339f8be
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
4 changes: 2 additions & 2 deletions docs/notebooks/21_export_map_to_html_png.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@
"metadata": {},
"outputs": [],
"source": [
"Map = geemap.Map(toolbar_ctrl=True)\n",
"Map = geemap.Map(toolbar_ctrl=True, layer_ctrl=True)\n",
"Map"
]
},
Expand All @@ -122,7 +122,7 @@
"# Add Earth Eninge layers to Map\n",
"Map.addLayer(dem, vis_params, 'SRTM DEM', True, 0.5)\n",
"Map.addLayer(landcover, {}, 'Land cover')\n",
"Map.addLayer(landsat7, {'bands': ['B4', 'B3', 'B2'], 'min': 20, 'max': 200}, 'Landsat 7')\n",
"Map.addLayer(landsat7, {'bands': ['B4', 'B3', 'B2'], 'min': 20, 'max': 200, 'gamma':1.5}, 'Landsat 7')\n",
"Map.addLayer(states, {}, \"US States\")"
]
},
Expand Down
4 changes: 2 additions & 2 deletions examples/notebooks/21_export_map_to_html_png.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@
"metadata": {},
"outputs": [],
"source": [
"Map = geemap.Map(toolbar_ctrl=True)\n",
"Map = geemap.Map(toolbar_ctrl=True, layer_ctrl=True)\n",
"Map"
]
},
Expand All @@ -122,7 +122,7 @@
"# Add Earth Eninge layers to Map\n",
"Map.addLayer(dem, vis_params, 'SRTM DEM', True, 0.5)\n",
"Map.addLayer(landcover, {}, 'Land cover')\n",
"Map.addLayer(landsat7, {'bands': ['B4', 'B3', 'B2'], 'min': 20, 'max': 200}, 'Landsat 7')\n",
"Map.addLayer(landsat7, {'bands': ['B4', 'B3', 'B2'], 'min': 20, 'max': 200, 'gamma':1.5}, 'Landsat 7')\n",
"Map.addLayer(states, {}, \"US States\")"
]
},
Expand Down
16 changes: 15 additions & 1 deletion geemap/geemap.py
Original file line number Diff line number Diff line change
Expand Up @@ -2960,14 +2960,23 @@ def add_landsat_ts_gif(
except Exception as e:
raise Exception(e)

def to_html(self, outfile, title="My Map", width="100%", height="880px"):
def to_html(
self,
outfile,
title="My Map",
width="100%",
height="880px",
add_layer_control=True,
):
"""Saves the map as a HTML file.
Args:
outfile (str): The output file path to the HTML file.
title (str, optional): The title of the HTML file. Defaults to 'My Map'.
width (str, optional): The width of the map in pixels or percentage. Defaults to '100%'.
height (str, optional): The height of the map in pixels. Defaults to '880px'.
add_layer_control (bool, optional): Whether to add the LayersControl. Defaults to True.
"""
try:

Expand All @@ -2979,6 +2988,11 @@ def to_html(self, outfile, title="My Map", width="100%", height="880px"):
if not os.path.exists(out_dir):
os.makedirs(out_dir)

if add_layer_control and self.layer_control is None:
layer_control = ipyleaflet.LayersControl(position="topright")
self.layer_control = layer_control
self.add_control(layer_control)

before_width = self.layout.width
before_height = self.layout.height

Expand Down

0 comments on commit 339f8be

Please sign in to comment.