📄 pathfinder.cs
字号:
object[] segmentCost = new object[count];
traceFlowSolver.FindPath(esriFlowMethod.esriFMConnected, esriShortestPathObjFn.esriSPObjFnMinMax, out _enumNetEID_Junctions, out _enumNetID_Edges, count, ref segmentCost);
OptimalPath op = new OptimalPath(_enumNetEID_Junctions, _enumNetID_Edges, segmentCost);
return op;
}
#endregion
#region 静态成员方法
/// <summary>
/// 获得当前鼠标点击的点
/// </summary>
/// <returns></returns>
public static IPoint GetCurrentPoint()
{
IRubberBand rubber;
IPoint point;
rubber = new RubberPointClass();
//得到在地图上点中的点
point = (IPoint)rubber.TrackNew(SystemFactory.MapControl.ActiveView.ScreenDisplay, null);
return point;
}
/// <summary>
/// 在地图上绘出经过与不经过的标志
/// </summary>
/// <param name="point"></param>
/// <param name="flag">1表示经过的路口,2表示经过道路,3表示不经过的路口,4表示不经过的道路</param>
public static void DrawNearestElement(IPoint point, int flag)
{
IScreenDisplay screenDisplay;
screenDisplay = SystemFactory.MapControl.ActiveView.ScreenDisplay;
IRgbColor rgbColor;
rgbColor = new RgbColorClass();
IGraphicsContainer container;
IElement element;
IGeometry selGeomerty = null;
selGeomerty = (IGeometry)point;
//将点中的点
element = new MarkerElementClass();
element.Geometry = point;
IMarkerElement pointMarkElement;
pointMarkElement = (IMarkerElement)element;
//设置点的形状
ISimpleMarkerSymbol pointMarkSymbol;
pointMarkSymbol = (ISimpleMarkerSymbol)pointMarkElement.Symbol;
switch (flag)
{
case 1:
rgbColor.Blue = 255;
pointMarkSymbol.Style = esriSimpleMarkerStyle.esriSMSCircle;
break;
case 2:
rgbColor.Blue = 255;
pointMarkSymbol.Style = esriSimpleMarkerStyle.esriSMSCircle;
break;
case 3:
rgbColor.Red = 255;
pointMarkSymbol.Style = esriSimpleMarkerStyle.esriSMSX;
break;
case 4:
rgbColor.Red = 255;
pointMarkSymbol.Style = esriSimpleMarkerStyle.esriSMSX;
break;
default:
break;
}
pointMarkSymbol.Color = rgbColor;
pointMarkElement.Symbol = pointMarkSymbol;
container = (IGraphicsContainer)SystemFactory.MapControl.Map;
//container.UpdateElement((IElement)pointMarkElement);
container.Reset();
IElement elementTemp = container.Next();
bool isExist = false;
//element = (IElement)pointMarkElement;
while (elementTemp != null)
{
if (elementTemp.Geometry.Envelope.XMax == point.Envelope.XMax
&& elementTemp.Geometry.Envelope.YMax == point.Envelope.YMax)
{
isExist = true;
break;
}
elementTemp = container.Next();
}
if (isExist == true)
{
container.DeleteElement(elementTemp);
container.AddElement((IElement)pointMarkElement, 0);
}
else
container.AddElement((IElement)pointMarkElement, 0);
SystemFactory.MapControl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);
}
public static void ClearElement(IPoint point)
{
IGraphicsContainer container = (IGraphicsContainer)SystemFactory.MapControl.Map;
container.Reset();
IElement elementTemp = container.Next();
while (elementTemp != null)
{
if (elementTemp.Geometry.Envelope.XMax == point.Envelope.XMax
&& elementTemp.Geometry.Envelope.YMax == point.Envelope.YMax)
{
container.DeleteElement(elementTemp);
break;
}
elementTemp = container.Next();
}
SystemFactory.MapControl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);
}
public static void ClearElement(IEnvelope envelope)
{
IGraphicsContainer container = (IGraphicsContainer)SystemFactory.MapControl.Map;
container.Reset();
IElement elementTemp = container.Next();
while (elementTemp != null)
{
if (elementTemp.Geometry.Envelope == envelope)
{
container.DeleteElement(elementTemp);
break;
}
elementTemp = container.Next();
}
SystemFactory.MapControl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);
}
/// <summary>
/// 清除所有设置
/// </summary>
public static void ClearAllElements()
{
IGraphicsContainer container = (IGraphicsContainer)SystemFactory.MapControl.Map;
container.DeleteAllElements();
SystemFactory.MapControl.ActiveView.Refresh();
//SystemFactory.MapControl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);
}
/// <summary>
/// 清除不通过设置
/// </summary>
public static void ClearCantPassSet()
{
IGraphicsContainer container = (IGraphicsContainer)SystemFactory.MapControl.Map;
container.Reset();
IElement elementTemp = container.Next();
//查找与不通过点style一致的点并删除之
while (elementTemp != null)
{
IMarkerElement markerElement = elementTemp as IMarkerElement;
if (markerElement == null)
continue;
ISimpleMarkerSymbol symbol = markerElement.Symbol as ISimpleMarkerSymbol;
if (symbol == null)
continue;
if (symbol.Style == esriSimpleMarkerStyle.esriSMSX)
{
container.DeleteElement(elementTemp);
}
elementTemp = container.Next();
}
SystemFactory.MapControl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);
}
/// <summary>
/// 清除必经设置
/// </summary>
public static void ClearMustPassSet()
{
IGraphicsContainer container = (IGraphicsContainer)SystemFactory.MapControl.Map;
container.Reset();
IElement elementTemp = container.Next();
//查找与通过点style一致的点并删除之
while (elementTemp != null)
{
IMarkerElement markerElement = elementTemp as IMarkerElement;
if (markerElement == null)
continue;
ISimpleMarkerSymbol symbol = markerElement.Symbol as ISimpleMarkerSymbol;
if (symbol == null)
continue;
if (symbol.Style == esriSimpleMarkerStyle.esriSMSCircle)
{
container.DeleteElement(elementTemp);
}
elementTemp = container.Next();
}
SystemFactory.MapControl.ActiveView.Refresh();
}
/// <summary>
/// 清除当前最佳路径
/// </summary>
/// <param name="PolyLine"></param>
public static void ClearOptimalRouteResult()
{
IGraphicsContainer container = (IGraphicsContainer)SystemFactory.MapControl.Map;
container.Reset();
IElement elementTemp = container.Next();
while (elementTemp != null)
{
if (elementTemp.Geometry.GeometryType == esriGeometryType.esriGeometryPolyline)
container.DeleteElement(elementTemp);
elementTemp = container.Next();
}
SystemFactory.MapControl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);
}
/// <summary>
/// 根据图层名称获得地图中指定的图层对象引用
/// </summary>
/// <param name="strLayer"></param>
/// <param name="map"></param>
/// <returns></returns>
public static IGeoFeatureLayer GetFeatureLayer(String strLayer, IMap map)
{
if (map == null)
{
return null;
}
ILayer pLayer;
IGroupLayer pGroupLayer;
IArray pVisibleLayersArray;
IGeoFeatureLayer pGeoFeatureLayer;
ICompositeLayer pCompositeLayer;
pVisibleLayersArray = new ESRI.ArcGIS.esriSystem.Array();
for (int i = 0; i < map.LayerCount; i++)
{
pLayer = map.get_Layer(i);
pCompositeLayer = pLayer as ICompositeLayer;
pGeoFeatureLayer = pLayer as IGeoFeatureLayer;
if (pCompositeLayer != null)
{
pGroupLayer = pLayer as IGroupLayer;
if ((pGroupLayer != null) && pGroupLayer.Visible)
{
for (int j = 0; j < pCompositeLayer.Count; j++)
{
pGeoFeatureLayer = pCompositeLayer.get_Layer(j) as IGeoFeatureLayer;
//System.Windows.Forms.MessageBox.Show(pGeoFeatureLayer.Name);
if ((pGeoFeatureLayer != null) && (strLayer.ToUpper() == pGeoFeatureLayer.Name.ToUpper()))
{
return pGeoFeatureLayer;
}
}
}
}
else if (pGeoFeatureLayer != null)
{
if (pLayer.Visible)
{
if (strLayer.ToUpper() == pGeoFeatureLayer.Name.ToUpper())
{
return pGeoFeatureLayer;
}
}
}
}
return null;
}
#endregion
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -