AnsweredAssumed Answered

Add point to created layer C#

Question asked by beniens on Dec 1, 2013
Latest reply on Dec 2, 2013 by beniens
Hi, I developing a tool to create new layer and save points in this layer when clicked to map. Now I can create new layer or add point, both not working and I am wondering, maybe someone could help me.
My code:
here I get coordinates and draw point.
  ESRI.ArcGIS.Display.IDisplayTransformation displayTransformation = screenDisplay.DisplayTransformation;             ESRI.ArcGIS.Geometry.IPoint point = displayTransformation.ToMapPoint(x, y);             screenDisplay.DrawPoint(point);

then I create element, layer, add element to layer and add layer to map.
        IElement elem = null;         elem = point as IElement;         IMap map = activeView.FocusMap;          IGraphicsLayer graphicsLayer;         graphicsLayer = new CompositeGraphicsLayerClass();         ((ILayer)graphicsLayer).Name = "New Layer";         (graphicsLayer as IGraphicsContainer).AddElement(elem, 0);         map.AddLayer(graphicsLayer as ILayer);


I have example code which do the same but create polygon.
ESRI.ArcGIS.Display.IRubberBand rubberBand = new ESRI.ArcGIS.Display.RubberPolygonClass();             ESRI.ArcGIS.Geometry.IGeometry geometry = rubberBand.TrackNew(screenDisplay, symbol);             screenDisplay.SetSymbol(symbol);             screenDisplay.DrawPolygon(geometry);             screenDisplay.FinishDrawing();              IElement elem = null;             IPolygonElement polygonElement = new PolygonElementClass();             elem = polygonElement as IElement;             elem.Geometry = geometry as ESRI.ArcGIS.Geometry.IGeometry;              IMap map = activeView.FocusMap;              IGraphicsLayer graphicsLayer;             if (map.LayerCount == 0)             {                 graphicsLayer = new CompositeGraphicsLayerClass();                 ((ILayer)graphicsLayer).Name = "New Layer";                 (graphicsLayer as IGraphicsContainer).AddElement(elem, 0);                 map.AddLayer(graphicsLayer as ILayer);             }             else             {                 ILayer layer = map.get_Layer(0);                 graphicsLayer = layer as IGraphicsLayer;                 (graphicsLayer as IGraphicsContainer).AddElement(elem, 0);             }              activeView.Refresh();


So maybe someone knows how to solve my problem?

Outcomes