From 767e0e7ab6ed9cc0719f8b76a68027f396a211e5 Mon Sep 17 00:00:00 2001 From: Qiusheng Wu Date: Fri, 19 Jul 2024 15:54:07 -0400 Subject: [PATCH] Fix add raster fit_bounds bug (#836) * Fix add raster bug * Fix Layer Editor bug --- leafmap/leafmap.py | 13 ++----------- leafmap/map_widgets.py | 28 ++++++++++++++-------------- 2 files changed, 16 insertions(+), 25 deletions(-) diff --git a/leafmap/leafmap.py b/leafmap/leafmap.py index 048672ff1c..85cb4f39c0 100644 --- a/leafmap/leafmap.py +++ b/leafmap/leafmap.py @@ -2369,19 +2369,11 @@ def add_raster( tile_layer.visible = visible self.add(tile_layer, index=layer_index) - bounds = tile_client.bounds() # [ymin, ymax, xmin, xmax] - bounds = ( - bounds[2], - bounds[0], - bounds[3], - bounds[1], - ) # [minx, miny, maxx, maxy] if zoom_to_layer: - self.zoom_to_bounds(bounds) + self.center = tile_client.center() + self.zoom = tile_client.default_zoom arc_add_layer(tile_layer.url, layer_name, True, 1.0) - if zoom_to_layer: - arc_zoom_to_extent(bounds[0], bounds[1], bounds[2], bounds[3]) if not hasattr(self, "cog_layer_dict"): self.cog_layer_dict = {} @@ -2400,7 +2392,6 @@ def add_raster( "indexes": indexes, "vis_bands": vis_bands, "band_names": tile_client.band_names, - "bounds": bounds, "vmin": vmin, "vmax": vmax, "nodata": nodata, diff --git a/leafmap/map_widgets.py b/leafmap/map_widgets.py index 2937e49695..f790a72a17 100644 --- a/leafmap/map_widgets.py +++ b/leafmap/map_widgets.py @@ -867,8 +867,21 @@ def on_apply_click(self): self._host_map.remove(old_layer) + if self._layer_dict["type"] == "LOCAL": + self._host_map.add_raster( + self._filename, + indexes=vis["indexes"], + colormap=vis["colormap"], + vmin=vis["vmin"], + vmax=vis["vmax"], + opacity=vis["opacity"], + nodata=self._nodata, + layer_name=self._layer_name, + zoom_to_layer=False, + layer_index=layer_index, + ) # Add support for hyperspectral data via HyperCoast - if self._xds is not None: + elif self._xds is not None: self._host_map.add_hyper( self._xds, type=self._layer_dict["hyper"], @@ -907,19 +920,6 @@ def on_apply_click(self): fit_bounds=False, layer_index=layer_index, ) - else: - self._host_map.add_raster( - self._filename, - indexes=vis["indexes"], - colormap=vis["colormap"], - vmin=vis["vmin"], - vmax=vis["vmax"], - opacity=vis["opacity"], - nodata=self._nodata, - layer_name=self._layer_name, - zoom_to_layer=False, - layer_index=layer_index, - ) def _remove_control(key): if widget := self._layer_dict.get(key, None):