emis-sapp/common/geo/XDGeoSdk.js

82 lines
1.9 KiB
JavaScript
Raw Normal View History

2025-08-15 06:22:52 +00:00
'use strict'
import * as turf from '@turf/turf';
import { deepClone } from '@/common/custom.js'
/*
中国边界数据 来源 阿里-高德
https://datav.aliyun.com/portal/school/atlas/area_selector
*/
import chinaBoundary from './china-boundary.json';
/*
XDGeoSdk
*/
class XDGeoSdk {
geoJson = null;
geoSimpleJson = null;
chinaPolygon = null;
chinaAreaBoundary = null;
chinaAreaMainLandBoundary = null;
chinaBox = null;
static instance = null;
constructor() {
this.instance = null
this.geoJson=chinaBoundary;
this.chinaAreaBoundary=deepClone(chinaBoundary.features[0].geometry.coordinates);
this.chinaAreaMainLandBoundary=this.chinaAreaBoundary[0][0];
this.chinaPolygon = chinaBoundary.features[0].geometry;
this.chinaBox=turf.bbox(this.chinaPolygon);
var options = {tolerance: 0.01, highQuality: false};
this.geoSimpleJson = turf.simplify(this.geoJson, options);
// console.log("===>this.chinaPolygon==>",this.chinaPolygon);
// console.log("===>geoSimpleJson==>",this.geoSimpleJson);
}
static getInstance() {
if (!this.instance) {
this.instance = new XDGeoSdk()
}
return this.instance
}
getChinaGeoJson(){
return this.geoJson;
// return this.geoSimpleJson;
}
getChinaPolygon(){
return this.chinaAreaBoundary;
}
getChinaMainLandPolygon(){
return this.chinaAreaMainLandBoundary;
}
isInChina(lat,lng) {
// [minLng, minLat, maxLng, maxLat]
const bbox = this.chinaBox;
const isInBbox = lng >= bbox[0] && lng <= bbox[2] && lat >= bbox[1] && lat <= bbox[3];
if (!isInBbox) {
return false;
}
const point = turf.point([lng, lat]);
const chinaPolygon = this.chinaPolygon;
let rst=turf.booleanPointInPolygon(point, chinaPolygon);
return rst;
}
}
export default XDGeoSdk;