import { computed, defineComponent, onMounted, ComputedRef, ref, watch } from "vue"; import Picker from "./Picker"; import { useStore } from "@/hook/useStore"; import useGlobalState from "@/store/global"; import useRoadUnitStore from "@/store/roadUnit"; import { Radio, Button, Switch, Select, Menu, message, Modal, Input, Checkbox, Dropdown } from "ant-design-vue"; import style from "@/assets/style/RoadUnit/map.module.less"; import { HpaasEventKey } from "@/modules/hpaas-core/types"; import { Feature, featureCollection } from "@turf/helpers"; import HPaaSDeckGL from "@/modules/hpaas-core/HPaaSDeckGL"; // import "@/utils/logtime"; import { feature, MultiPolygon, Polygon } from "@turf/turf"; import { PolygonFeatureType } from "@/modules/hpaas-core/tools/data/PolygonStore"; import { queryAllUserDefineArea } from "@/http/api_graphql"; export default defineComponent({ setup() { /** * 深圳市区域列表 */ const { areaList, getAreaListInShenZhen } = useStore(useGlobalState); /** * 模式 * 区域名称 * 选中道路名称 * 区域通行车辆、车次、车速分日表 */ const { mode, area: areaName, road: roadName, areaInfoByDate } = useStore(useRoadUnitStore); /** * 区域uid */ const areaUid: ComputedRef = computed(() => { return ( areaList.value.find((area) => { return area.name === areaName.value; })?.uid || "" ); }); /** * Dom挂载之后,渲染地图 */ const hpaasMap = ref(); const segmentDataDone = ref(0); const spinning = ref(true); let map: HPaaSDeckGL; const loadAreaFromServer = async () => { const result: { color: string; geometry: any; id: number; name: string; user_id: string; }[] = await queryAllUserDefineArea(); const list: any[] = []; const features: Feature[] = []; result.forEach((r) => { const _feature = feature(r.geometry, { color: r.color, name: r.name, id: r.id, }); features.push(_feature); }); return featureCollection(features); }; const initMap = async () => { const container = hpaasMap.value; if (container) { if (!map) map = new HPaaSDeckGL(container, { mode: "grey", initPitch: 0, mapType: "mapbox", wmsBaseUrl: "http://10.0.10.174:9999/geoserver/hpaas/wms", wfsBaseUrl: "http://10.0.10.174:9999/geoserver/hpaas/wfs", show100meters: false, showBaseUnit: true, }); // map.fitToArea(areaUid.value); map.events.on(HpaasEventKey.SEGMENT_DATA_LOADED, () => { segmentDataDone.value += 1; }); map.toolsCenter.options.pinBaseUnit = false; const featureCollection = await loadAreaFromServer(); map.polygonDrawLayer?.setData(featureCollection.features as PolygonFeatureType[]); // map.toolsCenter.actions.drawer.begin("polygon", features); } }; watch( () => areaUid.value, async () => { map.fitToArea(areaUid.value); } ); onMounted(() => { getAreaListInShenZhen(); initMap(); }); /** /** * 选中某一条道路,可视化 * 监听选中道路名称-roadName * 监听绘制区域内车次/速度可视化是否准备完成-mapOccOrSpeed(选中道路依赖于此) */ // const checkRoad = () => { // if (roadName.value) { // if (mapOccOrSpeed.value) { // mapOccOrSpeed.value.checkedLayer || mapOccOrSpeed.value.initCheckLines(); // mapOccOrSpeed.value.checkLines(roadName.value); // } // } else { // if (mapOccOrSpeed.value) { // mapOccOrSpeed.value.clearCheck(); // } // } // }; // watch([roadName, mapOccOrSpeed], () => { // checkRoad(); // }); function changeDrawType(type: "circle" | "polygon" | "rect" | "polygonbyroad" | "quickpolygon") { map.toolsCenter.actions.drawer.clearAll(); map.toolsCenter.actions.drawer.begin(type); } function selectPolygon(type: "single" | "multi") { map.polygonDrawLayer && map.toolsCenter.actions.selector.beginSelectPolygon(map.polygonDrawLayer, type); } function selectRoad() { map.toolsCenter.actions.selector.beginSelectRoad(); map.toolsCenter.selector.road?.on("ROAD_PICK", (feature) => { console.log("ROAD_PICK", feature); }); map.toolsCenter.selector.road?.on("SEGMENT_PICK", (feature) => { console.log("SEGMENT_PICK", feature); }); } /** * 选择路片段 */ function selectRoadSegment() { map.toolsCenter.actions.selector.beginSelectSegment(); map.toolsCenter.selector.road?.on("ROAD_PICK", (feature) => { console.log("ROAD_PICK", feature); }); map.toolsCenter.selector.road?.on("SEGMENT_PICK", (feature) => { console.log("SEGMENT_PICK", feature); }); } return () => (
{ return ( { changeDrawType("rect"); }} > 矩形 { changeDrawType("circle"); }} > 圆形 { changeDrawType("polygon"); }} > 多边形:点击 { changeDrawType("quickpolygon"); }} > 多边形:快速 { changeDrawType("polygonbyroad"); }} > 多边形:沿路 ); }} > 创建 { // toggleSelect(); }} overlay={() => { return ( { selectPolygon("single"); }} > 单选:面 { selectPolygon("multi"); }} > 多选: 面 { selectRoad(); }} > 单选: 路 { selectRoadSegment(); }} > 单选:路段 {}} disabled> 圈选(多选) ); }} > 选择
{ if (checked) { map.setDisplayMode("dark"); } else { map.setDisplayMode("grey"); } }} /> 暗色模式
{ if (checked) { map.toolsCenter.options.pinBaseUnit = true; } else { map.toolsCenter.options.pinBaseUnit = false; } }} /> 吸附到路
{ if (checked) { map.toolsCenter.options.pinFeature = true; } else { map.toolsCenter.options.pinFeature = false; } }} /> 吸附到图形
); }, });