From 2b6dfad687858785d002b18aa1ff810c61540841 Mon Sep 17 00:00:00 2001 From: Qiusheng Wu Date: Wed, 11 Sep 2024 08:58:47 -0500 Subject: [PATCH] Fix pylint errors (#888) * Fix pylint errors * Fix layer manager issue --- leafmap/__init__.py | 41 +++++----- leafmap/basemaps.py | 14 ++-- leafmap/bokehmap.py | 4 +- leafmap/common.py | 168 ++++++----------------------------------- leafmap/foliumap.py | 113 ++------------------------- leafmap/leafmap.py | 113 ++------------------------- leafmap/map_widgets.py | 8 +- leafmap/maplibregl.py | 2 +- leafmap/plotlymap.py | 4 +- leafmap/toolbar.py | 4 +- tests/test_foliumap.py | 10 --- tests/test_leafmap.py | 9 --- 12 files changed, 77 insertions(+), 413 deletions(-) diff --git a/leafmap/__init__.py b/leafmap/__init__.py index eb9f348c33..c3a3b8b487 100644 --- a/leafmap/__init__.py +++ b/leafmap/__init__.py @@ -42,25 +42,25 @@ def view_vector( """Visualize a vector dataset on the map. Args: - vector (Union[str, GeoDataFrame]): The file path or URL to the vector data, or a GeoDataFrame. - zoom_to_layer (bool, optional): Flag to zoom to the added layer. Defaults to True. - pickable (bool, optional): Flag to enable picking on the added layer. Defaults to True. - color_column (Optional[str], optional): The column to be used for color encoding. Defaults to None. - color_map (Optional[Union[str, Dict]], optional): The color map to use for color encoding. It can be a string or a dictionary. Defaults to None. - color_scheme (Optional[str], optional): The color scheme to use for color encoding. Defaults to "Quantiles". - Name of a choropleth classification scheme (requires mapclassify). - A mapclassify.MapClassifier object will be used - under the hood. Supported are all schemes provided by mapclassify (e.g. - 'BoxPlot', 'EqualInterval', 'FisherJenks', 'FisherJenksSampled', - 'HeadTailBreaks', 'JenksCaspall', 'JenksCaspallForced', - 'JenksCaspallSampled', 'MaxP', 'MaximumBreaks', - 'NaturalBreaks', 'Quantiles', 'Percentiles', 'StdMean', - 'UserDefined'). Arguments can be passed in classification_kwds. - color_k (Optional[int], optional): The number of classes to use for color encoding. Defaults to 5. - color_args (dict, optional): Additional keyword arguments that will be passed to assign_continuous_colors(). Defaults to {}. - open_args (dict, optional): Additional keyword arguments that will be passed to geopandas.read_file(). Defaults to {}. - map_args (dict, optional): Additional keyword arguments that will be passed to lonboard.Map. Defaults to {}. - **kwargs: Additional keyword arguments that will be passed to lonboard.Layer.from_geopandas() + vector (Union[str, GeoDataFrame]): The file path or URL to the vector data, or a GeoDataFrame. + zoom_to_layer (bool, optional): Flag to zoom to the added layer. Defaults to True. + pickable (bool, optional): Flag to enable picking on the added layer. Defaults to True. + color_column (Optional[str], optional): The column to be used for color encoding. Defaults to None. + color_map (Optional[Union[str, Dict]], optional): The color map to use for color encoding. It can be a string or a dictionary. Defaults to None. + color_scheme (Optional[str], optional): The color scheme to use for color encoding. Defaults to "Quantiles". + Name of a choropleth classification scheme (requires mapclassify). + A mapclassify.MapClassifier object will be used + under the hood. Supported are all schemes provided by mapclassify (e.g. + 'BoxPlot', 'EqualInterval', 'FisherJenks', 'FisherJenksSampled', + 'HeadTailBreaks', 'JenksCaspall', 'JenksCaspallForced', + 'JenksCaspallSampled', 'MaxP', 'MaximumBreaks', + 'NaturalBreaks', 'Quantiles', 'Percentiles', 'StdMean', + 'UserDefined'). Arguments can be passed in classification_kwds. + color_k (Optional[int], optional): The number of classes to use for color encoding. Defaults to 5. + color_args (dict, optional): Additional keyword arguments that will be passed to assign_continuous_colors(). Defaults to {}. + open_args (dict, optional): Additional keyword arguments that will be passed to geopandas.read_file(). Defaults to {}. + map_args (dict, optional): Additional keyword arguments that will be passed to lonboard.Map. Defaults to {}. + **kwargs: Additional keyword arguments that will be passed to lonboard.Layer.from_geopandas() Returns: lonboard.Map: A lonboard Map object. @@ -95,8 +95,7 @@ def view_pmtiles( map_args={}, **kwargs, ): - """ - Visualize PMTiles the map. + """Visualize PMTiles the map. Args: url (str): The URL of the PMTiles file. diff --git a/leafmap/basemaps.py b/leafmap/basemaps.py index 1ca34ed683..12b14019db 100644 --- a/leafmap/basemaps.py +++ b/leafmap/basemaps.py @@ -317,12 +317,12 @@ def xyz_to_leaflet(): # Add custom tiles. for tile_type, tile_dict in custom_tiles.items(): - for tile_provider, tile_info in tile_dict.items(): + for _, tile_info in tile_dict.items(): tile_info["type"] = tile_type leaflet_dict[tile_info["name"]] = tile_info # Add xyzservices.provider tiles. - for tile_provider, tile_info in get_xyz_dict().items(): + for _, tile_info in get_xyz_dict().items(): if tile_info["name"] in ignore_list: continue tile_info["url"] = tile_info.build_url() @@ -490,17 +490,19 @@ def xyz_to_bokeh(): return bokeh_dict -def search_qms(keywords, limit=10): +def search_qms(keywords, limit=10, timeout=600): """Search qms files for keywords. Reference: https://github.com/geopandas/xyzservices/issues/65 Args: keywords (str): Keywords to search for. limit (int): Number of results to return. + """ QMS_API = "https://qms.nextgis.com/api/v1/geoservices" services = requests.get( - f"{QMS_API}/?search={keywords}&type=tms&epsg=3857&limit={str(limit)}" + f"{QMS_API}/?search={keywords}&type=tms&epsg=3857&limit={str(limit)}", + timeout=timeout, ) services = services.json() if services["count"] == 0: @@ -511,9 +513,9 @@ def search_qms(keywords, limit=10): return services["results"][:limit] -def get_qms(service_id): +def get_qms(service_id, timeout=60): QMS_API = "https://qms.nextgis.com/api/v1/geoservices" - service_details = requests.get(f"{QMS_API}/{service_id}") + service_details = requests.get(f"{QMS_API}/{service_id}", timeout=timeout) return service_details.json() diff --git a/leafmap/bokehmap.py b/leafmap/bokehmap.py index 9b87409e9e..155652571a 100644 --- a/leafmap/bokehmap.py +++ b/leafmap/bokehmap.py @@ -6,7 +6,7 @@ from bokeh.io import output_notebook from .basemaps import xyz_to_bokeh from .common import * -from typing import Optional, List, Sequence, Tuple, Dict +from typing import Optional, List, Dict os.environ["OUTPUT_NOTEBOOK"] = "False" basemaps = Box(xyz_to_bokeh(), frozen_box=True) @@ -477,7 +477,7 @@ def to_streamlit( use_container_width (bool, optional): A flag indicating whether to use the full width of the container. Defaults to True. **kwargs: Arbitrary keyword arguments for bokeh.plotting.show(). """ - import streamlit as st + import streamlit as st # pylint: disable=E0401 self.figure.width = width self.figure.height = height diff --git a/leafmap/common.py b/leafmap/common.py index 79a1bbf3b8..0d7c5a28c9 100644 --- a/leafmap/common.py +++ b/leafmap/common.py @@ -667,33 +667,6 @@ def safe_extract( print("Data downloaded to: {}".format(final_path)) -def download_from_gdrive(gfile_url, file_name, out_dir=".", unzip=True, verbose=True): - """Download a file shared via Google Drive - (e.g., https://drive.google.com/file/d/18SUo_HcDGltuWYZs1s7PpOmOq_FvFn04/view?usp=sharing) - - Args: - gfile_url (str): The Google Drive shared file URL - file_name (str): The output file name to use. - out_dir (str, optional): The output directory. Defaults to '.'. - unzip (bool, optional): Whether to unzip the output file if it is a zip file. Defaults to True. - verbose (bool, optional): Whether to display or not the output of the function - """ - try: - from google_drive_downloader import GoogleDriveDownloader as gdd - except ImportError: - raise ImportError( - 'Please install googledrivedownloader using "pip install googledrivedownloader"' - ) - - file_id = gfile_url.split("/")[5] - if verbose: - print("Google Drive file id: {}".format(file_id)) - - out_dir = check_dir(out_dir) - dest_path = os.path.join(out_dir, file_name) - gdd.download_file_from_google_drive(file_id, dest_path, True, unzip) - - def create_download_link(filename, title="Click here to download: "): """Downloads a file from voila. Adopted from https://github.com/voila-dashboards/voila/issues/578 @@ -1813,7 +1786,7 @@ def get_api_key(name: Optional[str] = None, key: Optional[str] = None) -> Option return key elif name is not None: if _in_colab_shell(): - from google.colab import userdata + from google.colab import userdata # pylint: disable=E0611 try: return userdata.get(name) @@ -3278,8 +3251,8 @@ def html_to_streamlit( """ try: - import streamlit as st - import streamlit.components.v1 as components + import streamlit as st # pylint: disable=E0401 + import streamlit.components.v1 as components # pylint: disable=E0401 if isinstance(html, str): temp_path = None @@ -5518,40 +5491,6 @@ def add_crs(filename, epsg): src.crs = crs -def html_to_streamlit( - filename, width=None, height=None, scrolling=False, replace_dict={} -): - """Renders an HTML file as a Streamlit component. - Args: - filename (str): The filename of the HTML file. - width (int, optional): Width of the map. Defaults to None. - height (int, optional): Height of the map. Defaults to 600. - scrolling (bool, optional): Whether to allow the map to scroll. Defaults to False. - replace_dict (dict, optional): A dictionary of strings to replace in the HTML file. Defaults to {}. - - Raises: - ValueError: If the filename does not exist. - - Returns: - streamlit.components: components.html object. - """ - - import streamlit.components.v1 as components - - if not os.path.exists(filename): - raise ValueError("filename must exist.") - - f = open(filename, "r") - - html = f.read() - - for key, value in replace_dict.items(): - html = html.replace(key, value) - - f.close() - return components.html(html, width=width, height=height, scrolling=scrolling) - - class The_national_map_USGS: """ The national map is a collection of topological datasets, maintained by the USGS. @@ -6796,7 +6735,7 @@ async def download_file_lite(url, output=None, binary=False, overwrite=False, ** overwrite (bool, optional): Whether to overwrite the file if it exists. Defaults to False. """ import sys - import pyodide + import pyodide # pylint: disable=E0401 if "pyodide" not in sys.modules: raise ValueError("Pyodide is not available.") @@ -8261,7 +8200,7 @@ def arc_active_map(): arcpy.Map: The active map in ArcGIS Pro. """ if is_arcpy(): - import arcpy + import arcpy # pylint: disable=E0401 aprx = arcpy.mp.ArcGISProject("CURRENT") m = aprx.activeMap @@ -8277,7 +8216,7 @@ def arc_active_view(): arcpy.MapView: The active view in ArcGIS Pro. """ if is_arcpy(): - import arcpy + import arcpy # pylint: disable=E0401 aprx = arcpy.mp.ArcGISProject("CURRENT") view = aprx.activeView @@ -8318,7 +8257,7 @@ def arc_zoom_to_extent(xmin, ymin, xmax, ymax): ymax (float): The maximum y value of the extent. """ if is_arcpy(): - import arcpy + import arcpy # pylint: disable=E0401 view = arc_active_view() if view is not None: @@ -9164,8 +9103,12 @@ def transform_bbox_coords(bbox, src_crs, dst_crs, **kwargs): """ x1, y1, x2, y2 = bbox - x1, y1 = transform_coords(x1, y1, src_crs, dst_crs, **kwargs) - x2, y2 = transform_coords(x2, y2, src_crs, dst_crs, **kwargs) + x1, y1 = transform_coords( + x1, y1, src_crs, dst_crs, **kwargs + ) # pylint: disable=E0633 + x2, y2 = transform_coords( + x2, y2, src_crs, dst_crs, **kwargs + ) # pylint: disable=E0633 return [x1, y1, x2, y2] @@ -9209,7 +9152,9 @@ def coords_to_xy( width = src.width height = src.height if coord_crs != src.crs: - xs, ys = transform_coords(xs, ys, coord_crs, src.crs, **kwargs) + xs, ys = transform_coords( + xs, ys, coord_crs, src.crs, **kwargs + ) # pylint: disable=E0633 rows, cols = rasterio.transform.rowcol(src.transform, xs, ys, **kwargs) result = [[col, row] for col, row in zip(cols, rows)] @@ -9830,26 +9775,6 @@ def pillow_local_file_to_base64(image: Image.Image, temp_dir: str): display(HTML(htmlcode)) -def display_html(filename, width="100%", height="600px", **kwargs): - """Show an HTML file in a Jupyter notebook. - - Args: - filename (str): The path to the HTML file. - width (str, optional): The width of the HTML file. Defaults to "100%". - height (str, optional): The height of the HTML file. Defaults to "600px". - - Returns: - IFrame: An IFrame object. - """ - - from IPython.display import IFrame - - if not os.path.exists(filename): - raise Exception(f"File {filename} does not exist") - - return IFrame(filename, width=width, height=height, **kwargs) - - def get_nhd_basins( feature_ids, fsource="nwissite", @@ -12800,14 +12725,20 @@ def gedi_subset( """ try: - import harmony + import harmony # pylint: disable=E0401 except ImportError: install_package("harmony-py") import requests as re import geopandas as gpd from datetime import datetime - from harmony import BBox, Client, Collection, Environment, Request + from harmony import ( + BBox, + Client, + Collection, + Environment, + Request, + ) # pylint: disable=E0401 if out_dir is None: out_dir = os.getcwd() @@ -13426,7 +13357,7 @@ def convert_coordinates(x, y, source_crs, target_crs="epsg:4326"): transformer = pyproj.Transformer.from_crs(source_crs, target_crs, always_xy=True) # Perform the transformation - lon, lat = transformer.transform(x, y) + lon, lat = transformer.transform(x, y) # pylint: disable=E0633 # Return the converted coordinates return lon, lat @@ -13823,55 +13754,6 @@ def github_get_release_id_by_tag(username, repository, tag_name, access_token=No return None -def github_upload_asset_to_release( - username, repository, release_id, asset_path, access_token=None -): - """ - Uploads an asset to a GitHub release. - - Args: - username (str): GitHub username or organization name. - repository (str): Name of the GitHub repository. - release_id (int): ID of the release to upload the asset to. - asset_path (str): Path to the asset file. - access_token (str): Personal access token for authentication. - - Returns: - dict: The response JSON from the GitHub API if the upload is successful. - None: If the upload fails. - """ - if access_token is None: - access_token = get_api_key("GITHUB_API_TOKEN") - # GitHub API URL for uploading release assets - url = f"https://uploads.github.com/repos/{username}/{repository}/releases/{release_id}/assets" - - # Extract the filename from the asset path - asset_name = os.path.basename(asset_path) - - # Set the headers for the upload request - headers = { - "Authorization": f"token {access_token}", - "Content-Type": "application/octet-stream", - } - - # Set the parameters for the upload request - params = {"name": asset_name} - - # Open the asset file in binary mode - with open(asset_path, "rb") as asset_file: - # Make the request to upload the asset - response = requests.post(url, headers=headers, params=params, data=asset_file) - - # Check if the request was successful - if response.status_code == 201: - print(f"Successfully uploaded asset: {asset_name}") - return response.json() - else: - print(f"Error: Unable to upload asset (Status code: {response.status_code})") - print(response.json()) - return None - - def github_get_release_assets(username, repository, release_id, access_token=None): """ Fetches the assets for a given release. diff --git a/leafmap/foliumap.py b/leafmap/foliumap.py index 5be1f4c374..a495a36978 100644 --- a/leafmap/foliumap.py +++ b/leafmap/foliumap.py @@ -1418,7 +1418,7 @@ def add_geojson( if isinstance(in_geojson, str): if in_geojson.startswith("http"): if is_jupyterlite(): - import pyodide + import pyodide # pylint: disable=E0401 output = os.path.basename(in_geojson) @@ -1727,72 +1727,6 @@ def add_planet_by_quarter( ) layer.add_to(self) - def publish( - self, - name: Optional[str] = "Folium Map", - description: Optional[str] = "", - source_url: Optional[str] = "", - tags: Optional[List] = None, - source_file: Optional[str] = None, - open: Optional[bool] = True, - formatting=None, - token: Optional[str] = None, - **kwargs, - ): - """Publish the map to datapane.com - - Args: - name (str, optional): The document name - can include spaces, caps, symbols, etc., e.g. "Profit & Loss 2020". Defaults to "Folium Map". - description (str, optional): A high-level description for the document, this is displayed in searches and thumbnails. Defaults to ''. - source_url (str, optional): A URL pointing to the source code for the document, e.g. a GitHub repo or a Colab notebook. Defaults to ''. - tags (list, optional): A list of tags (as strings) used to categorise your document. Defaults to None. - source_file (str, optional): Path of jupyter notebook file to upload. Defaults to None. - open (bool, optional): Whether to open the map. Defaults to True. - formatting (ReportFormatting, optional): Set the basic styling for your report. - token (str, optional): The token to use to datapane to publish the map. See https://docs.datapane.com/tut-getting-started. Defaults to None. - """ - import webbrowser - import warnings - - if os.environ.get("USE_MKDOCS") is not None: - return - - warnings.filterwarnings("ignore") - try: - import datapane as dp - except Exception: - webbrowser.open_new_tab("https://docs.datapane.com/") - raise ImportError( - "The datapane Python package is not installed. You need to install and authenticate datapane first." - ) - - if token is None: - try: - _ = dp.ping(verbose=False) - except Exception as e: - if os.environ.get("DP_TOKEN") is not None: - dp.login(token=os.environ.get("DP_TOKEN")) - else: - raise Exception(e) - else: - dp.login(token) - - try: - dp.upload_report( - dp.Plot(self), - name=name, - description=description, - source_url=source_url, - tags=tags, - source_file=source_file, - open=open, - formatting=formatting, - **kwargs, - ) - - except Exception as e: - raise Exception(e) - def to_html(self, outfile: Optional[str] = None, **kwargs) -> str: """Exports a map as an HTML file. @@ -1853,13 +1787,13 @@ def to_streamlit( """ try: - import streamlit.components.v1 as components + import streamlit.components.v1 as components # pylint: disable=E0401 if add_layer_control: self.add_layer_control() if bidirectional: - from streamlit_folium import st_folium + from streamlit_folium import st_folium # pylint: disable=E0401 output = st_folium(self, width=width, height=height) return output @@ -1922,7 +1856,7 @@ def st_fit_bounds(self): """ try: - import streamlit as st + import streamlit as st # pylint: disable=E0401 if "map_bounds" in st.session_state: bounds = st.session_state["map_bounds"] @@ -2023,7 +1957,7 @@ def static_map( os.makedirs(out_dir) self.to_html(out_file) - display_html(src=out_file, width=width, height=height) + display_html(out_file, width=width, height=height) else: raise TypeError("The provided map is not a folium map.") @@ -3557,43 +3491,6 @@ def __init__(self, text, bottom=75, left=75): self.left = left -def delete_dp_report(name): - """Deletes a datapane report. - - Args: - name (str): Name of the report to delete. - """ - try: - import datapane as dp - - reports = dp.Report.list() - items = list(reports) - names = list(map(lambda item: item["name"], items)) - if name in names: - report = dp.Report.get(name) - url = report.blocks[0]["url"] - # print('Deleting {}...'.format(url)) - dp.Report.delete(dp.Report.by_id(url)) - except Exception as e: - raise Exception(e) - - -def delete_dp_reports(): - """Deletes all datapane reports.""" - try: - import datapane as dp - - reports = dp.Report.list() - for item in reports: - print(item["name"]) - report = dp.Report.get(item["name"]) - url = report.blocks[0]["url"] - print("Deleting {}...".format(url)) - dp.Report.delete(dp.Report.by_id(url)) - except Exception as e: - raise Exception(e) - - def linked_maps( rows=2, cols=2, diff --git a/leafmap/leafmap.py b/leafmap/leafmap.py index 3bd714811c..801174b36c 100644 --- a/leafmap/leafmap.py +++ b/leafmap/leafmap.py @@ -64,6 +64,7 @@ def __init__(self, **kwargs): self.geojson_layers = [] self.edit_mode = False self.edit_props = [] + self._layer_manager_widget = widgets.VBox() # sandbox path for Voila app to restrict access to system directories. if "sandbox_path" not in kwargs: @@ -245,7 +246,7 @@ def add(self, obj, index=None, **kwargs) -> None: super().add(obj, index=index) - if hasattr(self, "layer_manager_widget"): + if hasattr(self, "_layer_manager_widget"): self.update_layer_manager() def set_center(self, lon, lat, zoom=None) -> None: @@ -2284,7 +2285,7 @@ def to_streamlit( """ try: - import streamlit.components.v1 as components + import streamlit.components.v1 as components # pylint: disable=E0401 # if responsive: # make_map_responsive = """ @@ -2523,106 +2524,6 @@ def add_netcdf( **kwargs, ) - def add_raster_legacy( - self, - image: str, - bands: Optional[Union[int, list]] = None, - layer_name: Optional[str] = None, - colormap: Optional[str] = None, - x_dim: Optional[str] = "x", - y_dim: Optional[str] = "y", - fit_bounds: Optional[bool] = True, - ) -> None: - """Adds a local raster dataset to the map. - - Args: - image (str): The image file path. - bands (int or list, optional): The image bands to use. It can be either a number (e.g., 1) or a list (e.g., [3, 2, 1]). Defaults to None. - layer_name (str, optional): The layer name to use for the raster. Defaults to None. - colormap (str, optional): The name of the colormap to use for the raster, such as 'gray' and 'terrain'. More can be found at https://matplotlib.org/3.1.0/tutorials/colors/colormaps.html. Defaults to None. - x_dim (str, optional): The x dimension. Defaults to 'x'. - y_dim (str, optional): The y dimension. Defaults to 'y'. - fit_bounds (bool, optional): Whether to fit map bounds to raster bounds. Defaults to True. - """ - try: - import xarray_leaflet - - except Exception: - # import platform - # if platform.system() != "Windows": - # # install_from_github( - # # url='https://github.com/davidbrochart/xarray_leaflet') - # check_install('xarray_leaflet') - # import xarray_leaflet - # else: - raise ImportError( - "You need to install xarray_leaflet first. See https://github.com/davidbrochart/xarray_leaflet" - ) - - import warnings - import numpy as np - import rioxarray - - # import xarray as xr - import matplotlib.pyplot as plt - import matplotlib as mpl - - warnings.simplefilter("ignore") - - if isinstance(image, str): - if not os.path.exists(image): - print("The image file does not exist.") - return - - if colormap is None: - colormap = plt.cm.inferno - - if layer_name is None: - layer_name = "Layer_" + random_string() - - if isinstance(colormap, str): - colormap = mpl.colormaps[colormap] - - if isinstance(image, str): - da = rioxarray.open_rasterio(image, masked=True) - else: - da = image - - # print(da.rio.nodata) - - multi_band = False - if len(da.band) > 1: - multi_band = True - if bands is None: - bands = [3, 2, 1] - else: - bands = 1 - - if multi_band: - da = da.rio.write_nodata(0) - else: - da = da.rio.write_nodata(np.nan) - da = da.sel(band=bands) - - # crs = da.rio.crs - # nan = da.attrs['nodatavals'][0] - # da = da / da.max() - # # if multi_band: - # da = xr.where(da == nan, np.nan, da) - # da = da.rio.write_nodata(0) - # da = da.rio.write_crs(crs) - - if multi_band and type(bands) == list: - layer = da.leaflet.plot( - self, x_dim=x_dim, y_dim=y_dim, rgb_dim="band", fit_bounds=fit_bounds - ) - else: - layer = da.leaflet.plot( - self, x_dim=x_dim, y_dim=y_dim, colormap=colormap, fit_bounds=fit_bounds - ) - - layer.name = layer_name - def add_shp( self, in_shp: str, @@ -2738,7 +2639,7 @@ def add_geojson( if isinstance(in_geojson, str): if in_geojson.startswith("http"): if is_jupyterlite(): - import pyodide + import pyodide # pylint: disable=E0401 output = os.path.basename(in_geojson) @@ -3872,7 +3773,7 @@ def static_map( os.makedirs(out_dir) self.to_html(out_file) - display_html(src=out_file, width=width, height=height) + display_html(out_file, width=width, height=height) else: raise TypeError("The provided map is not an ipyleaflet map.") @@ -4617,7 +4518,9 @@ def update_layer_manager(self) -> None: """Update the Layer Manager.""" from .toolbar import layer_manager_gui - self.layer_manager_widget.children = layer_manager_gui(self, return_widget=True) + self._layer_manager_widget.children = layer_manager_gui( + self, return_widget=True + ) def add_oam_gui( self, position: Optional[str] = "topright", opened: bool = True diff --git a/leafmap/map_widgets.py b/leafmap/map_widgets.py index 5ccb579113..af60ad1ddb 100644 --- a/leafmap/map_widgets.py +++ b/leafmap/map_widgets.py @@ -299,7 +299,7 @@ def __init__( with legend_output: display(legend_widget) - def __check_if_allowed(value, value_name, allowed_list): + def __check_if_allowed(value, value_name, allowed_list): # pylint: disable=E0213 if value not in allowed_list: raise ValueError( "The " @@ -308,13 +308,13 @@ def __check_if_allowed(value, value_name, allowed_list): ) return True - def __convert_rgb_colors_to_hex(colors): + def __convert_rgb_colors_to_hex(colors): # pylint: disable=E0213 try: return [common.rgb_to_hex(x) for x in colors] except: raise ValueError("Unable to convert rgb value to hex.") - def __create_legend_items(keys, colors): + def __create_legend_items(keys, colors): # pylint: disable=E0213 legend_items = [] for index, key in enumerate(keys): color = colors[index] @@ -326,7 +326,7 @@ def __create_legend_items(keys, colors): legend_items.append(item) return legend_items - def __create_layout(**kwargs): + def __create_layout(**kwargs): # pylint: disable=E0213 height = Legend.__create_layout_property("height", None, **kwargs) min_height = Legend.__create_layout_property("min_height", None, **kwargs) diff --git a/leafmap/maplibregl.py b/leafmap/maplibregl.py index b9938e854a..af3a2dfd8d 100644 --- a/leafmap/maplibregl.py +++ b/leafmap/maplibregl.py @@ -2120,7 +2120,7 @@ def to_streamlit( Exception: If there is an error in creating the Streamlit component. """ try: - import streamlit.components.v1 as components + import streamlit.components.v1 as components # pylint: disable=E0401 import base64 raw_html = self.to_html().encode("utf-8") diff --git a/leafmap/plotlymap.py b/leafmap/plotlymap.py index b3dedfc7da..5c358bd82e 100644 --- a/leafmap/plotlymap.py +++ b/leafmap/plotlymap.py @@ -455,9 +455,9 @@ def add_stac_layer( opacity (float, optional): The opacity of the layer. Defaults to 1. """ tile_url = stac_tile( - url, collection, item, assets, bands, titiler_endpoint, **kwargs + url, collection, items, assets, bands, titiler_endpoint, **kwargs ) - center = stac_center(url, collection, item, titiler_endpoint) + center = stac_center(url, collection, items, titiler_endpoint) self.add_tile_layer(tile_url, name, attribution, opacity) self.set_center(lon=center[0], lat=center[1], zoom=10) diff --git a/leafmap/toolbar.py b/leafmap/toolbar.py index 1977731c5a..fcbc0549bf 100644 --- a/leafmap/toolbar.py +++ b/leafmap/toolbar.py @@ -6275,8 +6275,8 @@ def layer_opacity_changed(change): layers_button.observe(layers_btn_click, "value") layers_button.value = opened - if not hasattr(m, "layer_manager_widget"): - m.layer_manager_widget = toolbar_footer + if not hasattr(m, "_layer_manager_widget"): + m._layer_manager_widget = toolbar_footer if return_widget: return m.layer_widget diff --git a/tests/test_foliumap.py b/tests/test_foliumap.py index 42806b8510..78c580cf2a 100644 --- a/tests/test_foliumap.py +++ b/tests/test_foliumap.py @@ -277,16 +277,6 @@ def test_add_point_layer(self): out_str = m.to_html() assert "US Cities" in out_str - # def test_add_raster(self): - # """Check loading raster data""" - # with self.assertRaises(NotImplementedError): - # m = leafmap.Map() - # landsat_url = "https://drive.google.com/file/d/1vRkAWQYsLWCi6vcTMk8vLxoXMFbdMFn8/view?usp=sharing" - # leafmap.download_from_gdrive(landsat_url, "dem.tif", unzip=False) - # m.add_raster("dem.tif", colormap="terrain", layer_name="DEM") - # out_str = m.to_html() - # assert "DEM" in out_str - # def test_add_shp(self): # """Check adding shapefile""" # m = leafmap.Map() diff --git a/tests/test_leafmap.py b/tests/test_leafmap.py index 3b0b8bd5b0..fe6fc3411b 100644 --- a/tests/test_leafmap.py +++ b/tests/test_leafmap.py @@ -263,15 +263,6 @@ def test_add_point_layer(self): out_str = m.to_html() assert "US Cities" in out_str - # def test_add_raster(self): - # """Check loading raster data""" - # m = leafmap.Map() - # landsat_url = "https://drive.google.com/file/d/1vRkAWQYsLWCi6vcTMk8vLxoXMFbdMFn8/view?usp=sharing" - # leafmap.download_from_gdrive(landsat_url, "dem.tif", unzip=False) - # m.add_raster("dem.tif", colormap="terrain", layer_name="DEM") - # out_str = m.to_html() - # assert "DEM" in out_str - # # ensure fit_bounds keyword argument doesn't interfere with rendering # m = leafmap.Map() # m.add_raster("dem.tif", colormap="terrain", layer_name="DEM", fit_bounds=False)