我知道这里的解决方案并不遥远,但是我正在努力实现基于用户输入为地图比例尺分配数值的功能。该代码是很容易解释的,但是我希望用户从4种缩放状态中进行选择,并使用输入将数字值返回到我的地图作为缩放起点。
zoom=5
while True:
where = raw_input('Where would you like a map of?')
try:
heatmap = folium.Map(location=geo(where), tiles='Stamen Toner', zoom_start=zoom)
pointmap = folium.Map(location=geo(where), tiles='Stamen Toner', zoom_start=zoom)
except AttributeError, GeocoderServiceError:
print "Cannot create map with the given location. Please try again."
else:
break
while True:
zoom_state = ['city', 'state', 'country', 'world']
zoom_state= raw_input('What level of detail would you like: city, state, country, or world?')
try:
for response in zoom_state:
if response is ['city']:
zoom == 9
if response is ['state']:
zoom == 7
if response is ['country']:
zoom == 5
if response is ['world']:
zoom == 9
except TypeError, IndexError:
print 'Please enter: city, state, country, or world. Try again'
continue
else:
break
heatmap = folium.Map(location=geo(where), tiles='Stamen Toner', zoom_start=zoom)
pointmap = folium.Map(location=geo(where), tiles='Stamen Toner', zoom_start=zoom)
现在,我可以在zoom_state中放置任何内容,它将运行。
提前致谢!
您可能正在寻找这样的东西:
zoom=5
while True:
where = raw_input('Where would you like a map of?')
try:
heatmap = folium.Map(location=geo(where), tiles='Stamen Toner', zoom_start=zoom)
pointmap = folium.Map(location=geo(where), tiles='Stamen Toner', zoom_start=zoom)
except AttributeError, GeocoderServiceError:
print "Cannot create map with the given location. Please try again."
else:
break
while True:
zoom_level = {'city':9, 'state':7, 'country':5, 'world':9}
zoom_detail = raw_input('What level of detail would you like: city, state, country, or world?')
try:
zoom = zoom_level[str(zoom_detail)]
except TypeError, IndexError:
print 'Please enter: city, state, country, or world. Try again'
continue
else:
break
heatmap = folium.Map(location=geo(where), tiles='Stamen Toner', zoom_start=zoom)
pointmap = folium.Map(location=geo(where), tiles='Stamen Toner', zoom_start=zoom)
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句