forked from mapbox/mapbox.js-bower
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmapbox.internals.js
304 lines (258 loc) · 23.2 KB
/
mapbox.internals.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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
function corslite(url, callback, cors) {
var sent = false;
if (typeof window.XMLHttpRequest === 'undefined') {
return callback(Error('Browser not supported'));
}
if (typeof cors === 'undefined') {
var m = url.match(/^\s*https?:\/\/[^\/]*/);
cors = m && (m[0] !== location.protocol + '//' + location.domain +
(location.port ? ':' + location.port : ''));
}
var x = new window.XMLHttpRequest();
function isSuccessful(status) {
return status >= 200 && status < 300 || status === 304;
}
if (cors && !('withCredentials' in x)) {
// IE8-9
x = new window.XDomainRequest();
// Ensure callback is never called synchronously, i.e., before
// x.send() returns (this has been observed in the wild).
// See https://github.com/mapbox/mapbox.js/issues/472
var original = callback;
callback = function() {
if (sent) {
original.apply(this, arguments);
} else {
var that = this, args = arguments;
setTimeout(function() {
original.apply(that, args);
}, 0);
}
}
}
function loaded() {
if (
// XDomainRequest
x.status === undefined ||
// modern browsers
isSuccessful(x.status)) callback.call(x, null, x);
else callback.call(x, x, null);
}
// Both `onreadystatechange` and `onload` can fire. `onreadystatechange`
// has [been supported for longer](http://stackoverflow.com/a/9181508/229001).
if ('onload' in x) {
x.onload = loaded;
} else {
x.onreadystatechange = function readystate() {
if (x.readyState === 4) {
loaded();
}
};
}
// Call the callback with the XMLHttpRequest object as an error and prevent
// it from ever being called again by reassigning it to `noop`
x.onerror = function error(evt) {
// XDomainRequest provides no evt parameter
callback.call(this, evt || true, null);
callback = function() { };
};
// IE9 must have onprogress be set to a unique function.
x.onprogress = function() { };
x.ontimeout = function(evt) {
callback.call(this, evt, null);
callback = function() { };
};
x.onabort = function(evt) {
callback.call(this, evt, null);
callback = function() { };
};
// GET is the only supported HTTP Verb by XDomainRequest and is the
// only one supported here.
x.open('GET', url, true);
// Send the request. Sending data is not supported.
x.send(null);
sent = true;
return x;
}
if (typeof module !== 'undefined') module.exports = corslite;
},{}],2:[function(require,module,exports){
module.exports={
"author": "Mapbox",
"name": "mapbox.js",
"description": "mapbox javascript api",
"version": "2.2.3",
"homepage": "http://mapbox.com/",
"repository": {
"type": "git",
"url": "git://github.com/mapbox/mapbox.js.git"
},
"main": "src/index.js",
"dependencies": {
"corslite": "0.0.6",
"isarray": "0.0.1",
"leaflet": "0.7.7",
"mustache": "0.7.3",
"sanitize-caja": "0.1.3"
},
"scripts": {
"test": "eslint --no-eslintrc -c .eslintrc src && mocha-phantomjs test/index.html"
},
"license": "BSD-3-Clause",
"devDependencies": {
"browserify": "^6.3.2",
"clean-css": "~2.0.7",
"eslint": "^0.23.0",
"expect.js": "0.3.1",
"happen": "0.1.3",
"leaflet-fullscreen": "0.0.4",
"leaflet-hash": "0.2.1",
"marked": "~0.3.0",
"minifyify": "^6.1.0",
"minimist": "0.0.5",
"mocha": "1.17.1",
"mocha-phantomjs": "3.1.6",
"sinon": "1.10.2"
},
"optionalDependencies": {},
"engines": {
"node": "*"
}
}
},{}],3:[function(require,module,exports){
'use strict';
module.exports = {
HTTP_URL: 'http://a.tiles.mapbox.com/v4',
HTTPS_URL: 'https://a.tiles.mapbox.com/v4',
FORCE_HTTPS: false,
REQUIRE_ACCESS_TOKEN: true
};
},{}],4:[function(require,module,exports){
'use strict';
var config = require('./config'),
version = require('../package.json').version;
module.exports = function(path, accessToken) {
accessToken = accessToken || L.mapbox.accessToken;
if (!accessToken && config.REQUIRE_ACCESS_TOKEN) {
throw new Error('An API access token is required to use Mapbox.js. ' +
'See https://www.mapbox.com/mapbox.js/api/v' + version + '/api-access-tokens/');
}
var url = (document.location.protocol === 'https:' || config.FORCE_HTTPS) ? config.HTTPS_URL : config.HTTP_URL;
url = url.replace(/\/v4$/, '');
url += path;
url += url.indexOf('?') !== -1 ? '&access_token=' : '?access_token=';
if (config.REQUIRE_ACCESS_TOKEN) {
if (accessToken[0] === 's') {
throw new Error('Use a public access token (pk.*) with Mapbox.js, not a secret access token (sk.*). ' +
'See https://www.mapbox.com/mapbox.js/api/v' + version + '/api-access-tokens/');
}
url += accessToken;
}
return url;
};
module.exports.tileJSON = function(urlOrMapID, accessToken) {
if (urlOrMapID.indexOf('/') !== -1)
return urlOrMapID;
var url = module.exports('/v4/' + urlOrMapID + '.json', accessToken);
// TileJSON requests need a secure flag appended to their URLs so
// that the server knows to send SSL-ified resource references.
if (url.indexOf('https') === 0)
url += '&secure';
return url;
};
},{"../package.json":2,"./config":3}],5:[function(require,module,exports){
'use strict';
function utfDecode(c) {
if (c >= 93) c--;
if (c >= 35) c--;
return c - 32;
}
module.exports = function(data) {
return function(x, y) {
if (!data) return;
var idx = utfDecode(data.grid[y].charCodeAt(x)),
key = data.keys[idx];
return data.data[key];
};
};
},{}],6:[function(require,module,exports){
window.internals = {
url: require('./format_url'),
config: require('./config'),
util: require('./util'),
grid: require('./grid'),
request: require('./request')
};
},{"./config":3,"./format_url":4,"./grid":5,"./request":7,"./util":8}],7:[function(require,module,exports){
'use strict';
var corslite = require('corslite'),
strict = require('./util').strict,
config = require('./config');
var protocol = /^(https?:)?(?=\/\/(.|api)\.tiles\.mapbox\.com\/)/;
module.exports = function(url, callback) {
strict(url, 'string');
strict(callback, 'function');
url = url.replace(protocol, function(match, protocol) {
if (!('withCredentials' in new window.XMLHttpRequest())) {
// XDomainRequest in use; doesn't support cross-protocol requests
return document.location.protocol;
} else if (protocol === 'https:' || document.location.protocol === 'https:' || config.FORCE_HTTPS) {
return 'https:';
} else {
return 'http:';
}
});
function onload(err, resp) {
if (!err && resp) {
resp = JSON.parse(resp.responseText);
}
callback(err, resp);
}
return corslite(url, onload);
};
},{"./config":3,"./util":8,"corslite":1}],8:[function(require,module,exports){
'use strict';
function contains(item, list) {
if (!list || !list.length) return false;
for (var i = 0; i < list.length; i++) {
if (list[i] === item) return true;
}
return false;
}
module.exports = {
idUrl: function(_, t) {
if (_.indexOf('/') === -1) t.loadID(_);
else t.loadURL(_);
},
log: function(_) {
if (typeof console === 'object' &&
typeof console.error === 'function') {
console.error(_);
}
},
strict: function(_, type) {
if (typeof _ !== type) {
throw new Error('Invalid argument: ' + type + ' expected');
}
},
strict_instance: function(_, klass, name) {
if (!(_ instanceof klass)) {
throw new Error('Invalid argument: ' + name + ' expected');
}
},
strict_oneof: function(_, values) {
if (!contains(_, values)) {
throw new Error('Invalid argument: ' + _ + ' given, valid values are ' +
values.join(', '));
}
},
strip_tags: function(_) {
return _.replace(/<[^<]+>/g, '');
},
lbounds: function(_) {
// leaflet-compatible bounds, since leaflet does not do geojson
return new L.LatLngBounds([[_[1], _[0]], [_[3], _[2]]]);
}
};
},{}]},{},[6])
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIm5vZGVfbW9kdWxlcy9icm93c2VyaWZ5L25vZGVfbW9kdWxlcy9icm93c2VyLXBhY2svX3ByZWx1ZGUuanMiLCJub2RlX21vZHVsZXMvY29yc2xpdGUvY29yc2xpdGUuanMiLCJwYWNrYWdlLmpzb24iLCJzcmMvY29uZmlnLmpzIiwic3JjL2Zvcm1hdF91cmwuanMiLCJzcmMvZ3JpZC5qcyIsInNyYy9pbnRlcm5hbHMuanMiLCJzcmMvcmVxdWVzdC5qcyIsInNyYy91dGlsLmpzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBO0FDQUE7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQ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