Skip to content

Commit

Permalink
Update to support async loading of geo libs
Browse files Browse the repository at this point in the history
  • Loading branch information
mikepugh committed Feb 1, 2015
1 parent 9c75791 commit 9fe31d3
Show file tree
Hide file tree
Showing 2 changed files with 188 additions and 188 deletions.
282 changes: 141 additions & 141 deletions dist/angulargeo.js
Original file line number Diff line number Diff line change
@@ -1,141 +1,141 @@
/**
* Created by Mike on 1/31/14.
*/

(function() {
"use strict";

var angularGeo = angular.module('angular-geo', []);
angularGeo.constant('angularGeo_msgs', {
'errors.unsupportedBrowser':'Browser geolocation not supported',
'errors.noServices':'angularGeo could not locate any of the geo providers specified, verify that you have them properly linked',
'errors.noProviders':'angularGeo requires at least one geo provider'
});
angularGeo.provider('angularGeo', function () {
var $$geoConfig = {
providerSvcNames: [],
providers: []
};
var $$supportsGeolocation = false;
var $$watchId;
var $$currentProvider = 0;

return {
addProvider: function (providerSvcName) {
$$geoConfig.providerSvcNames.push(providerSvcName);
return this;
},
$get: function angularGeo($log, $q, $timeout, $rootScope, $injector, $window, angularGeo_msgs) {

$$supportsGeolocation = 'geolocation' in $window.navigator;

if($$geoConfig.providerSvcNames.length === 0) {
throw new Error(angularGeo_msgs.errors.noProviders);
}
// Instantiate the geo providers and store them within the $$geoConfig object
for(var i = 0; i < $$geoConfig.providerSvcNames.length; i++) {
if(!$injector.has($$geoConfig.providerSvcNames[i])) {
$log.error('angularGeo could not locate service ' + $$geoConfig.providerSvcNames[i]);
} else {
$$geoConfig.providers.push($injector.get($$geoConfig.providerSvcNames[i]));
}
}
var $$providers = $$geoConfig.providers;
if($$providers.length === 0) {
throw new Error(angularGeo_msgs.errors.noServices);
}

var $$geocode = function(address, bounds, region, restrictions, filters, promise) {
var deferred = promise || $q.defer();
var p = $$providers[$$currentProvider].geocode(address, bounds, region, restrictions, filters);
p.then(function(results) {
deferred.resolve(results);
}, function(err) {
if($$providers.length === 1) {
deferred.reject(err);
return;
}
if($$currentProvider < $$providers.length - 1) {
$$currentProvider++;
} else {
$$currentProvider = 0;
}
return $$geocode(address, bounds, region, restrictions, filters, deferred);
});
return deferred.promise;
};

var $$reverseGeo = function(latLng, bounds, region, restrictions, filters, promise) {
var deferred = promise || $q.defer();
var p = $$providers[$$currentProvider].reverseGeocode(latLng, bounds, region, restrictions, filters);
p.then(function(results) {
deferred.resolve(results);
}, function(err) {
if($$providers.length === 1) {
deferred.reject(err);
return;
}
if($$currentProvider < $$providers.length - 1) {
$$currentProvider++;
} else {
$$currentProvider = 0;
}
return $$reverseGeo(latLng, bounds, region, restrictions, filters, deferred);
});
return deferred.promise;
};

return {
geocode: function(address, bounds, region, restrictions, filters) {
return $$geocode(address, bounds, region, restrictions, filters, null);
},
reverseGeocode: function(latLng, bounds, region, restrictions, filters) {
return $$reverseGeo(latLng, bounds, region, restrictions, filters);
},
getCurrentPosition: function(options, autoReverseGeocode) {
var self = this;
if(!$$supportsGeolocation) {
throw new Error(angularGeo_msgs.errors.unsupportedBrowser);
}
var deferred = $q.defer();
$window.navigator.geolocation.getCurrentPosition(function(pos) {
if(autoReverseGeocode) {
var p = $$reverseGeo({latitude: pos.coords.latitude, longitude: pos.coords.longitude}, null, null, null, null);
p.then(function(results) {
deferred.resolve(results);
}, function(err) {
deferred.reject(err);
});
} else {
deferred.resolve(pos);
}
}, function(err) {
deferred.reject(err);
}, options);
return deferred.promise;
},
watchPosition: function(options) {
var self = this;
if(!$$supportsGeolocation) {
throw new Error(angularGeo_msgs.errors.unsupportedBrowser);
}
var deferred = $q.defer();
$$watchId = $window.navigator.geolocation.watchPosition(function(pos) {
$rootScope.$broadcast("angulargeo:watchposition", pos);
}, function(err) {
deferred.reject(err);
}, options);
return deferred.promise;

},
clearWatch: function() {
if(!$$supportsGeolocation) {
throw new Error(angularGeo_msgs.errors.unsupportedBrowser);
}
$window.navigator.geolocation.clearWatch($$watchId);
}
}
}
}
});
}).call(this);
/**
* Created by Mike on 1/31/14.
*/

(function() {
"use strict";

var angularGeo = angular.module('angular-geo', []);
angularGeo.constant('angularGeo_msgs', {
'errors.unsupportedBrowser':'Browser geolocation not supported',
'errors.noServices':'angularGeo could not locate any of the geo providers specified, verify that you have them properly linked',
'errors.noProviders':'angularGeo requires at least one geo provider'
});
angularGeo.provider('angularGeo', function () {
var $$geoConfig = {
providerSvcNames: [],
providers: []
};
var $$supportsGeolocation = false;
var $$watchId;
var $$currentProvider = 0;

return {
addProvider: function (providerSvcName) {
$$geoConfig.providerSvcNames.push(providerSvcName);
return this;
},
$get: function angularGeo($log, $q, $timeout, $rootScope, $injector, $window, angularGeo_msgs) {

$$supportsGeolocation = 'geolocation' in $window.navigator;

if($$geoConfig.providerSvcNames.length === 0) {
throw new Error(angularGeo_msgs.errors.noProviders);
}
// Instantiate the geo providers and store them within the $$geoConfig object
for(var i = 0; i < $$geoConfig.providerSvcNames.length; i++) {
if(!$injector.has($$geoConfig.providerSvcNames[i])) {
$log.error('angularGeo could not locate service ' + $$geoConfig.providerSvcNames[i]);
} else {
$$geoConfig.providers.push($injector.get($$geoConfig.providerSvcNames[i]));
}
}
var $$providers = $$geoConfig.providers;
if($$providers.length === 0) {
throw new Error(angularGeo_msgs.errors.noServices);
}

var $$geocode = function(address, bounds, region, restrictions, filters, promise) {
var deferred = promise || $q.defer();
var p = $$providers[$$currentProvider].geocode(address, bounds, region, restrictions, filters);
p.then(function(results) {
deferred.resolve(results);
}, function(err) {
if($$providers.length === 1) {
deferred.reject(err);
return;
}
if($$currentProvider < $$providers.length - 1) {
$$currentProvider++;
} else {
$$currentProvider = 0;
}
return $$geocode(address, bounds, region, restrictions, filters, deferred);
});
return deferred.promise;
};

var $$reverseGeo = function(latLng, bounds, region, restrictions, filters, promise) {
var deferred = promise || $q.defer();
var p = $$providers[$$currentProvider].reverseGeocode(latLng, bounds, region, restrictions, filters);
p.then(function(results) {
deferred.resolve(results);
}, function(err) {
if($$providers.length === 1) {
deferred.reject(err);
return;
}
if($$currentProvider < $$providers.length - 1) {
$$currentProvider++;
} else {
$$currentProvider = 0;
}
return $$reverseGeo(latLng, bounds, region, restrictions, filters, deferred);
});
return deferred.promise;
};

return {
geocode: function(address, bounds, region, restrictions, filters) {
return $$geocode(address, bounds, region, restrictions, filters, null);
},
reverseGeocode: function(latLng, bounds, region, restrictions, filters) {
return $$reverseGeo(latLng, bounds, region, restrictions, filters);
},
getCurrentPosition: function(options, autoReverseGeocode) {
var self = this;
if(!$$supportsGeolocation) {
throw new Error(angularGeo_msgs.errors.unsupportedBrowser);
}
var deferred = $q.defer();
$window.navigator.geolocation.getCurrentPosition(function(pos) {
if(autoReverseGeocode) {
var p = $$reverseGeo({latitude: pos.coords.latitude, longitude: pos.coords.longitude}, null, null, null, null);
p.then(function(results) {
deferred.resolve(results);
}, function(err) {
deferred.reject(err);
});
} else {
deferred.resolve(pos);
}
}, function(err) {
deferred.reject(err);
}, options);
return deferred.promise;
},
watchPosition: function(options) {
var self = this;
if(!$$supportsGeolocation) {
throw new Error(angularGeo_msgs.errors.unsupportedBrowser);
}
var deferred = $q.defer();
$$watchId = $window.navigator.geolocation.watchPosition(function(pos) {
$rootScope.$broadcast("angulargeo:watchposition", pos);
}, function(err) {
deferred.reject(err);
}, options);
return deferred.promise;

},
clearWatch: function() {
if(!$$supportsGeolocation) {
throw new Error(angularGeo_msgs.errors.unsupportedBrowser);
}
$window.navigator.geolocation.clearWatch($$watchId);
}
}
}
}
});
}).call(this);
94 changes: 47 additions & 47 deletions dist/providers/angulargeo-bing.js
Original file line number Diff line number Diff line change
@@ -1,47 +1,47 @@
/**
* Created by Mike on 2/02/14.
*/
(function() {
"use strict";
angular.module('angular-geo-providers.bing', [])
.provider('angularGeoBing', function() {
var $$q, $$log;
var $$configuration = {};
var $$http;

var $$geoEndpoint = "https://dev.virtualearth.net/REST/v1/Locations?q={0}&key={1}&jsonp=JSON_CALLBACK";
var $$rgeoEndpoint = "https://dev.virtualearth.net/REST/v1/Locations/{0}&key={1}&jsonp=JSON_CALLBACK";

var svc = {
geocode: function(address, bounds, region, restrictions, filters) {
var deferred = $$q.defer();
var httpPromise = $$http.jsonp($$geoEndpoint.replace("{0}", address));
httpPromise.success(function(data, status, headers, config) {
deferred.resolve(data);
})
.error(function(data, status, headers, config) {
deferred.reject({data: data, status: status});
});

return deferred.promise;
},
reverseGeocode: function(latLng, bounds, region, restrictions, filters) {

}
};
return {
name: 'angularGeoBing',
config: function(config) {
$$configuration.apiKey = config.apiKey;
$$geoEndpoint = $$geoEndpoint.replace("{1}", $$configuration.apiKey);
$$rgeoEndpoint = $$rgeoEndpoint.replace("{1}", $$configuration.apiKey);
},
$get: function($log, $q, $http) {
$$q = $q;
$$log = $log;
$$http = $http;
return svc;
}
}
});
}).call(this);
/**
* Created by Mike on 2/02/14.
*/
(function() {
"use strict";
angular.module('angular-geo-providers.bing', [])
.provider('angularGeoBing', function() {
var $$q, $$log;
var $$configuration = {};
var $$http;

var $$geoEndpoint = "https://dev.virtualearth.net/REST/v1/Locations?q={0}&key={1}&jsonp=JSON_CALLBACK";
var $$rgeoEndpoint = "https://dev.virtualearth.net/REST/v1/Locations/{0}&key={1}&jsonp=JSON_CALLBACK";

var svc = {
geocode: function(address, bounds, region, restrictions, filters) {
var deferred = $$q.defer();
var httpPromise = $$http.jsonp($$geoEndpoint.replace("{0}", address));
httpPromise.success(function(data, status, headers, config) {
deferred.resolve(data);
})
.error(function(data, status, headers, config) {
deferred.reject({data: data, status: status});
});

return deferred.promise;
},
reverseGeocode: function(latLng, bounds, region, restrictions, filters) {

}
};
return {
name: 'angularGeoBing',
config: function(config) {
$$configuration.apiKey = config.apiKey;
$$geoEndpoint = $$geoEndpoint.replace("{1}", $$configuration.apiKey);
$$rgeoEndpoint = $$rgeoEndpoint.replace("{1}", $$configuration.apiKey);
},
$get: function($log, $q, $http) {
$$q = $q;
$$log = $log;
$$http = $http;
return svc;
}
}
});
}).call(this);

0 comments on commit 9fe31d3

Please sign in to comment.