leaflet.mapCorrection.js 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572
  1. // this L.CRS.Baidu from https://github.com/muyao1987/leaflet-tileLayer-baidugaode/blob/master/src/tileLayer.baidu.js
  2. if (L.Proj) {
  3. L.CRS.Baidu = new L.Proj.CRS('EPSG:900913', '+proj=merc +a=6378206 +b=6356584.314245179 +lat_ts=0.0 +lon_0=0.0 +x_0=0 +y_0=0 +k=1.0 +units=m +nadgrids=@null +wktext +no_defs', {
  4. resolutions: function () {
  5. level = 19
  6. var res = [];
  7. res[0] = Math.pow(2, 18);
  8. for (var i = 1; i < level; i++) {
  9. res[i] = Math.pow(2, (18 - i))
  10. }
  11. return res;
  12. }(),
  13. origin: [0, 0],
  14. bounds: L.bounds([20037508.342789244, 0], [0, 20037508.342789244])
  15. });
  16. }
  17. L.TileLayer.ChinaProvider = L.TileLayer.extend({
  18. initialize: function(type, options) { // (type, Object)
  19. var providers = L.TileLayer.ChinaProvider.providers;
  20. options = options || {}
  21. var parts = type.split('.');
  22. var providerName = parts[0];
  23. var mapName = parts[1];
  24. var mapType = parts[2];
  25. var url = providers[providerName][mapName][mapType];
  26. function getcookie(objname){
  27. var arrstr = document.cookie.split("; ");
  28. for(var i=0;i<arrstr.length;i++){
  29. var temp = arrstr[i].split("=");
  30. if(temp[0]==objname)return unescape(temp[1]);
  31. }
  32. }
  33. var login_apikey = localStorage.apikey;
  34. //如果当前用户没有apikey则取配置中的默认key
  35. if(typeof(login_apikey) === 'undefined'){
  36. login_apikey = providers[providerName].key;
  37. }
  38. //url += "?apikey=" + login_apikey;
  39. options.subdomains = providers[providerName].Subdomains;
  40. //options.key = options.key || providers[providerName].key;
  41. options.key = options.key || login_apikey;
  42. if ('tms' in providers[providerName]) {
  43. options.tms = providers[providerName]['tms']
  44. }
  45. L.TileLayer.prototype.initialize.call(this, url, options);
  46. }
  47. });
  48. //
  49. L.TileLayer.ChinaProvider.providers = {
  50. TianDiTu: {
  51. Normal: {
  52. Map: "http://{s}.map.jms.gd/tile/tiandi/{z}/{x}/{y}.png?apikey={key}",
  53. Annotion: "http://{s}.map.jms.gd/tile/tiandi_cva/{z}/{x}/{y}.png?apikey={key}",
  54. Ibo: "http://{s}.map.jms.gd/tile/tiandi_ibo/{z}/{x}/{y}.png?apikey={key}",
  55. Mycva: "http://{s}.map.jms.gd/tile/tdt/{z}/{x}/{y}.png?apikey={key}",
  56. },
  57. Satellite: {
  58. Map: "http://{s}.map.jms.gd/tile/tiandi_wx/{z}/{x}/{y}.png?apikey={key}",
  59. },
  60. Terrain: {
  61. Map: "http://a.map.jms.gd/tile/tiandi_ter/{z}/{x}/{y}.png?apikey={key}",
  62. },
  63. Subdomains: ["a", "b", "c", "d"],
  64. key: "jm20240118"
  65. },
  66. GaoDe: {
  67. Normal: {
  68. Map: 'http://{s}.map.jms.gd/tile/shiliang/{z}/{x}/{y}.png?apikey={key}',
  69. XiangTu: 'http://{s}.map.jms.gd/tile/gd_xiangtu/{z}/{x}/{y}.png?apikey={key}',
  70. XiangTuGray: 'http://{s}.map.jms.gd/tile/gd_xiangtu_gray/{z}/{x}/{y}.png?apikey={key}',
  71. WuWenZi: 'http://{s}.map.jms.gd/tile/gd_wuwenzi/{z}/{x}/{y}.png?apikey={key}',
  72. LuWang: 'http://{s}.map.jms.gd/tile/luwang/{z}/{x}/{y}.png?apikey={key}',
  73. DiBiao: 'http://{s}.map.jms.gd/tile/gd_dibiao/{z}/{x}/{y}.png?apikey={key}',
  74. Test: "http://{s}.map.jms.gd/tile/test/{z}/{x}/{y}.png?apikey={key}",
  75. },
  76. Satellite: {
  77. Map: 'http://{s}.map.jms.gd/tile/weixing/{z}/{x}/{y}.png?apikey={key}'
  78. },
  79. Subdomains: ["a", "b", "c", "d"],
  80. key: "jm20240118"
  81. },
  82. Pengjiang: {
  83. Normal: {
  84. Map: "http://{s}.map.jms.gd/tile/pengjiang/{z}/{x}/{y}.png?apikey={key}"
  85. },
  86. Subdomains: ["a", "b", "c", "d"],
  87. key: "jm20240118"
  88. },
  89. Taishan: {
  90. Normal: {
  91. Map: "http://{s}.map.jms.gd/tile/taishan/{z}/{x}/{y}.png?apikey={key}"
  92. },
  93. Subdomains: ["a", "b", "c", "d"],
  94. key: "jm20240118"
  95. },
  96. Test: {
  97. Normal: {
  98. Test: "http://f.map.jms.gd/tile/test/{z}/{x}/{y}.png?apikey={key}",
  99. Test1: "http://f.map.jms.gd/tile/test1/{z}/{x}/{y}.png?apikey={key}",
  100. },
  101. Subdomains: ["a", "b", "c", "d"],
  102. key: "jm20240118"
  103. },
  104. Guangzhou: {
  105. Normal: {
  106. Hdpi: "http://{s}.map.jms.gd/tile/gz_hdpi/{z}/{x}/{y}.png?apikey={key}"
  107. },
  108. Subdomains: ["a", "b", "c", "d"],
  109. key: "jm20240118"
  110. },
  111. Google: {
  112. Normal: {
  113. Map: "",
  114. },
  115. Satellite: {
  116. Map: "http://{s}.map.jms.gd/tile/google_s/{z}/{x}/{y}.png?apikey={key}",
  117. },
  118. Subdomains: ["a", "b", "c", "d"],
  119. key: "jm20240118"
  120. },
  121. GoogleCn: {
  122. Normal: {
  123. Map: "http://{s}.map.jms.gd/tile/google/{z}/{x}/{y}.png?apikey={key}",
  124. Terrain: "http://{s}.map.jms.gd/tile/google_dx/{z}/{x}/{y}.png?apikey={key}",
  125. Annotion: "http://{s}.map.jms.gd/tile/google_h/{z}/{x}/{y}.png?apikey={key}",
  126. Ter: "http://{s}.map.jms.gd/tile/google_t/{z}/{x}/{y}.png?apikey={key}",
  127. },
  128. Satellite: {
  129. Map: "http://{s}.map.jms.gd/tile/google_s/{z}/{x}/{y}.png?apikey={key}",
  130. Annotion: "http://{s}.map.jms.gd/tile/google_wx/{z}/{x}/{y}.png?apikey={key}",
  131. },
  132. Subdomains: ["a", "b", "c", "d"],
  133. key: "jm20240118"
  134. },
  135. Tengxun: {
  136. Normal: {
  137. Map: "http://{s}.map.jms.gd/tile/tengxun/{z}/{x}/{y}.png?apikey={key}",
  138. Map9: "http://{s}.map.jms.gd/tile/tengxun_9/{z}/{x}/{y}.png?apikey={key}",
  139. Map8: "http://{s}.map.jms.gd/tile/tengxun_8/{z}/{x}/{y}.png?apikey={key}",
  140. Map4: "http://f.map.jms.gd/tile/tengxun_4/{z}/{x}/{y}.png?apikey={key}",
  141. Map3: "http://{s}.map.jms.gd/tile/tengxun_3/{z}/{x}/{y}.png?apikey={key}",
  142. Map2: "http://{s}.map.jms.gd/tile/tengxun_2/{z}/{x}/{y}.png?apikey={key}",
  143. Map1: "http://{s}.map.jms.gd/tile/tengxun_1/{z}/{x}/{y}.png?apikey={key}",
  144. },
  145. Satellite: {
  146. Map: "http://{s}.map.jms.gd/tile/tengxun_wx/{z}/{x}/{y}.png?apikey={key}"
  147. },
  148. Subdomains: ["a", "b", "c", "d"],
  149. key: "jm20240118"
  150. },
  151. Carto: {
  152. Normal: {
  153. Map: "http://{s}.map.jms.gd/tile/carto_label/{z}/{x}/{y}.png?apikey={key}",
  154. Light: "http://{s}.map.jms.gd/tile/railmap/{z}/{x}/{y}.png?apikey={key}",
  155. Dark: "http://{s}.map.jms.gd/tile/carto_dark/{z}/{x}/{y}.png?apikey={key}",
  156. },
  157. Subdomains: ["a", "b", "c", "d"],
  158. key: "jm20240118"
  159. },
  160. Thunderforest: {
  161. Normal: {
  162. Opencyclemap: "http://{s}.map.jms.gd/tile/opencyclemap/{z}/{x}/{y}.png?apikey={key}",
  163. Transport: "http://{s}.map.jms.gd/tile/transport/{z}/{x}/{y}.png?apikey={key}",
  164. Landscape: "http://{s}.map.jms.gd/tile/landscape/{z}/{x}/{y}.png?apikey={key}",
  165. Mobile: "http://{s}.map.jms.gd/tile/mobile-atlas/{z}/{x}/{y}.png?apikey={key}",
  166. Pioneer: "http://{s}.map.jms.gd/tile/pioneer/{z}/{x}/{y}.png?apikey={key}",
  167. Neighbourhood: "http://{s}.map.jms.gd/tile/neighbourhood/{z}/{x}/{y}.png?apikey={key}",
  168. Outdoors: "http://{s}.map.jms.gd/tile/outdoors/{z}/{x}/{y}.png?apikey={key}",
  169. Atlas: "http://{s}.map.jms.gd/tile/atlas/{z}/{x}/{y}.png?apikey={key}",
  170. TransportDark: "http://{s}.map.jms.gd/tile/transport-dark/{z}/{x}/{y}.png?apikey={key}",
  171. Spinal: "http://{s}.map.jms.gd/tile/spinal-map/{z}/{x}/{y}.png?apikey={key}",
  172. },
  173. Subdomains: ["a", "b", "c", "d"],
  174. key: "jm20240118"
  175. },
  176. OSM: {
  177. Normal: {
  178. Map: "http://{s}.map.jms.gd/tile/osm/{z}/{x}/{y}.png?apikey={key}",
  179. Topo: "http://{s}.map.jms.gd/tile/osm_topo/{z}/{x}/{y}.png?apikey={key}",
  180. Openstreetmap: "http://{s}.map.jms.gd/tile/openstreetmap/{z}/{x}/{y}.png?apikey={key}",
  181. winter: "http://{s}.map.jms.gd/tile/osm_winter/{z}/{x}/{y}.png?apikey={key}",
  182. summer: "http://{s}.map.jms.gd/tile/osm_summer/{z}/{x}/{y}.png?apikey={key}",
  183. cycling: "http://{s}.map.jms.gd/tile/osm_cycling/{z}/{x}/{y}.png?apikey={key}",
  184. },
  185. Subdomains: ["a", "b", "c", "d"],
  186. key: "jm20240118"
  187. },
  188. Opentopomap: {
  189. Normal: {
  190. Map: "http://{s}.map.jms.gd/tile/opentopomap/{z}/{x}/{y}.png?apikey={key}",
  191. },
  192. Subdomains: ["a", "b", "c", "d"],
  193. key: "jm20240118"
  194. },
  195. Baidu: {
  196. Normal: {
  197. Map: 'http://{s}.map.jms.gd/tile/baidu/{z}/{x}/{y}.png?apikey={key}'
  198. },
  199. Satellite: {
  200. Map: 'http://{s}.map.jms.gd/tile/baidu_wx/{z}/{x}/{y}.png?apikey={key}',
  201. },
  202. Subdomains: ["a", "b", "c", "d"],
  203. key: "jm20240118",
  204. tms: true
  205. },
  206. Openrailway: {
  207. Normal: {
  208. Map: "http://{s}.map.jms.gd/tile/openrailway/{z}/{x}/{y}.png?apikey={key}",
  209. Maxspeed: "http://{s}.map.jms.gd/tile/openrailway_maxspeed/{z}/{x}/{y}.png?apikey={key}",
  210. Elec: "http://{s}.map.jms.gd/tile/openrailway_elec/{z}/{x}/{y}.png?apikey={key}",
  211. },
  212. Subdomains: ["a", "b", "c", "d"],
  213. key: "jm20240118"
  214. },
  215. Stadia: {
  216. Normal: {
  217. Alidade_smooth: "http://{s}.map.jms.gd/tile/alidade_smooth/{z}/{x}/{y}.png?apikey={key}",
  218. Watercolor: "http://{s}.map.jms.gd/tile/stamen_watercolor/{z}/{x}/{y}.jpg?apikey={key}",
  219. Terrain: "http://{s}.map.jms.gd/tile/stamen_terrain/{z}/{x}/{y}.png?apikey={key}",
  220. Toner: "http://{s}.map.jms.gd/tile/stamen_toner/{z}/{x}/{y}.png?apikey={key}",
  221. },
  222. Subdomains: ["a", "b", "c", "d"],
  223. key: "jm20240118"
  224. },
  225. ArcgisCn: {
  226. Normal: {
  227. Community: "http://{s}.map.jms.gd/tile/arcgis_comm/{z}/{x}/{y}.png?apikey={key}",
  228. Gray: "http://{s}.map.jms.gd/tile/arcgis_gray/{z}/{x}/{y}.jpg?apikey={key}",
  229. Blue: "http://{s}.map.jms.gd/tile/arcgis_blue/{z}/{x}/{y}.png?apikey={key}",
  230. Warm: "http://{s}.map.jms.gd/tile/arcgis_warm/{z}/{x}/{y}.png?apikey={key}",
  231. },
  232. Subdomains: ["a", "b", "c", "d"],
  233. key: "jm20240118"
  234. },
  235. Arcgis: {
  236. Normal: {
  237. Street: "http://{s}.map.jms.gd/tile/arcgis_world_street/{z}/{x}/{y}.png?apikey={key}",
  238. Hillshade: "http://{s}.map.jms.gd/tile/arcgis_world_hillshade/{z}/{x}/{y}.png?apikey={key}",
  239. },
  240. Satellite: {
  241. Map: "http://{s}.map.jms.gd/tile/arcgis_world_imagery/{z}/{x}/{y}.png?apikey={key}",
  242. },
  243. Subdomains: ["a", "b", "c", "d"],
  244. key: "jm20240118"
  245. },
  246. Jl1: {
  247. Normal: {
  248. Map: "http://{s}.map.jms.gd/tile/jl1_2022/{z}/{x}/{y}.png?apikey={key}",
  249. Map2023: "http://{s}.map.jms.gd/tile/jl1_2023/{z}/{x}/{y}.png?apikey={key}",
  250. Map2024: "http://{s}.map.jms.gd/tile/jl1_2024/{z}/{x}/{y}.png?apikey={key}",
  251. },
  252. Subdomains: ["a", "b", "c", "d"],
  253. key: "jm20240118"
  254. },
  255. Geovis: {
  256. Normal: {
  257. Base: "http://{s}.map.jms.gd/tile/geovis_base/{z}/{x}/{y}.png?apikey={key}",
  258. },
  259. Subdomains: ["a", "b", "c", "d"],
  260. key: "jm20240118"
  261. },
  262. Stamen: {
  263. Terrain: {
  264. Lines: "http://{s}.map.jms.gd/tile/stamen_terrain_lines/{z}/{x}/{y}.png?apikey={key}",
  265. },
  266. Toner: {
  267. Lines: "http://{s}.map.jms.gd/tile/stamen_toner_lines/{z}/{x}/{y}.png?apikey={key}",
  268. },
  269. Subdomains: ["a", "b", "c", "d"],
  270. key: "jm20240118"
  271. },
  272. BingCn: {
  273. Normal: {
  274. Map: "http://{s}.map.jms.gd/tile/bing/{z}/{x}/{y}.png?apikey={key}",
  275. Dark: "http://{s}.map.jms.gd/tile/bing_dark/{z}/{x}/{y}.png?apikey={key}",
  276. Cf: "http://{s}.map.jms.gd/tile/bing_cf/{z}/{x}/{y}.png?apikey={key}", //实时路况
  277. },
  278. Subdomains: ["a", "b", "c", "d"],
  279. key: "jm20240118"
  280. },
  281. Bing: {
  282. Satellite: {
  283. Map: "http://{s}.map.jms.gd/tile/bing_aerial/{z}/{x}/{y}.png?apikey={key}",
  284. },
  285. Subdomains: ["a", "b", "c", "d"],
  286. key: "jm20240118"
  287. },
  288. Jiangmen: {
  289. Normal: {
  290. Map: "http://68.196.3.198/map/mapimg/tile/{z}/{x}/{y}?apikey={key}",
  291. },
  292. Subdomains: ["a", "b", "c", "d"],
  293. key: "jm20240118"
  294. },
  295. Maptiler: {
  296. Normal: {
  297. basic: "http://{s}.map.jms.gd/tile/maptiler_basic/{z}/{x}/{y}.png?apikey={key}",
  298. backdrop: "http://{s}.map.jms.gd/tile/maptiler_backdrop/{z}/{x}/{y}.png?apikey={key}",
  299. streets: "http://{s}.map.jms.gd/tile/maptiler_streets/{z}/{x}/{y}.png?apikey={key}",
  300. winter: "http://{s}.map.jms.gd/tile/maptiler_winter/{z}/{x}/{y}.png?apikey={key}",
  301. ocean: "http://{s}.map.jms.gd/tile/maptiler_ocean/{z}/{x}/{y}.png?apikey={key}",
  302. toner: "http://{s}.map.jms.gd/tile/maptiler_toner/{z}/{x}/{y}.png?apikey={key}",
  303. topo: "http://{s}.map.jms.gd/tile/maptiler_topo/{z}/{x}/{y}.png?apikey={key}",
  304. dataviz: "http://{s}.map.jms.gd/tile/maptiler_dataviz/{z}/{x}/{y}.png?apikey={key}",
  305. },
  306. Subdomains: ["a", "b", "c", "d"],
  307. key: "jm20240118"
  308. },
  309. mapbox: {
  310. Normal: {
  311. mapbox01: "http://{s}.map.jms.gd/tile/mapbox01/{z}/{x}/{y}.png?apikey={key}",
  312. },
  313. Subdomains: ["a", "b", "c", "d"],
  314. key: "jm20240118"
  315. },
  316. Nothing: {
  317. Normal: {
  318. Map: "http://map.jms.gd/static/img/512.png?apikey={key}",
  319. },
  320. Subdomains: ["a", "b", "c", "d"],
  321. key: "jm20240118"
  322. },
  323. };
  324. L.tileLayer.chinaProvider = function(type, options) {
  325. return new L.TileLayer.ChinaProvider(type, options);
  326. };
  327. //坐标转换
  328. L.CoordConver = function () {
  329. /**百度转84*/
  330. this.bd09_To_gps84 = function(lng, lat) {
  331. var gcj02 = this.bd09_To_gcj02(lng, lat);
  332. var map84 = this.gcj02_To_gps84(gcj02.lng, gcj02.lat);
  333. return map84;
  334. }
  335. /**84转百度*/
  336. this.gps84_To_bd09 = function (lng, lat) {
  337. var gcj02 = this.gps84_To_gcj02(lng, lat);
  338. var bd09 = this.gcj02_To_bd09(gcj02.lng, gcj02.lat);
  339. return bd09;
  340. }
  341. /**84转火星*/
  342. this.gps84_To_gcj02 = function (lng, lat) {
  343. var dLat = transformLat(lng - 105.0, lat - 35.0);
  344. var dLng = transformLng(lng - 105.0, lat - 35.0);
  345. var radLat = lat / 180.0 * pi;
  346. var magic = Math.sin(radLat);
  347. magic = 1 - ee * magic * magic;
  348. var sqrtMagic = Math.sqrt(magic);
  349. dLat = (dLat * 180.0) / ((a * (1 - ee)) / (magic * sqrtMagic) * pi);
  350. dLng = (dLng * 180.0) / (a / sqrtMagic * Math.cos(radLat) * pi);
  351. var mgLat = lat + dLat;
  352. var mgLng = lng + dLng;
  353. var newCoord = {
  354. lng: mgLng,
  355. lat: mgLat
  356. };
  357. return newCoord;
  358. }
  359. /**火星转84*/
  360. this.gcj02_To_gps84 = function (lng, lat) {
  361. var coord = transform(lng, lat);
  362. var lontitude = lng * 2 - coord.lng;
  363. var latitude = lat * 2 - coord.lat;
  364. var newCoord = {
  365. lng: lontitude,
  366. lat: latitude
  367. };
  368. return newCoord;
  369. }
  370. /**火星转百度*/
  371. this.gcj02_To_bd09 = function (x, y) {
  372. var z = Math.sqrt(x * x + y * y) + 0.00002 * Math.sin(y * x_pi);
  373. var theta = Math.atan2(y, x) + 0.000003 * Math.cos(x * x_pi);
  374. var bd_lng = z * Math.cos(theta) + 0.0065;
  375. var bd_lat = z * Math.sin(theta) + 0.006;
  376. var newCoord = {
  377. lng: bd_lng,
  378. lat: bd_lat
  379. };
  380. return newCoord;
  381. }
  382. /**百度转火星*/
  383. this.bd09_To_gcj02 = function (bd_lng, bd_lat) {
  384. var x = bd_lng - 0.0065;
  385. var y = bd_lat - 0.006;
  386. var z = Math.sqrt(x * x + y * y) - 0.00002 * Math.sin(y * x_pi);
  387. var theta = Math.atan2(y, x) - 0.000003 * Math.cos(x * x_pi);
  388. var gg_lng = z * Math.cos(theta);
  389. var gg_lat = z * Math.sin(theta);
  390. var newCoord = {
  391. lng: gg_lng,
  392. lat: gg_lat
  393. };
  394. return newCoord;
  395. }
  396. var pi = 3.1415926535897932384626;
  397. var a = 6378245.0;
  398. var ee = 0.00669342162296594323;
  399. var x_pi = pi * 3000.0 / 180.0;
  400. var R = 6378137;
  401. function transform(lng, lat) {
  402. var dLat = transformLat(lng - 105.0, lat - 35.0);
  403. var dLng = transformLng(lng - 105.0, lat - 35.0);
  404. var radLat = lat / 180.0 * pi;
  405. var magic = Math.sin(radLat);
  406. magic = 1 - ee * magic * magic;
  407. var sqrtMagic = Math.sqrt(magic);
  408. dLat = (dLat * 180.0) / ((a * (1 - ee)) / (magic * sqrtMagic) * pi);
  409. dLng = (dLng * 180.0) / (a / sqrtMagic * Math.cos(radLat) * pi);
  410. var mgLat = lat + dLat;
  411. var mgLng = lng + dLng;
  412. var newCoord = {
  413. lng: mgLng,
  414. lat: mgLat
  415. };
  416. return newCoord;
  417. }
  418. function transformLat(x, y) {
  419. 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));
  420. ret += (20.0 * Math.sin(6.0 * x * pi) + 20.0 * Math.sin(2.0 * x * pi)) * 2.0 / 3.0;
  421. ret += (20.0 * Math.sin(y * pi) + 40.0 * Math.sin(y / 3.0 * pi)) * 2.0 / 3.0;
  422. ret += (160.0 * Math.sin(y / 12.0 * pi) + 320 * Math.sin(y * pi / 30.0)) * 2.0 / 3.0;
  423. return ret;
  424. }
  425. function transformLng(x, y) {
  426. var ret = 300.0 + x + 2.0 * y + 0.1 * x * x + 0.1 * x * y + 0.1 * Math.sqrt(Math.abs(x));
  427. ret += (20.0 * Math.sin(6.0 * x * pi) + 20.0 * Math.sin(2.0 * x * pi)) * 2.0 / 3.0;
  428. ret += (20.0 * Math.sin(x * pi) + 40.0 * Math.sin(x / 3.0 * pi)) * 2.0 / 3.0;
  429. ret += (150.0 * Math.sin(x / 12.0 * pi) + 300.0 * Math.sin(x / 30.0 * pi)) * 2.0 / 3.0;
  430. return ret;
  431. }
  432. }
  433. L.coordConver = function () {
  434. return new L.CoordConver()
  435. }
  436. L.tileLayer.chinaProvider = function (type, options) {
  437. options = options || {}
  438. options.corrdType = getCorrdType(type);
  439. return new L.TileLayer.ChinaProvider(type, options);
  440. //获取坐标类型
  441. function getCorrdType(type) {
  442. var parts = type.split('.');
  443. var providerName = parts[0];
  444. var zbName = "wgs84"
  445. switch (providerName) {
  446. case "Tengxun":
  447. case "GaoDe":
  448. case "Pengjiang":
  449. case "GoogleCn": //google中国地图
  450. case "ArcgisCn":
  451. case "BingCn":
  452. case "Test":
  453. zbName = "gcj02";
  454. break;
  455. case "Baidu":
  456. zbName = "bd09";
  457. break;
  458. case "Carto":
  459. case "Thunderforest":
  460. case "OSM":
  461. case "TianDiTu":
  462. case "Jl1":
  463. case "Openrailway":
  464. case "Bing":
  465. case "Jiangmen":
  466. case "Google":
  467. case "mapbox":
  468. zbName = "wgs84";
  469. break;
  470. }
  471. return zbName;
  472. }
  473. };
  474. L.GridLayer.include({
  475. _setZoomTransform: function (level, _center, zoom) {
  476. var center = _center;
  477. if (center != undefined && this.options) {
  478. if (this.options.corrdType == 'gcj02') {
  479. center = L.coordConver().gps84_To_gcj02(_center.lng, _center.lat);
  480. } else if (this.options.corrdType == 'bd09') {
  481. center = L.coordConver().gps84_To_bd09(_center.lng, _center.lat);
  482. }
  483. }
  484. var scale = this._map.getZoomScale(zoom, level.zoom),
  485. translate = level.origin.multiplyBy(scale)
  486. .subtract(this._map._getNewPixelOrigin(center, zoom)).round();
  487. if (L.Browser.any3d) {
  488. L.DomUtil.setTransform(level.el, translate, scale);
  489. } else {
  490. L.DomUtil.setPosition(level.el, translate);
  491. }
  492. },
  493. _getTiledPixelBounds: function (_center) {
  494. var center = _center;
  495. if (center != undefined && this.options) {
  496. if (this.options.corrdType == 'gcj02') {
  497. center = L.coordConver().gps84_To_gcj02(_center.lng, _center.lat);
  498. } else if (this.options.corrdType == 'bd09') {
  499. center = L.coordConver().gps84_To_bd09(_center.lng, _center.lat);
  500. }
  501. }
  502. var map = this._map,
  503. mapZoom = map._animatingZoom ? Math.max(map._animateToZoom, map.getZoom()) : map.getZoom(),
  504. scale = map.getZoomScale(mapZoom, this._tileZoom),
  505. pixelCenter = map.project(center, this._tileZoom).floor(),
  506. halfSize = map.getSize().divideBy(scale * 2);
  507. return new L.Bounds(pixelCenter.subtract(halfSize), pixelCenter.add(halfSize));
  508. }
  509. })