Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix folium split-map cors bug #1023

Merged
merged 1 commit into from
Dec 14, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion leafmap/foliumap.py
Original file line number Diff line number Diff line change
Expand Up @@ -609,13 +609,16 @@ def add_raster(
layer_name (str, optional): The layer name to use. Defaults to 'Raster'.
array_args (dict, optional): Additional arguments to pass to `array_to_image`. Defaults to {}.
"""

import sys
import numpy as np
import xarray as xr

if isinstance(source, np.ndarray) or isinstance(source, xr.DataArray):
source = common.array_to_image(source, **array_args)

if "google.colab" in sys.modules:
kwargs["cors_all"] = True

tile_layer, tile_client = common.get_local_tile_layer(
source,
indexes=indexes,
Expand Down Expand Up @@ -2557,6 +2560,13 @@ def split_map(
left_array_args (dict, optional): The arguments for array_to_image for the left layer. Defaults to {}.
right_array_args (dict, optional): The arguments for array_to_image for the right layer. Defaults to {}.
"""
import sys

if "google.colab" in sys.modules:
client_args = {"cors_all": True}
else:
client_args = {"cors_all": False}

if "max_zoom" not in left_args:
left_args["max_zoom"] = 30
if "max_native_zoom" not in left_args:
Expand Down Expand Up @@ -2618,6 +2628,7 @@ def split_map(
left_layer,
tile_format="folium",
return_client=True,
client_args=client_args,
**left_args,
)
bounds = common.image_bounds(left_client)
Expand All @@ -2640,6 +2651,7 @@ def split_map(
left_layer,
return_client=True,
tile_format="folium",
client_args=client_args,
**left_args,
)
else:
Expand Down Expand Up @@ -2679,6 +2691,7 @@ def split_map(
right_layer,
tile_format="folium",
return_client=True,
client_args=client_args,
**right_args,
)
bounds = common.image_bounds(right_client)
Expand All @@ -2700,6 +2713,7 @@ def split_map(
right_layer,
return_client=True,
tile_format="folium",
client_args=client_args,
**right_args,
)
else:
Expand Down
Loading