-
Notifications
You must be signed in to change notification settings - Fork 685
/
Copy pathshared.js
62 lines (56 loc) · 1.81 KB
/
shared.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
// This is a list of example API codes, to make this preview
// functioning. Please register with the providers to use them
// with your own app.
var exampleAPIcodes = {
'HERE': {
'app_id': 'tFZyfnyJAmhfh5gdoGcR',
'app_code': 'vJ8o9OCQ1o0Y2wwbRspzSA'
},
'Thunderforest': {
'apikey': 'db5ae1f5778a448ca662554581f283c5'
}
};
var origProviderInit = L.TileLayer.Provider.prototype.initialize;
L.TileLayer.Provider.include({
initialize: function (providerName, options) {
this._providerName = providerName;
options = options || {};
// replace example API codes in options
var provider = this._providerName.split('.')[0];
if (provider in exampleAPIcodes) {
// overwrite exampleAPIcodes with a placeholder to prevent accidental use
// of these API codes.
this._exampleAPIcodes = {};
for (var key in exampleAPIcodes[provider]) {
this._exampleAPIcodes[key] = '<your ' + key + '>';
}
L.extend(options, exampleAPIcodes[provider]);
}
origProviderInit.call(this, providerName, options);
}
});
// save the options while creating tilelayers to cleanly access them later.
var origTileLayerInit = L.TileLayer.prototype.initialize;
L.TileLayer.include({
initialize: function (url, options) {
this._options = options;
origTileLayerInit.apply(this, arguments);
}
});
L.tileLayer.provider.eachLayer = function (callback) {
for (var provider in L.TileLayer.Provider.providers) {
if (L.TileLayer.Provider.providers[provider].variants) {
for (var variant in L.TileLayer.Provider.providers[provider].variants) {
callback(provider + '.' + variant);
}
} else {
callback(provider);
}
}
};
if (!String.prototype.startsWith) {
String.prototype.startsWith = function (searchString, position) {
position = position || 0;
return this.substr(position, searchString.length) === searchString;
};
}