04MultipleSyncedViews.html 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8" />
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  6. <title>多屏联动</title>
  7. <link rel="stylesheet" href="../dist/index.css" />
  8. <link href="../cesium/Source/Widgets/widgets.css" rel="stylesheet">
  9. <script src="../cesium/Build/Cesium/Cesium.js"></script>
  10. <script src="../dist/index.js"></script>
  11. <script src="https://unpkg.com/axios/dist/axios.min.js"></script>
  12. <style>
  13. * {
  14. padding: 0;
  15. margin: 0;
  16. }
  17. </style>
  18. </head>
  19. <body>
  20. <div id='cesiumContainer' style="display: flex;flex-direction: column">
  21. <div id="map" style="display: flex;">
  22. <div id="map1" style="height: 90vh; width: 50vw;border:5px solid red;"></div>
  23. <div id="map2" style="height: 90vh; width: 50vw;"></div>
  24. </div>
  25. <div id="func" style="height: 10vh;">
  26. <button onclick="sync()">同步</button>
  27. </div>
  28. </div>
  29. </body>
  30. <script>
  31. window.CESIUM_BASE_URL = '../cesium/Build/Cesium';
  32. Cesium.Ion.defaultAccessToken = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJqdGkiOiI2MjIyODA4ZS0zNmRmLTQwNGMtYjZkNC0wOGY2NDdmODgyZTUiLCJpZCI6ODMyOCwiaWF0IjoxNjA2MjkyNDE1fQ.ZhhxNIJ-TzstpcavQBNL7xRwytBat3G2__3jr7lJ8yg'
  33. let isleft = true
  34. const source = new CTMapOl.source.XYZ({
  35. url: 'http://t0.tianditu.gov.cn/vec_w/wmts?SERVICE=WMTS&REQUEST=GetTile&VERSION=1.0.0&LAYER=vec&STYLE=default&TILEMATRIXSET=w&FORMAT=tiles&TILEMATRIX={z}&TILEROW={y}&TILECOL={x}&tk=86db5390161c4da2abe96c3fca00f403'
  36. })
  37. const tileLayer = new CTMapOl.layer.Tile({
  38. title: '天地图',
  39. source: source
  40. })
  41. var sourceMarker = new CTMapOl.source.XYZ({
  42. url: 'http://t0.tianditu.gov.cn/cva_w/wmts?SERVICE=WMTS&REQUEST=GetTile&VERSION=1.0.0&LAYER=cva&STYLE=default&TILEMATRIXSET=w&FORMAT=tiles&TILEMATRIX={z}&TILEROW={y}&TILECOL={x}&tk=86db5390161c4da2abe96c3fca00f403'
  43. })
  44. const tileMarker = new CTMapOl.layer.Tile({
  45. title: '标注图层',
  46. source: sourceMarker
  47. })
  48. const map = new CTMapOl.Map({
  49. view: new CTMapOl.View({
  50. projection: 'EPSG:3857',
  51. center: CTMapOl.extend.formatLayer.transCooordinateToOpenlayer([116.39, 39.91]),
  52. // center: [0, 0],
  53. zoom: 16,
  54. maxZoom: 18,
  55. minZoom: 1
  56. }),
  57. layers: [tileLayer, tileMarker],
  58. target: 'map1'
  59. })
  60. var viewer2 = CTMapOl.thrdime.viewercontrol.globalviewer('map2', CTMapOl.thrdime.viewercontrol.globalvieweroptions())
  61. viewer2._cesiumWidget._creditContainer.style.display = 'none'
  62. CTMapOl.thrdime.imagerylayercontrol.removeAll(viewer2, true)
  63. CTMapOl.thrdime.imagerylayercontrol.addImageryProvider(viewer2, CTMapOl.thrdime.imagerylayercontrol.gettdtImagery('vec', "vec_w"))
  64. CTMapOl.thrdime.imagerylayercontrol.addImageryProvider(viewer2, CTMapOl.thrdime.imagerylayercontrol.gettdtImagery('cva', "cva_w"))
  65. CTMapOl.thrdime.cameracontrol.setcamera(viewer2, CTMapOl.thrdime.cameracontrol.getcameraoptionswithdetile(116.39, 39.91, 5000, 0, -90, 0))
  66. function sync() {
  67. if (isleft) {
  68. document.getElementById('map1').style = "height: 90vh; width: 50vw;"
  69. document.getElementById('map2').style = "height: 90vh; width: 50vw;border:5px solid red;"
  70. const geom = new CTMapOl.geom.Point(map.getView().getCenter())
  71. geom.transform('EPSG:3857', 'EPSG:4326')
  72. CTMapOl.thrdime.cameracontrol.setcamera(viewer2, CTMapOl.thrdime.cameracontrol.getcameraoptionswithdetile(geom.flatCoordinates[0], geom.flatCoordinates[1], CTMapOl.thrdime.cameracontrol.zoomToHeight(map.getView().getZoom()), 0, -90, 0))
  73. } else {
  74. document.getElementById('map2').style = "height: 90vh; width: 50vw;"
  75. document.getElementById('map1').style = "height: 90vh; width: 50vw;border:5px solid red;"
  76. let pos = CTMapOl.thrdime.cameracontrol.getposition(viewer2)
  77. let lonlath = Cesium.Cartographic.fromCartesian(pos)
  78. const geom = new CTMapOl.geom.Point([lonlath.longitude * 180 / Math.PI, lonlath.latitude * 180 / Math.PI])
  79. geom.transform('EPSG:4326', 'EPSG:3857')
  80. map.getView().setCenter(geom.flatCoordinates)
  81. map.getView().setZoom(CTMapOl.thrdime.cameracontrol.heightToZoom(lonlath.height))
  82. }
  83. isleft = !isleft
  84. }
  85. </script>
  86. </html>