from geopandas import GeoDataFrame
from IPython.display import display
from ipywidgets import IntProgress
from iclientpy.jupyter import PortalThumbnail
from iclientpy.portal import Portal


def from_geodataframe_to_map(portal: Portal, gdf: GeoDataFrame, data_name: str, map_title: str, layer_name: str):
    progress = IntProgress()
    progress.max = 100
    progress.value = 0
    progress.description = '上传文件：'
    display(progress)

    def refresh_progress(read, total):
        progress.value = read

    data_id = portal.upload_dataframe_as_json(data_name, gdf, callback=refresh_progress)
    layer = portal.prepare_geojson_layer(data_id, layer_name)
    map_id = portal.create_map([layer], 3857, map_title)
    mr = portal.get_map(map_id)
    pm = PortalThumbnail(mr)
    display(pm)
    return map_id

{'avg_line_length': 33.36, 'max_line_length': 114, 'alphanum_fraction': 0.7302158273381295, 'licenses': ['Apache-2.0'], 'repository_name': 'SuperMap/iClientPython', 'path': 'iclientpy/iclientpy/data/portal.py', 'size': 844, 'lang': 'Python'}