CaiYuanYiTiHua/src/views/sys/exception/Converge/index.vue

1193 lines
34 KiB
Vue
Raw Normal View History

2024-07-31 10:27:27 +08:00
<template>
2024-11-24 09:20:21 +08:00
<div :id="mapContainerName" class="map-container">
<div class="search-container-box">
2024-11-25 11:10:17 +08:00
<SearchComponent
@toPosition="toPosition"
@handlerFilter="handlerFilter"
:layerSettings="layerSettings"
></SearchComponent>
2024-07-31 10:27:27 +08:00
</div>
2024-11-24 09:20:21 +08:00
<div class="map-type-switch-container">
<div class="switch-button" v-if="mapAngle == '3D'" @click="handlerChangeMapAngle()">
<TableOutlined style="font-size: 20px; position: relative; top: 1px; left: -6px" />
<span>&nbsp;二维地图</span>
</div>
<div class="switch-button" v-else @click="handlerChangeMapAngle()">
<GlobalOutlined style="font-size: 20px; position: relative; top: 1px; left: -6px" />
<span>&nbsp;三维地图</span>
</div>
<div class="home-button" @click="handlerInitialize">
<HomeOutlined />
</div>
</div>
</div>
2024-07-31 10:27:27 +08:00
</template>
<script lang="ts" setup>
2024-11-24 09:20:21 +08:00
import { ref, onMounted, defineExpose, defineEmits, defineProps, watch } from 'vue';
import { generateUUID } from '@/components/MapboxMaps/src/tool';
import { WktToGeojson } from '@/components/MapboxMaps/src/WktGeojsonTransform';
import mapboxgl, { Map, Popup } from 'mapbox-gl';
import { MAPBOX_TOKEN, TINADITU_TOKEN, MAP_VIEWER } from './config.ts';
import heatGeoJson from './data.json';
2024-11-25 17:05:26 +08:00
import { getPolygonCenter, getUserOrgs,getNetworkType } from '@/api/tiankongdi';
2024-11-24 09:20:21 +08:00
import axios from 'axios';
import SearchComponent from './SearchComponent.vue';
import { getAppEnvConfig } from '@/utils/env';
2024-11-27 08:53:40 +08:00
const { VITE_GLOB_API_URL,VITE_GLOB_LAN_API_URL } = getAppEnvConfig();
2024-11-24 09:20:21 +08:00
const VITE_GLOB_API_URL_VAR = ref<String>(VITE_GLOB_API_URL);
2024-11-24 09:38:16 +08:00
import { waiData } from '../LargeScreenMap/linyishi';
2024-11-24 09:20:21 +08:00
const mapContainerName = ref<String>();
mapContainerName.value = 'mapContainer-' + generateUUID();
2024-11-25 11:10:17 +08:00
const { VITE_GLOB_YINGXIANG_SERVER, VITE_GLOB_YAOGANYINGXIANG_SERVER } = getAppEnvConfig();
2024-11-25 17:05:26 +08:00
const networkType = ref("WAN");
2024-11-24 09:38:16 +08:00
//
import { TableOutlined, GlobalOutlined, HomeOutlined } from '@ant-design/icons-vue';
2024-11-25 11:10:17 +08:00
// 图层控制 历史影像
import { message, Modal } from 'ant-design-vue';
import U from 'mapbox-gl-utils';
import { MP } from './src/MP';
import { GeojsonToWkt } from './src/WktGeojsonTransform';
2024-07-31 10:27:27 +08:00
2024-11-24 09:38:16 +08:00
const emits = defineEmits([
'onload',
'handlerGetDetails',
'showMonitor',
'handlerQueryIntersectTif',
]);
2024-11-09 16:56:31 +08:00
2024-11-24 09:54:34 +08:00
let isZoomVisible: any = false;
2024-11-24 09:20:21 +08:00
let map: Map;
2024-11-24 09:38:16 +08:00
let mp: any = null;
2024-11-24 09:20:21 +08:00
const props = defineProps({
layer: Object,
2024-11-25 11:10:17 +08:00
defaultColor: String,
2024-11-24 09:20:21 +08:00
});
const layerSettings = ref<any>({});
2024-11-25 11:10:17 +08:00
const layerDefaultColor = ref<String>();
2024-11-24 09:20:21 +08:00
watch(
() => props.layer,
(val) => {
layerSettings.value = val;
2024-11-25 11:10:17 +08:00
layerDefaultColor.value = props.defaultColor;
2024-11-24 09:20:21 +08:00
},
);
// init map
const initMap = () => {
2024-07-31 10:27:27 +08:00
return new mapboxgl.Map({
2024-11-24 09:20:21 +08:00
container: mapContainerName.value,
language: 'zh-cmn',
projection: 'globe', // wgs84参考系
style: {
glyphs: 'mapbox://fonts/mapbox/{fontstack}/{range}.pbf',
version: 8,
sources: {
'raster-tiles': {
type: 'raster',
tiles: [
`http://t0.tianditu.gov.cn/DataServer?T=img_w&x={x}&y={y}&l={z}&tk=${TINADITU_TOKEN}`,
2024-07-31 10:27:27 +08:00
],
2024-11-24 09:20:21 +08:00
tileSize: 256,
2024-11-27 08:53:40 +08:00
minzoom: 1,
maxzoom: 17,
2024-11-24 09:20:21 +08:00
},
'raster-tiles-font': {
type: 'raster',
tiles: [
`https://t0.tianditu.gov.cn/DataServer?T=vec_w&x={x}&y={y}&l={z}&tk=${TINADITU_TOKEN}`,
2024-07-31 10:27:27 +08:00
],
2024-11-24 09:20:21 +08:00
tileSize: 256,
},
2024-11-25 09:22:00 +08:00
yaogan: {
type: 'raster',
2024-11-25 11:10:17 +08:00
tiles: [VITE_GLOB_YAOGANYINGXIANG_SERVER],
2024-11-25 09:22:00 +08:00
tileSize: 256,
2024-11-25 11:10:17 +08:00
minzoom: 16,
maxzoom: 24,
2024-11-25 09:22:00 +08:00
},
yingxiang: {
type: 'raster',
2024-11-25 11:10:17 +08:00
tiles: [VITE_GLOB_YINGXIANG_SERVER],
2024-11-25 09:22:00 +08:00
tileSize: 256,
2024-11-25 11:10:17 +08:00
minzoom: 16,
maxzoom: 24,
},
2024-07-31 10:27:27 +08:00
},
2024-11-24 09:20:21 +08:00
layers: [
{
id: 'tdt-vec-tiles',
type: 'raster',
source: 'raster-tiles-font',
maxZoom: 32,
},
{
id: 'tdt-img-tiles',
type: 'raster',
source: 'raster-tiles',
maxZoom: 32,
},
2024-11-25 09:22:00 +08:00
{
id: 'yaogan',
type: 'raster',
source: 'yaogan',
layout: {
2024-11-25 17:05:26 +08:00
visibility: networkType.value == 'LAN' ? 'visible' : 'none',
2024-11-25 09:22:00 +08:00
},
2024-11-25 11:10:17 +08:00
minzoom: 9,
maxzoom: 15,
2024-11-25 09:22:00 +08:00
},
{
id: 'yingxiang',
type: 'raster',
source: 'yingxiang',
layout: {
2024-11-25 17:05:26 +08:00
visibility: networkType.value == 'LAN' ? 'visible' : 'none',
2024-11-25 09:22:00 +08:00
},
2024-11-25 11:10:17 +08:00
minzoom: 13,
maxzoom: 24,
},
2024-11-24 09:20:21 +08:00
// {
// id: 'tdt-wms-tiles',
// type: 'raster',
// source: 'raster-tiles-geo',
// },
],
},
maxZoom: 22,
minZoom: 8,
zoom: 8,
pitch: 0,
center: [118.30207505530701, 35.30123435040745],
2024-07-31 10:27:27 +08:00
});
2024-11-24 09:20:21 +08:00
};
2024-08-01 17:25:52 +08:00
2024-11-26 09:49:19 +08:00
// load map info
async function loadMapInfo(){
try{
2024-11-27 08:53:40 +08:00
await axios.get(VITE_GLOB_LAN_API_URL+"/api/DroneCloudQuery/IsPublic").then(res=>{
if(res.data.result){
networkType.value = "WAN";
}else{
networkType.value = "LAN";
}
})
2024-11-26 09:49:19 +08:00
}catch(e){
networkType.value = "WAN";
}finally{
map = initMap();
2024-11-26 16:47:51 +08:00
2024-11-26 09:49:19 +08:00
map.on('load', () => {
//挂载mapbox-gl-utils
U.init(map);
mp = new MP(map);
// 添加地形数据
map.addSource('mapbox-dem', {
type: 'raster-dem',
tiles: [VITE_GLOB_API_URL_VAR.value + '/mapbox_terrain/{z}/{x}/{y}.png'],
tileSize: 256,
maxzoom: 13,
minzoom: 10,
});
2024-11-26 16:47:51 +08:00
map.setTerrain({ source: 'mapbox-dem', exaggeration: 1 });
2024-11-26 09:49:19 +08:00
// 设置2D地图
map.easeTo({ pitch: 0, bearing: 0, duration: 1000 });
map.dragRotate.disable(); // 禁用拖动旋转
map.pitchWithRotate = false; // 禁用旋转时俯仰变化
mapAngle.value = '2D';
handlerCheckUserOrgs();
// handlerLoadMaskLayer();
getMaskData();
handlerDealStreet();
handlerDealCountry();
// 视频监控
addMonitorLayer();
});
}
}
2024-11-24 09:20:21 +08:00
// 获取图斑面数据
const polygonVisibility = ref<String>('none');
2024-11-24 09:20:21 +08:00
const isRootLevel = ref<Boolean>(false);
async function handlerCheckUserOrgs() {
let orgs = await getUserOrgs({});
let isLevel = orgs.find((item, index) => {
return item.name == '临沂市' || item.parentId == 0 || item.parentName == '根节点';
2024-07-31 10:27:27 +08:00
});
2024-11-24 09:20:21 +08:00
if (isLevel) {
isRootLevel.value = true;
handlerLoadPolygon('', '', '', '1');
} else {
isRootLevel.value = false;
handlerLoadPolygon();
2024-08-01 17:25:52 +08:00
}
2024-11-24 09:20:21 +08:00
}
2024-08-01 17:25:52 +08:00
2024-11-24 09:20:21 +08:00
function handlerLoadPolygon(code = '', filter = '', type = '', level = '') {
2024-07-31 10:27:27 +08:00
let sql_filter;
let map_filter;
let type_filter;
2024-11-24 09:20:21 +08:00
let table_filter = layerSettings.value.tablename;
let field_filter = '&field="gid","tubantype","Id",';
2024-11-24 09:20:21 +08:00
let color_filter: any = [];
if (code) {
sql_filter = '&filter="countyid"=\'' + code + "'";
} else {
sql_filter = '';
2024-07-31 10:27:27 +08:00
}
2024-11-25 09:22:00 +08:00
if (filter && filter != '全部') {
2024-11-24 13:22:16 +08:00
map_filter = ['all', ['==', ['get', 'tubantype'], filter]];
2024-11-25 09:22:00 +08:00
} else {
map_filter = ['!=', ['get', 'gid'], 0];
2024-07-31 10:27:27 +08:00
}
2024-11-24 09:20:21 +08:00
let legend = layerSettings.value.legend[0];
color_filter.push('case');
for (const key in legend) {
color_filter.push(['all', ['==', ['get', 'tubantype'], key]]);
color_filter.push(legend[key].colour);
}
2024-11-25 11:10:17 +08:00
color_filter.push(layerDefaultColor.value);
2024-11-24 09:20:21 +08:00
switch (type) {
case '农用地':
type_filter = ['==', ['get', 'typename'], '农用地'];
break;
case '建设用地':
type_filter = ['==', ['get', 'typename'], '建设用地'];
break;
case '推堆土':
type_filter = ['==', ['get', 'typename'], '推堆土'];
break;
}
if (filter && type) {
map_filter.push(type_filter);
} else if (!filter && type) {
map_filter = ['all', ['!=', ['get', 'gid'], 0], type_filter];
2024-07-31 10:27:27 +08:00
}
2024-08-01 17:25:52 +08:00
2024-11-24 09:20:21 +08:00
if (map.getSource('historyLayerLine')) {
polygonVisibility.value = map.getLayoutProperty('historyLayerLine', 'visibility');
map.removeLayer('historyLayerLine');
map.removeLayer('historyLayerFill');
map.removeSource('historyLayerLine');
map.removeSource('historyLayerFill');
}
2024-08-01 17:25:52 +08:00
2024-11-24 09:20:21 +08:00
if (level) {
} else {
sql_filter =
'&filter=streetid in ( select CAST("OrgId" AS VARCHAR) from sys_userorg where "UserId" = ' +
localStorage.getItem('userid') +
') or countyid in ( select CAST("OrgId" AS VARCHAR) from sys_userorg where "UserId" = ' +
localStorage.getItem('userid') +
')';
2024-08-01 17:25:52 +08:00
}
2024-11-24 09:20:21 +08:00
2024-07-31 10:27:27 +08:00
map.addLayer({
2024-11-24 09:20:21 +08:00
id: 'historyLayerLine',
type: 'line',
source: {
type: 'vector',
tiles: [
VITE_GLOB_API_URL_VAR.value +
'/api/DroneCaseInfoSingle/QueryVectorTileByTable?z={z}&x={x}&y={y}&table=' +
table_filter +
sql_filter +
field_filter,
],
minzoom: 1,
maxzoom: 20,
cluster: true, // 启用聚合
clusterMaxZoom: 0, // 最大聚合缩放级别
clusterRadius: 0, // 聚合半径
},
'source-layer': table_filter,
layout: {
'line-join': 'round',
'line-cap': 'round',
visibility: polygonVisibility.value,
},
filter: map_filter,
paint: {
'line-color': color_filter,
'line-width': 5,
},
});
map.addLayer({
id: 'historyLayerFill',
type: 'fill',
source: {
type: 'vector',
tiles: [
VITE_GLOB_API_URL_VAR.value +
'/api/DroneCaseInfoSingle/QueryVectorTileByTable?z={z}&x={x}&y={y}&table=' +
table_filter +
sql_filter +
field_filter,
],
minzoom: 1,
maxzoom: 20,
cluster: false,
},
'source-layer': table_filter,
filter: map_filter,
layout: {
visibility: polygonVisibility.value,
},
paint: {
'fill-color': color_filter,
'fill-opacity': 0.5,
},
});
emits('onload');
2024-11-25 09:22:00 +08:00
2024-11-24 09:20:21 +08:00
map.on('click', 'historyLayerFill', (e) => {
console.log('handlerGetDetails', e.features[0].properties);
emits('handlerGetDetails', e.features[0].properties);
});
}
// 获取和处理图斑点数据
const currentCode = ref('');
async function handlerDealPoint(code = '') {
2024-07-31 10:27:27 +08:00
let sql_filter;
2024-11-24 09:20:21 +08:00
if (code) {
sql_filter = '"countyid"=\'' + code + "'";
} else {
sql_filter = '';
2024-07-31 10:27:27 +08:00
}
2024-11-24 09:20:21 +08:00
let points = await getPolygonCenter({ tablename: 'view_drone_shp_data', filter: sql_filter });
2024-07-31 10:27:27 +08:00
let heatdata = {
2024-11-24 09:20:21 +08:00
type: 'FeatureCollection',
features: [],
};
points?.forEach((item, index) => {
let geometry = WktToGeojson(item['centroid_point']);
let feature = {
geometry: geometry,
properties: {
mag: 1,
},
};
heatdata.features.push(feature);
});
2024-07-31 10:27:27 +08:00
handlerLoadHeatLayer(heatdata);
2024-11-24 09:20:21 +08:00
if (map.getLayer('clusters')) {
map.moveLayer('clusters', 'heatLayer');
map.moveLayer('cluster-count', 'heatLayer');
map.moveLayer('unclustered-point', 'heatLayer');
2024-07-31 10:27:27 +08:00
}
2024-11-24 09:20:21 +08:00
}
2024-07-31 10:27:27 +08:00
2024-11-24 09:20:21 +08:00
function toPosition(item) {
handlerLocation(item, 17.2);
2024-08-05 08:25:10 +08:00
handlerLoadSearchResult(item);
2024-11-24 09:20:21 +08:00
}
2024-08-05 08:25:10 +08:00
2024-11-24 09:20:21 +08:00
function handlerFilter(item) {
2024-08-05 08:25:10 +08:00
// handlerLoadPolygon("",item);
2024-11-24 09:20:21 +08:00
if (isRootLevel.value) {
handlerLoadPolygon('', item, '', '1');
} else {
handlerLoadPolygon('', item, '', '');
2024-08-05 08:25:10 +08:00
}
2024-11-24 09:20:21 +08:00
}
function handlerLoadSearchResult(item) {
2024-08-05 08:25:10 +08:00
let geojson = {
2024-11-24 09:20:21 +08:00
type: 'FeatureCollection',
features: [
2024-08-05 08:25:10 +08:00
{
2024-11-24 09:20:21 +08:00
type: 'Feature',
geometry: {
type: 'Point',
2024-08-05 08:25:10 +08:00
coordinates: item.location,
2024-11-24 09:20:21 +08:00
},
properties: {
2024-08-05 08:25:10 +08:00
name: item.id,
2024-11-24 09:20:21 +08:00
},
2024-08-05 08:25:10 +08:00
},
2024-11-24 09:20:21 +08:00
],
2024-08-05 08:25:10 +08:00
};
2024-08-08 10:26:37 +08:00
// if (map.getSource("searchSource")) {
// map.getSource("searchSource").setData(geojson);
// } else {
// map.addSource("searchSource", {
// type: "geojson",
// data: geojson,
// });
// }
2024-08-05 08:25:10 +08:00
2024-08-08 10:26:37 +08:00
// if (map.hasImage("searchIcon")) {
// } else {
// map.loadImage(
// "/public/statistical/search-icon.png",
// function (error, image) {
// if (error) throw error;
// map.addImage("searchIcon", image);
// }
// );
// }
2024-08-05 08:25:10 +08:00
2024-08-08 10:26:37 +08:00
// if (map.getLayer("searchLayer")) {
// } else {
// map.addLayer({
// id: "searchLayer",
// type: "symbol",
// source: "searchSource",
// layout: {
// "icon-image": "searchIcon",
// "icon-size": 1.2,
// "text-field": "{name}",
// "text-offset": [0, 2],
// "text-anchor": "top",
// "text-size": 12,
// },
// paint: {
// "text-color": "#fff",
// },
// });
// }
2024-11-24 09:20:21 +08:00
}
// 加载热力图图斑数据
function handlerLoadHeatLayer(heatdata) {
if (map.getSource('heatSource')) {
map.getSource('heatSource').setData(heatdata);
} else {
map.addSource('heatSource', {
type: 'geojson',
data: heatdata,
});
map.addLayer({
id: 'heatLayer',
type: 'heatmap',
source: 'heatSource',
maxzoom: 13,
minzoom: 7,
layout: {
visibility: 'none',
},
paint: {
'heatmap-weight': ['interpolate', ['linear'], ['get', 'mag'], 0, 1, 7, 0],
'heatmap-intensity': ['interpolate', ['linear'], ['zoom'], 0, 1, 9, 3],
'heatmap-color': [
'interpolate',
['linear'],
['heatmap-density'],
0,
'rgba(33,102,172,0)',
0.2,
'rgba(103,169,207,0.8)',
0.4,
'rgba(209,229,240,0.8)',
0.6,
'rgba(253,219,199,0.8)',
0.8,
'rgba(239,138,98,0.8)',
1,
'rgba(178,24,43,0.8)',
],
'heatmap-radius': ['interpolate', ['linear'], ['zoom'], 4, 7, 11, 20],
'heatmap-opacity': ['interpolate', ['linear'], ['zoom'], 7, 0, 8, 1],
},
});
2024-08-05 08:25:10 +08:00
}
2024-07-31 10:27:27 +08:00
2024-11-24 09:20:21 +08:00
if (map.getLayer('heatLayer')) {
map.moveLayer('heatLayer', 'historyLayerLine');
map.moveLayer('heatLayer', 'historyLayerFill');
if (map.getLayer('clusters')) {
map.moveLayer('clusters', 'heatLayer');
map.moveLayer('cluster-count', 'heatLayer');
map.moveLayer('unclustered-point', 'heatLayer');
}
2024-07-31 10:27:27 +08:00
}
2024-11-24 09:20:21 +08:00
}
2024-07-31 10:27:27 +08:00
2024-11-24 09:20:21 +08:00
// 地图定位
function handlerLocation(lngLat, zoom) {
2024-07-31 10:27:27 +08:00
map.flyTo({
2024-11-24 09:20:21 +08:00
center: lngLat,
zoom: zoom,
bearing: 0,
speed: 1, // 飞行速度
curve: 2, // 飞行曲线
essential: true,
easing(t) {
// 飞行动画函数
return t;
},
2024-07-31 10:27:27 +08:00
});
2024-11-24 09:20:21 +08:00
}
2024-07-31 10:27:27 +08:00
2024-11-24 09:20:21 +08:00
// 获取县区边界数据
const handlerDealCountry = (countyName: String = '临沂市'): void => {
2024-07-31 10:27:27 +08:00
let center = {};
let zoom;
2024-11-24 09:20:21 +08:00
let filterName = '';
if (countyName == '临沂市') {
center = { lng: 118.72504868812163, lat: 35.180072027132915 };
zoom = 7.848587811931849;
handlerLocation([center['lng'], center['lat']], zoom);
} else if (countyName) {
center = MAP_VIEWER[countyName].center;
zoom = MAP_VIEWER[countyName].zoom;
handlerLocation([center['lng'], center['lat']], zoom);
filterName = countyName;
}
2024-07-31 10:27:27 +08:00
axios({
2024-11-24 09:20:21 +08:00
method: 'get',
// url:`http://175.27.168.120:8080/geoserver/linyishi/ows?service=WFS&version=1.0.0&request=GetFeature&typeName=linyishi%3Axianjie&maxFeatures=50&outputFormat=application%2Fjson&cql_filter=xzqmc%20like%20%27%25${filterName}%25%27`,
url: `http://120.222.154.7:8090/geoserver/linyishi/ows?service=WFS&version=1.0.0&request=GetFeature&typeName=linyishi%3Axianjie&maxFeatures=50&outputFormat=application%2Fjson`,
}).then((res) => {
handlerLoadPanelLayer(res.data);
handlerLoadCountyLayer(res.data);
});
};
/**
*
* 县区边界countyLayer
* 县区面板图层countyPanelLayer
* 乡镇边界streetLayer
* 乡镇名称图层streetLabelLayer
* 遮罩图层mb-tag
* 图斑线historyLayerLine
* 图斑面historyLayerFill
*
* */
// 渲染县区边界数据
const handlerLoadCountyLayer = (geojson) => {
2024-07-31 10:27:27 +08:00
// 绘制线
2024-11-24 09:20:21 +08:00
if (map.getSource('countySource')) {
map.getSource('countySource').setData(geojson);
} else {
map.addSource('countySource', {
type: 'geojson',
data: geojson,
});
map.addLayer({
id: 'countyLayer',
type: 'line',
source: 'countySource',
paint: {
'line-color': '#6f7ff4', // 设置线的颜色
'line-width': 3, // 设置线的宽度
},
});
if (map.getLayer('countyPanelLayer')) {
map.moveLayer('countyLayer', 'countyPanelLayer');
}
}
2024-11-24 09:20:21 +08:00
};
2024-11-24 09:20:21 +08:00
// 渲染县界白板图层
const handlerLoadPanelLayer = (geojson) => {
if (map.getSource('countyPanelLayer')) {
map.getSource('countyPanelSource').setData(geojson);
} else {
map.addSource('countyPanelSource', {
type: 'geojson',
data: geojson,
});
map.addLayer({
id: 'countyPanelLayer',
type: 'fill',
source: 'countyPanelSource',
layout: {
visibility: 'none',
},
paint: {
'fill-color': [
'case',
['==', ['get', 'xzqdm_1'], '371302'],
'#49B0F9',
['==', ['get', 'xzqdm_1'], '371311'],
'#3EABFA',
['==', ['get', 'xzqdm_1'], '371312'],
'#27A2FB',
['==', ['get', 'xzqdm_1'], '3713122'],
'#34E6B1',
['==', ['get', 'xzqdm_1'], '3713001'],
'#1099FB',
['==', ['get', 'xzqdm_1'], '3713271'],
'#0695FB',
['==', ['get', 'xzqdm_1'], '371321'],
'#058DEE',
['==', ['get', 'xzqdm_1'], '371322'],
'#09C78E',
['==', ['get', 'xzqdm_1'], '371323'],
'#047DD4',
['==', ['get', 'xzqdm_1'], '371324'],
'#94D515',
['==', ['get', 'xzqdm_1'], '371325'],
'#0568B0',
['==', ['get', 'xzqdm_1'], '371326'],
'#3EABFA',
['==', ['get', 'xzqdm_1'], '371327'],
'#49B0F9',
['==', ['get', 'xzqdm_1'], '371328'],
'#27A2FB',
['==', ['get', 'xzqdm_1'], '371329'],
'#94D515',
'#1099FB',
],
'fill-opacity': 0.9,
},
});
2024-11-24 09:20:21 +08:00
// if(map.getLayer("countyPanelLayer")){
// map.moveLayer("countyPanelLayer","countyLayer");
// map.moveLayer("countyPanelLayer","historyLayerLine");
// map.moveLayer("countyPanelLayer","historyLayerFill");
// }
}
2024-11-24 09:20:21 +08:00
};
2024-08-19 17:26:11 +08:00
2024-11-24 09:20:21 +08:00
function getMaskData() {
2024-08-19 17:26:11 +08:00
axios({
2024-11-24 09:20:21 +08:00
method: 'get',
url: `http://120.222.154.7:8090/geoserver/linyishi/ows?service=WFS&version=1.0.0&request=GetFeature&typeName=linyishi%3Ashijie&maxFeatures=50&outputFormat=application%2Fjson`,
}).then((res) => {
let geojson = { DATA: res.data.features[0].geometry.coordinates[0][0] };
2024-08-19 17:26:11 +08:00
2024-11-24 09:20:21 +08:00
handlerLoadMaskLayer(geojson);
});
}
2024-08-19 17:26:11 +08:00
2024-11-24 09:20:21 +08:00
// 加载地图遮罩
function handlerLoadMaskLayer(geojson) {
2024-08-19 10:51:59 +08:00
map.addLayer({
2024-11-24 09:20:21 +08:00
//蒙版图层 //通过边界数据反选 达到挖洞效果
id: 'mb-tag',
type: 'fill',
source: {
2024-08-19 10:51:59 +08:00
type: 'geojson',
data: {
2024-11-24 09:20:21 +08:00
type: 'Feature',
geometry: {
2024-08-19 10:51:59 +08:00
type: 'Polygon',
coordinates: [
2024-11-24 09:20:21 +08:00
[
2024-08-19 10:51:59 +08:00
// 多边形外围 需要进行遮罩的点 这里是给世界地图加遮罩 所以是世界的四个端点
[-180, 90],
[180, 90],
[180, -90],
[-180, -90],
2024-11-24 09:20:21 +08:00
],
geojson.DATA,
2024-08-19 10:51:59 +08:00
],
2024-11-24 09:20:21 +08:00
},
2024-08-19 10:51:59 +08:00
},
2024-11-24 09:20:21 +08:00
},
paint: {
2024-08-19 10:51:59 +08:00
'fill-color': '#ffffff',
'fill-opacity': 1 /* 透明度 */,
2024-11-24 09:20:21 +08:00
},
layout: {
2024-08-19 10:51:59 +08:00
visibility: 'visible',
2024-11-24 09:20:21 +08:00
},
2024-08-19 10:51:59 +08:00
});
2024-11-24 09:20:21 +08:00
}
2024-08-19 10:51:59 +08:00
2024-11-24 09:20:21 +08:00
// 获取乡镇数据
const handlerDealStreet = (countyName: String = '临沂市'): void => {
2024-08-19 10:51:59 +08:00
axios({
2024-11-24 09:20:21 +08:00
method: 'get',
url: `http://175.27.168.120:8080/geoserver/linyishi/ows?service=WFS&version=1.0.0&request=GetFeature&typeName=linyishi%3Azhenjie&maxFeatures=10000&outputFormat=application%2Fjson`,
}).then((res) => {
handlerLoadStreetLayer(res.data);
});
};
// 渲染乡镇边界数据
const handlerLoadStreetLayer = (geojson) => {
2024-08-19 10:51:59 +08:00
// 绘制线
2024-11-24 09:20:21 +08:00
if (map.getSource('streetSource')) {
map.getSource('streetSource').setData(geojson);
} else {
map.addSource('streetSource', {
type: 'geojson',
data: geojson,
minzoom: 10,
maxzoom: 24,
});
map.addLayer({
id: 'streetLayer',
type: 'line',
source: 'streetSource',
paint: {
'line-color': '#42befb', // 设置线的颜色
'line-width': 2, // 设置线的宽度
},
minzoom: 10,
maxzoom: 24,
});
2024-08-19 10:51:59 +08:00
2024-11-24 09:20:21 +08:00
map.addLayer({
id: 'streetLabelLayer',
type: 'symbol',
source: 'streetSource',
layout: {
'text-field': ['get', 'xzqmc'],
'text-font': ['Open Sans Bold', 'Arial Unicode MS Bold'],
'text-size': 12,
'text-anchor': 'center',
},
paint: {
'text-color': '#041B36',
'text-halo-color': '#fff',
'text-halo-width': 2,
},
});
}
};
2024-08-19 10:51:59 +08:00
2024-11-24 09:20:21 +08:00
let VillageGeojson = {};
const handlerLoadVillageLayer = () => {
2024-08-19 10:51:59 +08:00
// 绘制线
2024-11-24 09:20:21 +08:00
if (map.getSource('villageSource')) {
map.getSource('villageSource').setData(VillageGeojson);
} else {
map.addSource('villageSource', {
type: 'geojson',
data: VillageGeojson,
minzoom: 12,
maxzoom: 24,
});
map.addLayer({
id: 'villageLayer',
type: 'line',
source: 'villageSource',
paint: {
'line-color': '#42befb', // 设置线的颜色
'line-width': 2, // 设置线的宽度
},
minzoom: 12,
maxzoom: 24,
});
2024-07-31 10:27:27 +08:00
2024-11-24 09:20:21 +08:00
map.addLayer({
id: 'villageLabelLayer',
type: 'symbol',
source: 'villageSource',
layout: {
'text-field': ['get', 'zldwmc'],
'text-font': ['Open Sans Bold', 'Arial Unicode MS Bold'],
'text-size': 12,
'text-anchor': 'center',
},
paint: {
'text-color': '#041B36',
'text-halo-color': '#fff',
'text-halo-width': 2,
},
});
}
};
// 控制图层显示隐层
/**
* 热力图heatLayer
*
* 图斑线historyLayerLine
*
* 图斑面historyLayerFill
*
* 行政区划countyLayer
*
*
*
* */
function handlerChangeLayerVisible(layerName, checked) {
2024-07-31 10:27:27 +08:00
if (checked) {
2024-11-24 09:20:21 +08:00
map.setLayoutProperty(layerName, 'visibility', 'visible');
2024-07-31 10:27:27 +08:00
} else {
2024-11-24 09:20:21 +08:00
map.setLayoutProperty(layerName, 'visibility', 'none');
2024-07-31 10:27:27 +08:00
}
2024-11-24 09:20:21 +08:00
if (layerName == 'countyPanelLayer') {
if (map.getLayer('countyPanelLayer')) {
map.moveLayer('countyPanelLayer', 'streetLayer');
map.moveLayer('countyPanelLayer', 'streetLabelLayer');
map.moveLayer('countyPanelLayer', 'countyLayer');
map.moveLayer('countyPanelLayer', 'historyLayerFill');
map.moveLayer('countyPanelLayer', 'historyLayerLine');
}
}
2024-11-24 09:20:21 +08:00
}
2024-07-31 10:27:27 +08:00
2024-11-24 09:20:21 +08:00
// 切换县区
function handlerChangeCounty(county, type = '') {
handlerLoadPolygon(county.code, type);
2024-07-31 10:27:27 +08:00
handlerDealPoint(county.code);
handlerDealCountry(county.name);
2024-11-24 09:20:21 +08:00
}
2024-07-31 10:27:27 +08:00
2024-11-24 09:20:21 +08:00
const mapAngle = ref<String>('2D');
const handlerChangeMapAngle = () => {
if (map) {
const currentPitch = map.getPitch();
if (currentPitch === 0) {
map.easeTo({ pitch: 60, bearing: 0, duration: 1000 });
map.dragRotate.enable(); // 启用拖动旋转
map.pitchWithRotate = true; // 启用旋转时俯仰变化
mapAngle.value = '3D';
} else {
map.easeTo({ pitch: 0, bearing: 0, duration: 1000 });
map.dragRotate.disable(); // 禁用拖动旋转
map.pitchWithRotate = false; // 禁用旋转时俯仰变化
mapAngle.value = '2D';
}
2024-11-09 16:56:31 +08:00
}
2024-11-24 09:20:21 +08:00
};
// 回到初始视角
const handlerInitialize = () => {
map.flyTo({
2024-11-24 09:20:21 +08:00
center: [118.30207505530701, 35.30123435040745], // 设置中心点坐标
zoom: 8, // 设置缩放等级
2024-11-25 11:10:17 +08:00
pitch: 0,
bearing: 0,
duration: 1000,
});
2024-11-24 09:20:21 +08:00
};
2024-11-24 09:20:21 +08:00
onMounted(() => {
2024-07-31 10:27:27 +08:00
mapboxgl.accessToken = MAPBOX_TOKEN;
2024-11-23 16:37:08 +08:00
2024-11-26 09:49:19 +08:00
// 获取网络环境后加载地图
loadMapInfo();
2024-11-25 17:05:26 +08:00
2024-11-26 09:49:19 +08:00
})
2024-11-09 16:56:31 +08:00
2024-11-26 09:49:19 +08:00
2024-11-25 17:05:26 +08:00
2024-11-24 09:20:21 +08:00
// 抛出函数
defineExpose({
handlerChangeCounty, // 切换县区
2024-07-31 10:27:27 +08:00
handlerChangeLayerVisible, // 控制图层显示隐藏
handlerLoadPolygon,
2024-11-24 09:38:16 +08:00
handlerDrawPolygon, // 绘制范围
handlerDeletePolygon, // 取消绘制
2024-11-23 16:16:58 +08:00
handlerChangeTifLayer, // 图层切换
2024-11-24 09:20:21 +08:00
});
2024-11-23 16:16:58 +08:00
2024-11-24 09:38:16 +08:00
/* 图层控制 视频监控*/
2024-11-23 16:16:58 +08:00
2024-11-24 09:38:16 +08:00
import MonitoringData from './MonitoringData.json';
2024-11-23 16:16:58 +08:00
2024-11-24 09:38:16 +08:00
function addMonitorLayer() {
2024-11-23 16:16:58 +08:00
// 加载监控图标
map.loadImage('/monitor/monitor.png', function (error, image) {
2024-11-24 09:38:16 +08:00
if (error) throw error;
if (!map.hasImage('monitorIcon')) {
2024-11-23 16:16:58 +08:00
map.addImage('monitorIcon', image);
2024-11-24 09:38:16 +08:00
}
2024-11-23 16:16:58 +08:00
});
// 加载监控数据源
map.addSource('JianKongSource', {
2024-11-24 09:38:16 +08:00
type: 'geojson',
data: MonitoringData,
2024-11-23 16:16:58 +08:00
});
// 加载监控图层
map.addLayer({
2024-11-24 09:38:16 +08:00
id: 'JianKong',
type: 'symbol',
source: 'JianKongSource',
layout: {
2024-11-23 16:16:58 +08:00
'icon-image': 'monitorIcon',
'icon-size': 0.8,
'text-field': ['get', 'name'],
'text-size': 12,
'text-font': ['Open Sans Semibold', 'Arial Unicode MS Bold'],
'text-offset': [0, 1.6],
'text-anchor': 'top',
2024-11-25 09:22:00 +08:00
'text-allow-overlap': true,
2024-11-23 16:16:58 +08:00
visibility: 'none',
2024-11-25 09:22:00 +08:00
'icon-allow-overlap': true,
2024-11-24 09:38:16 +08:00
},
paint: {
2024-11-23 16:16:58 +08:00
'text-color': '#041B36',
'text-halo-color': '#fff',
'text-halo-width': 2,
2024-11-24 09:38:16 +08:00
},
2024-11-25 09:22:00 +08:00
minzoom: 0, // 最小缩放级别
maxzoom: 22, // 最大缩放级别
2024-11-23 16:16:58 +08:00
});
map.on('click', 'JianKong', (e) => {
2024-11-24 09:38:16 +08:00
// 显示弹窗
emits('showMonitor', e.features[0].properties);
2024-11-23 16:16:58 +08:00
});
2024-11-24 09:38:16 +08:00
}
2024-11-23 16:16:58 +08:00
2024-11-24 09:38:16 +08:00
function handlerDeletePolygon() {
mp.deleteDraw();
}
function handlerDrawPolygon() {
2024-11-25 09:22:00 +08:00
// 先移除查询的影像图层
handlerDeleteHistoryLayer();
2024-11-24 09:38:16 +08:00
mp.draw('Polygon');
mp.on('Polygon', function (e) {
Modal.confirm({
title: '是否查询历史影像?',
onCancel() {
// mp.deleteDraw();
},
async onOk() {
2024-11-23 16:16:58 +08:00
let geojson = {
2024-11-24 09:38:16 +08:00
type: 'Feature',
geometry: {
type: 'Polygon',
coordinates: [],
},
};
2024-11-23 16:16:58 +08:00
let coordinates = [];
e?.forEach((item, index) => {
coordinates?.push([item.lng, item.lat]);
});
coordinates.push(coordinates[0]);
2024-11-24 09:38:16 +08:00
geojson.geometry.coordinates[0] = coordinates;
let wktStr = GeojsonToWkt(geojson.geometry);
emits('handlerQueryIntersectTif', wktStr);
},
});
// emit('mapDraw', 'Polygon', e);
2024-11-23 16:16:58 +08:00
});
}
2024-11-25 11:10:17 +08:00
const tifLayers = ref([]);
2024-11-25 09:22:00 +08:00
2024-11-24 09:38:16 +08:00
function handlerChangeTifLayer(item) {
if (item.type == 'historyLayer' || item.type == 'speciaLayer') {
if (item.checked) {
// 加载
if (map.getLayer(item.id)) {
map.setLayoutProperty(item.id, 'visibility', 'visible');
} else {
map.addSource('source' + item.id, {
type: 'raster',
tiles: [item.url],
tileSize: 256,
});
map.addLayer({
id: item.id,
type: 'raster',
source: 'source' + item.id,
layout: {
visibility: 'visible',
},
paint: {},
});
2024-11-25 11:10:17 +08:00
if (item.type == 'historyLayer') {
tifLayers.value.push(item.id);
console.log('tifLayers', tifLayers.value);
}
2024-11-23 16:16:58 +08:00
2024-11-24 09:38:16 +08:00
map.moveLayer(item.id, 'historyLayerFill');
map.moveLayer(item.id, 'historyLayerLine');
2024-11-23 16:16:58 +08:00
}
2024-11-24 09:38:16 +08:00
} else {
2024-11-23 16:16:58 +08:00
map.setLayoutProperty(item.id, 'visibility', 'none');
2024-11-24 09:38:16 +08:00
}
} else if (item.type == 'dataLayer') {
if (item.id == 'Monitor') {
if (map.getLayer('JianKong')) {
if (item.checked) {
map.setLayoutProperty('JianKong', 'visibility', 'visible');
} else {
map.setLayoutProperty('JianKong', 'visibility', 'none');
}
2024-11-23 16:16:58 +08:00
}
2024-11-24 09:38:16 +08:00
} else if (item.id == 'Data') {
if (map.getLayer('historyLayerLine')) {
if (item.checked) {
map.setLayoutProperty('historyLayerLine', 'visibility', 'visible');
map.setLayoutProperty('historyLayerFill', 'visibility', 'visible');
} else {
map.setLayoutProperty('historyLayerLine', 'visibility', 'none');
map.setLayoutProperty('historyLayerFill', 'visibility', 'none');
}
2024-11-23 16:16:58 +08:00
}
2024-11-24 09:38:16 +08:00
}
} else if (item.type == 'baseLayer') {
switch (item.id) {
2024-11-23 16:16:58 +08:00
case 1:
2024-11-24 09:38:16 +08:00
handlerChangeLayerVisible('tdt-img-tiles', false);
handlerChangeLayerVisible('tdt-vec-tiles', true);
2024-11-25 11:10:17 +08:00
handlerChangeLayerVisible('yaogan', false);
handlerChangeLayerVisible('yingxiang', false);
2024-11-24 09:38:16 +08:00
handlerChangeLayerVisible('countyPanelLayer', false);
2024-11-23 16:16:58 +08:00
break;
case 2:
2024-11-24 09:38:16 +08:00
handlerChangeLayerVisible('tdt-img-tiles', true);
2024-11-25 11:10:17 +08:00
handlerChangeLayerVisible('yaogan', true);
handlerChangeLayerVisible('yingxiang', true);
2024-11-24 09:38:16 +08:00
handlerChangeLayerVisible('tdt-vec-tiles', false);
handlerChangeLayerVisible('countyPanelLayer', false);
2024-11-23 16:16:58 +08:00
break;
case 3:
2024-11-24 09:38:16 +08:00
handlerChangeLayerVisible('tdt-img-tiles', false);
handlerChangeLayerVisible('tdt-vec-tiles', false);
2024-11-25 11:10:17 +08:00
handlerChangeLayerVisible('yaogan', false);
handlerChangeLayerVisible('yingxiang', false);
2024-11-24 09:38:16 +08:00
handlerChangeLayerVisible('countyPanelLayer', true);
2024-11-23 16:16:58 +08:00
break;
}
2024-11-24 09:38:16 +08:00
}
2024-11-25 09:22:00 +08:00
2024-11-25 11:10:17 +08:00
function handlerChangeTifLayer(item) {
if (item.type == 'historyLayer' || item.type == 'speciaLayer') {
if (item.checked) {
// 加载
if (map.getLayer(item.id)) {
map.setLayoutProperty(item.id, 'visibility', 'visible');
} else {
map.addSource('source' + item.id, {
type: 'raster',
tiles: [item.url],
tileSize: 256,
});
map.addLayer({
id: item.id,
type: 'raster',
source: 'source' + item.id,
layout: {
visibility: 'visible',
},
paint: {},
});
tifLayers.value.push(item.id);
map.moveLayer(item.id, 'historyLayerFill');
map.moveLayer(item.id, 'historyLayerLine');
}
} else {
map.setLayoutProperty(item.id, 'visibility', 'none');
}
} else if (item.type == 'dataLayer') {
if (item.id == 'Monitor') {
if (map.getLayer('JianKong')) {
if (item.checked) {
map.setLayoutProperty('JianKong', 'visibility', 'visible');
} else {
map.setLayoutProperty('JianKong', 'visibility', 'none');
}
}
} else if (item.id == 'Data') {
if (map.getLayer('historyLayerLine')) {
if (item.checked) {
map.setLayoutProperty('historyLayerLine', 'visibility', 'visible');
map.setLayoutProperty('historyLayerFill', 'visibility', 'visible');
} else {
map.setLayoutProperty('historyLayerLine', 'visibility', 'none');
map.setLayoutProperty('historyLayerFill', 'visibility', 'none');
}
}
}
} else if (item.type == 'baseLayer') {
switch (item.id) {
case 1:
handlerChangeLayerVisible('tdt-img-tiles', false);
handlerChangeLayerVisible('tdt-vec-tiles', true);
handlerChangeLayerVisible('countyPanelLayer', false);
break;
case 2:
handlerChangeLayerVisible('tdt-img-tiles', true);
handlerChangeLayerVisible('tdt-vec-tiles', false);
handlerChangeLayerVisible('countyPanelLayer', false);
break;
case 3:
handlerChangeLayerVisible('tdt-img-tiles', false);
handlerChangeLayerVisible('tdt-vec-tiles', false);
handlerChangeLayerVisible('countyPanelLayer', true);
break;
}
}
2024-11-24 11:07:37 +08:00
}
2024-11-25 11:10:17 +08:00
}
function handlerDeleteHistoryLayer() {
tifLayers.value?.forEach((item, index) => {
if (map.getLayer(item)) {
map.removeLayer(item);
map.removeSource('source' + item);
}
});
tifLayers.value = [];
}
2024-07-31 10:27:27 +08:00
</script>
<style type="less" scoped>
2024-11-24 09:20:21 +08:00
.map-container {
width: 100%;
height: 100%;
position: relative;
}
.search-container-box {
position: absolute;
width: 330px;
height: 40px;
top: 72px;
left: 73px;
z-index: 9999;
}
2024-11-09 16:56:31 +08:00
2024-11-24 09:20:21 +08:00
.map-type-switch-container {
width: 280px;
height: 40px;
position: absolute;
top: 72px;
right: 23px;
z-index: 9999;
font-size: 22px;
color: #fff;
text-align: center;
line-height: 40px;
cursor: pointer;
}
.map-type-switch-container .switch-button {
line-height: 40px;
width: 150px;
height: 40px;
float: left;
background: url(/map/change-view-btn.png);
2024-11-24 09:20:21 +08:00
background-size: 100% 100%;
}
2024-11-24 09:20:21 +08:00
.map-type-switch-container .switch-button span {
font-size: 14px;
}
2024-11-24 09:20:21 +08:00
.home-button {
width: 100px;
height: 100px;
background: url(/map/home-btn.png);
background-size: 100% 100%;
2024-11-24 09:20:21 +08:00
float: right;
position: relative;
top: -25px;
line-height: 100px;
text-align: center;
}
::v-deep .mapboxgl-ctrl-logo {
display: none !important;
}
2024-07-31 10:27:27 +08:00
</style>