0
public void OnMouseDown(int Button, int Shift, int X, int Y)
{
  IMxDocument mxDoc = m_App.Document as IMxDocument;
  IActiveView activeView = mxDoc.FocusMap as IActiveView;
  IScreenDisplay screenDisplay = activeView.ScreenDisplay;

  ISimpleLineSymbol lineSymbol = new SimpleLineSymbolClass();
  IRgbColor rgbColor = new RgbColorClass();
  rgbColor.Red = 255;
  lineSymbol.Color = rgbColor;

  IRubberBand rubberLine = new RubberLineClass();
  IPolyline newPolyline = (IPolyline)rubberLine.TrackNew(screenDisplay, (ISymbol)lineSymbol);

  screenDisplay.StartDrawing(screenDisplay.hDC, (short)esriScreenCache.esriNoScreenCache);
  screenDisplay.SetSymbol((ISymbol)lineSymbol);
  screenDisplay.DrawPolyline(newPolyline);
  screenDisplay.FinishDrawing();    
}

这是绘制折线的功能。但我希望折线会自动存储在“线”层中,这可能吗?

4

1 回答 1

1

你的问题有点不清楚。您的“线条”图层是否已经存在?

如果您希望您的图层成为要素图层而不是图形图层,请在工作空间中创建要素类,然后像这样将线对象添加到其中(对不起,它在 vb.net 中):

Dim pFeature as IFeature
pFeature = pFeatureClass.CreateFeature()
pFeature.Shape = newPolyline
pFeature.Store()

然后从您的要素类创建一个要素图层并将其添加到地图中:

Dim pFeatureLayer as IFeatureLayer
pFeatureLayer.FeatureClass = pFeatureClass
pFeatureLayer.Name = "Lines"
Dim pMap as IMap = pMxDoc.FocusMap
pMap.AddLayer(pFeatureLayer)
于 2013-12-12T16:42:32.250 回答