Pergunta

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();    
}

This is function to draw polylines. But I want that polylines will be automatically storing in "Lines" layer, that is possible ?

Foi útil?

Solução

Your question is a little unclear. Does your 'lines' layer already exist?

If you want your layer to be a featurelayer rather than a graphics layer, then create a featureclass in a workspace, and add your line object to it like this (sorry it's in vb.net):

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

Then create a featurelayer from your featureclass and add it to the map:

Dim pFeatureLayer as IFeatureLayer
pFeatureLayer.FeatureClass = pFeatureClass
pFeatureLayer.Name = "Lines"
Dim pMap as IMap = pMxDoc.FocusMap
pMap.AddLayer(pFeatureLayer)
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top