f55_videoMaterial.html 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  5. <meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=0,minimum-scale=1.0,maximum-scale=1.0" />
  6. <meta name="author" content="火星科技 http://mars3d.cn " />
  7. <meta name="apple-touch-fullscreen" content="yes" />
  8. <meta name="apple-mobile-web-app-capable" content="yes" />
  9. <meta name="apple-mobile-web-app-status-bar-style" content="black" />
  10. <meta name="format-detection" content="telephone=no" />
  11. <meta name="x5-fullscreen" content="true" />
  12. <meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1" />
  13. <!-- 标题及搜索关键字 -->
  14. <meta name="keywords" content="火星科技,cesium,3D,GIS,marsgis,三维,地球,地图,开发,框架,系统,示例,资料,模型,离线,外包,合肥,安徽,中国" />
  15. <meta
  16. name="description"
  17. content="火星科技 合肥火星 合肥火星科技 合肥火星科技有限公司 leaflet leaflet框架 leaflet开发 cesium cesium开发 cesium框架 三维 地球 模型 gis marsgis 地图离线 地图开发 地图框架 地图外包 框架 开发 外包 地图离线 二维地图 三维地图 全景漫游 地理信息系统 云GIS 三维GIS GIS平台 WebGIS"
  18. />
  19. <link rel="shortcut icon" type="image/x-icon" href="" />
  20. <title>视频材质 </title>
  21. <!--第三方lib-->
  22. <script
  23. type="text/javascript"
  24. src="../lib/include-lib.js"
  25. libpath="../lib/"
  26. include="jquery,font-awesome,bootstrap,bootstrap-checkbox,bootstrap-slider,layer,haoutil,turf,mars3d"
  27. ></script>
  28. <link href="css/style.css" rel="stylesheet" />
  29. </head>
  30. <body class="dark">
  31. <!--加载前进行操作提示,优化用户体验-->
  32. <div id="mask" class="signmask" onclick="removeMask()"></div>
  33. <div id="mars3dContainer" class="mars3d-container"></div>
  34. <!-- 面板 -->
  35. <div class="infoview">
  36. <input type="button" class="btn btn-primary" value="贴地矩形" onclick="drawRectangle()" />
  37. <input type="button" class="btn btn-primary" value="贴地面" onclick="drawPolygon(true)" />
  38. <input type="button" class="btn btn-primary" value="立体面" onclick="drawPolygon(false)" />
  39. <input type="button" class="btn btn-primary" value="清除" onclick="removeAll()" />
  40. <table class="mars-table">
  41. <tbody>
  42. <tr>
  43. <td>方向:</td>
  44. <td>
  45. <input id="txtAngle" />
  46. </td>
  47. </tr>
  48. <tr>
  49. <td>状态:</td>
  50. <td>
  51. <button id="video-play" type="button" class="btn btn-primary"><span class="fa fa-pause" aria-hidden="true"></span> 暂停</button>
  52. </td>
  53. </tr>
  54. </tbody>
  55. </table>
  56. </div>
  57. <video id="trailer" style="display: none" muted="muted" autoplay="autoplay" loop="loop" crossorigin="" controls="">
  58. <source src="//data.mars3d.cn/file/video/lukou.mp4" type="video/mp4" />
  59. </video>
  60. <script src="./js/common.js"></script>
  61. <script type="text/javascript">
  62. "use script"; //开发环境建议开启严格模式
  63. var map;
  64. var graphicLayer;
  65. var videoElement;
  66. function initMap(options) {
  67. //合并属性参数,可覆盖config.json中的对应配置
  68. var mapOptions = mars3d.Util.merge(options, {
  69. scene: {
  70. center: { lat: 28.44134, lng: 119.482687, alt: 199, heading: 227, pitch: -28 },
  71. },
  72. });
  73. //创建三维地球场景
  74. map = new mars3d.Map("mars3dContainer", mapOptions);
  75. //添加参考三维模型
  76. var tiles3dLayer = new mars3d.layer.TilesetLayer({
  77. name: "县城社区",
  78. url: "//data.mars3d.cn/3dtiles/qx-shequ/tileset.json",
  79. position: { alt: 11.5 },
  80. maximumScreenSpaceError: 1,
  81. maximumMemoryUsage: 1024,
  82. });
  83. map.addLayer(tiles3dLayer);
  84. videoElement = document.getElementById("trailer");
  85. //可以使视频元素与Cesium的模拟时钟同步
  86. let synchronizer = new Cesium.VideoSynchronizer({
  87. clock: map.clock,
  88. element: videoElement,
  89. });
  90. map.clock.shouldAnimate = true;
  91. $("#video-play").click(function () {
  92. if (map.clock.shouldAnimate) {
  93. map.clock.shouldAnimate = false;
  94. $(this).html('<span class="fa fa-play" aria-hidden="true"></span> 播放');
  95. } else {
  96. map.clock.shouldAnimate = true;
  97. $(this).html('<span class="fa fa-pause" aria-hidden="true"></span> 暂停');
  98. }
  99. });
  100. $("#txtAngle")
  101. .slider({ min: 0, max: 360, step: 1, value: 0 })
  102. .on("change", (e) => {
  103. if (e && e.value) {
  104. rotation = Cesium.Math.toRadians(e.value.newValue);
  105. }
  106. });
  107. //允许编辑
  108. map.graphicLayer.hasEdit = true;
  109. //创建矢量数据图层
  110. graphicLayer = new mars3d.layer.GraphicLayer();
  111. map.addLayer(graphicLayer);
  112. //2.在layer上绑定监听事件
  113. graphicLayer.on(mars3d.EventType.click, function (event) {
  114. console.log("监听layer,单击了矢量对象", event);
  115. });
  116. graphicLayer.on(mars3d.EventType.mouseOver, function (event) {
  117. console.log("监听layer,鼠标移入了矢量对象", event);
  118. });
  119. graphicLayer.on(mars3d.EventType.mouseOut, function (event) {
  120. console.log("监听layer,鼠标移出了矢量对象", event);
  121. });
  122. //可在图层上绑定popup,对所有加到这个图层的矢量数据都生效
  123. graphicLayer.bindPopup("我是layer上绑定的Popup");
  124. //可在图层上绑定tooltip,对所有加到这个图层的矢量数据都生效
  125. // graphicLayer.bindTooltip('我是layer上绑定的Tooltip')
  126. //可在图层绑定右键菜单,对所有加到这个图层的矢量数据都生效
  127. graphicLayer.bindContextMenu([
  128. {
  129. text: "删除对象",
  130. iconCls: "fa fa-trash-o",
  131. callback: function (e) {
  132. var graphic = e.graphic;
  133. if (graphic) {
  134. graphicLayer.removeGraphic(graphic);
  135. }
  136. },
  137. },
  138. ]);
  139. //加一些演示数据
  140. addGraphic_01(graphicLayer);
  141. addGraphic_02(graphicLayer);
  142. }
  143. //竖立视频
  144. function addGraphic_01(graphicLayer) {
  145. var graphic = new mars3d.graphic.PolygonEntity({
  146. positions: [
  147. [119.481299, 28.439988, 140],
  148. [119.481162, 28.440102, 140],
  149. [119.481163, 28.440101, 130],
  150. [119.481296, 28.439986, 130],
  151. ],
  152. style: {
  153. image: videoElement,
  154. stRotationDegree: 0, //视频旋转角度
  155. },
  156. });
  157. graphicLayer.addGraphic(graphic);
  158. }
  159. //地面视频
  160. function addGraphic_02(graphicLayer) {
  161. var graphic = new mars3d.graphic.PolygonEntity({
  162. positions: [
  163. [119.481749, 28.440171],
  164. [119.481385, 28.440457],
  165. [119.481911, 28.44094],
  166. [119.482254, 28.440653],
  167. ],
  168. style: {
  169. image: videoElement,
  170. // transparent: true,
  171. // opacity: 0.6,
  172. stRotationDegree: 130, //视频旋转角度
  173. clampToGround: true,
  174. },
  175. });
  176. graphicLayer.addGraphic(graphic);
  177. }
  178. var rotation = 0;
  179. function getRotationValue() {
  180. return rotation;
  181. }
  182. function drawRectangle() {
  183. map.graphicLayer.startDraw({
  184. type: "rectangle",
  185. style: {
  186. color: "#ffff00",
  187. opacity: 0.2,
  188. clampToGround: true,
  189. },
  190. success: function (graphic) {
  191. graphic.entityGraphic.material = videoElement;
  192. graphic.entityGraphic.rotation = new Cesium.CallbackProperty(getRotationValue, false);
  193. graphic.entityGraphic.stRotation = new Cesium.CallbackProperty(getRotationValue, false);
  194. },
  195. });
  196. }
  197. //绘制这个polygon的时候,点的绘制顺序和面的角度不同,会使画面翻转
  198. function drawPolygon(clampToGround) {
  199. map.graphicLayer.startDraw({
  200. type: "polygon",
  201. style: {
  202. color: "#ffff00",
  203. opacity: 0.2,
  204. clampToGround: clampToGround,
  205. },
  206. success: function (graphic) {
  207. graphic.entityGraphic.material = videoElement;
  208. graphic.entityGraphic.stRotation = new Cesium.CallbackProperty(getRotationValue, false);
  209. },
  210. });
  211. }
  212. function removeAll() {
  213. map.graphicLayer.clear();
  214. graphicLayer.clear();
  215. }
  216. </script>
  217. </body>
  218. </html>