LightMap.vue 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. <template>
  2. <div class="light-map">
  3. <map
  4. id="prevMap"
  5. map-id="prevMap"
  6. class="light-map-map"
  7. :markers="mapLoader.content.value || []"
  8. :polygons="polygon"
  9. :polyline="polyline"
  10. :enable-poi="false"
  11. :scale="10"
  12. :longitude="AppCofig.defaultLonLat[0]"
  13. :latitude="AppCofig.defaultLonLat[1]"
  14. />
  15. <SimpleDropDownPicker
  16. class="light-map-region-picker"
  17. v-model:modelValue="selectedRegion"
  18. :columns="regionLoader.content.value"
  19. />
  20. </div>
  21. </template>
  22. <script setup lang="ts">
  23. import { getCurrentInstance, ref, watch } from 'vue';
  24. import { useSimpleDataLoader } from '@/common/composeabe/SimpleDataLoader';
  25. import { geoJsonToWechatMapShapes } from '@/common/utils/geoJsonToWechatMap';
  26. import LightVillageApi from '@/api/light/LightVillageApi';
  27. import MapApi from '@/api/map/MapApi';
  28. import AppCofig from '@/common/config/AppCofig';
  29. import type { MapMarker, MapPolygon, MapPolyline } from '@/types/Map';
  30. import SimpleDropDownPicker from '@/common/components/SimpleDropDownPicker.vue';
  31. const instance = getCurrentInstance();
  32. const mapCtx = uni.createMapContext('prevMap', instance);
  33. const selectedRegion = ref<number>();
  34. const regionLoader = useSimpleDataLoader(async () => {
  35. return [
  36. {
  37. id: undefined as any,
  38. name: '厦门市 · 湖里区',
  39. },
  40. ]
  41. });
  42. const mapLoader = useSimpleDataLoader<MapMarker[]>(async () => {
  43. const res = (await LightVillageApi.getVillageList(undefined, selectedRegion.value, undefined, 1, 12)).map((p, i) => {
  44. const maker : MapMarker = {
  45. ...p,
  46. id: p.id ?? i,
  47. title: p.villageName,
  48. longitude: Number(p.longitude),
  49. latitude: Number(p.latitude),
  50. width: 30,
  51. height: 30,
  52. iconPath: '',
  53. callout: {
  54. content: p.villageName,
  55. color: '#000000',
  56. fontSize: 12,
  57. bgColor: '#ffffff',
  58. borderRadius: 5,
  59. },
  60. }
  61. if (p.isLight) {
  62. if (p.lightValue >= 1) {
  63. maker.iconPath = `https://mncdn.wenlvti.net/app_static/xiangyuan/images/map/LightSun.png`;
  64. } else if (p.lightValue >= 0.5) {
  65. maker.iconPath = `https://mncdn.wenlvti.net/app_static/xiangyuan/images/map/LightMoon.png`;
  66. } else if (p.lightValue >= 0.25) {
  67. maker.iconPath = `https://mncdn.wenlvti.net/app_static/xiangyuan/images/map/LightStar.png`;
  68. } else {
  69. maker.iconPath = `https://mncdn.wenlvti.net/app_static/xiangyuan/images/map/LightStar.png`;
  70. }
  71. const size = (p.lightValue + 0.5) * 36;
  72. maker.width = size;
  73. maker.height = size;
  74. } else {
  75. maker.width = 15;
  76. maker.height = 15;
  77. maker.iconPath = `https://mncdn.wenlvti.net/app_static/xiangyuan/images/map/StarNotLight.png`;
  78. }
  79. return maker as MapMarker;
  80. });
  81. /* const countryGeoJsonData = await MapApi.loadCountryGeoJsonData();
  82. const { polygons, polylines: geoPolylines } = geoJsonToWechatMapShapes(countryGeoJsonData, {
  83. fillColor: '#344A41',
  84. strokeColor: '#4AB58A',
  85. strokeWidth: 2,
  86. level: 'abovebuildings',
  87. });
  88. polygon.value.push(...polygons);
  89. polyline.value = geoPolylines; */
  90. setTimeout(() => {
  91. mapCtx.includePoints({
  92. points: res.map(p => {
  93. if (!p.longitude || !p.latitude) {
  94. p.longitude = AppCofig.defaultLonLat[0];
  95. p.latitude = AppCofig.defaultLonLat[1];
  96. }
  97. return {
  98. latitude: p.latitude,
  99. longitude: p.longitude,
  100. }
  101. }),
  102. padding: [20, 20, 20, 20],
  103. });
  104. }, 200);
  105. return res;
  106. });
  107. const polygon = ref<MapPolygon[]>([
  108. /* {
  109. fillColor: '#000',
  110. level: 'abovebuildings',
  111. points: [
  112. { latitude: -89, longitude: 0 },
  113. { latitude: 89, longitude: 0 },
  114. { latitude: 89, longitude: 179.999 },
  115. { latitude: -89, longitude: 179.999 },
  116. ]
  117. } */
  118. ]);
  119. const polyline = ref<MapPolyline[]>([]);
  120. watch(selectedRegion, async () => {
  121. mapLoader.loadData(undefined, true);
  122. });
  123. </script>
  124. <style lang="scss">
  125. .light-map {
  126. position: relative;
  127. width: 100%;
  128. height: 600rpx;
  129. border-radius: 30rpx;
  130. overflow: hidden;
  131. .light-map-map {
  132. width: 100%;
  133. height: 600rpx;
  134. }
  135. .light-map-region-picker {
  136. position: absolute;
  137. bottom: 20rpx;
  138. left: 50%;
  139. transform: translateX(-50%);
  140. z-index: 100;
  141. }
  142. }
  143. </style>