import random import pandas as pd import pydeck as pdk import geopandas as gpd def create_map(data_url, path_save, field): gdf = gpd.read_file(data_url) max_field = gdf[field].max() print(max_field) # Obtiene el bounding box total bounding_box = gdf.total_bounds # El bounding box total es una tupla con las coordenadas (minx, miny, maxx, maxy) x_array = [bounding_box[0], bounding_box[2]] y_array = [bounding_box[1], bounding_box[3]] # y_array = [bounding_box[0], bounding_box[2]] # x_array = [bounding_box[1], bounding_box[3]] x_min = min(x_array) x_max = max(x_array) y_min = min(y_array) y_max = max(y_array) LAND_COVER = [[[x_max, y_min], [x_max, y_max], [x_min, y_max], [x_min, y_min]]] INITIAL_VIEW_STATE = pdk.ViewState(latitude=((y_min+y_max)/2), longitude=((x_min+x_max)/2), zoom=11, max_zoom=16, pitch=45, bearing=0) polygon = pdk.Layer( "PolygonLayer", LAND_COVER, stroked=False, # processes the data as a flat longitude-latitude pair get_polygon="-", get_fill_color=[255,255,255, 20], ) geojson_2 = pdk.Layer( "GeoJsonLayer", data_url, opacity=0.8, coverage=0.5, elevation_scale=5, stroked=False, filled=True, extruded=True, pickable=True, wireframe=True, get_elevation=f"properties.{field}*10", get_fill_color=f"[properties.{field}*255/{max_field}, 255-(properties.{field}*255/{max_field}), 255-(properties.{field}*255/{max_field}), 180]", get_line_color=[255,255,255], ) # get_fill_color=f"[(-1/12960)*(((properties.{field}*255/{max_field})-90)*((properties.{field}*255/{max_field})-90))+255, 255-(properties.{field}*255/{max_field}), 255-(properties.{field}*255/{max_field}), 180] # Cargar tu estilo personalizado de Mapbox GL JSON custom_style = "https://tileserver.ipsilum.com/styles/osm/style.json" r = pdk.Deck(layers=[geojson_2], initial_view_state=INITIAL_VIEW_STATE, map_style=custom_style, tooltip={"text": "Count: {properties." + str(field) +"}"}) r.to_html(path_save) return path_save #create_map('https://sd1.d3.ipsilum.com/files_uploaded/Zonas_Policiales.geojson', '/home/data3/master_folder/htmls/zonas_policiales.html', 'zona') create_map('https://sd1.d3.ipsilum.com/files_uploaded/salida_con_puntos_Zonas_Policiales.geojson.geojson', '/home/data3/master_folder/htmls/puntos_y_zonas_policiales_2.html', 'npuntos')