You need to download the turf plugin in advance, command: npm install @turf/turf
use:
import * as turf from '@turf/turf';
Judging whether the point is in the plane: (lonlatValid() is just a verification method written by myself, which can be ignored)
const piontisin = (rtkobj: any) => {
if (lonlatValid(rtkobj.orderpoint_x) && lonlatValid(rtkobj.orderpoint_y) == true) {
//判断点是否在面内
let point_arr = turf.point(
transform(
[Number(rtkobj.orderpoint_x), Number(rtkobj.orderpoint_y)],
'EPSG:4326',
'EPSG:3857'
)
);
let poly = turf.polygon([
[
transform([Number(rtkobj.p1_x), Number(rtkobj.p1_y)], 'EPSG:4326', 'EPSG:3857'),
transform([Number(rtkobj.p2_x), Number(rtkobj.p2_y)], 'EPSG:4326', 'EPSG:3857'),
transform([Number(rtkobj.p3_x), Number(rtkobj.p3_y)], 'EPSG:4326', 'EPSG:3857'),
transform([Number(rtkobj.p4_x), Number(rtkobj.p4_y)], 'EPSG:4326', 'EPSG:3857'),
transform([Number(rtkobj.p1_x), Number(rtkobj.p1_y)], 'EPSG:4326', 'EPSG:3857')
]
]);
let isin = turf.booleanPointInPolygon(point_arr, poly);
if (isin == false) {
message.error('点不位于面内!');
}
}
};