mapLegend.vue 2.0 KB

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