Getting RequireJS async plugin working with almond.js
Asked Answered
S

2

9

I read the following article on how to get Google Maps, and gmaps.js to work with RequireJS. However, when I build my project, RequireJS is swapped with Almond. In the article above, it states that Almond will not work with the RequireJS async plugin. Without the async plugin, Google's dependencies are not loaded, and gmaps.js throw an error.

Is there a way to work around the issue and still load Google maps code in a project that uses Almond rather than RequireJS?

Santossantosdumont answered 16/12, 2012 at 5:48 Comment(0)
T
1

Yeah I'm finding this too. Dynamic libraries cannot be loaded it says. I guess you'll have to download it locally.

Tybalt answered 27/6, 2013 at 15:18 Comment(0)
T
0

Almond.js can't handle with asynchronous plugins. You may use jQuery.Deferred to load the libraries.

var googleMapsLoader = function(func, options) {
    var defaults = { 
        "sensor"   : "false", 
        "v"        : "3", 
        "key"      : "", 
        "language" : "pt", 
        "region"   : "br",
        "libraries": ""
     };

     $.when($.ajax({
         type: "GET",
         dataType: "script",
         data: $.extend({}, defaults, options),
         url: "https://maps.google.com/maps/api/js",
         crossDomain: true
     })).then(function() {
         func();
     });
};

/*
 * Loading Google Maps API with $.Deferred.
 */
googleMapsLoader(function() {
    // You may call your code here.
}, {
    "libraries" : "geometry,places",
    "v"         : "3.7"
});

Look at this example using $.Deferred and Maplace.

Trichroism answered 13/7, 2016 at 18:24 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.