IFeatureCursor pFeatCursor;
IFeatureClass pfeatClass;
IFeatureLayer pfeatlayer;
IFeature pfeature;
IEnvelope pEnv;
IRgbColor pColor;
stdole.Font pFont;
IPoint pt;
IElement pEle;
ITextElement pTextEle;
IGraphicsContainer pGraphisContainer;
ITextSymbol pTextSymbol;
IActiveView pActiveView;
pfeatlayer = (IFeatureLayer)axMapControl1.get_Layer(0);
pfeatClass = pfeatlayer.FeatureClass;
pFeatCursor = pfeatClass.Search(null, false);
pfeature = pFeatCursor.NextFeature();
int fieldIdx;
int i;
fieldIdx = pfeature.Fields.FindField("CNTRY_NAME");
pColor = new RgbColorClass();
pColor.Blue = 255;
pFont = new stdole.StdFontClass();
pFont.Name = "楷体";
pTextSymbol = new TextSymbolClass();
pTextSymbol.Color = pColor;
pTextSymbol.Font = pFont as stdole.IFontDisp;
pTextSymbol.Size = 10;
pGraphisContainer = axMapControl1.Map as IGraphicsContainer;
pActiveView = axMapControl1.Map as IActiveView;
while (pfeature != null)
{
pEnv = pfeature.Extent;
pt = new PointClass();
pt.PutCoords(pEnv.XMin + pEnv.Width * 0.5, pEnv.YMin + pEnv.Height * 0.5);
pTextEle = new TextElementClass();
pTextEle.Symbol = pTextSymbol;
pTextEle.Text = pfeature.get_Value(fieldIdx).ToString();
pEle = pTextEle as IElement;
pEle.Geometry = pt;
pGraphisContainer.AddElement(pEle, 0);
pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, pEnv);
pt = null;
pTextEle = null;
pfeature = pFeatCursor.NextFeature();
}
string CurrentPath = Directory.GetCurrentDirectory();
Directory.SetCurrentDirectory(CurrentPath + "\\..\\..\\..\\..\\..\\data\\WORLD");
string FilePath = Directory.GetCurrentDirectory();
axMapControl1.AddShapeFile(FilePath, "country.shp");
axMapControl1.AddShapeFile(FilePath, "rivers.shp");
axMapControl1.AddShapeFile(FilePath, "cities.shp");
IMap pMap;
int i;
pMap = axMapControl1.Map;
for (i = 0; i <= pMap.LayerCount - 1; i++)
{
axMapControl2.Map.AddLayer(pMap.get_Layer(i));
}
}
private void axMapControl1_OnMouseDown(object sender, ESRI.ArcGIS.Controls.IMapControlEvents2_OnMouseDownEvent e)
{
if (e.button == 1)
{ axMapControl1.Extent = axMapControl1.TrackRectangle(); }
else if (e.button == 2)
{ axMapControl1.Pan(); }
}
private void axMapControl1_OnExtentUpdated(object sender, IMapControlEvents2_OnExtentUpdatedEvent e)
{
IEnvelope pEnv;
pEnv =(IEnvelope)e.newEnvelope;
IGraphicsContainer pGraphicsContainer;
IActiveView pActiveView;
pGraphicsContainer = axMapControl2.Map as IGraphicsContainer;
pActiveView = pGraphicsContainer as IActiveView;
pGraphicsContainer.DeleteAllElements();
IRectangleElement pRectangelEle;
pRectangelEle = new RectangleElementClass();
IElement pEle;
pEle = pRectangelEle as IElement;
pEle.Geometry = pEnv;
IRgbColor pColor;
pColor = new RgbColorClass();
pColor.Red = 255;
pColor.Transparency = 255;
ILineSymbol pOutline;
pOutline = new SimpleLineSymbolClass();
pOutline.Color = pColor;
pOutline.Width = 2;
pColor = new RgbColorClass();
pColor.Transparency = 0;
IFillSymbol pFillSymbol;
pFillSymbol = new SimpleFillSymbolClass();
pFillSymbol.Color = pColor;
pFillSymbol.Outline = pOutline;
IFillShapeElement pFillshapeEle;
pFillshapeEle = pEle as IFillShapeElement;
pFillshapeEle.Symbol = pFillSymbol;
pEle = pFillshapeEle as IElement;
pGraphicsContainer.AddElement(pEle,0);
pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);
}
private void axMapControl2_OnMouseDown(object sender, IMapControlEvents2_OnMouseDownEvent e)
{
IPoint point = new PointClass();
point.PutCoords(e.mapX, e.mapY);
axMapControl1.CenterAt(point);
}
}
转载请注明原文地址:https://blackberry.8miu.com/read-32921.html