Skip to content
This repository was archived by the owner on Nov 30, 2018. It is now read-only.

Commit 75e2496

Browse files
author
ralphsaunders
committed
Add config option to prevent loading Maps API
Angular Google Maps loads the Google Maps API when Angular configures all modules. This means the API is requested on every page load, which is undesirable for Google Maps for Work customers who're charged on every page view. As outlined in issue [1604](#1604 (comment)) the ability to delay loading of the API would be beneficial. This commit adds a new service to the google map API provider as well as a new configuration option, `preventLoad: true`. Here's how one would use this new feature to asynchronously load the API at a later time in the Angular lifecycle: var app = angular.module('app', ['uiGmapgoogle-maps']) .config(['uiGmapGoogleMapApiProvider', function(uiGmapGoogleMapApiProvider) { var options = { preventLoad: true }; uiGmapGoogleMapApiProvider.configure(options); }]) .controller('myController', ['$scope', 'uiGmapGoogleMapApi', 'uiGmapGoogleMapApiManualLoader', function($scope, uiGmapGoogleMapApi, uiGmapGoogleMapApiManualLoader) { window.setTimeout(function() { uiGmapGoogleMapApiManualLoader.load(); }, 2000); uiGmapGoogleMapApi.then(function(maps) { // Standard maps code }); }])
1 parent 44810c3 commit 75e2496

File tree

42 files changed

+110
-20101
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+110
-20101
lines changed

dist/angular-google-maps-street-view.js

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/*! angular-google-maps 2.1.6 2015-08-31
1+
/*! angular-google-maps 2.1.6 2015-11-17
22
* AngularJS directives for Google Maps
33
* git: https://github.com/angular-ui/angular-google-maps.git
44
*/
@@ -76,8 +76,9 @@ return UUID;
7676
;(function() {
7777
angular.module('uiGmapgoogle-maps.providers').factory('uiGmapMapScriptLoader', [
7878
'$q', 'uiGmapuuid', function($q, uuid) {
79-
var getScriptUrl, includeScript, isGoogleMapsLoaded, scriptId;
79+
var getScriptUrl, includeScript, isGoogleMapsLoaded, scriptId, usedConfiguration;
8080
scriptId = void 0;
81+
usedConfiguration = void 0;
8182
getScriptUrl = function(options) {
8283
if (options.china) {
8384
return 'http://maps.google.cn/maps/api/js?';
@@ -91,7 +92,7 @@ return UUID;
9192
};
9293
includeScript = function(options) {
9394
var omitOptions, query, script;
94-
omitOptions = ['transport', 'isGoogleMapsForWork', 'china'];
95+
omitOptions = ['transport', 'isGoogleMapsForWork', 'china', 'preventLoad'];
9596
if (options.isGoogleMapsForWork) {
9697
omitOptions.push('key');
9798
}
@@ -124,16 +125,29 @@ return UUID;
124125
window[randomizedFunctionName] = null;
125126
deferred.resolve(window.google.maps);
126127
};
127-
if (window.navigator.connection && window.Connection && window.navigator.connection.type === window.Connection.NONE) {
128+
if (window.navigator.connection && window.Connection && window.navigator.connection.type === window.Connection.NONE && !options.preventLoad) {
128129
document.addEventListener('online', function() {
129130
if (!isGoogleMapsLoaded()) {
130131
return includeScript(options);
131132
}
132133
});
133-
} else {
134+
} else if (!options.preventLoad) {
134135
includeScript(options);
135136
}
137+
usedConfiguration = options;
138+
usedConfiguration.randomizedFunctionName = randomizedFunctionName;
136139
return deferred.promise;
140+
},
141+
manualLoad: function() {
142+
var config;
143+
config = usedConfiguration;
144+
if (!isGoogleMapsLoaded()) {
145+
return includeScript(config);
146+
} else {
147+
if (window[config.randomizedFunctionName]) {
148+
return window[config.randomizedFunctionName]();
149+
}
150+
}
137151
}
138152
};
139153
}
@@ -145,7 +159,8 @@ return UUID;
145159
v: '3',
146160
libraries: '',
147161
language: 'en',
148-
sensor: 'false'
162+
sensor: 'false',
163+
preventLoad: false
149164
};
150165
this.configure = function(options) {
151166
angular.extend(this.options, options);
@@ -158,7 +173,15 @@ return UUID;
158173
})(this)
159174
];
160175
return this;
161-
});
176+
}).service('uiGmapGoogleMapApiManualLoader', [
177+
'uiGmapMapScriptLoader', function(loader) {
178+
return {
179+
load: function() {
180+
loader.manualLoad();
181+
}
182+
};
183+
}
184+
]);
162185

163186
}).call(this);
164187
;(function() {

dist/angular-google-maps-street-view.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)