-
Notifications
You must be signed in to change notification settings - Fork 1
/
basemap-mapbox.user.js
94 lines (76 loc) · 3.25 KB
/
basemap-mapbox.user.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
// ==UserScript==
// @id iitc-plugin-basemap-mapbox@balthild
// @name IITC plugin: MapBox map tiles
// @category Map Tiles
// @version 0.1
// @description Add the MapBox map tiles as an optional layer.
// @include https://*.ingress.com/intel*
// @include http://*.ingress.com/intel*
// @match https://*.ingress.com/intel*
// @match http://*.ingress.com/intel*
// @include https://*.ingress.com/mission/*
// @include http://*.ingress.com/mission/*
// @match https://*.ingress.com/mission/*
// @match http://*.ingress.com/mission/*
// @grant none
// ==/UserScript==
function wrapper(plugin_info) {
// ensure plugin framework is there, even if iitc is not yet loaded
if (typeof window.plugin !== 'function') window.plugin = function() {};
// PLUGIN START ////////////////////////////////////////////////////////
// Access token can be applied for free at https://www.mapbox.com/maps/
var mapBoxUserName = 'xxxx';
var mapBoxAccessToken = 'pk.XXXXXXXX';
// see https://www.mapbox.com/api-documentation/?language=cURL#styles
var mapStyles = {
// '[style id]': 'Layer Name',
// 'cjas1sv4s09qt2smz1nyf3wok': 'MapBox Scenic',
// 'cjas7e263j04l2rquka2eoyar': 'MapBox Bright',
};
// see https://www.mapbox.com/api-documentation/?language=cURL#maps
var mapIDs = {
// '[map id]': 'Layer Name',
'mapbox.streets': 'MapBox Streets',
'mapbox.light': 'MapBox Light',
'mapbox.dark': 'MapBox Dark',
};
// use own namespace for plugin
window.plugin.mapTileMapBox = {
addLayer: function() {
var osmOpt = {
attribution: 'Map data © MapBox',
maxNativeZoom: 18,
maxZoom: 21,
};
var layers = {};
var ratio = window.devicePixelRatio < 2 ? '' : '@2x';
for (var style in mapStyles) {
layers['https://api.mapbox.com/styles/v1/' + mapBoxUserName + '/' + style + '/tiles/256/{z}/{x}/{y}' + ratio + '?access_token=' + mapBoxAccessToken] = mapStyles[style];
}
for (var id in mapIDs) {
layers['https://api.mapbox.com/v4/' + id + '/{z}/{x}/{y}' + ratio + '.png?access_token=' + mapBoxAccessToken] = mapIDs[id];
}
for (var url in layers) {
var layer = new L.TileLayer(url, osmOpt);
layerChooser.addBaseLayer(layer, layers[url]);
}
},
};
var setup = window.plugin.mapTileMapBox.addLayer;
// PLUGIN END //////////////////////////////////////////////////////////
setup.info = plugin_info; //add the script info data to the function as a property
if (!window.bootPlugins) window.bootPlugins = [];
window.bootPlugins.push(setup);
// if IITC has already booted, immediately run the 'setup' function
if (window.iitcLoaded && typeof setup === 'function') setup();
} // wrapper end
// inject code into site context
var script = document.createElement('script');
var info = {};
if (typeof GM_info !== 'undefined' && GM_info && GM_info.script) info.script = {
version: GM_info.script.version,
name: GM_info.script.name,
description: GM_info.script.description
};
script.appendChild(document.createTextNode('(' + wrapper + ')(' + JSON.stringify(info) + ');'));
(document.body || document.head || document.documentElement).appendChild(script);