MCPcopy Index your code
hub / github.com/opengeos/leafmap / geojson_layer

Function geojson_layer

leafmap/leafmap.py:7681–7828  ·  view source on GitHub ↗

Adds a GeoJSON file to the map. Args: in_geojson (str | dict): The file path or http URL to the input GeoJSON or a dictionary containing the geojson. layer_name (str, optional): The layer name to be used.. Defaults to "GeoJSON". style (dict, optio

(
    in_geojson: Union[str, Dict],
    layer_name: Optional[str] = "GeoJSON",
    style: Optional[dict] = {},
    hover_style: Optional[dict] = {},
    style_callback: Optional[Callable] = None,
    fill_colors: Optional[list[str]] = None,
    encoding: Optional[str] = "utf-8",
    **kwargs,
)

Source from the content-addressed store, hash-verified

7679
7680
7681def geojson_layer(
7682 in_geojson: Union[str, Dict],
7683 layer_name: Optional[str] = "GeoJSON",
7684 style: Optional[dict] = {},
7685 hover_style: Optional[dict] = {},
7686 style_callback: Optional[Callable] = None,
7687 fill_colors: Optional[list[str]] = None,
7688 encoding: Optional[str] = "utf-8",
7689 **kwargs,
7690) -> None:
7691 """Adds a GeoJSON file to the map.
7692
7693 Args:
7694 in_geojson (str | dict): The file path or http URL to the input
7695 GeoJSON or a dictionary containing the geojson.
7696 layer_name (str, optional): The layer name to be used.. Defaults to
7697 "GeoJSON".
7698 style (dict, optional): A dictionary specifying the style to be used.
7699 Defaults to {}.
7700 hover_style (dict, optional): Hover style dictionary. Defaults to {}.
7701 style_callback (function, optional): Styling function that is called
7702 for each feature, and should return the feature style. This
7703 styling function takes the feature as argument. Defaults to None.
7704 fill_colors (list, optional): The random colors to use for filling
7705 polygons. Defaults to ["black"].
7706 info_mode (str, optional): Displays the attributes by either on_hover
7707 or on_click. Any value other than "on_hover" or "on_click" will
7708 be treated as None. Defaults to "on_hover".
7709 zoom_to_layer (bool, optional): Whether to zoom to the layer after
7710 adding it to the map. Defaults to False.
7711 encoding (str, optional): The encoding of the GeoJSON file. Defaults
7712 to "utf-8".
7713
7714 Raises:
7715 FileNotFoundError: The provided GeoJSON file could not be found.
7716 """
7717 import json
7718 import random
7719 import shutil
7720
7721 import geopandas as gpd
7722
7723 gdf = None
7724
7725 try:
7726 if isinstance(in_geojson, str):
7727 if in_geojson.startswith("http"):
7728 if common.is_jupyterlite():
7729 import pyodide # pylint: disable=E0401
7730
7731 output = os.path.basename(in_geojson)
7732
7733 output = os.path.abspath(output)
7734 obj = pyodide.http.open_url(in_geojson)
7735 with open(output, "w") as fd:
7736 shutil.copyfileobj(obj, fd)
7737 with open(output, "r") as fd:
7738 data = json.load(fd)

Callers 2

split_mapMethod · 0.70
split_mapFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected