import HPaaSMap from "@/modules/hpaas-core/hpaas"; import { ref, Ref } from "vue"; export const useHpaasSelector = (map: Ref) => { const isSelecting = ref(false); const selectMode = ref(""); /** * 选择多边形 */ function selectPolygon(type: "single" | "multi") { selectMode.value = "polygon"; isSelecting.value = true; map.value?.polygonDrawLayer && map.value?.toolsCenter.actions.selector.beginSelectPolygon(map.value.polygonDrawLayer, type); } /** * 选择路 */ function selectRoad() { selectMode.value = "road"; map.value?.toolsCenter.actions.selector.beginSelectRoad(); map.value?.toolsCenter.selector.road?.on("ROAD_PICK", (feature) => { console.log("ROAD_PICK", feature); }); map.value?.toolsCenter.selector.road?.on("SEGMENT_PICK", (feature) => { console.log("SEGMENT_PICK", feature); }); } /** * 选择路片段 */ function selectRoadSegment() { selectMode.value = "roadSegment"; map.value?.toolsCenter.actions.selector.beginSelectSegment(); map.value?.toolsCenter.selector.road?.on("ROAD_PICK", (feature) => { console.log("ROAD_PICK", feature); }); map.value?.toolsCenter.selector.road?.on("SEGMENT_PICK", (feature) => { console.log("SEGMENT_PICK", feature); }); } function clearSelect() { map.value?.toolsCenter.actions.selector.clearAll(); isSelecting.value = false; } return { isSelecting, selectMode, selectPolygon, selectRoad, selectRoadSegment, clearSelect, }; };