index.vue 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <template>
  2. <div class="map" ref="map"></div>
  3. </template>
  4. <script>
  5. import { listSite } from "@/api/site/site";
  6. export default {
  7. data() {
  8. return {
  9. queryParams: {
  10. page: 1,
  11. size: 10000,
  12. },
  13. loading: true,
  14. list: []
  15. }
  16. },
  17. created() {
  18. this.getList();
  19. },
  20. mounted() {
  21. this.map = new T.Map(this.$refs.map);
  22. this.map.centerAndZoom(new T.LngLat(104.066541, 30.572269), 8);
  23. this.map.addControl(new T.Control.Zoom());
  24. this.map.addControl(new T.Control.MapType());
  25. },
  26. methods: {
  27. handleQuery() {
  28. this.getList();
  29. },
  30. getList() {
  31. this.loading = true;
  32. listSite({page: 1, size: 10000,}).then(response => {
  33. this.list = response.data.records || [];
  34. if (this.list.length > 0) {
  35. this.map.centerAndZoom(new T.LngLat(+this.list[0].lon, +this.list[0].lat), 8);
  36. }
  37. this.list.forEach((item) => {
  38. const point = new T.LngLat(+item.lon, +item.lat);
  39. const marker = new T.Marker(point);
  40. marker.addEventListener('click', () => {
  41. this.handleSiteClick(item);
  42. })
  43. this.map.addOverLay(marker);
  44. })
  45. this.loading = false;
  46. }
  47. );
  48. },
  49. handleSiteClick(site) {
  50. this.$router.push(`/analysis/task/realtime/${site.siteId}`);
  51. }
  52. }
  53. };
  54. </script>
  55. <style scoped lang="scss">
  56. .map {
  57. width: 100%;
  58. height: calc(100vh - 90px);
  59. }
  60. </style>