Code
//获得属性值
string ManagerId = dgvK001.Rows[e.RowIndex].Cells[0].Value.ToString();
string RoadId = dgvK001.Rows[e.RowIndex].Cells[2].Value.ToString();
if (RoadId.IndexOf("S") != -1 || RoadId.IndexOf("G") != -1)
RoadId = RoadId.Substring(0, 4);
string StartStake = dgvK001.Rows[e.RowIndex].Cells[5].Value.ToString();
//遍历整个地图
for (int i = 0; i < axMapControl.LayerCount; i++)
{
IFeatureLayer pLayer = null;
IFeatureClass iFeatureClass = null;
//获得图层
pLayer = (IFeatureLayer)axMapControl.get_Layer(i);
iFeatureClass = pLayer.FeatureClass;
//定义AE游标
IFeatureCursor pCursor;
//构建查询条件
IQueryFilter pFilter = new QueryFilterClass();
//多字段查询
pFilter.WhereClause = " LXBM = '" + RoadId.Trim() + "'" + " AND DWDM = '" + ManagerId.Trim() + "'" + " AND QDZH=" + StartStake.Trim() + "";
try
{
pCursor = iFeatureClass.Search(pFilter, false);
IFeature pFeature;
//获得查询的元素
pFeature = pCursor.NextFeature();
if (pFeature != null)
{
//要素的定义,如果是点直接定位
if (pFeature.Shape.GeometryType == esriGeometryType.esriGeometryPoint)
{
this.axMapControl.CenterAt((IPoint)pFeature.Shape);
}
else
{
//获得定位的范围
IEnvelope pEnv = pFeature.Shape.Envelope;
pEnv.Expand(5, 5, true);
axMapControl.ActiveView.Extent = pEnv;
}
axMapControl.ActiveView.Refresh();
axMapControl.ActiveView.ScreenDisplay.UpdateWindow();
//用于解决先定位后闪烁的问题
//自定义闪烁功能
switch (pFeature.Shape.GeometryType)
{
case esriGeometryType.esriGeometryPoint:
FlashFeature.FlashPoint(axMapControl, axMapControl.ActiveView.ScreenDisplay, pFeature.Shape);
break;
case esriGeometryType.esriGeometryPolyline:
FlashFeature.FlashLine(axMapControl, axMapControl.ActiveView.ScreenDisplay, pFeature.Shape);
break;
case esriGeometryType.esriGeometryPolygon:
FlashFeature.FlashPolygon(axMapControl, axMapControl.ActiveView.ScreenDisplay, pFeature.Shape);
break;
default:
break;
}
axMapControl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeoSelection, null, null);
axMapControl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null);
break;
}
}
catch { }
}
这边要注意的是你需要定位的图层必须要有你需要查询的属性,在遍历整个地图的话则比较难统一字段,所以在获得元素的地方需要Catch掉容错.
图层也可以直接定义,假如你知道的话.
【推荐】腾讯云新用户域名抢购1元起,抓紧抢购
· 精准率首次超过人类!阿里巴巴机器阅读理解打破世界纪录
· 技术帖:每天被今日头条推送文章 背后的算法技术是什么?
· 支付宝实体版老黄历问世:全球限量1000册
· 趣店被蚂蚁金服送上纽交所,现在是时候该独立了
· 蚂蚁宝卡升级:支付宝/微博即将免流
» 更多新闻...
· 以操作系统的角度述说线程与进程
· 软件测试转型之路
· 门内门外看招聘
· 大道至简,职场上做人做事做管理