【发布时间】:2021-02-22 06:00:24
【问题描述】:
前段时间,我使用较旧的 Google JS 库版本创建了一个 Google Geochart 小部件。现在谷歌建议升级以更新到加载器 api 而不是 jsapi。无论我如何加载库,对我来说,可视化库都无法正确加载,因此在尝试实例化 GeoChart 对象时我得到一个未定义的结果。其他人也遇到过这个问题吗?
(JS代码是Dojo小部件函数的形式)
update : function(obj, callback){
this._contextObj = obj;
this._resetSubscriptions();
if (this.apiAccessKey && this.apiAccessKey !== "") {
google.charts.load('current', {
'packages':['geochart'],
// Note: you will need to get a mapsApiKey for your project.
// See: https://developers.google.com/chart/interactive/docs/basic_load_libs#load-settings
'mapsApiKey': this.apiAccessKey
});
google.charts.setOnLoadCallback(this.drawChart(callback));
} else {
var message = " Google Geochart needs an active API key to work!";
console.error(this._logNode + message);
alert(message);
}
},
drawChart : function (callback) {
// Run this as soon as google charts is loaded.
// Create map and its container.
if (!this.geoMap) {
this.geoMap = new google.visualization.GeoChart(this.geoMapContainer);
}
if (this._contextObj){
this._getObjects(this._contextObj.getGuid,callback);
} else {
this._getObjects(null,callback);
}
this._executeCallback(callback);
},
【问题讨论】:
标签: javascript google-maps google-visualization