control_swipeBetweenMaps.html 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. <!--********************************************************************
  2. * Copyright© 2000 - 2021 SuperMap Software Co.Ltd. All rights reserved.
  3. *********************************************************************-->
  4. <!DOCTYPE html>
  5. <html lang="en">
  6. <head>
  7. <meta charset="UTF-8" />
  8. <title data-i18n="resources.title_swipeBetweenMaps"></title>
  9. <script type="text/javascript" src="../js/include-web.js"></script>
  10. <script type="text/javascript" include="compare" src="../../dist/mapboxgl/include-mapboxgl.js"></script>
  11. <style>
  12. body {
  13. margin: 0;
  14. overflow: hidden;
  15. background: #fff;
  16. width: 100%;
  17. height: 100%;
  18. position: absolute;
  19. top: 0;
  20. }
  21. body * {
  22. -webkit-touch-callout: none;
  23. -webkit-user-select: none;
  24. -moz-user-select: none;
  25. -ms-user-select: none;
  26. user-select: none;
  27. }
  28. .map {
  29. position: absolute;
  30. top: 0;
  31. bottom: 0;
  32. width: 100%;
  33. }
  34. </style>
  35. </head>
  36. <body>
  37. <div id="wrapper">
  38. <div id="before" class="map"></div>
  39. <div id="after" class="map"></div>
  40. <div class="controls"></div>
  41. </div>
  42. <script type="text/javascript">
  43. var host = window.isLocal ? window.server : 'https://iserver.supermap.io',
  44. chinaUrl = host + '/iserver/services/map-china400/rest/maps/China/zxyTileImage.png?z={z}&x={x}&y={y}',
  45. chinaDarkUrl =
  46. host + '/iserver/services/map-china400/rest/maps/ChinaDark/zxyTileImage.png?z={z}&x={x}&y={y}',
  47. attribution =
  48. "<a href='https://www.mapbox.com/about/maps/' target='_blank'>© Mapbox </a>" +
  49. " with <span>© <a href='https://iclient.supermap.io' target='_blank'>SuperMap iClient</a> | </span>" +
  50. " Map Data <span>© <a href='http://support.supermap.com.cn/product/iServer.aspx' target='_blank'>SuperMap iServer</a></span> ";
  51. var beforeMap = new mapboxgl.Map({
  52. container: 'before',
  53. style: {
  54. version: 8,
  55. sources: {
  56. 'raster-tiles': {
  57. attribution: attribution,
  58. type: 'raster',
  59. tiles: [chinaUrl],
  60. tileSize: 256
  61. }
  62. },
  63. layers: [
  64. {
  65. id: 'before',
  66. type: 'raster',
  67. source: 'raster-tiles',
  68. minzoom: 0,
  69. maxzoom: 22
  70. }
  71. ]
  72. },
  73. center: [0, 0],
  74. zoom: 0
  75. });
  76. beforeMap.addControl(new mapboxgl.supermap.LogoControl(), 'bottom-right');
  77. beforeMap.addControl(new mapboxgl.NavigationControl(), 'top-left');
  78. var afterMap = new mapboxgl.Map({
  79. container: 'after',
  80. style: {
  81. version: 8,
  82. sources: {
  83. 'raster-tiles': {
  84. type: 'raster',
  85. tiles: [chinaDarkUrl],
  86. tileSize: 256
  87. }
  88. },
  89. layers: [
  90. {
  91. id: 'after',
  92. type: 'raster',
  93. source: 'raster-tiles',
  94. minzoom: 0,
  95. maxzoom: 22
  96. }
  97. ]
  98. },
  99. center: [0, 0],
  100. zoom: 0
  101. });
  102. //mapbox 卷帘(对比)控件, mapbox-gl-compare v0.3.0版本,新增container属性
  103. var map = new mapboxgl.Compare(beforeMap, afterMap, '#wrapper');
  104. </script>
  105. </body>
  106. </html>