來自:http://blog.sina.com.cn/s/blog_4d0b75870100o960.html
//獲取最近的結點,然後在 OnMouseMove中顯示
//pnt:鼠標移動點
//mapSize:設置的地理范圍
public static IPoint GetNearestVertex(IActiveView actview, IPoint pnt, double mapSize)
{
IPoint vetex = null;
IPoint hitPnt=new PointClass();
IHitTest hitTest = null;
IPointCollection pntColl =new MultipointClass();
IProximityOperator prox = null;
double hitdis=0;
int hitpartindex=0,hitsegindex=0;
Boolean rside = false;
IFeatureCache2 featCache = new FeatureCacheClass();
double pixelSize = ConvertMapUnitsToPixels(actview, mapSize); //將地理范圍轉化為像素
featCache.Initialize(pnt, pixelSize); //初始化緩存
for (int i = 0; i < actview.FocusMap.LayerCount; i++)
{
//只有點、線、面並且可視的圖層才加入緩存
IFeatureLayer featLayer =(IFeatureLayer) actview.FocusMap.get_Layer(i);
if (featLayer != null && featLayer.Visible == true &&
(featLayer.FeatureClass.ShapeType==esriGeometryType.esriGeometryPolyline ||
featLayer.FeatureClass.ShapeType == esriGeometryType.esriGeometryPolygon ||
featLayer.FeatureClass.ShapeType == esriGeometryType.esriGeometryPoint))
{
featCache.AddFeatures(featLayer.FeatureClass, null);
for (int j = 0; j < featCache.Count; j++)
{
IFeature feat = featCache.get_Feature(j);
hitTest =(IHitTest ) feat.Shape;
//捕捉節點,另外可以設置esriGeometryHitPartType,捕捉邊線點,中間點等。
if (hitTest.HitTest(pnt, mapSize, esriGeometryHitPartType.esriGeometryPartVertex, hitPnt, ref hitdis, ref hitpartindex, ref hitsegindex, ref rside))
{
object obj=Type.Missing ;
pntColl.AddPoint(hitPnt,ref obj,ref obj);
break;
}
}
}
}
prox =(IProximityOperator)pnt;
double minDis=0, dis=0;
for (int i = 0; i < pntColl.PointCount; i++)
{
IPoint tmpPnt=pntColl.get_Point(i);
dis= prox.ReturnDistance(tmpPnt);
if (i == 0)
{
minDis = dis;
vetex = tmpPnt;
}
else
{
if (dis < minDis)
{
minDis = dis;
vetex = tmpPnt;
}
}
}
return vetex;
}
動態分段可以做,有點小復雜,需要做數據處理;
具體做法可以參考:bbs.esrichina-bj.cn/ESRI/thread-56565-1-1.html
你可以把你實現的功能過程(你如何得到那兩個節點的?高亮就行?)說出來,這樣可以進一步探討其它的方法!
不懂,另請高手吧。