import HPaaSMap from "@/modules/hpaas-core/hpaas"; import { Ref, ref } from "vue"; export const useHpaasDrawer = (map: Ref) => { const isDrawing = ref(false); const currentDrawingType = ref(""); /** * 改变绘制类型 */ function changeDrawType(type: "circle" | "polygon" | "rect" | "polygonbyroad" | "quickpolygon") { map.value?.toolsCenter.actions.drawer.begin(type); isDrawing.value = true; currentDrawingType.value = type; } /** * 清除绘制 */ function cancelDraw() { map.value?.toolsCenter.actions.drawer.clearAll(); isDrawing.value = false; } /** * 获取绘制结果 */ function getDrawResult() { return map.value?.toolsCenter.actions.drawer.getComboedFeature(); } // watch( // () => map.value, // () => { // map.value?.events.on(HpaasEventKey.DRAW_CREATED, (feature: Feature) => { // console.log("DRAW_CREATED", feature); // drawedFeature = feature; // }); // map.value?.events.on(HpaasEventKey.DRAW_UPDATED, (feature: Feature) => { // console.log("DRAW_UPDATED", feature); // drawedFeature = feature; // }); // } // ); return { isDrawing, currentDrawingType, changeDrawType, cancelDraw, getDrawResult, }; };