forked from glenrobertson/leaflet-tilelayer-geojson
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Request.js
42 lines (37 loc) · 1.16 KB
/
Request.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
L.Request = {
get: function (url, callback, responseType) {
var req = new XMLHttpRequest();
req.onreadystatechange = function() {
if (req.readyState != 4) {
return;
}
var s = req.status,
data;
data = L.Request._getResponse(req, responseType);
// status 0 + response check for file:// URLs
if ((s >= 200 && s < 300) || s == 304 || (s == 0 && data)) {
callback(null, data);
} else {
callback(s + ': ' + req.statusText, null);
}
};
req.open('GET', url, true);
if (responseType) {
req.responseType = responseType;
}
req.send();
return req;
},
binaryGet: function (url, callback) {
return L.Request.get(url, callback, 'arraybuffer');
},
_getResponse: function(req, responseType) {
var response;
if (responseType && responseType === 'arraybuffer') {
response = req.response;
} else {
response = req.responseText;
}
return response;
}
};