-
Notifications
You must be signed in to change notification settings - Fork 1
/
GeoAPI.js
109 lines (90 loc) · 2.23 KB
/
GeoAPI.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
var GeoAPI = angular.module('GeoAPI', []);
GeoAPI.factory('GeoAPI', function($http, $q){
var self = this;
this.conf = {
url: '//apiv1.geoapi.es/',
type: 'JSON',
key: '',
sandbox: 0
};
this._data = {
lastQuery: {
url: '',
params: {}
},
lastResult: {
status: 0,
data: {}
}
};
return {
setConfig: function(constant, value){
self.conf[constant] = value;
},
getLastQuery: function(){
return self._data.lastQuery;
},
getLastResult: function(){
return self._data.lastResult;
},
_call: function(accion, params, deferred){
angular.extend(params, angular.copy(self.conf));
delete params.url;
$http({
method: 'GET',
url: self.conf.url + accion,
params: params
}).then(function(data){
self._data = {
lastQuery: {
url: data.config.url,
params: data.config.params
},
lastResult: {
status: data.status,
data: data.data
}
};
if(data.status != 200){
deferred.reject(data);
console.log("Error: ", data);
}else{
deferred.resolve(data.data);
}
});
return deferred.promise;
},
calles: function calles(params){ /*CPRO, CMUM, CUN, CPOS*/
var deferred = $q.defer();
return this._call('calles', params, deferred);
},
comunidades: function comunidades(params){ /**/
var deferred = $q.defer();
return this._call('comunidades', params, deferred);
},
cps: function cps(params){ /*CPRO, CMUM, CUN*/
var deferred = $q.defer();
return this._call('cps', params, deferred);
},
municipios: function municipios(params){ /*CPRO*/
var deferred = $q.defer();
return this._call('municipios', params, deferred);
},
nucleos: function nucleos(params){ /*CPRO, CMUM, NENTSI50*/
var deferred = $q.defer();
return this._call('nucleos', params, deferred);
},
poblaciones: function poblaciones(params){ /*CPRO, CMUM*/
var deferred = $q.defer();
return this._call('poblaciones', params, deferred);
},
provincias: function provincias(params){ /*CCOM*/
var deferred = $q.defer();
return this._call('provincias', params, deferred);
},
qcalles: function qcalles(params){ /*QUERY*/
var deferred = $q.defer();
return this._call('qcalles', params, deferred);
}
};
});