-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathbasemap-gaode-vip.user.js
More file actions
219 lines (161 loc) · 7.86 KB
/
basemap-gaode-vip.user.js
File metadata and controls
219 lines (161 loc) · 7.86 KB
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
// ==UserScript==
// @id iitc-plugin-gaode-maps
// @name IITC plugin: Gaode maps
// @category Map Tiles
// @version 0.0.1.20170510.72801
// @namespace https://github.com/jonatkins/ingress-intel-total-conversion
// @description [local-2017-05-10-072801] Add various map layers Gaode Maps.
// @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 AUTHORS: writing a plugin outside of the IITC build environment? if so, delete these lines!!
//(leaving them in place might break the 'About IITC' page or break update checks)
plugin_info.buildName = 'local';
plugin_info.dateTimeVersion = '20170510.72801';
plugin_info.pluginId = 'basemap-gaode';
//END PLUGIN AUTHORS NOTE
// PLUGIN START ////////////////////////////////////////////////////////
window.plugin.mapGaode = function() {};
/////////// begin Gaode transformer /////////
var GaodeTransformer = window.plugin.mapGaode.GaodeTransformer = function() {};
GaodeTransformer.prototype.a = 6378245.0;
GaodeTransformer.prototype.ee = 0.00669342162296594323;
GaodeTransformer.prototype.transformToGcj = function(wgLat, wgLng) {
if (this.isOutOfChina(wgLat, wgLng) || this.isInsideTaiwan(wgLat, wgLng)) {
return {lat: wgLat, lng: wgLng};
}
dLat = this.transformLat(wgLng - 105.0, wgLat - 35.0);
dLng = this.transformLng(wgLng - 105.0, wgLat - 35.0);
radLat = wgLat / 180.0 * Math.PI;
magic = Math.sin(radLat);
magic = 1 - this.ee * magic * magic;
sqrtMagic = Math.sqrt(magic);
dLat = (dLat * 180.0) / ((this.a * (1 - this.ee)) / (magic * sqrtMagic) * Math.PI);
dLng = (dLng * 180.0) / (this.a / sqrtMagic * Math.cos(radLat) * Math.PI);
mgLat = wgLat + dLat;
mgLng = wgLng + dLng;
return {lat: mgLat, lng: mgLng};
};
GaodeTransformer.prototype.transformToWgs = function(gcjLat, gcjLng) {
if (this.isOutOfChina(gcjLat, gcjLng) || this.isInsideTaiwan(gcjLat, gcjLng)) {
return {lat: gcjLat, lng: gcjLng};
}
wgsLat = gcjLat;
wgsLng = gcjLng;
do {
gcjL = this.transformToGcj(wgsLat, wgsLng);
dLat = gcjL.lat - gcjLat;
dLng = gcjL.lng - gcjLng;
wgsLat -= dLat;
wgsLng -= dLng;
} while (Math.abs(dLat) > 1e-10 || Math.abs(dLng) > 1e-10);
return {lat: wgsLat, lng: wgsLng};
};
GaodeTransformer.prototype.transformLat = function(x, y) {
var ret = -100.0 + 2.0 * x + 3.0 * y + 0.2 * y * y + 0.1 * x * y + 0.2 * Math.sqrt(Math.abs(x));
ret += (20.0 * Math.sin(6.0 * x * Math.PI) + 20.0 * Math.sin(2.0 * x * Math.PI)) * 2.0 / 3.0;
ret += (20.0 * Math.sin(y * Math.PI) + 40.0 * Math.sin(y / 3.0 * Math.PI)) * 2.0 / 3.0;
ret += (160.0 * Math.sin(y / 12.0 * Math.PI) + 320 * Math.sin(y * Math.PI / 30.0)) * 2.0 / 3.0;
return ret;
};
GaodeTransformer.prototype.transformLng = function(x, y) {
var ret = 300.0 + x + 2.0 * y + 0.1 * x * x + 0.1 * x * y + 0.1 * Math.sqrt(Math.abs(x));
ret += (20.0 * Math.sin(6.0 * x * Math.PI) + 20.0 * Math.sin(2.0 * x * Math.PI)) * 2.0 / 3.0;
ret += (20.0 * Math.sin(x * Math.PI) + 40.0 * Math.sin(x / 3.0 * Math.PI)) * 2.0 / 3.0;
ret += (150.0 * Math.sin(x / 12.0 * Math.PI) + 300.0 * Math.sin(x / 30.0 * Math.PI)) * 2.0 / 3.0;
return ret;
};
GaodeTransformer.prototype.isOutOfChina = function(lat, lng) {
if (lng < 72.004 || lng > 137.8347) return true;
if (lat < 0.8293 || lat > 55.8271) return true;
return false;
};
GaodeTransformer.prototype.isInsideTaiwan = function(lat, lng) {
return (21.8056 < lat && lat < 25.3637 && 119.9914 < lng && lng < 122.1849);
};
/////////// end Gaode transformer /////////
var gaodeTransformer = new GaodeTransformer();
window.plugin.mapGaode.setupGaodeLayer = function() {
L.GaodeLayer = L.TileLayer.extend({
options: {
subdomains: ['1', '2', '3', '4'],
maxZoom: 19,
detectRetina: true,
attribution: '© <a href="https://gaode.com">高德地图</a>'
},
_getTilePos: function (tilePoint) {
var origin = this._map.getPixelOrigin(),
tileSize = this._getTileSize();
ori = this._map._getCenterLayerPoint();
latLng = this._map.layerPointToLatLng(ori);
latLng = gaodeTransformer.transformToWgs(latLng.lat, latLng.lng);
dst = this._map.latLngToLayerPoint(new L.LatLng(latLng.lat, latLng.lng));
tilePos = tilePoint.multiplyBy(tileSize).subtract(origin).subtract(ori.subtract(dst));
return tilePos;
},
_update: function() {
if (!this._map) { return; }
var map = this._map,
bounds = map.getPixelBounds(),
zoom = map.getZoom(),
tileSize = this._getTileSize();
if (zoom > this.options.maxZoom || zoom < this.options.minZoom) {
return;
}
ori = this._map._getCenterLayerPoint();
latLng = this._map.layerPointToLatLng(ori);
latLng = gaodeTransformer.transformToWgs(latLng.lat, latLng.lng);
dst = this._map.latLngToLayerPoint(new L.LatLng(latLng.lat, latLng.lng));
bounds = L.bounds(
bounds.min.subtract(dst.subtract(ori)),
bounds.max.subtract(dst.subtract(ori))
);
var tileBounds = L.bounds(
bounds.min.divideBy(tileSize)._floor(),
bounds.max.divideBy(tileSize)._floor());
this._addTilesFromCenterOut(tileBounds);
if (this.options.unloadInvisibleTiles || this.options.reuseTiles) {
this._removeOtherTiles(tileBounds);
}
}
});
L.gaodeLayer = function(url, options) {
return new L.GaodeLayer(url, options);
};
};
window.plugin.mapGaode.setup = function() {
window.plugin.mapGaode.setupGaodeLayer();
var gaodeSat = L.gaodeLayer('http://wprd0{s}.is.autonavi.com/appmaptile?style=6&x={x}&y={y}&z={z}', {type: 'SATELLITE'});
layerChooser.addBaseLayer(gaodeSat, 'Gaode Satellite');
var gaodeRoad = L.gaodeLayer('http://grid.amap.com/grid/{z}/{x}/{y}', {type: 'ROADS'});
layerChooser.addBaseLayer(gaodeRoad, 'Gaode Roads');
var gaodeHybrid = L.layerGroup([
L.gaodeLayer('http://wprd0{s}.is.autonavi.com/appmaptile?style=6&x={x}&y={y}&z={z}', {type: 'SATELLITE'}),
L.gaodeLayer('http://wprd0{s}.is.autonavi.com/appmaptile?style=8&x={x}&y={y}&z={z}', {type: 'TRANSPARENT', opacity: 0.75})
]);
layerChooser.addBaseLayer(gaodeHybrid, 'Gaode Hybrid');
};
var setup = window.plugin.mapGaode.setup;
// 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);