AE编辑点要素编辑
來自:http://blog.163.com/liuyang1285@126/blog/static/128913086201212151123418/?latestBlog
AE編輯--新增要素
AE編輯-線要素編輯
AE編輯-點要素編輯
2012-02-21 17:11:23|分類: 工作 |標簽: |字號大中小訂閱
點的捕捉
指定捕捉圖層(開發(fā)中以電纜溝點圖層為捕捉圖層),設(shè)置捕捉半徑和捕捉要素顯示的標注信息,在OnMouseMove事件中處理實現(xiàn)。
pt_Move = m_pScrD.DisplayTransformation.ToMapPoint(X, Y);
if (m_pLineFeedback == null)
{
//清?空textelment markelment[IGroupElement]
m_pAV.GraphicsContainer.Reset();
IElementProperties elementProperties_temp = null;
IElement elment = m_pAV.GraphicsContainer.Next();
while (elment != null)
{
elementProperties_temp = elment as IElementProperties;
if (elementProperties_temp.Name.StartsWith("SnapLabel"))
{
m_pAV.GraphicsContainer.DeleteElement(elment);
}
elment = m_pAV.GraphicsContainer.Next();
}
m_pAV.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, m_pAV.Extent);
}
featureCache = new FeatureCacheClass();
//如果已經(jīng)擁有緩沖區(qū),而且當前點依然在該緩沖區(qū)內(nèi)部,那么不會填充生成新的緩沖
if (!featureCache.Contains(pt_Move))
{
featureCache.Initialize(pt_Move, Convert.ToDouble(clsHelper.GetConfigValue("SnapRadius")));//10
featureCache.AddFeatures(featureLayer.FeatureClass);
IFeature feature;
IGeometry geometry;
int indexFeature, countFeature;
countFeature = featureCache.Count;
for (indexFeature = 0; indexFeature < countFeature; indexFeature++)
{
feature = featureCache.get_Feature(indexFeature);
if (feature != null)
{
geometry = feature.Shape;
IPoint hitPoint = new PointClass();
double hitDist = 0;
int hitPartIndex = 0;
bool bRightSide = false;
int hitSegmentIndex = 0;
IHitTest hitTest = geometry as IHitTest;
//m_pAV.Extent.Width / 200
if (hitTest.HitTest(pt_Move, 2, esriGeometryHitPartType.esriGeometryPartVertex, hitPoint, ref hitDist, ref hitPartIndex, ref hitSegmentIndex, ref bRightSide))
{
AddPointElement(m_pAV, hitPoint, feature.get_Value(feature.Fields.FindField("TRENCHID")).ToString());
break;//只高亮顯示一個要素
}
}
}
}
///
/// </summary>
/// <param name="pActiveView"></param>
/// <param name="pPoint"></param>
/// <param name="strLabel"></param>
private void AddPointElement(IActiveView pActiveView, IPoint pPoint, string strLabel)
{
IMarkerElement pMarkerElement = new MarkerElementClass();
IElement pElement;
ISimpleMarkerSymbol pMarkerSymbol = new SimpleMarkerSymbol();
IRgbColor pRgbColor = new RgbColorClass();
pRgbColor.Red = 0;
pRgbColor.Green = 255;
pRgbColor.Blue = 25;
pMarkerSymbol.Color = pRgbColor;
pMarkerSymbol.Size = 5; //單位為像素
pMarkerSymbol.Style = esriSimpleMarkerStyle.esriSMSCircle;
pMarkerElement.Symbol = (IMarkerSymbol)pMarkerSymbol;
pElement = (IElement)pMarkerElement;
pElement.Geometry = (IGeometry)pPoint;
IElementProperties elementProperties_Trench = pMarkerElement as IElementProperties;
elementProperties_Trench.Name = "SnapLabelPoint";
pActiveView.GraphicsContainer.AddElement(pMarkerElement as IElement, 0);
//pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, m_pAV.Extent);
ITextElement pTextElement = new TextElementClass();
IElement element_text;
ISimpleTextSymbol simpleTextSymbol = new TextSymbolClass();
stdole.StdFont myFont = new stdole.StdFont();
myFont.Name = "Courier New";
myFont.Size = 10;
simpleTextSymbol.Font = myFont as stdole.IFontDisp;
IRgbColor myColor = new RgbColorClass();
myColor.Red = 150;
myColor.Green = 0;
myColor.Blue = 0;
simpleTextSymbol.Color = myColor;
simpleTextSymbol.Angle = 0;
simpleTextSymbol.RightToLeft = false;
simpleTextSymbol.VerticalAlignment = esriTextVerticalAlignment.esriTVATop;
simpleTextSymbol.HorizontalAlignment = esriTextHorizontalAlignment.esriTHAFull;
simpleTextSymbol.BreakCharacter = 20;
pTextElement.Symbol = simpleTextSymbol;
pTextElement.Text = "電纜溝:" + strLabel;
pTextElement.ScaleText = true;//隨地圖比例尺變化
element_text = pTextElement as IElement;
element_text.Geometry = (IGeometry)pPoint;
IElementProperties elementProperties = pTextElement as IElementProperties;
elementProperties.Name = "SnapLabelText";
pActiveView.GraphicsContainer.AddElement(pTextElement as IElement, 0);
pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, m_pAV.Extent);
}
//獲取要素
private IElement getElement(IPoint pPt, esriGeometryType geometryType)
{
IEnumElement pEnumElement;
IElement pEle;
pEnumElement = pGraphicContainer.LocateElements(pPt, pActiveView.Extent.Width / 100);
if (pEnumElement != null)
{
pEnumElement.Reset();
pEle = pEnumElement.Next();
while (pEle != null)
{
if (pEle.Geometry.GeometryType == geometryType)
{
return pEle;
}
pEle = pEnumElement.Next();
}
}
return null;
}
點的移動
點的移動,實現(xiàn)步驟,首先MouseDown選中某點,MouseMove移動該點,MouseUp更新點的空間位置(與點拓撲關(guān)聯(lián)的要素也要同時更新)。
選擇點要素,用到接口類 IDisplayFeedback,移動點用到類 IMovePointFeedback
IPoint pPoint;
OnMouseDown事件中選擇點要素后,并支持鼠標拖拽移動
IHitTest pHitTest_Point;
bool BoolHitTest_Point;
IPoint pPtHit_Point = null;
hitElement = getElement(pPt, esriGeometryType.esriGeometryPoint);
if (hitElement != null)//捕捉到點要素
{
pPoint = hitElement.Geometry as IPoint;
pDisplayFeedback = new MovePointFeedbackClass();
pDisplayFeedback.Display = pScreenDisplay;
((IMovePointFeedback)pDisplayFeedback).Start(pPoint, pPt);
}
鼠標移動:public override void OnMouseMove(int Button, int Shift, int X, int Y)
{
IPoint pPt = new PointClass();
pPt = pScreenDisplay.DisplayTransformation.ToMapPoint(X, Y);
if (pDisplayFeedback != null)
{
pDisplayFeedback.MoveTo(pPt);
}
}
鼠標MouseUp,保存新的要素空間位置以及相關(guān)屬性信息:
private bool StoreFeatureGeometry(IFeature pFeature, IGeometry pIGeometry)
{
try
{
var pFeatureClass = pFeature.Class as IFeatureClass;
var pDataset = pFeatureClass as IDataset;
IWorkspace pWorkspace = pDataset.Workspace;
var pWorkspaceEdit = pWorkspace as IWorkspaceEdit;
pWorkspaceEdit.StartEditing(false);
pWorkspaceEdit.StartEditOperation();
//修T改nodeid|s_nodeid,e_nodeid
if (pIGeometry.GeometryType == esriGeometryType.esriGeometryPoint)
{
string strNodeId = (pIGeometry as IPoint).X.ToString("0.000")+
"-" + (pIGeometry as IPoint).Y.ToString("0.000");
pFeature.set_Value(pFeature.Fields.FindField("NODEID"), strNodeId);
}
else if (pIGeometry.GeometryType == esriGeometryType.esriGeometryPolyline)
{
IPolyline polyline = pIGeometry as IPolyline;
string strSNodeId = polyline.FromPoint.X.ToString("0.000")+
"-" + polyline.FromPoint.Y.ToString("0.000");
string strENodeId = polyline.ToPoint.X.ToString("0.000") +
"-" + polyline.ToPoint.Y.ToString("0.000");
pFeature.set_Value(pFeature.Fields.FindField("S_NODEID"), strSNodeId);
pFeature.set_Value(pFeature.Fields.FindField("E_NODEID"), strENodeId);
}
pFeature.Shape = pIGeometry;
pFeature.Store();
pWorkspaceEdit.StopEditOperation();
pWorkspaceEdit.StopEditing(true);
return true;
}
catch (Exception ex)
{
return false;
}
}
點要素屬性的修改
首先獲取要編輯的IFeature,Set_Value(index,value)對字段賦值,最后Store()保存。
總結(jié)
- 上一篇: 为什么说iOS 16.2正式版值得更新
- 下一篇: 久远的回忆