MCPcopy Index your code
hub / github.com/python-visualization/folium / TopoJson

Class TopoJson

folium/features.py:942–1121  ·  view source on GitHub ↗

Creates a TopoJson object for plotting into a Map. Parameters ---------- data: file, dict or str. The TopoJSON data you want to plot. * If file, then data will be read in the file and fully embedded in Leaflet's JavaScript. * If dict, then data will

Source from the content-addressed store, hash-verified

940
941
942class TopoJson(JSCSSMixin, Layer):
943 """
944 Creates a TopoJson object for plotting into a Map.
945
946 Parameters
947 ----------
948 data: file, dict or str.
949 The TopoJSON data you want to plot.
950 * If file, then data will be read in the file and fully
951 embedded in Leaflet's JavaScript.
952 * If dict, then data will be converted to JSON and embedded
953 in the JavaScript.
954 * If str, then data will be passed to the JavaScript as-is.
955
956 object_path: str
957 The path of the desired object into the TopoJson structure.
958 Ex: 'objects.myobject'.
959 style_function: function, default None
960 A function mapping a TopoJson geometry to a style dict.
961 name : string, default None
962 The name of the Layer, as it will appear in LayerControls
963 overlay : bool, default False
964 Adds the layer as an optional overlay (True) or the base layer (False).
965 control : bool, default True
966 Whether the Layer will be included in LayerControls.
967 show: bool, default True
968 Whether the layer will be shown on opening.
969 smooth_factor: float, default None
970 How much to simplify the polyline on each zoom level. More means
971 better performance and smoother look, and less means more accurate
972 representation. Leaflet defaults to 1.0.
973 tooltip: GeoJsonTooltip, Tooltip or str, default None
974 Display a text when hovering over the object. Can utilize the data,
975 see folium.GeoJsonTooltip for info on how to do that.
976
977 Examples
978 --------
979 >>> # Providing file that shall be embedded.
980 >>> TopoJson(open("foo.json"), "object.myobject")
981 >>> # Providing filename that shall not be embedded.
982 >>> TopoJson("foo.json", "object.myobject")
983 >>> # Providing dict.
984 >>> TopoJson(json.load(open("foo.json")), "object.myobject")
985 >>> # Providing string.
986 >>> TopoJson(open("foo.json").read(), "object.myobject")
987
988 >>> # Provide a style_function that color all states green but Alabama.
989 >>> style_function = lambda x: {
990 ... "fillColor": (
991 ... "#0000ff" if x["properties"]["name"] == "Alabama" else "#00ff00"
992 ... )
993 ... }
994 >>> TopoJson(topo_json, "object.myobject", style_function=style_function)
995
996 """
997
998 _template = Template(
999 """

Callers 1

__init__Method · 0.85

Calls 1

TemplateClass · 0.90

Tested by

no test coverage detected