Hello everyone.
I have developed a tool with Visual Studio 2010, which inserts an image. Tif to give the user click in the area of view of ArcMap, the image is inserted into the TOC but no picture in the area of view, but to move your mouse to pan tool, you can view the picture but remains visible in the area of view.
I attached the script.
regards
Ivan
++++++ script
protected override void OnMouseDown(ESRI.ArcGIS.Desktop.AddIns.Tool.MouseEventArgs arg)
{
IMxDocument mxdoc = ArcMap.Document;
ESRI.ArcGIS.Display.IScreenDisplay screenDisplay = mxdoc.ActiveView.ScreenDisplay;
punto = screenDisplay.DisplayTransformation.ToMapPoint(arg.X, arg.Y);
string dir = @"\\Miserver\imagenes\";
ESRI.ArcGIS.Carto.IActiveView activeView = mxdoc.ActivatedView;
screenDisplay.StartDrawing(screenDisplay.hDC, (System.Int16)
ESRI.ArcGIS.Display.esriScreenCache.esriNoScreenCache); // Explicit cast.
ESRI.ArcGIS.Display.ISimpleMarkerSymbol simpleMarkerSymbol = new
ESRI.ArcGIS.Display.SimpleMarkerSymbolClass();
ESRI.ArcGIS.Display.ISymbol symbol = simpleMarkerSymbol as
ESRI.ArcGIS.Display.ISymbol; // Dynamic cast.
screenDisplay.SetSymbol(symbol);
ESRI.ArcGIS.Display.IDisplayTransformation displayTransformation =
screenDisplay.DisplayTransformation;
IWorkspace espacio = VersionedArcSdeWorkspace("MiserverGis", "sde:sqlserver:MiserverGis", "MiBaseGis", "dbo.DEFAULT");
IFeatureWorkspace featureWorkspace = (IFeatureWorkspace)espacio;
IFeatureClass featureClass = featureWorkspace.OpenFeatureClass("MiBaseGis.dbo.Grilaimg");
IGeometry queryGeometry = punto;
// Create the spatial filter. "highwayFeatureClass" is the feature class containing
// the highway data. Set the SubFields property to "FULL_NAME", as only that field is
// going to be displayed.
ISpatialFilter spatialFilter = new SpatialFilterClass();
spatialFilter.Geometry = queryGeometry;
spatialFilter.GeometryField = featureClass.ShapeFieldName;
spatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects;
spatialFilter.SubFields = "NH";
// Find the position of the "FULL_NAME" field in the highway feature class.
int nameNH = featureClass.FindField("NH");
// Execute the query and iterate through the cursor's results.
IFeatureCursor highwayCursor = featureClass.Search(spatialFilter, false);
IFeature highwayFeature = null;
string varNh = string.Empty;
string hoja = string.Empty;
if ((highwayFeature = highwayCursor.NextFeature()) != null)
{
varNh = highwayFeature.get_Value(nameNH).ToString();
Type factoryType = Type.GetTypeFromProgID("esriDataSourcesRaster.RasterWorkspaceFactory");
IWorkspaceFactory wsFactory = (IWorkspaceFactory)Activator.CreateInstance(factoryType);
IRasterWorkspace2 rasterWS = (IRasterWorkspace2)wsFactory.OpenFromFile(dir,0);
IRasterDataset rds = rasterWS.OpenRasterDataset("h"+varNh + ".tif");
IRasterLayer rasterLayer = new RasterLayerClass();
rasterLayer.CreateFromDataset(rds);
IMap mapa = activeView.FocusMap;
mapa.AddLayer(rasterLayer);
activeView.Refresh();
}
else MessageBox.Show("image not found.");
}