简体   繁体   中英

Google Geochart visualization library not loaded

I have created a Google Geochart widget some time ago with an older Google JS library version. Nowadays Google advised to upgrade to update to the loader api instead of the jsapi. No matter how I load the libraries, for me the visualization library doesn't load properly, hence I get an undefined when trying to instantiate a GeoChart object. Did anybody else encounter this issue as well?

(The JS code is in the form of Dojo widget functions)

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 expects a reference to a function --> this.drawChart

not the result of a function --> this.drawChart(callback)

try as follows...

google.charts.setOnLoadCallback(function () {
  this.drawChart(callback);
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM