从Bokeh Google Maps包装器(fitBounds())调用Javascript方法
我有一个带有几个Lat/Lng数据点的bokeh Google maps绘图,我想使用Google maps v3 API的fitBounds()方法来设置缩放级别 我有一个谷歌地图绘图和运行,在我的网站上显示和显示数据点,但我需要手动设置缩放从Bokeh Google Maps包装器(fitBounds())调用Javascript方法,javascript,google-maps-api-3,bokeh,Javascript,Google Maps Api 3,Bokeh,我有一个带有几个Lat/Lng数据点的bokeh Google maps绘图,我想使用Google maps v3 API的fitBounds()方法来设置缩放级别 我有一个谷歌地图绘图和运行,在我的网站上显示和显示数据点,但我需要手动设置缩放 导入bokeh.io 导入bokeh.models 导入bokeh.plotting 作为pd进口熊猫 数据={ “纬度[度]:[18.46,25.7,32.3], “经度[度]:[-66,-80.2,-64.8], } data\u frame=pd.
导入bokeh.io
导入bokeh.models
导入bokeh.plotting
作为pd进口熊猫
数据={
“纬度[度]:[18.46,25.7,32.3],
“经度[度]:[-66,-80.2,-64.8],
}
data\u frame=pd.DATAFAME.from\u dict(数据)
数据源=bokeh.models.ColumnDataSource(数据框架)
平均纬度=数据帧['Latitude[deg]”。平均()
平均值=数据帧['经度]].平均值()
gmap\u options=bokeh.models.GMapOptions(lat=mean\u lat,lng=mean\u lng,zoom=10,map\u type='satellite')
xy_gmap=bokeh.plotting.gmap('SuPeRSeCrEtAPIkey',gmap_选项)
xy_gmap.圆(x=”经度[deg]”,y=”纬度[deg]”,源=数据_源,颜色=“红色”)
#像这样的回调?可以在页面加载后使用JavaScript调用,并更新地图缩放??
#xy_gmap.fitBounds(x=”经度“,”y=”纬度“,”源=数据_源)
bokeh.io.show(xy_gmap)
我希望地图的边界以尽可能低的缩放率将所有点都包含在我的数据帧中(正如fitBounds()在Javascript中所做的那样)。目前,地图只能缩放到手动设置的水平。从Bokeh 1.2开始,没有内置的方法来实现这一点。我能提供的唯一建议是,在JavaScript端有一个全局
Bokeh.index
,其中有一个GMapPlotView
,用于您创建的相应GmapPlot
。此视图有一个属性.map
,它是实际的Google地图对象。您可以从JavaScript代码中对其调用fitBounds
方法。BokehGMapPlot
对象遵循Google的领先wrt绘制边界,因此如果它们得到更新,轴等应该响应
否则,我只能建议讨论将其作为新功能添加 开始回答bigreddot描述的两种方法(使用JS Bokeh.index和Python集成) 博克指数 在Javascript控制台中,您可以使用以下命令(在一些JS代码中应该是不言自明的) 请注意,Bokeh google maps实现不会在google maps数据层上绘制数据,而是在地图上方的Bokeh画布上绘制数据(这就是为什么在地图平铺和图形之间平移地图时会出现延迟) Python集成
正在进行中……感谢您为我指明了正确的方向。我会研究这个方法,如果我能做点什么,我会提出一个问题和请求。只要注意如果你真的启动了PR:在项目中实现这一点的方法是在
GMapPlot
中添加一个新属性,然后在BokehJS中基于该属性应用fitBounds
(或不)(也就是说,不需要过多使用Bokeh.index
)
> var gmapPlotView;
> for (var property in Bokeh.index) { if (Bokeh.index[property].constructor.name == 'GMapPlotView') {gmapPlotView = Bokeh.index[property];} } // Get the correct object, in the case that you have multiple plots, but only one map plot
> var bounds = gmapPlotView.map.getBounds(); // To start from existing bounds
> var bounds = google.maps.LatLngBounds(); // To start with fresh bounds
> var place = new google.maps.LatLng(45.5983128 ,8.9172776); // Coordinates of place to put bounds, repeat for all points
> bounds.extend(place); // Add each place to the bounds object
> gmapPlotView.map.fitBounds(bounds); // Set the maps new bounds