public SelectResult SelectPoint(GISVertex vertex, List <GISFeature> features, GISView view, GISExtent MinSelectExtent) { Double distance = Double.MaxValue; int id = -1; for (int i = 0; i < features.Count; i++) //找最近的feature判断是否有效 { if (MinSelectExtent.IntersectOrNot(features[i].spatialpart.extent) == false) { continue; } GISPoint point = (GISPoint)(features[i].spatialpart); double dist = point.Distance(vertex); if (dist < distance)//每次找到最小的距离并记录id号 { distance = dist; id = i; } } Console.WriteLine("id:" + id.ToString()); //测试id是否存在 Console.WriteLine(features[id].spatialpart.centroid.x.ToString() + "|" + features[id].spatialpart.centroid.y.ToString()); Console.WriteLine("鼠标点到元素点在地图上相距" + distance.ToString()); //此处的distance是features中最近的元素点到鼠标点映射到地图上点的距离 //精选 if (id == -1) //经过遍历 没有与minsextent相交的点则跳出 { SelectedFeature = null; return(SelectResult.TooFar); } else { double screendistance = view.ToScreenDistance(vertex, features[id].spatialpart.centroid); //Console.WriteLine(screendistance); if (screendistance < GISConst.MinScreenDistance) { SelectedFeature = features[id]; return(SelectResult.OK); } else { SelectedFeature = null; return(SelectResult.TooFar);//即使在粗选相交 精选距离也超过了限制 则返回 } } }
public SelectResult SelectLine(GISVertex vertex, List <GISFeature> features, GISView view, GISExtent MinSelectExtent) { Double distance = Double.MaxValue; int id = -1; for (int i = 0; i < features.Count; i++) //找最近的feature判断是否有效 { if (MinSelectExtent.IntersectOrNot(features[i].spatialpart.extent) == false) { continue; } GISLine line = (GISLine)(features[i].spatialpart); double dist = line.Distance(vertex); //Console.WriteLine("dist:" + dist); if (dist < distance)//每次找到最小的距离并记录id号 { distance = dist; id = i; } } Console.WriteLine("id:" + id.ToString());//测试id是否存在 //Console.WriteLine(distance); //精选 if (id == -1)//经过遍历 没有与minsextent相交的点则跳出 { SelectedFeature = null; return(SelectResult.TooFar); } else { double screendistance = view.ToScreenDistance(distance); if (screendistance < GISConst.MinScreenDistance) { SelectedFeature = features[id]; return(SelectResult.OK); } else { SelectedFeature = null; return(SelectResult.TooFar);//即使在粗选相交 精选距离也超过了限制 则返回 } } }