components_slideshow_vue.html 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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_componentsSlideshow_Vue'></title>
  9. <script type="text/javascript" include="vue" 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. .sm-component-slideshow {
  18. position: absolute;
  19. top: 40px;
  20. left: 30px;
  21. width: 400px;
  22. height: 380px;
  23. border-radius: 4px;
  24. }
  25. </style>
  26. </head>
  27. <body style=" margin: 0;overflow: hidden;background: #fff;width: 100%;height:100%;position: absolute;top: 0;">
  28. <div id="main">
  29. <sm-web-map map-id='567946816' :map-options="mapOptions" server-url='https://www.supermapol.com'
  30. tianditu-key='1d109683f4d84198e37a38c442d68311' @load="mapLoaded">
  31. </sm-web-map>
  32. <sm-slideshow :collapsed="false" :autoplay="autoplay" :pagination="pagination" @change="slideChange">
  33. <sm-slideshow-item v-for="item of content" :key="item.title">
  34. <h3 style="margin-top: 8px;">{{ item.title }}</h3>
  35. <p style="padding: 8px;">{{ item.description }}</p>
  36. <img :src="item.image" style="width: 300px; height: 170px;" />
  37. </sm-slideshow-item>
  38. </sm-slideshow>
  39. </div>
  40. <script>
  41. new Vue({
  42. el: '#main',
  43. data() {
  44. return {
  45. mapOptions: {
  46. zoom: 14,
  47. pitch: 60,
  48. center: [103.93424623295097, 33.03730377719067]
  49. },
  50. content: '',
  51. pagination: {
  52. type: 'bullets',
  53. clickable: true
  54. },
  55. autoplay: {
  56. delay: 3000,
  57. disableOnInteraction: false
  58. }
  59. };
  60. },
  61. created() {
  62. this.setDataFn = this.setData.bind(this);
  63. this.getData(this.setDataFn);
  64. },
  65. beforeDestroy() {
  66. this.marker && this.marker.remove() && (this.marker = null);
  67. },
  68. methods: {
  69. getData(cb) {
  70. var jsonName = /en/.test(SuperMap.Lang.getCode()) ? 'jiuzhai-en' : 'jiuzhai';
  71. $.get(`../data/jiuzhai/${jsonName}.json`, function (res) {
  72. cb && cb(res);
  73. });
  74. },
  75. setData(res) {
  76. this.content = res;
  77. },
  78. slideChange(options) {
  79. let coordinates = this.content[options.realIndex].coordinates;
  80. this.map.flyTo({ center: coordinates });
  81. if (!this.marker) {
  82. this.marker = new mapboxgl.Marker()
  83. .setLngLat(coordinates)
  84. .addTo(this.map);
  85. } else {
  86. this.marker.setLngLat(coordinates)
  87. }
  88. },
  89. mapLoaded(e) {
  90. this.map = e.map;
  91. }
  92. }
  93. })
  94. </script>
  95. </body>
  96. </html>