//Get the coordinates IPoint newSite = new Point(); IActiveView activeView = ArcMap.Document.ActiveView; IScreenDisplay screenDisplay = activeView.ScreenDisplay; IPoint clickedPoint = screenDisplay.DisplayTransformation.ToMapPoint(arg.X, arg.Y); newSite.PutCoords(clickedPoint.X, clickedPoint.Y); newSite.SpatialReference = clickedPoint.SpatialReference; //Reproject if required if (newSite.SpatialReference.Name != "GCS_North_American_1983") { //Reprojeter ISpatialReferenceFactory srFactory = new SpatialReferenceEnvironment(); ISpatialReference sr; IGeographicCoordinateSystem gcs = srFactory.CreateGeographicCoordinateSystem((int)esriSRGeoCSType.esriSRGeoCS_NAD1983); sr = gcs; newSite.Project(sr); } //... //Skip a long and boring part where I determine strings to edit attributes... //... //Get the Layer ILayer layerPlants = FindLayer("Plants Lucie"); //Note : the FindLayer function loops through the datasets, and then through the layers, to return an ILayer //Get the Feature Class IFeatureLayer featurelayerPlants = layerPlants as IFeatureLayer; IFeatureClass featureclassPlants = featurelayerPlants.FeatureClass; //Make sure the FeatureClass has a proper geometry (point) if (featureclassPlants.ShapeType == esriGeometryType.esriGeometryPoint) { //Create the point IFeature plant = featureclassPlants.CreateFeature(); plant.Shape = newSite; //... //Boring part where I edit the point attributes //... //Commit du nouveau point plant.Store(); //Refresh the active view to see the new point activeView.Refresh(); }
The active view of a document can be either the map or the page layout depending on which view the document is in. If you want your tool to only work on the map then get your active view reference from the document's focus map reference instead of its active view reference.
IActiveView activeView = ArcMap.Document.ActiveView;
Change the line above to get the focus map instead of the active view. When the document is in layout view then your tool will only respond to clicks on the map and will ignore clicks on the layout.
IActiveView activeView = ArcMap.Document.ActiveView;
IMap focusMap = ArcMap.Document.FocusMap;
IScreenDisplay screenDisplay = activeView.ScreenDisplay; IPoint clickedPoint = screenDisplay.DisplayTransformation.ToMapPoint(arg.X, arg.Y);
You should have changed this line:
IActiveView activeView = ArcMap.Document.ActiveView;
To this:
IActiveView activeView = ArcMap.Document.FocusMap As IActiveView;