components_timeline_supermap.html 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301
  1. <!--********************************************************************
  2. * Copyright© 2000 - 2020 SuperMap Software Co.Ltd. All rights reserved.
  3. *********************************************************************-->
  4. <!DOCTYPE html>
  5. <html>
  6. <head>
  7. <meta charset="UTF-8" />
  8. <title data-i18n="resources.title_componentsTimeLineSupermap_Vue"></title>
  9. <script type="text/javascript" include="vue,jquery" src="../js/include-web.js"></script>
  10. <script
  11. include="echarts-vue,iclient-mapboxgl-vue,mapbox-gl-enhance"
  12. src="../../dist/mapboxgl/include-mapboxgl.js"
  13. ></script>
  14. <style>
  15. #main {
  16. margin: 0 auto;
  17. width: 100%;
  18. height: 100%;
  19. }
  20. .sm-component-time-line {
  21. position: absolute;
  22. bottom: 20px;
  23. width: 100%;
  24. height: 80px;
  25. z-index: 1000;
  26. }
  27. .sm-supermap-title {
  28. position: absolute;
  29. top: 20px;
  30. left: 20px;
  31. width: 600px;
  32. height: 50px;
  33. z-index: 1000;
  34. }
  35. .sm-time-info {
  36. position: absolute;
  37. top: 20px;
  38. right: 50px;
  39. width: 300px;
  40. height: 50px;
  41. z-index: 1000;
  42. }
  43. .sm-component-spin {
  44. background: transparent !important;
  45. }
  46. </style>
  47. </head>
  48. <body style=" margin: 0;overflow: hidden;background: #fff;width: 100%;height:100%;position: absolute;top: 0;">
  49. <div id="main">
  50. <sm-web-map
  51. server-url="https://www.supermapol.com"
  52. :map-id="35063750"
  53. :tianditu-key="tiandituKey"
  54. :map-options="mapOptions"
  55. :loading="loading"
  56. @load="load"
  57. ></sm-web-map>
  58. <sm-time-line
  59. ref="timeLine"
  60. :data="data"
  61. :play-interval="2000"
  62. :next-enable="nextEnable"
  63. :label="label"
  64. @timelinechanged="timelineChanged"
  65. @timelineplaychanged="timelineplaychanged"
  66. ></sm-time-line>
  67. <sm-border type="border6" class="sm-supermap-title">
  68. <sm-text
  69. title="超图大厦(成都)周边历史影像"
  70. :font-style="{fontSize: '28px', fontWeight: 600}"
  71. ></sm-text>
  72. </sm-border>
  73. <sm-border type="border6" class="sm-time-info">
  74. <sm-text :title="timeInfo" :font-style="{fontSize: '18px', fontWeight: 600}"></sm-text>
  75. </sm-border>
  76. </div>
  77. <script>
  78. var label = [
  79. '2016年11月26日',
  80. '2017年4月13日',
  81. '2017年5月25日',
  82. '2017年11月11日',
  83. '2017年12月19日',
  84. '2018年1月10日',
  85. '2018年5月25日',
  86. '2019年11月11日'
  87. ];
  88. new Vue({
  89. el: '#main',
  90. data() {
  91. return {
  92. mapStatus: [],
  93. mapQueue: [],
  94. loading: false,
  95. readyNext: true,
  96. nextEnable: false,
  97. tiandituKey: 'f16b023603de8ae8fdd09a2c0feb1ec2',
  98. tooltip: {
  99. formatter: function(params) {
  100. return params.name;
  101. }
  102. },
  103. label: {
  104. formatter: function(val, index) {
  105. return label[index];
  106. }
  107. },
  108. url:
  109. 'https://www.supermapol.com/proxy/iserver/services/map_supermap_building1_qqm0ighb/rest/maps/',
  110. encodeUrl:
  111. '/image.png?viewBounds=%7B"leftBottom"%3A%7B"x"%3A11586898.539611159%2C"y"%3A3570491.9618448047%7D%2C"rightTop"%3A%7B"x"%3A11588127.387288133%2C"y"%3A3571087.184938393%7D%7D%20&center=%7B"x"%3A11587505.74%2C"y"%3A3570771.31%7D&width=1920&scale=0.000346564548&prjCoordSys=%7B"epsgCode"%3A3857%7D&transparent=true&height=930',
  112. data: [
  113. 'T20161126',
  114. 'T20170413',
  115. 'T20170525',
  116. 'T20171111',
  117. 'T20171219',
  118. 'T20180110',
  119. 'T20180525',
  120. 'T20191111'
  121. ],
  122. timeInfo: label[0],
  123. mapOptions: {
  124. style: { version: 8, sources: {}, layers: [] },
  125. center: [104.0924, 30.5217],
  126. zoom: 18,
  127. bearing: 0,
  128. pitch: 0,
  129. tileSize: 1024,
  130. rasterTileSize: 1024
  131. }
  132. };
  133. },
  134. computed: {
  135. allLoaded() {
  136. if (this.mapStatus.length) {
  137. var allLoaded = true;
  138. this.mapStatus.forEach(function(item) {
  139. if (!item.status) {
  140. allLoaded = false;
  141. }
  142. });
  143. return allLoaded;
  144. }
  145. return false;
  146. }
  147. },
  148. watch: {
  149. mapStatus: {
  150. handler() {
  151. var nextEnable = false;
  152. var currentIndex = this.currentIndex;
  153. this.mapStatus.forEach(function(item, index) {
  154. if (currentIndex === index && item.status) {
  155. nextEnable = true;
  156. }
  157. });
  158. this.nextEnable = nextEnable;
  159. }
  160. },
  161. allLoaded() {
  162. this.playState && this.setPlayState(true);
  163. this.nextEnable = null;
  164. }
  165. },
  166. created() {
  167. SuperMap.Components.setTheme({ textColor: '#fff', background: 'rgb(0,0,0,0)' });
  168. this.$on('addlayerssucceeded', this.updateNextRasterSource);
  169. this.$on('loadingChange', this.loadingChange);
  170. },
  171. methods: {
  172. load(e) {
  173. this.map = e.map;
  174. this.resetMapLoadStatus();
  175. },
  176. loadingChange(status) {
  177. this.loading = status;
  178. },
  179. timelineplaychanged(val) {
  180. this.playState = val.playState;
  181. },
  182. timelineChanged(val) {
  183. var currentIndex = (val && val.currentIndex) || 0;
  184. var dataId = this.data[currentIndex];
  185. var imageUrl = this.url + dataId + this.encodeUrl;
  186. this.currentIndex = currentIndex;
  187. var sourceId = this.data[0];
  188. if (!this.readyNext) {
  189. this.mapQueue.push({ key: dataId, sourceId: sourceId, imageUrl: imageUrl });
  190. return;
  191. }
  192. this.readyNext = false;
  193. this.timeInfo = label[currentIndex];
  194. this.updateRasterSource(sourceId, imageUrl);
  195. },
  196. updateRasterSource(sourceId, imageUrl) {
  197. if (this.map.getLayer(sourceId)) {
  198. this.map.setLayoutProperty(sourceId, 'visibility', 'none');
  199. }
  200. sourceId = sourceId + '_image';
  201. var source = this.map.getSource(sourceId);
  202. if (!source) {
  203. this.map.addSource(sourceId, {
  204. type: 'image',
  205. url: imageUrl,
  206. coordinates: [
  207. [104.08688053674865, 30.524020349913428],
  208. [104.09791946324947, 30.524020349913428],
  209. [104.09791946324947, 30.519414264971005],
  210. [104.08688053674865, 30.519414264971005]
  211. ]
  212. });
  213. this.map.addLayer({
  214. id: sourceId,
  215. type: 'raster',
  216. source: sourceId,
  217. paint: {
  218. 'raster-fade-duration': 0
  219. }
  220. });
  221. } else {
  222. source.updateImage({ url: imageUrl });
  223. }
  224. this.$emit('addlayerssucceeded');
  225. },
  226. updateNextRasterSource() {
  227. this.readyNext = true;
  228. if (this.mapQueue.length) {
  229. var { id: mapId, sourceId, imageUrl } = this.mapQueue.shift();
  230. this.updateRasterSource(sourceId, imageUrl);
  231. } else {
  232. var key = this.data[this.currentIndex];
  233. var sourceCaches = this.map.style.sourceCaches;
  234. var beforeIds = [];
  235. for (var sourceId in sourceCaches) {
  236. beforeIds.push(sourceId);
  237. }
  238. }
  239. !this.allLoaded && this.isAllSourceLoaded(key, beforeIds);
  240. },
  241. setPlayState(status) {
  242. this.$refs.timeLine.setPlayState(status);
  243. },
  244. isAllSourceLoaded(key, sourceIds) {
  245. if (this.timer) {
  246. clearInterval(this.timer);
  247. this.timer = null;
  248. }
  249. var map = this.map;
  250. var _this = this;
  251. this.timer = setInterval(function() {
  252. _this.$emit('loadingChange', true);
  253. var loaded = true;
  254. sourceIds.forEach(function(id) {
  255. if (_this.map && _this.map.style) {
  256. if (!_this.map.getSource(id)) {
  257. return true;
  258. }
  259. if (!_this.map.isSourceLoaded(id)) {
  260. loaded = false;
  261. }
  262. return _this.map.isSourceLoaded(id);
  263. }
  264. return true;
  265. });
  266. _this.nextEnable = false;
  267. if (loaded && _this.mapStatus) {
  268. clearInterval(_this.timer);
  269. _this.timer = null;
  270. var mapStatus = _this.mapStatus.concat();
  271. mapStatus.forEach(function(info) {
  272. if (info.key === key) {
  273. info.status = true;
  274. }
  275. });
  276. _this.mapStatus = mapStatus;
  277. _this.$emit('loadingChange', false);
  278. }
  279. }, 100);
  280. },
  281. resetMapLoadStatus() {
  282. var mapStatus = [];
  283. if (this.mapStatus && this.mapStatus.length) {
  284. mapStatus = this.mapStatus.map(function(info) {
  285. info.status = false;
  286. return info;
  287. });
  288. } else {
  289. this.data.forEach(function(key) {
  290. mapStatus.push({ key: key, status: false });
  291. });
  292. }
  293. this.mapStatus = mapStatus;
  294. }
  295. }
  296. });
  297. </script>
  298. </body>
  299. </html>