Google 未加载 Geochart 可视化库
Google Geochart visualization library not loaded
前段时间我使用较旧的 Google JS 库版本创建了一个 Google Geochart 小部件。如今 Google 建议升级以更新加载程序 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);
},
setOnLoadCallback
需要对函数的引用 --> this.drawChart
不是函数的结果 --> this.drawChart(callback)
尝试如下...
google.charts.setOnLoadCallback(function () {
this.drawChart(callback);
});
前段时间我使用较旧的 Google JS 库版本创建了一个 Google Geochart 小部件。如今 Google 建议升级以更新加载程序 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);
},
setOnLoadCallback
需要对函数的引用 --> this.drawChart
不是函数的结果 --> this.drawChart(callback)
尝试如下...
google.charts.setOnLoadCallback(function () {
this.drawChart(callback);
});