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

237 views Asked by At

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.

2

There are 2 answers

0
Rizwan On BEST ANSWER

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();
            }
        }
    }
4
Alexandre Dubé On

Starting with v0.6, ol3-google-maps gets released with OpenLayers compiled within. You do not need to load the OpenLayers library separately from there on.

Also, please not that for each release, the OpenLayers version used may be different. If you wish to use OpenLayers 3.18.1, then you should use ol3-google-maps v0.11.0.