Upon zoom, it’ll change the scale of the geometry and crop the geometry
import geoviews as gv
import holoviews as hv
from cartopy import feature as cf
from shapely.geometry import box
import geopandas as gpd
import cartopy.crs as ccrs
hv.extension("bokeh")
def show_features(x_range, y_range):
if x_range is None:
x_range = (-180, 180)
if y_range is None:
y_range = (-90, 90)
if (x_range[1] - x_range[0]) < 5:
scale = "10m"
elif (x_range[1] - x_range[0]) < 20:
scale = "50m"
else:
scale = "110m"
print(scale)
padding = 3
clip_box = box(
x_range[0] - padding,
y_range[0] - padding,
x_range[1] + padding,
y_range[1] + padding,
)
states = gpd.clip(
gpd.GeoDataFrame(
geometry=gpd.GeoSeries(cf.STATES.with_scale(scale).geometries())
),
clip_box,
)
coastline = gpd.clip(
gpd.GeoDataFrame(
geometry=gpd.GeoSeries(cf.COASTLINE.with_scale(scale).geometries())
),
clip_box,
)
return gv.Path(coastline) * gv.Path(states)
point = (
gv.Points((-88, 40), crs=ccrs.PlateCarree())
.opts(color="red", size=25)
.opts(global_extent=True, projection=ccrs.PlateCarree())
)
range_stream = hv.streams.RangeXY(source=point)
features = hv.DynamicMap(show_features, streams=[range_stream])
ds_features = features.opts(projection=ccrs.PlateCarree())
point * ds_features