main
徐景良 2025-11-20 12:04:46 +08:00
parent a41dd51128
commit dd48f7bec9
2 changed files with 189 additions and 0 deletions

View File

@ -176,6 +176,11 @@
import Water from './source/water.vue'; import Water from './source/water.vue';
import Goods from './source/goods.vue'; import Goods from './source/goods.vue';
import Barrack from './source/barrack.vue'; import Barrack from './source/barrack.vue';
import axios from 'axios';
import * as turf from '@turf/turf';
import {getPointNearByPoints,arrayToPointGeoJSON,geojsonPointToArray} from './ts/GeoTools'
import { getAppEnvConfig } from '@/utils/env';
let { VITE_GLOB_API_URL } = getAppEnvConfig();
const props = defineProps({ const props = defineProps({
chartConfig: { chartConfig: {
@ -758,10 +763,98 @@
}); });
} }
// 线
const clueInfo = ref({});
//
const waterSources = ref()
const waterList = ref();
async function handlerLoadWaterData(){
axios.get("http://221.2.83.254:9007/geoserver/ksp/ows?service=WFS&version=1.0.0&request=GetFeature&typeName=ksp%3Ananbeibushluiyuanhebing&maxFeatures=50000&outputFormat=application%2Fjson").then(res=>{
waterSources.value = res.data;
})
}
//
const Sources = ref();
const goodsList = ref();
async function handlerLoadGoodsData(){
let querys = {
name:null,
areaname:"feixian"
}
axios({
method: "get",
url: VITE_GLOB_API_URL + '/api/FireManagement/Loadwuzichubei',
data: querys,
headers: {
'X-Token': localStorage.getItem("X-Token")
}
}).then(res=>{
console.log(res);
})
}
//
const barrackSources = ref();
const barrackList = ref();
async function handlerLoadbarrackData(){
let querys = {
name:null,
areaname:"feixian"
}
axios({
method: "get",
url: VITE_GLOB_API_URL + '/api/FireManagement/GetAllYingFang',
data: querys,
headers: {
'X-Token': localStorage.getItem("X-Token")
}
}).then(res=>{
console.log(res.data.result);
debugger;
})
}
//
async function handlerGetNearByWater(){
let cluePoint = turf.point([Number(clueInfo.value?.lng),Number(clueInfo.value?.lat)]);
let radius = option.dataStyle.distanceradio*1000;
const clueBuffer = turf.buffer(cluePoint, radius, { units: "meters" });
let result = turf.pointsWithinPolygon(waterSources.value, clueBuffer);
waterList.value = result;
}
onMounted(() => { onMounted(() => {
//
handlerLoadWaterData();
handlerLoadGoodsData();
handlerLoadbarrackData();
// //
const sql = props.chartConfig.request?.requestSQLContent?.sql; const sql = props.chartConfig.request?.requestSQLContent?.sql;
EventBus.on(props.chartConfig.id + 'dataupdate', (data) => { EventBus.on(props.chartConfig.id + 'dataupdate', (data) => {
clueInfo.value = data;
//
handlerGetNearByWater();
// //
endCoor = [data.lng, data.lat]; endCoor = [data.lng, data.lat];
props.chartConfig.request.requestSQLContent.sql = replaceSqlParams(sql, { Id: data.id }); props.chartConfig.request.requestSQLContent.sql = replaceSqlParams(sql, { Id: data.id });
@ -769,6 +862,8 @@
useChartDataFetch(props.chartConfig, useChartEditStore, (resData: any[]) => { useChartDataFetch(props.chartConfig, useChartEditStore, (resData: any[]) => {
option.dataset = resData; option.dataset = resData;
}); });
}); });
}); });

View File

@ -0,0 +1,94 @@
import * as turf from "@turf/turf";
/**
*
* @param targetPoint : [118.4234,34.483083]
* @param sourcePoints : geojson
* @param distance : 1000
* @result geojson
**/
export const getPointNearByPoints = (targetPoint,sourcePoints,distance) => {
try{
// 处理目标点
let point = turf.point([Number(targetPoint[0]),Number(targetPoint[1])]);
// 生成缓冲区
let buffer = turf.buffer(point, distance, { units: "meters" });
// 获取缓冲区范围内的点
let result = turf.pointsWithinPolygon(sourcePoints, buffer);
return result;
}catch(e){
return false;
}
}
/**
* GeoJSON FeatureCollectionPoint
* @param {Array} list
* @param {Object} options
* @param {String} options.lngKey "lng"
* @param {String} options.latKey "lat"
* @returns {Object} GeoJSON FeatureCollection
*/
export const arrayToPointGeoJSON = (list, options = {lngKey:"lng",latKey:"lat"}) => {
const { lngKey = "lng",latKey = "lat"} = options;
return {
type: "FeatureCollection",
features: list.filter(item => item[lngKey] != null && item[latKey] != null).map(item => ({
type: "Feature",
geometry: {
type: "Point",
coordinates: [
Number(item[lngKey]),
Number(item[latKey])
]
},
properties: {
...item
}
}))
};
}
/**
* GeoJSON Point FeatureCollection
* @param {Object} geojson GeoJSON FeatureCollection
* @param {Object} options
* @param {String} options.lngKey "lng"
* @param {String} options.latKey "lat"
* @returns {Array}
*/
export const geojsonPointToArray = (geojson, options = {lngKey:"lng",latKey:"lat"}) => {
const { lngKey = "lng", latKey = "lat" } = options;
if (!geojson || geojson.type !== "FeatureCollection") {
console.error("输入必须是 FeatureCollection");
return [];
}
return geojson.features.filter(f => f.geometry && f.geometry.type === "Point").map(f => {
const [lng, lat] = f.geometry.coordinates;
return {
...f.properties,
[lngKey]: lng,
[latKey]: lat
};
});
}
export const parsePointToArray = (pointStr) => {
if (!pointStr) return null;
// 去除前后空格、统一格式
pointStr = pointStr.trim();
// 匹配 POINT(...) 中的数字(支持用空格或逗号分隔)
const match = pointStr.match(/POINT\s*\(\s*([\d.-]+)[ ,]+([\d.-]+)\s*\)/i);
if (!match) return null;
const lng = parseFloat(match[1]);
const lat = parseFloat(match[2]);
return [lng, lat];
}