我正在尝试检查一个点是否在多边形内。这是我的功能:
import { containsXY } from 'ol/extent';
isInside(polygon, longitude, latitude) {
polygon = JSON.parse(polygon); // Polygon is originally = JSON.stringify([[long1, lat1],[long2, lat2], ...])
let poli = new Polygon(polygon);
// Try 1: Not working
console.log("Result --> ", containsXY(poli, latitude, longitude));
console.log("Result --> ", containsXY(poli, longitude, latitude));
console.log("Result --> ", containsXY(poli.getExtent(), latitude, longitude));
console.log("Result --> ", containsXY(poli.getExtent(), longitude, latitude));
// Try 2: Not working
let coordinate = this.to3857([longitude, latitude]);
console.log("Result --> ", containsXY(poli, coordinate[0], coordinate[1]));
console.log("Result --> ", containsXY(poli, coordinate[1], coordinate[0]));
console.log("Result --> ", containsXY(poli.getExtent(), coordinate[0], coordinate[1]));
console.log("Result --> ", containsXY(poli.getExtent(), coordinate[1], coordinate[0]));
// Try 3: Not working
coordinate = this.to4326([longitude, latitude]);
console.log("Result --> ", containsXY(poli, coordinate[0], coordinate[1]));
console.log("Result --> ", containsXY(poli, coordinate[1], coordinate[0]));
console.log("Result --> ", containsXY(poli.getExtent(), coordinate[0], coordinate[1]));
console.log("Result --> ", containsXY(poli.getExtent(), coordinate[1], coordinate[0]));
}
所有结果都是false
。如何检查坐标是否在多边形中?OpenLayers API 对我没有任何帮助。
提前致谢