zhangxiao
2024-08-20 e47b788ff5f5c699c682999c95da17eb284ca21d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<template>
    <div style="display: none">
        <div ref="mapTextContainer"></div>
    </div>
</template>
<script lang="ts" setup>
import { cloneDeep } from "lodash-es";
 
// type LabelStyle = {
//     [k in keyof CSSStyleDeclaration]?: any;
// };
const props = withDefaults(
    defineProps<{
        options: AMap.TextOptions;
    }>(),
    {
        options: () => {
            return {
                content: ""
            };
        }
    }
);
const emits = defineEmits<{
    (e: "dbclick"): void;
    (e: "click"): void;
    (e: "mouseover"): void;
    (e: "mouseout"): void;
}>();
 
const map = inject<any>("map");
 
const mapTextContainer = ref<HTMLElement>();
 
watchEffect(() => {
    if (!map.value) return;
    let options = cloneDeep(props.options);
    const text = new AMap.Text(options);
    text.setMap(map.value);
    text.on("dblclick", () => {
        emits("dbclick");
    });
    text.on("click", () => {
        emits("click");
    });
    text.on("mouseover", () => {
        emits("mouseover");
    });
    text.on("mouseout", () => {
        emits("mouseout");
    });
});
</script>
<style lang="scss" scoped></style>