mapLegend.vue 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. <template>
  2. <div class="map-legend-container">
  3. <div class="map-legend">
  4. <div v-for="(item, index) in legendArr" :key="`${type}-${item.name}-${index}`" class="legend-item">
  5. <span class="legend-dot" v-if="item.color" :style="{ backgroundColor: item.color }"></span>
  6. <img class="legend-icon" v-else :src="item.icon" alt="" />
  7. <span class="legend-label">{{ item.name }}</span>
  8. </div>
  9. </div>
  10. <div class="map-legend">
  11. <div v-for="(item, index) in legendArr2" :key="`${type}-${item.name}-${index}`" class="legend-item">
  12. <span class="legend-dot" v-if="item.color" :style="{ backgroundColor: item.color }"></span>
  13. <img class="legend-icon" v-else :src="item.icon" alt="" />
  14. <span class="legend-label">{{ item.name }}</span>
  15. </div>
  16. </div>
  17. </div>
  18. </template>
  19. <script setup>
  20. import legendIcon1 from "@/assets/images/common/legend-icon-1.png";
  21. import legendIcon2 from "@/assets/images/common/legend-icon-2.png";
  22. import legendIcon3 from "@/assets/images/common/legend-icon-3.png";
  23. import { ref, onMounted } from "vue";
  24. const props = defineProps({
  25. type: {
  26. type: String,
  27. default: "作物分布",
  28. },
  29. });
  30. const legendObj = {
  31. 物候期分布: [
  32. { label: "抽穗期", color: "#E17C00" },
  33. { label: "拔节期", color: "#985300" },
  34. { label: "孕穗期", color: "#512D00" },
  35. ],
  36. 预警分布: [
  37. { label: "干旱等级Ⅰ级", color: "#BD231E" },
  38. { label: "干旱等级Ⅰ级", color: "#FF6600" },
  39. { label: "干旱等级Ⅰ级", color: "#FFCD00" },
  40. ],
  41. 农场分布: [
  42. { label: "冷链冷库", icon: legendIcon1 },
  43. { label: "加工厂", icon: legendIcon2 },
  44. ],
  45. 农服管理: [{ label: "冷链仓库", icon: legendIcon3 }],
  46. };
  47. const legendArr = ref([]);
  48. const legendArr2 = ref([]);
  49. onMounted(() => {
  50. fetchMapLegend();
  51. fetchLandTypes();
  52. });
  53. const fetchMapLegend = () => {
  54. VE_API.warning.fetchMapLegend().then((res) => {
  55. if (res.code === 0 && res.data && res.data.length > 0) {
  56. legendArr.value = res.data;
  57. }
  58. });
  59. };
  60. const fetchLandTypes = () => {
  61. VE_API.warning.fetchLandTypes().then((res) => {
  62. if (res.code === 0 && res.data && res.data.length > 0) {
  63. legendArr2.value = res.data;
  64. }
  65. });
  66. };
  67. </script>
  68. <style lang="scss" scoped>
  69. .map-legend-container {
  70. display: flex;
  71. gap: 10px;
  72. position: fixed;
  73. bottom: 40px;
  74. right: 430px;
  75. }
  76. .map-legend {
  77. padding: 6px 20px;
  78. display: flex;
  79. align-items: center;
  80. gap: 20px;
  81. background: rgba(0, 0, 0, 0.6);
  82. border-radius: 20px;
  83. z-index: 9;
  84. color: #ffffff;
  85. font-size: 16px;
  86. .legend-item {
  87. display: flex;
  88. align-items: center;
  89. gap: 8px;
  90. .legend-dot {
  91. width: 15px;
  92. height: 15px;
  93. // border-radius: 50%;
  94. background: #f2a038; // 默认颜色,实际由内联样式覆盖
  95. }
  96. .legend-icon {
  97. width: 20px;
  98. height: 20px;
  99. }
  100. }
  101. }
  102. </style>