wujingjing
2025-02-25 4f33e1e616e2a59112a6265073124abd7f0e81ed
src/components/chat/chatComponents/summaryCom/components/recordSetTable/map/BasicMap.vue
@@ -34,7 +34,7 @@
            </div>
         </div>
      </div>
      <LayerControl v-if="olMap" :olMap="olMap" class="absolute top-3 left-3 z-10" />
      <!-- <LayerControl v-if="olMap" :olMap="olMap" class="absolute top-3 left-3 z-10" /> -->
      <!-- <PropertyPanel class="absolute top-14 left-10 z-14"></PropertyPanel> -->
      <PanelTool
@@ -42,10 +42,13 @@
         ref="panelToolRef"
         :propertyMap="propertyMap"
         :propertyConfigMap="propertyConfigMap"
         class="absolute top-12 right-2 z-14"
         class="absolute top-0 right-2 z-14 h-full"
         :olMap="olMap"
         :isFullscreen="isFullscreen"
         @toggleFullScreen="toggleFullScreen"
      ></PanelTool>
      <!-- <el-button class="absolute top-3 right-4" @click="changeTheme" type="primary">切换主题</el-button> -->
      <Search class="absolute top-0 left-2 z-14 w-fit" :olMap="olMap" :propertyMap="propertyMap"  :propertyConfigMap="propertyConfigMap"/>
   </div>
</template>
@@ -68,7 +71,9 @@
import equipPic from './img/equip.svg';
import LayerControl from './LayerControl.vue';
import PanelTool from './panelTool/index.vue';
import Search from './Search.vue';
import {
   getMapDrawStyles,
   getMapLayerGroupList,
   getMapLayersByPost,
   getMapThemeList,
@@ -81,29 +86,37 @@
import { MarkerOverlay } from '/@/model/map/overlay/marker';
import { useCompRef } from '/@/utils/types';
import { formatDate } from '/@/utils/formatTime';
import { MapPanelTool } from './types';
const panelToolRef = useCompRef(PanelTool);
const props = withDefaults(
   defineProps<{
      data: any;
      config?: {
         sourceType: GaoDeSourceType;
         markerIsVisible: boolean;
      };
      isFullscreen: boolean;
   }>(),
   {
      config: () => ({
         sourceType: GaoDeSourceType.Vector,
         markerIsVisible: true,
      }),
   }
);
const locationCurrent = () => {
   olMap.value.locationCurrent();
};
const colsArray = computed(() => {
   return props.data.cols ?? [];
});
const emit = defineEmits(['markerClick', 'closeInfoWindow']);
const emit = defineEmits(['markerClick', 'closeInfoWindow', 'toggleFullScreen']);
const toggleFullScreen = () => {
   emit('toggleFullScreen');
};
const containerRef = ref<HTMLDivElement>(null);
const infoWindowRef = ref<HTMLDivElement>(null);
@@ -258,6 +271,7 @@
const handleVectorTileClick = (feature, layer) => {
   panelToolRef.value.featureClick(feature);
   feature && panelToolRef.value.setActivePanel(MapPanelTool.Property);
   // setActiveStyle(feature,layer);
};
const propertyMap = ref({});
@@ -273,9 +287,8 @@
const maxResolution = 1;
const getText = function (feature, resolution) {
   const oname = feature.get('oname');
   let text = `first-${oname[0]}`;
const getText = function (textContent, resolution) {
   let text = `${textContent}`;
   if (resolution > maxResolution) {
      text = '';
   }
@@ -290,10 +303,10 @@
   return text;
};
const createTextStyle = (feature, resolution) => {
const createTextStyle = (textContent, resolution) => {
   return new Style({
      text: new Text({
         text: getText(feature, resolution),
         text: getText(textContent, resolution),
         font: '14px Arial',
         fill: new Fill({ color: '#000' }),
         stroke: new Stroke({ color: '#fff', width: 2 }),
@@ -304,11 +317,11 @@
};
const styleMap: Record<string, Record<string, Style>> = {
   junction: {},
   pipe: {},
   point: {},
   line: {},
   polygon: {},
};
/** @description 已经做的layer,后续全部做好,可以不做判断 */
const unsupportedLayers = ['dma1', 'dma2', 'dma3'];
const layerStyleFunc = function (feature, resolution) {
   const shape = feature.getGeometry().getType();
@@ -316,49 +329,51 @@
   switch (shape) {
      case 'Point':
         const pSize = feature.get('psize');
         if (!pSize) return null;
         const pcolor = feature.get('pcolor');
         const pkey = `${pSize}_${pcolor}`;
         const pstyle = feature.get('pstyle');
         const pointStyle = olMap.value.getPointStyles({
            size: pSize,
            color: pcolor,
            style: pstyle,
         });
         if (!styleMap.junction[pkey]) {
            styleMap.junction[pkey] = new Style({
               image: new Circle({
                  radius: pSize,
                  fill: new Fill({ color: `#${pcolor}` }),
               }),
            });
         }
         // const textStyle = createTextStyle(feature, resolution);
         styles.push(styleMap.junction[pkey]);
         styles.push(pointStyle);
         break;
      case 'LineString':
         const lSize = feature.get('lsize');
         if (!lSize) return null;
         const lColor = feature.get('lcolor');
         const lKey = `${lSize}_${lColor}`;
         if (!styleMap.pipe[lKey]) {
            styleMap.pipe[lKey] = new Style({
               // image: new Circle({
               //    radius: lsize,
               //    fill: new Fill({ color: `#${color}` }),
               // }),
               stroke: new Stroke({
                  color: `#${lColor}`,
                  width: lSize,
               }),
            });
         }
         styles.push(styleMap.pipe[lKey]);
         const lstyle = feature.get('lstyle');
         const pSize1 = feature.get('psize');
         const pcolor1 = feature.get('pcolor');
         const pStyle1 = feature.get('pstyle');
         const lineStyle = olMap.value.getLineStyles({
            lsize: lSize,
            lcolor: lColor,
            lstyle: lstyle,
            psize: pSize1,
            pcolor: pcolor1,
            pstyle: pStyle1,
         });
         styles.push(...lineStyle);
         break;
      case 'Polygon':
         const pColor = feature.get('pcolor');
         const lSize1 = feature.get('lsize');
         const lColor1 = feature.get('lcolor');
         const lstyle1 = feature.get('lstyle');
         const polygonStyle = olMap.value.getPolygonStyles({
            pcolor: pColor,
            lsize: lSize1,
            lcolor: lColor1,
            lstyle: lstyle1,
         });
         styles.push(...polygonStyle);
         break;
      default:
         break;
   }
   const otype = feature.get('otype');
   // switch (otype) {
   //    case 'WDM_JUNCTIONS':
   //       const textStyle = createTextStyle(feature, resolution);
@@ -369,9 +384,13 @@
   // }
   //#region ====================== 添加标注 ======================
   const tString = feature.get('tstring');
   if (tString) {
      const textStyle = createTextStyle(feature, resolution);
      styles.push(textStyle);
   const tStringStyle = olMap.value.getLabelStyles({
      textContent: tString,
      resolution,
   });
   if (tStringStyle) {
      styles.push(tStringStyle);
   }
   //#endregion
@@ -384,6 +403,11 @@
   return groupList;
};
const getDrawStyles = async () => {
   const res = await getMapDrawStyles();
   const styleList = res?.values ?? [];
   olMap.value.setDrawStyles(styleList);
};
const getThemeList = async () => {
   const res = await getMapThemeList();
@@ -406,7 +430,6 @@
         type: 'theme',
         activeTheme: null,
         legends: null,
      };
      mapGroupItem.children.push(data);
      return preVal;
@@ -414,21 +437,22 @@
   olMap.value.setAllThemes(themeTreeData);
};
const initVectorTileLayer = async () => {
   await getDrawStyles();
   const res = await getMapLayersByPost();
   const layers = reverse(res?.layers ?? []);
   if (layers.length === 0) return;
   const layerModels = [];
   for (const item of layers) {
      const styleFunc = unsupportedLayers.includes(item.id) ? undefined : layerStyleFunc;
      const styleFunc = olMap.value.unsupportedLayers.includes(item.id) ? undefined : layerStyleFunc;
      const layer = olMap.value.addCustomLayer(`${MAIN_URL}map/get_vector_tile?x={x}&y={y}&z={z}&layer_id=${item.id}`, styleFunc);
      layer.set('originStyle', styleFunc);
      layerModels.push(layer);
   }
   getGroupList().then((groupList) => {
      olMap.value.setAllLayers(layerModels, layers, groupList);
   });
   if (layers.length === 0) return;
   getThemeList();
   getPropertyList();
   olMap.value.on('featureChange', handleVectorTileClick);
@@ -437,7 +461,6 @@
   olMap.value = new OLMap({
      container: containerRef.value,
      sourceType: props.config?.sourceType,
      markerIsVisible: props.config?.markerIsVisible,
   });
   addMarkerLayer();