xuehualu0413-cesium-online.html 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8" />
  5. <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  6. <meta name="renderer" content="webkit">
  7. <meta name="viewport" content="width=device-width, minimum-scale=1.0, initial-scale=1, user-scalable=no" />
  8. <title>BimAngle.com - Trial version</title>
  9. <script src="https://cesium.com/downloads/cesiumjs/releases/1.101/Build/Cesium/Cesium.js"></script>
  10. <link href="https://cesium.com/downloads/cesiumjs/releases/1.101/Build/Cesium/Widgets/widgets.css" rel="stylesheet">
  11. <style>
  12. html, body, #cesiumContainer {
  13. width: 100%;
  14. height: 100%;
  15. margin: 0;
  16. padding: 0;
  17. overflow: hidden;
  18. }
  19. </style>
  20. </head>
  21. <body>
  22. <div id="cesiumContainer"></div>
  23. <script>
  24. var url = './xuehualu0413.gltf';
  25. var longitude = 935.873335235304;
  26. var latitude = 3358.17730140791;
  27. var height = 0;
  28. //set home view
  29. Cesium.Camera.DEFAULT_VIEW_RECTANGLE = Cesium.Rectangle.fromDegrees(90, -20, 110, 90);
  30. //Please replace it with your own token
  31. const TIANDITU_TOKEN = '01e768fa9e1bcf33ae174c9231479793';
  32. var options = {
  33. // Google Maps (Has been blocked)
  34. // imageryProvider: new Cesium.UrlTemplateImageryProvider({ url: "http://mt1.google.cn/vt/lyrs=s&hl=zh-CN&x={x}&y={y}&z={z}&s=Gali" }),
  35. // TianDiTu(https://www.tianditu.gov.cn/) - China Only
  36. imageryProvider: new Cesium.WebMapTileServiceImageryProvider({
  37. url: 'http://t0.tianditu.com/img_w/wmts?service=wmts&request=GetTile&version=1.0.0&LAYER=img&tileMatrixSet=w&TileMatrix={TileMatrix}&TileRow={TileRow}&TileCol={TileCol}&style=default&format=tiles&tk=' + TIANDITU_TOKEN,
  38. layer: 'tdtBasicLayer',
  39. style: 'default',
  40. format: 'tiles',
  41. tileMatrixSetID: 'GoogleMapsCompatible',
  42. show: true,
  43. maximumLevel: 18
  44. }),
  45. };
  46. var viewer = new Cesium.Viewer('cesiumContainer', options);
  47. var modelMatrix = Cesium.Transforms.eastNorthUpToFixedFrame(
  48. Cesium.Cartesian3.fromDegrees(longitude, latitude, height)
  49. );
  50. var primitive = viewer.scene.primitives.add(Cesium.Model.fromGltf({
  51. url: url,
  52. modelMatrix: modelMatrix,
  53. scale: 1.0,
  54. dequantizeInShader: false,
  55. minimumPixelSize: 1.0
  56. }));
  57. primitive.readyPromise.then(function(model){
  58. var center = new Cesium.Cartesian3();
  59. Cesium.Matrix4.multiplyByPoint(model.modelMatrix, model.boundingSphere.center, center);
  60. var boundingSphere = new Cesium.BoundingSphere(center, model.boundingSphere.radius * 1.5);
  61. viewer.camera.flyToBoundingSphere(boundingSphere);
  62. });
  63. var selectedEntity = new Cesium.Entity();
  64. var handler = new Cesium.ScreenSpaceEventHandler(viewer.scene.canvas);
  65. handler.setInputAction(
  66. function (movement) {
  67. var pick = viewer.scene.pick(movement.position);
  68. if (Cesium.defined(pick) && Cesium.defined(pick.node)) {
  69. var node = pick.primitive.gltf.nodes[pick.node.id];
  70. selectedEntity.name = node.name || "<null>";
  71. selectedEntity.description = 'Loading <div class="cesium-infoBox-loading"></div>';
  72. viewer.selectedEntity = selectedEntity;
  73. if(node.extras){
  74. selectedEntity.description = '<table class="cesium-infoBox-defaultTable"><tbody>' +
  75. '<tr><th>DbId</th><td>' + node.extras.DbId + '</td></tr>' +
  76. '<tr><th>ExId</th><td>' + node.extras.ExId + '</td></tr>' +
  77. '</tbody></table>';
  78. }else{
  79. selectedEntity.description = '<table class="cesium-infoBox-defaultTable"><tbody>' +
  80. '</tbody></table>';
  81. }
  82. }
  83. },
  84. Cesium.ScreenSpaceEventType.LEFT_CLICK
  85. );
  86. </script>
  87. </body>
  88. </html>