Search code examples
openlayersopenlayers-3ol3-google-maps

Upgrading ol3-google-maps 0.4 to 0.13 resulting in this.setMap is not a function error


I have been using ol3-google-maps 0.4 for quite some time but now had to upgrade it to 0.10 (or higher). So I am replacing the content of my ol3gm.js (0.4) to latest (0.13). With 0.4 my application works fine, but as soon as I switch to 0.13 get "this.setMap is not a function error".

Using Openlayers 3.18.1

Could someone let me know the difference between the two and How to resolve this issue.


Solution

  • As explained by Alexandre that from v0.6 onwards ol3-google-maps gets released with OpenLayers compiled within.

    Since I was using ol3gm v0.4 which didn't included Openlayers in it I was loading the ol.js and Google APIs at the initialization of the application and once the base layer change event was fired was loading ol3gm.js at runtime, hence the issue. Made that library loading sequence correct and the problem was resolved. If anyone facing similar issue can use the below code to wait until olgm is available to use.

      var googleInterval = setInterval(function(){
            initmapController()
        }, 1000);
        function initmapController() {
            $("#loadingOverLay").removeClass('hide')
            if (google.maps !== undefined){
                if(typeof olgm !== "undefined") {
                    $("#loadingOverLay").addClass('hide')
                    clearInterval(googleInterval);
                    init();
                }
            }
        }