Â
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);
case esriGeometryType.esriGeometryPolygon:
FlashFeature.FlashPolygon(axMapControl, axMapControl.ActiveView.ScreenDisplay, pFeature.Shape);
default:
axMapControl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeoSelection, null, null);
axMapControl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null);
break;
}
}
catch { }
}
这边要注意的是你需要定位的图层必须要有你需要查询的属性,在遍历整个地图的话则比较难统一字段,所以在获得元素的地方需要Catch掉容错.
图层也可以直接定义,假如你知道的话.
版权说明
如果标题未标有<转载、转>等字则属于作者原创,欢迎转载,其版权归作者和博客园共有。
作 者:温景良
<a href="http://home.cnblogs.com/u/wenjl520/">温景良(Jason)</a>
<a href="http://home.cnblogs.com/u/wenjl520/followees">关注 - 32</a>
<a href="http://home.cnblogs.com/u/wenjl520/followers">粉丝 - 161</a>
<a>+加关注</a>
<a></a>
<a href="http://www.ucancode.com/index.htm" target="_blank">【推荐】超50万VC++源码: 大型工控、组态\仿真、建模CAD源码2018!</a>
<a href="https://dnspod.cloud.tencent.com/act/yearendsales?from=IT&fromSource=gwzcw.741110.741110.741110" target="_blank">【推荐】腾讯云新用户域名抢购1元起,抓紧抢购</a>
<b>最新IT新闻</b>:
<b>最新知识库文章</b>: