f55_video3D.html 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463
  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>视频3D贴物投射 </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. <style>
  30. .infoview input {
  31. vertical-align: middle;
  32. padding-top: 2px;
  33. padding-bottom: 2px;
  34. }
  35. </style>
  36. </head>
  37. <body class="dark">
  38. <!--加载前进行操作提示,优化用户体验-->
  39. <div id="mask" class="signmask" onclick="removeMask()"></div>
  40. <div id="mars3dContainer" class="mars3d-container"></div>
  41. <!-- 面板 -->
  42. <div id="toolbar" class="infoview">
  43. <input type="button" class="btn btn-primary" value="视频投放" onclick="createViewForVideo()" />
  44. <input type="button" class="btn btn-primary" value="图片投放" onclick="createViewForPicture()" />
  45. <input type="button" class="btn btn-primary" value="文本投放" onclick="createText()" />
  46. <input type="button" class="btn btn-primary" value="颜色投放" onclick="createViewForColor()" />
  47. <input type="button" class="btn btn-info" value="清除" onclick="clearVideo()" />
  48. <table class="mars-table">
  49. <tbody>
  50. <tr>
  51. <td>混合系数:</td>
  52. <td>
  53. <input id="txtMixNum" />
  54. </td>
  55. <td>调整 透明度</td>
  56. </tr>
  57. <tr>
  58. <td>水平拉伸:</td>
  59. <td>
  60. <input id="cameraFov" />
  61. </td>
  62. <td>调整 水平拉伸</td>
  63. </tr>
  64. <tr>
  65. <td>相机宽高比例:</td>
  66. <td>
  67. <input id="cameraWidHei" />
  68. </td>
  69. <td>调整 垂直拉伸</td>
  70. </tr>
  71. <tr>
  72. <td>视椎框线:</td>
  73. <td>
  74. <div class="checkbox checkbox-info checkbox-inline">
  75. <input type="checkbox" id="chkDebugFrustum" value="this" name="jiaodu" checked />
  76. <label for="chkDebugFrustum">显示框线</label>
  77. </div>
  78. </td>
  79. <td></td>
  80. </tr>
  81. <tr>
  82. <td>调整位置:</td>
  83. <td>
  84. <input id="btnSelCamera" type="button" class="btn btn-info" value="相机" />
  85. <input id="btnSelView" type="button" class="btn btn-info" value="视点" />
  86. </td>
  87. <td>鼠标图上点选</td>
  88. </tr>
  89. <tr>
  90. <td>键盘微调:</td>
  91. <td>步长<input id="rotateDeg" type="number" value="0.05" min="0.001" max="2" class="form-control" style="width: 90px" />度</td>
  92. <td>
  93. <div class="checkbox checkbox-info checkbox-inline">
  94. <input id="chkCameraFollow" type="checkbox" class="checkbox checkbox-info checkbox-inline" value="相机跟随" />
  95. <label for="chkCameraFollow">相机跟随</label>
  96. </div>
  97. </td>
  98. </tr>
  99. </tbody>
  100. </table>
  101. <input id="btnPlayPause" type="button" class="btn btn-info" value="播放暂停" />
  102. <input id="btnLocate" type="button" class="btn btn-info" value="返回相机视点" />
  103. <input id="btnConsoleJson" type="button" class="btn btn-info" value="打印参数" />
  104. </div>
  105. <script src="./js/common.js"></script>
  106. <script type="text/javascript">
  107. "use script"; //开发环境建议开启严格模式
  108. var map;
  109. var graphicLayer;
  110. var selectedView;
  111. function initMap(options) {
  112. //合并属性参数,可覆盖config.json中的对应配置
  113. var mapOptions = mars3d.Util.merge(options, {
  114. scene: {
  115. center: { lat: 31.843366, lng: 117.205566, alt: 132, heading: 179, pitch: -56 },
  116. fxaa: true, //不开启抗锯齿,编辑时界面会闪烁
  117. globe: {
  118. depthTestAgainstTerrain: true, //不加无法投射到地形上
  119. },
  120. },
  121. });
  122. //创建三维地球场景
  123. map = new mars3d.Map("mars3dContainer", mapOptions);
  124. //添加参考三维模型
  125. var tiles3dLayer = new mars3d.layer.TilesetLayer({
  126. name: "合肥国家大学科技园",
  127. url: "//data.mars3d.cn/3dtiles/qx-hfdxy/tileset.json",
  128. position: { alt: -24 },
  129. maximumScreenSpaceError: 1,
  130. maximumMemoryUsage: 1024,
  131. });
  132. map.addLayer(tiles3dLayer);
  133. //创建Graphic图层
  134. graphicLayer = new mars3d.layer.GraphicLayer();
  135. map.addLayer(graphicLayer);
  136. //绑定属性及处理事件
  137. bindEvnet();
  138. //加一些演示数据
  139. addGraphic_01();
  140. }
  141. // 加载已配置好的视频(此参数为界面上“打印参数”按钮获取的)
  142. function addGraphic_01() {
  143. var video3D = new mars3d.graphic.Video3D({
  144. type: mars3d.graphic.Video3D.Type.Video,
  145. url: "//data.mars3d.cn/file/video/menqian.mp4",
  146. position: [117.20551, 31.842824, 41.4],
  147. cameraPosition: [117.205457, 31.842984, 63.9],
  148. style: {
  149. fovDegree: 84.3,
  150. aspectRatio: 2.6,
  151. opacity: 0.8,
  152. camera: {
  153. direction: {
  154. x: 0.07331987934745406,
  155. y: -0.31686588753316797,
  156. z: -0.9456321719412325,
  157. },
  158. right: {
  159. x: 0.8826585211077188,
  160. y: 0.46201009007723565,
  161. z: -0.08637483304041443,
  162. },
  163. up: {
  164. x: -0.4642608430704491,
  165. y: 0.8283373020603265,
  166. z: -0.3135588997412374,
  167. },
  168. },
  169. },
  170. showFrustum: true,
  171. });
  172. graphicLayer.addGraphic(video3D);
  173. selectedView = video3D; //记录下
  174. }
  175. //视频投放
  176. function createViewForVideo() {
  177. //取屏幕中心点
  178. var cartesian = map.getCenter({ format: false });
  179. if (!cartesian) {
  180. return;
  181. }
  182. var showFrustum = $("#chkDebugFrustum").is(":checked");
  183. var opacity = Number($("#txtMixNum").val());
  184. var cameraPosition = Cesium.clone(map.scene.camera.position);
  185. //构造投射体
  186. var video3D = new mars3d.graphic.Video3D({
  187. type: mars3d.graphic.Video3D.Type.Video,
  188. url: "//data.mars3d.cn/file/video/lukou.mp4",
  189. position: cartesian,
  190. cameraPosition: cameraPosition,
  191. style: {
  192. opacity: opacity,
  193. },
  194. showFrustum: showFrustum,
  195. });
  196. graphicLayer.addGraphic(video3D);
  197. selectedView = video3D; //记录下
  198. }
  199. //图片投放
  200. function createViewForPicture() {
  201. //取屏幕中心点
  202. var cartesian = map.getCenter({ format: false });
  203. if (!cartesian) {
  204. return;
  205. }
  206. var showFrustum = $("#chkDebugFrustum").is(":checked");
  207. var opacity = Number($("#txtMixNum").val());
  208. var cameraPosition = Cesium.clone(map.scene.camera.position);
  209. //构造投射体
  210. var video3D = new mars3d.graphic.Video3D({
  211. type: mars3d.graphic.Video3D.Type.Image,
  212. url: "./img/tietu/gugong.jpg",
  213. position: cartesian,
  214. cameraPosition: cameraPosition,
  215. style: {
  216. opacity: opacity,
  217. },
  218. showFrustum: showFrustum,
  219. });
  220. graphicLayer.addGraphic(video3D);
  221. selectedView = video3D; //记录下
  222. }
  223. //文本投放
  224. function createText() {
  225. var cartesian = map.getCenter({ format: false });
  226. if (!cartesian) {
  227. return;
  228. }
  229. var showFrustum = $("#chkDebugFrustum").is(":checked");
  230. var opacity = Number($("#txtMixNum").val());
  231. var cameraPosition = Cesium.clone(map.scene.camera.position);
  232. //构造投射体
  233. var video3D = new mars3d.graphic.Video3D({
  234. type: mars3d.graphic.Video3D.Type.Text,
  235. position: cartesian,
  236. cameraPosition: cameraPosition,
  237. style: {
  238. text: "Mars3D 火星科技 2021",
  239. opacity: opacity,
  240. textStyles: {
  241. font: "50px 楷体",
  242. fill: true,
  243. fillColor: new Cesium.Color(1.0, 1.0, 0.0, 1.0),
  244. stroke: true,
  245. strokeWidth: 2,
  246. strokeColor: new Cesium.Color(1.0, 1.0, 1.0, 0.8),
  247. backgroundColor: new Cesium.Color(1.0, 1.0, 1.0, 0.1),
  248. textBaseline: "top",
  249. padding: 40,
  250. },
  251. },
  252. showFrustum: showFrustum,
  253. });
  254. graphicLayer.addGraphic(video3D);
  255. selectedView = video3D; //记录下
  256. }
  257. //颜色投放
  258. function createViewForColor() {
  259. //取屏幕中心点
  260. var cartesian = map.getCenter({ format: false });
  261. if (!cartesian) {
  262. return;
  263. }
  264. var cameraPosition = Cesium.clone(map.scene.camera.position);
  265. var showFrustum = $("#chkDebugFrustum").is(":checked");
  266. var opacity = Number($("#txtMixNum").val());
  267. //构造投射体
  268. var video3D = new mars3d.graphic.Video3D({
  269. type: mars3d.graphic.Video3D.Type.Color,
  270. position: cartesian,
  271. cameraPosition: cameraPosition,
  272. style: {
  273. color: Cesium.Color.CYAN.withAlpha(0.5),
  274. opacity: opacity,
  275. },
  276. showFrustum: showFrustum,
  277. });
  278. graphicLayer.addGraphic(video3D);
  279. selectedView = video3D; //记录下
  280. }
  281. //清除
  282. function clearVideo() {
  283. graphicLayer.clear();
  284. selectedView = null;
  285. }
  286. //键盘微调控制
  287. function bindEvnet() {
  288. $("#chkDebugFrustum").change(function () {
  289. if (!selectedView) {
  290. return;
  291. }
  292. var showFrustum = $(this).is(":checked");
  293. selectedView.showFrustum = showFrustum;
  294. });
  295. $("#txtMixNum")
  296. .slider({ min: 0, max: 1, step: 0.1, value: 0.7 })
  297. .on("change", (e) => {
  298. if (selectedView && e?.value) {
  299. selectedView.opacity = e.value.newValue;
  300. }
  301. });
  302. $("#cameraFov")
  303. .slider({ min: 30, max: 120, step: 0.1, value: 45 })
  304. .on("change", (e) => {
  305. if (!selectedView) {
  306. return;
  307. }
  308. selectedView.fovDegree = e.value.newValue;
  309. });
  310. $("#cameraWidHei")
  311. .slider({ min: 0.5, max: 3, step: 0.05, value: 1.6 })
  312. .on("change", (e) => {
  313. if (selectedView && e?.value) {
  314. selectedView.aspectRatio = e.value.newValue;
  315. }
  316. });
  317. $("#btnSelCamera").click(function () {
  318. if (!selectedView) {
  319. return;
  320. }
  321. map.graphicLayer.startDraw({
  322. type: "point",
  323. success: (graphic) => {
  324. var point = graphic.point;
  325. graphic.remove(); //删除绘制的点
  326. selectedView.cameraPosition = point;
  327. },
  328. });
  329. });
  330. $("#btnSelView").click(function () {
  331. if (!selectedView) {
  332. return;
  333. }
  334. map.graphicLayer.startDraw({
  335. type: "point",
  336. success: (graphic) => {
  337. var point = graphic.point;
  338. graphic.remove(); //删除绘制的点
  339. selectedView.position = point;
  340. },
  341. });
  342. });
  343. //修改坐标 end
  344. $("#btnLocate").click(function () {
  345. if (!selectedView) {
  346. return;
  347. }
  348. selectedView.flyTo();
  349. });
  350. $("#btnConsoleJson").click(function () {
  351. if (!selectedView) {
  352. return;
  353. }
  354. var params = JSON.stringify(selectedView.toJSON());
  355. console.log(params);
  356. haoutil.msg(params);
  357. });
  358. $("#btnPlayPause").click(function () {
  359. if (!selectedView) {
  360. return;
  361. }
  362. selectedView.play = !selectedView.play;
  363. });
  364. document.addEventListener(
  365. "keydown",
  366. function (e) {
  367. switch (e.keyCode) {
  368. default:
  369. break;
  370. case "A".charCodeAt(0):
  371. rotateCamera(mars3d.graphic.Video3D.RatateDirection.LEFT);
  372. break;
  373. case "D".charCodeAt(0):
  374. rotateCamera(mars3d.graphic.Video3D.RatateDirection.RIGHT);
  375. break;
  376. case "W".charCodeAt(0):
  377. rotateCamera(mars3d.graphic.Video3D.RatateDirection.TOP);
  378. break;
  379. case "S".charCodeAt(0):
  380. rotateCamera(mars3d.graphic.Video3D.RatateDirection.BOTTOM);
  381. break;
  382. case "Q".charCodeAt(0): //Q键
  383. rotateCamera(mars3d.graphic.Video3D.RatateDirection.ALONG);
  384. break;
  385. case "E".charCodeAt(0): //E
  386. rotateCamera(mars3d.graphic.Video3D.RatateDirection.INVERSE);
  387. break;
  388. }
  389. },
  390. false
  391. );
  392. }
  393. //微调视频
  394. function rotateCamera(dir) {
  395. if (!selectedView) {
  396. return;
  397. }
  398. selectedView.rotateCamera(dir, $("#rotateDeg").val() * 1);
  399. var cameraFollow = $(this).is(":checked");
  400. if (cameraFollow) {
  401. map.camera.direction = selectedView.camera.direction;
  402. map.camera.right = selectedView.camera.right;
  403. map.camera.up = selectedView.camera.up;
  404. }
  405. }
  406. </script>
  407. </body>
  408. </html>