加载高德底图和自定义瓦片

  1. <!DOCTYPE>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  6. <meta name="viewport" content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=no">
  7. <title>高德瓦片</title>
  8. <link rel="stylesheet" href="./dist/zyzc.css">
  9. <script type="text/javascript" src="dist/maptalks.js"></script>
  10. <style>
  11. * {
  12. margin: 0;
  13. padding: 0;
  14. }
  15. #map {
  16. width: 100vw;
  17. height: 100vh;
  18. }
  19. </style>
  20. </head>
  21. <body>
  22. <div id="map"></div>
  23. <script type="text/javascript">
  24. const config = {
  25. tileGD: "http://www.zyzcgis.xyz/tile/wg/mobile/gaode/",
  26. tileGDBZ: 'https://www.zyzcgis.xyz/tile/wg/mobile/gaodeBiaoZhu/',
  27. }
  28. var map = new maptalks.Map('map', {
  29. center: [114.426383, 30.62696],
  30. zoom: 14,
  31. minZoom: 10,
  32. maxZoom: 19,
  33. attribution: false
  34. baseLayer: new maptalks.TileLayer('base', {
  35. urlTemplate: 'http://wprd{s}.is.autonavi.com/appmaptile?lang=zh_cn&size=1&style=7&z={z}&x={x}&y={y}&scl=1&ltype=11',
  36. subdomains: ['01', '02', '03', '04']
  37. }),
  38. layers: [
  39. new maptalks.TileLayer('wg', {
  40. urlTemplate: (x, y, z) => {
  41. return `${config.tileGD}${z}/${y}/${x}.png`;
  42. }
  43. }),
  44. new maptalks.TileLayer('wgbz', {
  45. urlTemplate: (x, y, z) => {
  46. return `${config.tileGDBZ}${z}/${y}/${x}.png`;
  47. }
  48. }),
  49. ]
  50. });
  51. </script>
  52. </body>
  53. </html>

加载百度底图和自定义瓦片

  1. <!DOCTYPE>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  6. <meta name="viewport" content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=no">
  7. <title>百度瓦片</title>
  8. <link rel="stylesheet" href="./dist/zyzc.css">
  9. <script type="text/javascript" src="dist/maptalks.js"></script>
  10. <style>
  11. * {
  12. margin: 0;
  13. padding: 0;
  14. }
  15. #map {
  16. width: 100vw;
  17. height: 100vh;
  18. }
  19. </style>
  20. </head>
  21. <body>
  22. <div id="map"></div>
  23. <script type="text/javascript">
  24. const config = {
  25. tileBZ: "http://www.zyzcgis.xyz/tile/wg/pc/baidu/"
  26. }
  27. var map = new maptalks.Map('map', {
  28. center: [114.426383, 30.62696],
  29. zoom: 14,
  30. minZoom: 10,
  31. maxZoom: 19,
  32. attribution: false,
  33. spatialReference: {
  34. projection: 'baidu'
  35. },
  36. baseLayer: new maptalks.TileLayer('base', {
  37. urlTemplate: 'http://online{s}.map.bdimg.com/onlinelabel/?qt=tile&x={x}&y={y}&z={z}&styles=pl&scaler=1&p=1',
  38. subdomains: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
  39. }),
  40. layers: [
  41. new maptalks.TileLayer('wg', {
  42. urlTemplate: (x, y, z) => {
  43. let diff = Math.pow(2, z - 1);
  44. return config.tileBZ + 'L' + z + '/R' + toHex(diff - 1 - y, 8) + '/C' + toHex(x + diff, 8) +
  45. '.png';
  46. },
  47. subdomains: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
  48. }),
  49. ]
  50. });
  51. function toHex(num, length) {
  52. let zero = "";
  53. for (let i = 0; i < length; i++) {
  54. zero += "0";
  55. }
  56. let temp = num.toString(16);
  57. let result = zero + temp;
  58. result = result.substr(temp.length, length);
  59. return result;
  60. }
  61. </script>
  62. </body>
  63. </html>