components_flyto_vue.html 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. <!--********************************************************************
  2. * Copyright© 2000 - 2021 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_componentsFlyTo_Vue'></title>
  9. <script type="text/javascript" include="vue, jquery" src="../js/include-web.js"></script>
  10. <script include="iclient-mapboxgl-vue,mapbox-gl-enhance" src="../../dist/mapboxgl/include-mapboxgl.js"></script>
  11. <style>
  12. #main {
  13. margin: 0 auto;
  14. width: 100%;
  15. height: 100%;
  16. }
  17. #features {
  18. position: absolute;
  19. width: 26%;
  20. left: 73%;
  21. top: 90px;
  22. background-color: #fafafa;
  23. color: rgba(0, 0, 0, 0.65);
  24. }
  25. section {
  26. padding: 25px 50px;
  27. line-height: 25px;
  28. opacity: 0.25;
  29. font-size: 13px;
  30. }
  31. section.active {
  32. opacity: 1;
  33. }
  34. .content-item img {
  35. width: 100%;
  36. height: 220px;
  37. margin-bottom: 10px;
  38. }
  39. </style>
  40. </head>
  41. <body style=" margin: 0;overflow: hidden;background: #fff;width: 100%;height:100%;position: absolute;top: 0;">
  42. <div id="main">
  43. <sm-web-map :map-id="567946816" server-url="https://www.supermapol.com"
  44. tianditu-key="1d109683f4d84198e37a38c442d68311" @load="mapLoaded">
  45. <sm-fly-to :data="data" :fly-options="flyOptions" :collapsed="false" :autoplay="false"
  46. @change="handleFlyChange"></sm-fly-to>
  47. </sm-web-map>
  48. <div id="features" class="sm-component-fly-controller">
  49. <section v-if="currentContent" :class="{ active: currentContent && currentContent.title === activeTitle }">
  50. <h3>{{ currentContent.title }}</h3>
  51. <h5>{{ currentContent.subtitle }}</h5>
  52. <div class="content-item">
  53. <img :src="currentContent.image" />
  54. <span>{{ currentContent.description }}</span>
  55. </div>
  56. </section>
  57. </div>
  58. </div>
  59. <script>
  60. new Vue({
  61. el: '#main',
  62. data() {
  63. return {
  64. data: null,
  65. flyOptions: {
  66. duration: 1500,
  67. zoom: 15,
  68. pitch: 60
  69. },
  70. activeTitle: null,
  71. currentContent: null
  72. }
  73. },
  74. created() {
  75. this.setDataFn = this.setData.bind(this);
  76. this.getData(this.setDataFn);
  77. },
  78. methods: {
  79. getData(cb) {
  80. var jsonName = /en/.test(SuperMap.Lang.getCode()) ? 'jiuzhai-en' : 'jiuzhai';
  81. $.get(`../data/jiuzhai/${jsonName}.json`, function (res) {
  82. cb && cb(res);
  83. });
  84. },
  85. setData(res) {
  86. if (res) {
  87. this.data = res.map(item => {
  88. const nextItem = {
  89. location: item.coordinates
  90. };
  91. switch (item.title) {
  92. case '上季节海':
  93. case '五花海':
  94. case 'Upper Seasonal Lakes':
  95. case 'Wu Hua Hai':
  96. nextItem.flyOptions = Object.assign({}, this.flyOptions, {
  97. bearing: -8
  98. });
  99. break;
  100. case '下季节海':
  101. case 'Lower Seasonal Lake':
  102. nextItem.flyOptions = Object.assign({}, this.flyOptions, {
  103. bearing: -68
  104. });
  105. break;
  106. case '五彩池':
  107. case 'Five Coloured Pond':
  108. nextItem.flyOptions = Object.assign({}, this.flyOptions, {
  109. duration: 1000,
  110. bearing: 0
  111. });
  112. break;
  113. case '珍珠滩瀑布':
  114. case '"Pearl Shoals Waterfall':
  115. nextItem.flyOptions = Object.assign({}, this.flyOptions, {
  116. pitch: 17
  117. });
  118. break;
  119. case '扎如寺':
  120. case 'Zharu Temple':
  121. nextItem.flyOptions = Object.assign({}, this.flyOptions, {
  122. bearing: 16,
  123. pitch: 37
  124. });
  125. break;
  126. }
  127. return nextItem;
  128. });
  129. this.contentList = [].concat(res);
  130. this.currentContent = this.contentList[0];
  131. }
  132. },
  133. handleFlyChange(data) {
  134. this.setActiveChapter(data.activeIndex);
  135. },
  136. setActiveChapter(activeIndex) {
  137. var activeItem = this.contentList[activeIndex];
  138. var chapterName = activeItem.title;
  139. if (chapterName === this.activeTitle) {
  140. return;
  141. }
  142. this.currentContent = activeItem;
  143. this.activeTitle = chapterName;
  144. if (!this.marker) {
  145. this.marker = new mapboxgl.Marker()
  146. .setLngLat(activeItem.coordinates)
  147. .addTo(this.map);
  148. } else {
  149. this.marker.setLngLat(activeItem.coordinates)
  150. }
  151. },
  152. mapLoaded(e) {
  153. this.map = e.map;
  154. }
  155. },
  156. })
  157. </script>
  158. </body>
  159. </html>