Vector
In [1]:
Copied!
import os
import json
import random
import requests
from ipyleaflet import Map, GeoJSON
if not os.path.exists('countries.geo.json'):
url = 'https://github.com/jupyter-widgets/ipyleaflet/raw/master/examples/countries.geo.json'
r = requests.get(url)
with open('countries.geo.json', 'w') as f:
f.write(r.content.decode("utf-8"))
with open('countries.geo.json', 'r') as f:
data = json.load(f)
def random_color(feature):
return {
'color': 'black',
'fillColor': random.choice(['red', 'yellow', 'green', 'orange']),
}
m = Map(center=(50.6252978589571, 0.34580993652344), zoom=3)
geo_json = GeoJSON(
data=data,
style={
'opacity': 1, 'dashArray': '9', 'fillOpacity': 0.1, 'weight': 1
},
hover_style={
'color': 'white', 'dashArray': '0', 'fillOpacity': 0.5
},
style_callback=random_color
)
m.add(geo_json)
m
import os
import json
import random
import requests
from ipyleaflet import Map, GeoJSON
if not os.path.exists('countries.geo.json'):
url = 'https://github.com/jupyter-widgets/ipyleaflet/raw/master/examples/countries.geo.json'
r = requests.get(url)
with open('countries.geo.json', 'w') as f:
f.write(r.content.decode("utf-8"))
with open('countries.geo.json', 'r') as f:
data = json.load(f)
def random_color(feature):
return {
'color': 'black',
'fillColor': random.choice(['red', 'yellow', 'green', 'orange']),
}
m = Map(center=(50.6252978589571, 0.34580993652344), zoom=3)
geo_json = GeoJSON(
data=data,
style={
'opacity': 1, 'dashArray': '9', 'fillOpacity': 0.1, 'weight': 1
},
hover_style={
'color': 'white', 'dashArray': '0', 'fillOpacity': 0.5
},
style_callback=random_color
)
m.add(geo_json)
m
Out[1]:
Map(center=[50.6252978589571, 0.34580993652344], controls=(ZoomControl(options=['position', 'zoom_in_text', 'z…
In [2]:
Copied!
import json
from ipyleaflet import Map, GeoJSON
with open('countries.geo.json', 'r') as f:
data = json.load(f)
geo_json = GeoJSON(
data=data,
)
m.add(geo_json)
m
import json
from ipyleaflet import Map, GeoJSON
with open('countries.geo.json', 'r') as f:
data = json.load(f)
geo_json = GeoJSON(
data=data,
)
m.add(geo_json)
m
Out[2]:
Map(center=[50.6252978589571, 0.34580993652344], controls=(ZoomControl(options=['position', 'zoom_in_text', 'z…
In [3]:
Copied!
import zzfdemo
import chardet
import zzfdemo
import chardet
In [4]:
Copied!
# # style={
# # 'opacity': 1, 'dashArray': '9', 'fillOpacity': 0.1, 'weight': 1
# # }
# # hover_style={
# # 'color': 'red', 'dashArray': '0', 'fillOpacity': 0.5
# # }
# m = zzfdemo.Map()
# m.scroll_wheel_zoom = True
# # m.add_basemap("OpenTopoMap")
# # m.add_geojson("china.geojson")
# m.add_shapefile("./data/china.shp")
# m
# # style={
# # 'opacity': 1, 'dashArray': '9', 'fillOpacity': 0.1, 'weight': 1
# # }
# # hover_style={
# # 'color': 'red', 'dashArray': '0', 'fillOpacity': 0.5
# # }
# m = zzfdemo.Map()
# m.scroll_wheel_zoom = True
# # m.add_basemap("OpenTopoMap")
# # m.add_geojson("china.geojson")
# m.add_shapefile("./data/china.shp")
# m
Out[4]:
Map(center=[34.32, 108.55], controls=(ZoomControl(options=['position', 'zoom_in_text', 'zoom_in_title', 'zoom_…
In [ ]:
Copied!