|
@@ -5,8 +5,8 @@
|
|
|
<i class="left-decoration" />
|
|
|
<div class="box">
|
|
|
<div v-show="!hideBox" class="box2">
|
|
|
- <div class="box-title">{{ legend.title }}</div>
|
|
|
- <div v-for="(item, index) in legend.data" :key="index" class="box-item">
|
|
|
+ <div class="box-title">{{ legendTitle }}</div>
|
|
|
+ <div v-for="(item, index) in legend" :key="index" class="box-item">
|
|
|
<div class="checked-box" @click="handleClick(item)">
|
|
|
<i :class="!!item.checked ? 'checked' : 'unchecked'" />
|
|
|
<div class="text">{{ item.name }}</div>
|
|
@@ -23,25 +23,19 @@
|
|
|
|
|
|
<script setup lang="ts">
|
|
|
import 'ol/ol.css';
|
|
|
+import mmJson from '@/assets/json/mm.json';
|
|
|
import { olMap } from '@/utils/olMap/olMap';
|
|
|
-interface LegendItem {
|
|
|
- name: string;
|
|
|
- color: string;
|
|
|
- checked: boolean;
|
|
|
-}
|
|
|
-interface Legend {
|
|
|
- show: boolean;
|
|
|
- title: string;
|
|
|
- data: LegendItem[];
|
|
|
-}
|
|
|
+import { deepClone } from '@/utils';
|
|
|
interface Props {
|
|
|
activeMap: string;
|
|
|
points?: [];
|
|
|
distributionData?: [];
|
|
|
- legend?: Legend;
|
|
|
+ legendTitle?: string;
|
|
|
}
|
|
|
const containerScale = inject('containerScale');
|
|
|
-const props = withDefaults(defineProps<Props>(), {});
|
|
|
+const props = withDefaults(defineProps<Props>(), {
|
|
|
+ legendTitle: '风险等级'
|
|
|
+});
|
|
|
const emits = defineEmits(['update:drawing', 'selectGraphics']);
|
|
|
|
|
|
const mapRef = ref(null);
|
|
@@ -80,6 +74,32 @@ watch(
|
|
|
deep: true
|
|
|
}
|
|
|
);
|
|
|
+let legend = ref([]);
|
|
|
+// 更新分布图数据
|
|
|
+const updateMask = () => {
|
|
|
+ if (!map || !map.createMask) return;
|
|
|
+ const data = [];
|
|
|
+ legend.value.forEach((item) => {
|
|
|
+ if (!!item.checked) {
|
|
|
+ data.push(item);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ map.createMask(data);
|
|
|
+};
|
|
|
+watch(
|
|
|
+ () => props.distributionData,
|
|
|
+ () => {
|
|
|
+ const data = deepClone(props.distributionData);
|
|
|
+ data.forEach((item) => {
|
|
|
+ item.checked = true;
|
|
|
+ });
|
|
|
+ legend.value = data;
|
|
|
+ updateMask();
|
|
|
+ },
|
|
|
+ {
|
|
|
+ deep: true
|
|
|
+ }
|
|
|
+);
|
|
|
|
|
|
const init = () => {
|
|
|
const id = props.activeMap === 'imageMap' ? ['YZT1640925052482', 'YZT1695608158269'] : ['YZT1708679726700', 'YZT1695608158269'];
|
|
@@ -93,11 +113,10 @@ const init = () => {
|
|
|
// 加载完成事件
|
|
|
onLoadCompleted: (yMap) => {
|
|
|
yztMap = yMap;
|
|
|
- // initMouseTool(map);
|
|
|
- // map.createVecByJson(mmJson, '茂名市');
|
|
|
+ map.createVecByJson(mmJson, '茂名市');
|
|
|
handleResize();
|
|
|
map.addMarker(props.points);
|
|
|
- map.createMask(props.distributionData);
|
|
|
+ map.createMask(legend.value);
|
|
|
}
|
|
|
});
|
|
|
};
|
|
@@ -109,7 +128,9 @@ const clearMarker = () => {
|
|
|
};
|
|
|
const handleClick = (item) => {
|
|
|
item.checked = !item.checked;
|
|
|
+ updateMask();
|
|
|
};
|
|
|
+
|
|
|
defineExpose({ addMarker, clearMarker });
|
|
|
const handleResize = () => {
|
|
|
let containerScaleData = !!containerScale ? containerScale() : {
|