Real-time monitoring of whether the vehicle leaves the factory

function isExists(obj, objarr) {
if (JSON.stringify(objarr).indexOf(JSON.stringify(obj)) >= 0) {
return true;
}
return false;
}

function enclosure (obj) {
var ptExist = [];
var _pts = []; // _
var _pt1 = new AMap.LngLat (116.400, 39.914);
var _pt2 = new AMap.LngLat (116.400, 39.914);
var _pt3 = new AMap.LngLat (116.400, 39.914);
var _pt4 = new AMap.LngLat (116.400, 39.914);
_pts.push (_pt1);
_pts.push (_pt2);
_pts.push (_pt3);
_pts.push (_pt4);

var polygons = [];
var objPolygon = new Object();
for (var i = 0; i < obj.length; i++) {
var arr = obj[i].ArticlePoints.split(",");
var x, y;
var pts = [];
for (var j = 0; j < arr.length; j++) {
if (j % 2 === 0) {
x = arr[j];
} else {
y = arr[j];
pts.push(new AMap.LngLat(parseFloat(x),parseFloat(y)));
}
}
objPolygon.polygon = new AMap.Polygon(pts);
objPolygon.id = obj.ID;
polygons.push(objPolygon);
}

for (var i = 0; i < polygons.length; i++) {
for (var index=0; index<_pts.length;index++) {
var result = AMapLib.GeoUtils.isPointInPolygon(_pts[index], polygons[i] .polygon);
if (result) {
alert("The point is inside the polygon");
if (!isExists(_pts[index], ptExist)) {
ptExist.push(_pts[index]);
_pts.pop(_pts[index ] ]);
}
} else {
if (isExists(_pts[index], ptExist)) {
ptExist.pop(_pts[index]);
alert(polygons[i].id + "Fence has space");//here You can alert whether there are vacancies according to the number of vehicles that the fence can accommodate
}

}
}
}
}

 

The judgment class geoutils.js provided by Baidu is used here.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324930655&siteId=291194637