f80_property.html 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491
  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>Property属性机制演示 </title>
  21. <!--第三方lib-->
  22. <script
  23. type="text/javascript"
  24. src="../lib/include-lib.js"
  25. libpath="../lib/"
  26. include="jquery,font-awesome,bootstrap,layer,haoutil,turf,mars3d"
  27. ></script>
  28. <link href="css/style.css" rel="stylesheet" />
  29. <style>
  30. .infoview {
  31. width: 250px;
  32. line-height: 40px;
  33. }
  34. </style>
  35. </head>
  36. <body class="dark">
  37. <!--加载前进行操作提示,优化用户体验-->
  38. <div id="mask" class="signmask" onclick="removeMask()"></div>
  39. <div id="mars3dContainer" class="mars3d-container"></div>
  40. <!-- 面板 -->
  41. <div class="infoview">
  42. <div>属性机制演示:</div>
  43. <input type="button" class="btn btn-primary" value="SampleProperty" onclick="demoSampleProperty()" />
  44. <input type="button" class="btn btn-primary" value="TimeIntervalCollectionProperty" onclick="demoTimeIntervalCollectionProperty()" />
  45. <input type="button" class="btn btn-primary" value="ConstantProperty" onclick="demoConstantProperty()" />
  46. <input type="button" class="btn btn-primary" value="CompositeProperty" onclick="demoCompositeProperty()" />
  47. <input type="button" class="btn btn-primary" value="SampledPositionProperty" onclick="demoSampledPositionProperty()" />
  48. <input type="button" class="btn btn-primary" value="ColorMaterialProperty" onclick="demoColorMaterialProperty()" />
  49. <input type="button" class="btn btn-primary" value="ColorMaterialProperty2" onclick="demoColorMaterialProperty2()" />
  50. <input type="button" class="btn btn-primary" value="CallbackProperty" onclick="demoCallbackProperty()" />
  51. <input type="button" class="btn btn-primary" value="ReferenceProperty" onclick="demoReferenceProperty()" />
  52. <input type="button" class="btn btn-primary" value="PropertyBag" onclick="demoPropertyBag()" />
  53. <input type="button" class="btn btn-primary" value="VelocityVectorProperty" onclick="demoVelocityVectorProperty()" />
  54. </div>
  55. <script src="./js/common.js"></script>
  56. <script type="text/javascript">
  57. "use script"; //开发环境建议开启严格模式
  58. var map;
  59. var graphicLayer;
  60. function initMap(options) {
  61. //合并属性参数,可覆盖config.json中的对应配置
  62. var mapOptions = mars3d.Util.merge(options, {
  63. scene: {
  64. center: { lat: 31.81506, lng: 117.23734, alt: 1768, heading: 322, pitch: -33 },
  65. fxaa: true,
  66. },
  67. });
  68. //创建三维地球场景
  69. map = new mars3d.Map("mars3dContainer", mapOptions);
  70. // 创建矢量图层
  71. graphicLayer = new mars3d.layer.GraphicLayer();
  72. map.addLayer(graphicLayer);
  73. }
  74. function demoSampleProperty() {
  75. graphicLayer.clear();
  76. // 创建盒子
  77. var marsBox = new mars3d.graphic.BoxEntity({
  78. position: [117.220164, 31.834887, 39.6],
  79. style: {
  80. dimensions: new Cesium.Cartesian3(400.0, 300.0, 500.0),
  81. color: "rgba(0,255,255,0.8)",
  82. outline: true,
  83. },
  84. });
  85. graphicLayer.addGraphic(marsBox);
  86. //指定固定时间 ,方便写演示代码。
  87. map.clock.currentTime = Cesium.JulianDate.fromDate(new Date("2017-08-25 08:00:00"));
  88. // 演示属性机制
  89. var property = new Cesium.SampledProperty(Cesium.Cartesian3);
  90. property.addSample(Cesium.JulianDate.fromDate(new Date("2017-08-25 08:00:00")), new Cesium.Cartesian3(400.0, 300.0, 100.0));
  91. property.addSample(Cesium.JulianDate.fromDate(new Date("2017-08-25 08:00:20")), new Cesium.Cartesian3(400.0, 300.0, 900.0));
  92. //让盒子一直存在
  93. // property.addSample(Cesium.JulianDate.fromDate(new Date('2017-08-26 00:00:00')), new Cesium.Cartesian3(400.0, 300.0, 900.0))
  94. marsBox.setStyle({ dimensions: property });
  95. }
  96. function demoTimeIntervalCollectionProperty() {
  97. graphicLayer.clear();
  98. //指定固定时间 ,方便写演示代码。
  99. map.clock.currentTime = Cesium.JulianDate.fromIso8601("2017-08-25T00:00:00.00Z");
  100. // 创建盒子
  101. var marsBox = new mars3d.graphic.BoxEntity({
  102. position: [117.220164, 31.834887, 39.6],
  103. style: {
  104. dimensions: new Cesium.Cartesian3(400.0, 300.0, 500.0),
  105. color: "rgba(255,255,0,0.8)",
  106. outline: true,
  107. },
  108. });
  109. graphicLayer.addGraphic(marsBox);
  110. // 演示属性机制
  111. var property = new Cesium.TimeIntervalCollectionProperty();
  112. property.intervals.addInterval(
  113. Cesium.TimeInterval.fromIso8601({
  114. iso8601: "2017-08-25T00:00:00.00Z/2017-08-25T00:00:02.00Z",
  115. isStartIncluded: true,
  116. isStopIncluded: false,
  117. data: new Cesium.Cartesian3(400.0, 300.0, 200.0),
  118. })
  119. );
  120. property.intervals.addInterval(
  121. Cesium.TimeInterval.fromIso8601({
  122. iso8601: "2017-08-25T00:00:02.00Z/2017-08-25T00:00:04.00Z",
  123. isStartIncluded: true,
  124. isStopIncluded: false,
  125. data: new Cesium.Cartesian3(400.0, 300.0, 400.0),
  126. })
  127. );
  128. property.intervals.addInterval(
  129. Cesium.TimeInterval.fromIso8601({
  130. iso8601: "2017-08-25T00:00:04.00Z/2017-08-25T00:00:06.00Z",
  131. isStartIncluded: true,
  132. isStopIncluded: false,
  133. data: new Cesium.Cartesian3(400.0, 300.0, 500.0),
  134. })
  135. );
  136. property.intervals.addInterval(
  137. Cesium.TimeInterval.fromIso8601({
  138. iso8601: "2017-08-25T00:00:06.00Z/2017-08-25T00:00:08.00Z",
  139. isStartIncluded: true,
  140. isStopIncluded: true,
  141. data: new Cesium.Cartesian3(400.0, 300.0, 700.0),
  142. })
  143. );
  144. marsBox.setStyle({ dimensions: property });
  145. }
  146. function demoConstantProperty() {
  147. graphicLayer.clear();
  148. // 创建盒子
  149. var marsBox = new mars3d.graphic.BoxEntity({
  150. position: [117.220164, 31.834887, 39.6],
  151. style: {
  152. dimensions: new Cesium.Cartesian3(400.0, 300.0, 500.0),
  153. color: "rgba(0,255,0,0.8)",
  154. outline: true,
  155. },
  156. });
  157. graphicLayer.addGraphic(marsBox);
  158. setTimeout(() => {
  159. // 演示属性机制
  160. //会创建一个新的ConstantProperty
  161. // marsBox.entityGraphic.dimensions = new Cesium.Cartesian3(400.0, 300.0, 200.0)
  162. //会修改原有的ConstantProperty的值。
  163. marsBox.entityGraphic.dimensions.setValue(new Cesium.Cartesian3(400.0, 300.0, 700.0));
  164. }, 2000);
  165. }
  166. //
  167. function demoCompositeProperty() {
  168. graphicLayer.clear();
  169. //指定固定时间 ,方便写演示代码。
  170. map.clock.currentTime = Cesium.JulianDate.fromIso8601("2017-08-25T00:00:00.00Z");
  171. // 创建盒子
  172. var marsBox = new mars3d.graphic.BoxEntity({
  173. position: [117.220164, 31.834887, 39.6],
  174. style: {
  175. dimensions: new Cesium.Cartesian3(400.0, 300.0, 500.0),
  176. color: "rgba(0,255,255,0.8)",
  177. outline: true,
  178. },
  179. });
  180. graphicLayer.addGraphic(marsBox);
  181. // 演示属性机制
  182. // 1 sampledProperty
  183. var sampledProperty = new Cesium.SampledProperty(Cesium.Cartesian3);
  184. sampledProperty.addSample(Cesium.JulianDate.fromIso8601("2017-08-25T00:00:00.00Z"), new Cesium.Cartesian3(400.0, 300.0, 100.0));
  185. sampledProperty.addSample(Cesium.JulianDate.fromIso8601("2017-08-25T00:00:10.00Z"), new Cesium.Cartesian3(400.0, 300.0, 500.0));
  186. // 2 ticProperty
  187. var ticProperty = new Cesium.TimeIntervalCollectionProperty();
  188. ticProperty.intervals.addInterval(
  189. Cesium.TimeInterval.fromIso8601({
  190. iso8601: "2017-08-25T00:00:10.00Z/2017-08-25T00:00:12.00Z",
  191. isStartIncluded: true,
  192. isStopIncluded: false,
  193. data: new Cesium.Cartesian3(400.0, 300.0, 600.0),
  194. })
  195. );
  196. ticProperty.intervals.addInterval(
  197. Cesium.TimeInterval.fromIso8601({
  198. iso8601: "2017-08-25T00:00:12.00Z/2017-08-25T00:00:14.00Z",
  199. isStartIncluded: true,
  200. isStopIncluded: false,
  201. data: new Cesium.Cartesian3(400.0, 300.0, 700.0),
  202. })
  203. );
  204. ticProperty.intervals.addInterval(
  205. Cesium.TimeInterval.fromIso8601({
  206. iso8601: "2017-08-25T00:00:14.00Z/2017-08-25T00:00:16.00Z",
  207. isStartIncluded: true,
  208. isStopIncluded: false,
  209. data: new Cesium.Cartesian3(400.0, 300.0, 800.0),
  210. })
  211. );
  212. ticProperty.intervals.addInterval(
  213. Cesium.TimeInterval.fromIso8601({
  214. iso8601: "2017-08-25T00:00:16.00Z/2017-08-25T00:00:18.00Z",
  215. isStartIncluded: true,
  216. isStopIncluded: true,
  217. data: new Cesium.Cartesian3(400.0, 300.0, 900.0),
  218. })
  219. );
  220. // 3 compositeProperty
  221. var compositeProperty = new Cesium.CompositeProperty();
  222. compositeProperty.intervals.addInterval(
  223. Cesium.TimeInterval.fromIso8601({
  224. iso8601: "2017-08-25T00:00:00.00Z/2017-08-25T00:00:10.00Z",
  225. data: sampledProperty,
  226. })
  227. );
  228. compositeProperty.intervals.addInterval(
  229. Cesium.TimeInterval.fromIso8601({
  230. iso8601: "2017-08-25T00:00:10.00Z/2017-08-25T00:00:20.00Z",
  231. isStartIncluded: false,
  232. isStopIncluded: false,
  233. data: ticProperty,
  234. })
  235. );
  236. // 4 设置dimensions
  237. marsBox.setStyle({ dimensions: compositeProperty });
  238. }
  239. // 使盒子进行移动
  240. function demoSampledPositionProperty() {
  241. graphicLayer.clear();
  242. // 创建盒子
  243. var marsBox = new mars3d.graphic.BoxEntity({
  244. position: [117.198461, 31.834956, 40.2],
  245. style: {
  246. dimensions: new Cesium.Cartesian3(100.0, 200.0, 300.0),
  247. color: "rgba(2,255,123,0.8)",
  248. outline: true,
  249. },
  250. });
  251. graphicLayer.addGraphic(marsBox);
  252. //指定固定时间 ,方便写演示代码。
  253. map.clock.currentTime = Cesium.JulianDate.fromDate(new Date("2017-08-25 08:00:00"));
  254. // 演示属性机制
  255. var property = new Cesium.SampledPositionProperty();
  256. property.addSample(Cesium.JulianDate.fromDate(new Date("2017-08-25 08:00:00")), Cesium.Cartesian3.fromDegrees(117.198461, 31.834956, 40.2));
  257. property.addSample(Cesium.JulianDate.fromDate(new Date("2017-08-25 08:00:20")), Cesium.Cartesian3.fromDegrees(117.231979, 31.833411, 35.6));
  258. marsBox.position = property;
  259. }
  260. //
  261. function demoColorMaterialProperty() {
  262. graphicLayer.clear();
  263. // 创建盒子
  264. var marsBox = new mars3d.graphic.BoxEntity({
  265. position: [117.220164, 31.834887, 39.6],
  266. style: {
  267. dimensions: new Cesium.Cartesian3(400.0, 300.0, 500.0),
  268. color: "rgba(0,0,255,0.8)",
  269. outline: true,
  270. },
  271. });
  272. graphicLayer.addGraphic(marsBox);
  273. // 演示属性机制
  274. setTimeout(() => {
  275. marsBox.setStyle({ material: new Cesium.ColorMaterialProperty(new Cesium.Color(0, 1, 0)) });
  276. // 以上代码等同于
  277. // marsBox.setStyle({ material: new Cesium.Color(0, 1, 0) })
  278. }, 3000);
  279. }
  280. function demoColorMaterialProperty2() {
  281. graphicLayer.clear();
  282. // 创建盒子
  283. var marsBox = new mars3d.graphic.BoxEntity({
  284. position: [117.220164, 31.834887, 39.6],
  285. style: {
  286. dimensions: new Cesium.Cartesian3(400.0, 300.0, 500.0),
  287. color: "rgba(0,0,255,0.8)",
  288. outline: true,
  289. },
  290. });
  291. graphicLayer.addGraphic(marsBox);
  292. //指定固定时间 ,方便写演示代码。
  293. map.clock.currentTime = Cesium.JulianDate.fromDate(new Date("2017-08-25 08:00:00"));
  294. // 演示属性机制
  295. var colorProperty = new Cesium.SampledProperty(Cesium.Color);
  296. colorProperty.addSample(Cesium.JulianDate.fromDate(new Date("2017-08-25 08:00:00")), new Cesium.Color(0, 0, 1));
  297. colorProperty.addSample(Cesium.JulianDate.fromDate(new Date("2017-08-25 08:00:10")), new Cesium.Color(1, 1, 0));
  298. marsBox.setStyle({ material: new Cesium.ColorMaterialProperty(colorProperty) });
  299. }
  300. //
  301. function demoCallbackProperty() {
  302. graphicLayer.clear();
  303. // 创建盒子
  304. var marsBox = new mars3d.graphic.BoxEntity({
  305. position: [117.220164, 31.834887, 39.6],
  306. style: {
  307. dimensions: new Cesium.Cartesian3(400.0, 300.0, 500.0),
  308. color: "rgba(0,255,255,0.8)",
  309. outline: true,
  310. },
  311. });
  312. graphicLayer.addGraphic(marsBox);
  313. // 演示属性机制
  314. var len = 100.0;
  315. var property = new Cesium.CallbackProperty(function (time, result) {
  316. result = result || new Cesium.Cartesian3(400.0, 300.0, 500.0);
  317. len += 3.0;
  318. if (len > 900.0) {
  319. len = 100.0;
  320. }
  321. result.x = 400.0;
  322. result.y = 300.0;
  323. result.z = len;
  324. return result;
  325. }, false);
  326. marsBox.setStyle({ dimensions: property });
  327. }
  328. //
  329. function demoReferenceProperty() {
  330. graphicLayer.clear();
  331. // 创建蓝色盒子
  332. var marsBox = new mars3d.graphic.BoxEntity({
  333. position: [117.220164, 31.834887, 39.6],
  334. style: {
  335. dimensions: new Cesium.Cartesian3(400.0, 300.0, 500.0),
  336. color: "rgba(0,0,255,0.8)",
  337. outline: true,
  338. },
  339. });
  340. graphicLayer.addGraphic(marsBox);
  341. //指定固定时间 ,方便写演示代码。
  342. map.clock.currentTime = Cesium.JulianDate.fromDate(new Date("2017-08-25 08:00:00"));
  343. // 演示属性机制
  344. var property = new Cesium.SampledProperty(Cesium.Cartesian3);
  345. property.addSample(Cesium.JulianDate.fromDate(new Date("2017-08-25 08:00:00")), new Cesium.Cartesian3(400.0, 300.0, 100.0));
  346. property.addSample(Cesium.JulianDate.fromDate(new Date("2017-08-25 08:00:20")), new Cesium.Cartesian3(400.0, 300.0, 900.0));
  347. property.addSample(Cesium.JulianDate.fromDate(new Date("2017-08-26 00:00:00")), new Cesium.Cartesian3(400.0, 300.0, 900.0)); //让盒子一直存在
  348. marsBox.setStyle({ dimensions: property });
  349. //另外一个红色盒子
  350. var redBox = new mars3d.graphic.BoxEntity({
  351. position: [117.225643, 31.843242, 37.9],
  352. style: {
  353. dimensions: new Cesium.Cartesian3(400.0, 300.0, 500.0),
  354. color: "rgba(255,0,0,0.8)",
  355. outline: true,
  356. },
  357. });
  358. graphicLayer.addGraphic(redBox);
  359. // 演示属性机制
  360. var collection = graphicLayer.dataSource.entities;
  361. let dimensions = new Cesium.ReferenceProperty(collection, marsBox.uuid, ["box", "dimensions"]);
  362. redBox.setStyle({ dimensions: dimensions });
  363. }
  364. //
  365. function demoPropertyBag() {
  366. graphicLayer.clear();
  367. // 创建盒子
  368. var marsBox = new mars3d.graphic.BoxEntity({
  369. position: [117.220164, 31.834887, 39.6],
  370. style: {
  371. dimensions: new Cesium.Cartesian3(400.0, 300.0, 500.0),
  372. color: "rgba(0,0,255,0.8)",
  373. outline: true,
  374. },
  375. });
  376. graphicLayer.addGraphic(marsBox);
  377. //指定固定时间 ,方便写演示代码。
  378. map.clock.currentTime = Cesium.JulianDate.fromDate(new Date("2017-08-25 08:00:00"));
  379. // 演示属性机制
  380. var zp = new Cesium.SampledProperty(Number);
  381. zp.addSample(Cesium.JulianDate.fromDate(new Date("2017-08-25 08:00:00")), 100.0);
  382. zp.addSample(Cesium.JulianDate.fromDate(new Date("2017-08-25 08:00:10")), 800.0);
  383. let dimensions = new Cesium.PropertyBag({
  384. x: 400.0,
  385. y: 300.0,
  386. z: zp,
  387. });
  388. marsBox.setStyle({ dimensions: dimensions });
  389. }
  390. //
  391. function demoVelocityVectorProperty() {
  392. graphicLayer.clear();
  393. let propertyFJ = getSampledPositionProperty([
  394. [117.198461, 31.834956, 40.2],
  395. [117.231979, 31.833411, 35.6],
  396. ]);
  397. var graphic = new mars3d.graphic.BillboardEntity({
  398. position: propertyFJ,
  399. orientation: new Cesium.VelocityOrientationProperty(propertyFJ),
  400. style: {
  401. image: "img/marker/huojian.svg",
  402. scale: 0.5,
  403. alignedAxis: new Cesium.VelocityVectorProperty(propertyFJ, true),
  404. },
  405. });
  406. graphicLayer.addGraphic(graphic);
  407. }
  408. //计算演示的SampledPositionProperty轨迹
  409. function getSampledPositionProperty(points) {
  410. let property = new Cesium.SampledPositionProperty();
  411. let start = map.clock.currentTime;
  412. let positions = mars3d.LatLngArray.toCartesians(points);
  413. for (let i = 0; i < positions.length; i++) {
  414. let time = Cesium.JulianDate.addSeconds(start, i * 20, new Cesium.JulianDate());
  415. let position = positions[i];
  416. property.addSample(time, position);
  417. }
  418. return property;
  419. }
  420. </script>
  421. </body>
  422. </html>