protected override void OnMouseDown(MouseEventArgs arg) { IMxDocument mxDocument = ArcMap.Application.Document as IMxDocument; // Get reference to the current map IMap map = mxDocument.FocusMap; IPoint userPoint = null; if (m_Position != null) userPoint = m_Position; else { IDisplayTransformation dispTransformation = mxDocument.ActiveView.ScreenDisplay.DisplayTransformation; userPoint = dispTransformation.ToMapPoint(arg.X, arg.Y); } bool isPolylineLayer = false; IActiveView activeView = mxDocument.ActiveView; // Get the TOC IContentsView IContentsView = mxDocument.CurrentContentsView; //Set the featureLayer IGeoFeatureLayer featureLayer = null; // Get the selected layer System.Object selectedItem = IContentsView.SelectedItem; if (selectedItem is IGeoFeatureLayer) { featureLayer = selectedItem as IGeoFeatureLayer; //Check to make sure that the selected layer is a polyline layer if (featureLayer.FeatureClass.ShapeType == esriGeometryType.esriGeometryPolyline) { isPolylineLayer = true; } } //Only preform these actions if user selected a polyline layer if (isPolylineLayer) { if (activeView != null) { IScreenDisplay screenDisplay = activeView.ScreenDisplay; IRubberBand rubberBand = new RubberLineClass(); IGeometry geometry = rubberBand.TrackNew(screenDisplay, null); //We need to make the geometry zaware to keep from getting an error during AddPolylineToGeoDatabase MakeZAware(geometry); IPointCollection pointCollection = (IPointCollection)geometry; Point pointClass = new Point(); //Loops through all the points on the polyline and gives it a Z value of 0 or its //actual z value if a user clicked a point where that was known for (int i = 0; i < pointCollection.PointCount; i++) { IPoint tempPoint = pointClass.AddZToPoint(pointCollection.get_Point(i)); pointCollection.UpdatePoint(i, tempPoint); } IPolyline polyline = (IPolyline)pointCollection; AddPolylineToGeoDatabase(featureLayer, polyline, mxDocument); } } }
Solved! Go to Solution.
protected override void OnMouseDown(MouseEventArgs arg) { // Get reference to the current map IMap map = mxDocument.FocusMap; IPoint userPoint = null; if (m_Position != null) userPoint = m_Position; else { IDisplayTransformation dispTransformation = mxDocument.ActiveView.ScreenDisplay.DisplayTransformation; userPoint = dispTransformation.ToMapPoint(arg.X, arg.Y); } if (m_NewLineFeedback == null) { m_NewLineFeedback = new NewLineFeedbackClass(); IScreenDisplay screenDisplay = activeView.ScreenDisplay; m_NewLineFeedback.Display = screenDisplay; m_PointCollect = new PolylineClass(); m_NewLineFeedback.Start(userPoint); m_PointCollect.AddPoint(userPoint); } else { m_NewLineFeedback.AddPoint(userPoint); m_PointCollect.AddPoint(userPoint); } }
protected override void OnMouseDown(MouseEventArgs arg) { // Get reference to the current map IMap map = mxDocument.FocusMap; IPoint userPoint = null; if (m_Position != null) userPoint = m_Position; else { IDisplayTransformation dispTransformation = mxDocument.ActiveView.ScreenDisplay.DisplayTransformation; userPoint = dispTransformation.ToMapPoint(arg.X, arg.Y); } if (m_NewLineFeedback == null) { m_NewLineFeedback = new NewLineFeedbackClass(); IScreenDisplay screenDisplay = activeView.ScreenDisplay; m_NewLineFeedback.Display = screenDisplay; m_PointCollect = new PolylineClass(); m_NewLineFeedback.Start(userPoint); m_PointCollect.AddPoint(userPoint); } else { m_NewLineFeedback.AddPoint(userPoint); m_PointCollect.AddPoint(userPoint); } }