Python 散景 Google 根据缩放映射动态字形大小
Python bokeh Google Maps dynamic glyph size based on zoom
是否可以在 Python 散景中以基于缩放的动态大小在 GMapPlot
canvas 中绘制 Circle()
字形对象?我想显示一个圆形区域,其中我有中心点和以米为单位的半径。我希望根据缩放 Google 地图以更小和更大的尺寸显示这个圆圈。
这可以通过某种方式实现吗?
更新:
我可以使用以下代码绘制固定大小的圆圈:
from bokeh.document import Document
from bokeh.embed import file_html
from bokeh.resources import INLINE
from bokeh.models import (GMapPlot, GMapOptions, ColumnDataSource,
Circle, DataRange1d, PanTool, WheelZoomTool, BoxSelectTool)
map_options = GMapOptions(lat=30.29, lng=-97.73, map_type="roadmap", zoom=11)
plot = GMapPlot(x_range=DataRange1d(), y_range=DataRange1d(), map_options=map_options,
title="Austin", api_key=GOOGLE_API_KEY)
source = ColumnDataSource(data=dict(lat=[30.29, 30.20, 30.29],
lon=[-97.70, -97.74, -97.78],))
circle = Circle(x="lon", y="lat", size=15, fill_color="blue", fill_alpha=0.8,
line_color=None)
plot.add_glyph(source, circle)
plot.add_tools(PanTool(), WheelZoomTool(), BoxSelectTool())
# Save HTML file
doc = Document()
doc.add_root(plot)
filename = './google_maps_test.html'
with open(filename, "w") as f:
f.write(file_html(doc, INLINE, 'Google Maps plot'))
这里 size=15
表示像素或一些固定大小,当我滚动图表时不会改变...我可以在我的 ColumnDataSource
对象中有一个 radius
这些值将是以米为单位的半径(例如 50、75、100)。我会使用 size=radius
...
谢谢!
Circle
字形接受 size
和 radius
属性(之一)。默认情况下 size
是 "screen units"(基本上是像素)。这就是为什么无论缩放级别如何,它们都保持相同大小的原因。如果您希望圆圈随缩放级别缩放,最好提供 radius
值,因为默认情况下 radius
被解释为 "data space units"。 IE。在这种情况下,它将以米为单位(因为 GMapPlot
轴的单位是米)。
circle = Circle(x="lon",
y="lat",
# corresponds to 15 meters, so scales accordingly with zoom
radius=15,
fill_color="blue",
fill_alpha=0.8,
line_color=None)
是否可以在 Python 散景中以基于缩放的动态大小在 GMapPlot
canvas 中绘制 Circle()
字形对象?我想显示一个圆形区域,其中我有中心点和以米为单位的半径。我希望根据缩放 Google 地图以更小和更大的尺寸显示这个圆圈。
这可以通过某种方式实现吗?
更新: 我可以使用以下代码绘制固定大小的圆圈:
from bokeh.document import Document
from bokeh.embed import file_html
from bokeh.resources import INLINE
from bokeh.models import (GMapPlot, GMapOptions, ColumnDataSource,
Circle, DataRange1d, PanTool, WheelZoomTool, BoxSelectTool)
map_options = GMapOptions(lat=30.29, lng=-97.73, map_type="roadmap", zoom=11)
plot = GMapPlot(x_range=DataRange1d(), y_range=DataRange1d(), map_options=map_options,
title="Austin", api_key=GOOGLE_API_KEY)
source = ColumnDataSource(data=dict(lat=[30.29, 30.20, 30.29],
lon=[-97.70, -97.74, -97.78],))
circle = Circle(x="lon", y="lat", size=15, fill_color="blue", fill_alpha=0.8,
line_color=None)
plot.add_glyph(source, circle)
plot.add_tools(PanTool(), WheelZoomTool(), BoxSelectTool())
# Save HTML file
doc = Document()
doc.add_root(plot)
filename = './google_maps_test.html'
with open(filename, "w") as f:
f.write(file_html(doc, INLINE, 'Google Maps plot'))
这里 size=15
表示像素或一些固定大小,当我滚动图表时不会改变...我可以在我的 ColumnDataSource
对象中有一个 radius
这些值将是以米为单位的半径(例如 50、75、100)。我会使用 size=radius
...
谢谢!
Circle
字形接受 size
和 radius
属性(之一)。默认情况下 size
是 "screen units"(基本上是像素)。这就是为什么无论缩放级别如何,它们都保持相同大小的原因。如果您希望圆圈随缩放级别缩放,最好提供 radius
值,因为默认情况下 radius
被解释为 "data space units"。 IE。在这种情况下,它将以米为单位(因为 GMapPlot
轴的单位是米)。
circle = Circle(x="lon",
y="lat",
# corresponds to 15 meters, so scales accordingly with zoom
radius=15,
fill_color="blue",
fill_alpha=0.8,
line_color=None)