private void axMapControl1_OnMouseMove(object sender, IMapControlEvents2_OnMouseMoveEvent e)
{
axMapControl1.ShowMapTips = true;
IFeatureLayer pFeatureLayer = axMapControl1.Map.get_Layer(0) as IFeatureLayer;
pFeatureLayer.DisplayField = "Name";
pFeatureLayer.ShowTips = true;
}
private void axMapControl1_OnMouseMove(object sender, IMapControlEvents2_OnMouseMoveEvent e)
{
IFeatureLayer pFeatureLayer = axMapControl1.Map.get_Layer(0) as IFeatureLayer;
pFeatureLayer.DisplayField = "Name";
pFeatureLayer.ShowTips = true;
string pTip;
pTip = pFeatureLayer.get_TipText(e.mapX, e.mapY, axMapControl1.ActiveView.FullExtent.Width / 10000);
if (pTip != null)
{
toolTip1.SetToolTip(axMapControl1, "名称:" + pTip);
}
else //当 ToolTip 空间显示的内容为 null 的时候,就不会显示了!相当于隐藏了!
{
toolTip1.SetToolTip(axMapControl1, "");
}
}
选择要素
private void axMapControl1_OnMouseDown(object sender, IMapControlEvents2_OnMouseDownEvent e)
{
axMapControl1.MousePointer = esriControlsMousePointer.esriPointerDefault;
IMap pMap = axMapControl1.Map;
IGeometry pGeometry = axMapControl1.TrackRectangle(); //获取框选几何
ISelectionEnvironment pSelectionEnv = new SelectionEnvironment(); //新建选择环境
IRgbColor pColor = new RgbColor();
pColor.Red = 255;
pSelectionEnv.DefaultColor = pColor; //设置高亮显示的颜色!
pMap.SelectByShape(pGeometry, pSelectionEnv, false); //选择图形!
axMapControl1.Refresh(esriViewDrawPhase.esriViewGeoSelection, null, null);
}
IFeatureLayer pFeatureLayer = axMapControl1.Map.get_Layer(0) as IFeatureLayer;
IFeatureLayerDefinition pFeatLyrDef = pFeatureLayer as IFeatureLayerDefinition; //新建 IFeatureLayerDefinition 接口实例
pFeatLyrDef.DefinitionExpression = "Area > 20"; //定义筛选条件
axMapControl1.ActiveView.Refresh();
IFeatureLayer pFeatureLayer = axMapControl1.Map.get_Layer(0) as IFeatureLayer;
IFeatureLayerDefinition pFeatLyrDef = pFeatureLayer as IFeatureLayerDefinition;
pFeatLyrDef.DefinitionExpression = "Area > 20";
axMapControl1.ActiveView.Refresh(); //重新定义的图层
IQueryFilter pQueryFilter = new QueryFilter();
pQueryFilter.WhereClause = "POP > 10";
IFeatureSelection pFeatSel = pFeatureLayer as IFeatureSelection;
pFeatSel.SelectFeatures(pQueryFilter, esriSelectionResultEnum.esriSelectionResultNew, false);
axMapControl1.Refresh(esriViewDrawPhase.esriViewGeoSelection, null, null); //在新定义图层的基础上进行的查询
IFeatureLayer pNewFeat = pFeatLyrDef.CreateSelectionLayer("New Layer", true, null, null); //新建的图层包括上面两者的交集部分!
pFeatSel.Clear();
axMapControl1.Map.AddLayer(pNewFeat);
MessageBox.Show(axMapControl1.Map.LayerCount.ToString());
IFeatureLayer pFeatureLayer = axMapControl1.Map.get_Layer(0) as IFeatureLayer;
IQueryFilter pQueryFilter = new QueryFilter(); //建立查询
pQueryFilter.WhereClause = "POP > 10";
IFeatureSelection pFeatSel = pFeatureLayer as IFeatureSelection; //新建 IFeatureSelection 接口实例
pFeatSel.SelectFeatures(pQueryFilter, esriSelectionResultEnum.esriSelectionResultNew, false); //实现方法,选择筛选的部分!
axMapControl1.Refresh(esriViewDrawPhase.esriViewGeoSelection, null, null);