#!/usr/bin/env python # coding: utf-8 # [![image](https://jupyterlite.rtfd.io/en/latest/_static/badge.svg)](https://demo.leafmap.org/lab/index.html?path=notebooks/104_point_style.ipynb) # [![image](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/opengeos/leafmap/blob/master/docs/notebooks/104_point_style.ipynb) # [![image](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/opengeos/leafmap/HEAD) # # **Plotting point data with custom styles** # # Uncomment the following line to install [leafmap](https://leafmap.org) if needed. # In[ ]: # %pip install -U leafmap # In[ ]: from leafmap import leafmap # ## Load GeoJSON data # In[ ]: url = ( "https://github.com/opengeos/datasets/releases/download/world/world_cities.geojson" ) # In[ ]: m = leafmap.Map() point_style = { "radius": 5, "color": "red", "fillOpacity": 0.8, "fillColor": "blue", "weight": 3, } hover_style = {"fillColor": "yellow", "fillOpacity": 1.0} m.add_geojson( url, point_style=point_style, hover_style=hover_style, layer_name="World Cities" ) m # ## Load GoeDataFrame # In[ ]: import geopandas as gpd # In[ ]: gdf = gpd.read_file(url) # In[ ]: m = leafmap.Map() point_style = { "radius": 5, "color": "red", "fillOpacity": 0.8, "fillColor": "blue", "weight": 3, } hover_style = {"fillColor": "yellow", "fillOpacity": 1.0} m.add_gdf( gdf, point_style=point_style, hover_style=hover_style, layer_name="World Cities" ) m # ## Load Random Data # In[ ]: import geopandas, pandas as pd, numpy as np import random # In[ ]: # Function to generate random coordinates within latitude and longitude bounds def random_coordinates(n, lat_min=-90, lat_max=90, lon_min=-180, lon_max=180): """Generates n random latitude/longitude coordinates. Args: n (int): The number of coordinates to generate. lat_min (float): Minimum latitude. Defaults to -90. lat_max (float): Maximum latitude. Defaults to 90. lon_min (float): Minimum longitude. Defaults to -180. lon_max (float): Maximum longitude. Defaults to 180. Returns: pandas.DataFrame: A DataFrame containing 'Longitude' and 'Latitude' columns. """ latitudes = [random.uniform(lat_min, lat_max) for _ in range(n)] longitudes = [random.uniform(lon_min, lon_max) for _ in range(n)] return pd.DataFrame({"Longitude": longitudes, "Latitude": latitudes}) numpoints = 1000 # Generate random coordinates across the globe df = random_coordinates(numpoints) # Add a 'Conc' column (optional, for demonstration) df["Conc"] = np.random.randn(numpoints) + 17 # Example data # Create GeoDataFrame gdf = geopandas.GeoDataFrame( df, geometry=geopandas.points_from_xy(df.Longitude, df.Latitude), crs="EPSG:4326" ) m = leafmap.Map() # Start with a low zoom to show the global distribution # Add the GeoDataFrame to the map m.add_gdf( gdf, hover_style={"fillColor": "yellow", "fillOpacity": 1.0}, point_style={ "radius": 5, "color": "red", "fillColor": "red", "fillOpacity": 0.5, "opacity": 0.5, }, ) m