从后台取出N条数据,每条数据中都包含3个点的信息(x1,y1)(x2,y2)(x3,y3),我用(x1,y1)(x2,y2)这两个点连城线,再对线做缓冲区分析,需要判断(x3,y3)这个点是否与该缓冲区相交。 但是没法把(x3,y3)这个点参数传到bufferAnalystProcess()函数中,就无法匹配对应点和缓冲区判断,导致一个点和两个缓冲区判断或不同的点和同一缓冲区比较。 试了好几种方法都不好使,这是其中一种,望大神指点。
function callback_getPoint(data) { //从后台取出多行数据
if (data == "") {
alert("无数据");
return;
}
var row = data.split("|");
for (var i = 0; i < row.length; i++) {
myPointsList= [new SuperMap.Geometry.Point(row[i].split(",")[0], row[i].split(",")[1]),
new SuperMap.Geometry.Point(row[i].split(",")[2], row[i].split(",")[3])]
point= new SuperMap.Geometry.Point(row[i].split(",")[6], row[i].split(",")[7]);
addPath();
bufferAnalystProcess();
}
}
function addPath() {
var pathFeature = new SuperMap.Feature.Vector();
gpsLine = new SuperMap.Geometry.LineString(myPointsList);
pathFeature.geometry = gpsLine;
pathFeature.style = styleLine;
resultLayer.addFeatures(pathFeature);
}
function bufferAnalystProcess() {
if (!gpsLine) {
alert("请生成路径,用于缓冲区分析");
return;
}
var bufferServiceByGeometry = new SuperMap.REST.BufferAnalystService(url2),
bufferDistance = new SuperMap.REST.BufferDistance({
value: 0.001
}),
bufferSetting = new SuperMap.REST.BufferSetting({
endType: SuperMap.REST.BufferEndType.ROUND,
leftDistance: bufferDistance,
rightDistance: bufferDistance,
semicircleLineSegment: 3
}),
geoBufferAnalystParam = new SuperMap.REST.GeometryBufferAnalystParameters({
sourceGeometry: gpsLine,
bufferSetting: bufferSetting
});
bufferServiceByGeometry.events.on(
{
"processCompleted": bufferAnalystCompleted
});
bufferServiceByGeometry.processAsync(geoBufferAnalystParam);
}
function bufferAnalystCompleted(BufferAnalystEventArgs) {
var feature = new SuperMap.Feature.Vector();
bufferResultGeometry = BufferAnalystEventArgs.result.resultGeometry;
feature.geometry = bufferResultGeometry;
feature.style = styleRegion;
resultLayer.addFeatures(feature);
if (bufferResultGeometry.intersects(point)) {
alert("相交");
} else {
alert("不相交");
}
})
}