Skip to content

Commit

Permalink
Fix folium split-map cors bug (#1023)
Browse files Browse the repository at this point in the history
  • Loading branch information
giswqs authored Dec 14, 2024
1 parent 2f4c60a commit 609ee83
Showing 1 changed file with 15 additions and 1 deletion.
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

0 comments on commit 609ee83

Please sign in to comment.