Skip to content

Instantly share code, notes, and snippets.

@martinstreicher
Created September 30, 2016 18:07
Show Gist options
  • Save martinstreicher/13f0e27dc2c4f9f1b699e05d8a103236 to your computer and use it in GitHub Desktop.
Save martinstreicher/13f0e27dc2c4f9f1b699e05d8a103236 to your computer and use it in GitHub Desktop.
define([
'mapbox-gl-supported'
], function(
isMapboxGlSupported
) {
// the function that will load the map code and initialize
// the map, or if the map code has been loaded, just
// initialize the map.
var loadAndInitMap;
// feature detection -- webGL detected.
if(isMapboxGlSupported()) {
// here is where we make the initialization dependent
// on the loading of MapboxGL.
loadAndInitMap = function() {
require(['mapbox-gl'], function(initMap) {
initMap();
});
};
// once feature detection is complete, go ahead and start
// loading the MapboxGL library in the background. The
// inner initMap function is not called because we are
// saving it for when the user clicks.
require(['mapbox-gl'], function(initMap) {});
} else {
// feature detection -- webGL not detected.
// here is where we make the initialization dependent
// on the loading of Mapbox.js.
loadAndInitMap = function() {
require(['mapbox.js'], function(initMap) {
initMap();
});
};
// once feature detection is complete, go ahead and start
// loading the Mapbox.js library in the background. The
// inner initMap function is not called because we are
// saving it for when the user clicks.
require(['mapbox.js'], function(initMap) {});
}
// the user click will initialize the map, but wait until the
// correct library has been loaded.
$(".map-container").click(loadAndInitMap);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment