【已测试通过】::ArcGISServer简单查询并高亮显示
简单查询并高亮显示代码(vb.net)::测试通过
.MapResourceManager属性中增加一个名为Selection的MapResource,并将它移动到编号为0的位置,即显示在所有MapResource最上面。
如图添加相关控件:
以下是vb.net代码:(参考Flyingis C#代码http://flyingis.cnblogs.com/)
在Button1_Click添加如下代码
Dim resource_index As Integer = 1
Dim targetlayername As String = "Country"
Dim datatable As System.Data.DataTable = Nothing
'直接获取MapResourceName为world的MapFunctionality,它的编号为1
Dim mf As ESRI.ArcGIS.ADF.Web.DataSources.IMapFunctionality = Map1.GetFunctionality(resource_index)
'先得到functionality,再获取resource
Dim gisresource As ESRI.ArcGIS.ADF.Web.DataSources.IGISResource = mf.Resource
Dim supported As Boolean = gisresource.SupportsFunctionality(GetType(ESRI.ArcGIS.ADF.Web.DataSources.IQueryFunctionality))
If supported = True Then
Dim qfunc As ESRI.ArcGIS.ADF.Web.DataSources.IQueryFunctionality
qfunc = gisresource.CreateFunctionality(GetType(ESRI.ArcGIS.ADF.Web.DataSources.IQueryFunctionality), Nothing)
Dim layerIds() As String = Nothing
Dim layerNames() As String = Nothing
qfunc.GetQueryableLayers(Nothing, layerIds, layerNames)
Dim spatialfilter As New ESRI.ArcGIS.ADF.Web.SpatialFilter()
spatialfilter.ReturnADFGeometries = False
spatialfilter.MaxRecords = 1000
spatialfilter.WhereClause = TextBox2.Text
datatable = qfunc.Query(Nothing, layerIds(3), spatialfilter)
End If
If Not datatable Is Nothing Then
Dim ds As New System.Data.DataSet()
ds.Tables.Add(datatable)
TreeViewPlus1.ShowClearAllButton = False
'//将结果绑定到TreeViewPlus控件上
TreeViewPlus1.BindToDataSet(ds)
TreeViewPlus1.Nodes(0).Expanded = True
End If
'查询结果高亮显示
'重新获得Map1控件所有的functionality
Dim getfunc As IEnumerable = Map1.GetFunctionalities()
Dim gResource As ESRI.ArcGIS.ADF.Web.DataSources.Graphics.MapResource = Nothing
Dim gFunc As IGISFunctionality = Nothing
For Each gFunc In getfunc
'找到名为"Selection"的MapResource
If gFunc.Resource.Name = "selection" Then
'down cast到ESRI.ArcGIS.ADF.Web.DataSources.Graphics.MapResource
gResource = gFunc.Resource
End If
Next
If gResource Is Nothing Then
Return
End If
Dim gLayer As ESRI.ArcGIS.ADF.Web.Display.Graphics.ElementGraphicsLayer = Nothing
Dim dTable As System.Data.DataTable = Nothing
For Each dTable In gResource.Graphics.Tables
If TypeOf dTable Is ESRI.ArcGIS.ADF.Web.Display.Graphics.ElementGraphicsLayer Then
gLayer = dTable
End If
Next
If gLayer Is Nothing Then
gLayer = New ESRI.ArcGIS.ADF.Web.Display.Graphics.ElementGraphicsLayer()
gResource.Graphics.Tables.Add(gLayer)
End If
'清除已有数据
gLayer.Clear()
Dim drs As Data.DataRowCollection = datatable.Rows
Dim shpind As Integer = -1
Dim i As Integer = 0
For i = 0 To (datatable.Columns.Count - 1)
If datatable.Columns(i).DataType Is GetType(ESRI.ArcGIS.ADF.Web.Geometry.Geometry) Then
shpind = i
End If
Next
'Throw an exception
Dim ex0 As New Exception("No geometry available in datatable")
Try
Dim dr As Data.DataRow
For Each dr In drs
Dim geom As ESRI.ArcGIS.ADF.Web.Geometry.Geometry = dr(shpind)
'创建一个GraphicElement
Dim ge As New ESRI.ArcGIS.ADF.Web.Display.Graphics.GraphicElement(geom, System.Drawing.Color.Yellow)
ge.Symbol.Transparency = 50.0
'将GraphicElement添加到ElementGraphicsLayer中
gLayer.Add(ge)
Next
Catch ex As Exception
Throw ex
End Try
If (Map1.ImageBlendingMode = ImageBlendingMode.WebTier) Then
Map1.Refresh()
ElseIf (Map1.ImageBlendingMode = ImageBlendingMode.Browser) Then
'只刷新Graphics Resource
Map1.RefreshResource(gResource.Name)
End If
效果图
![](http://bbs.esrichina-bj.cn/ESRI/attachments/forumid_25/20071113_f910b5dbf66ca5909d3ffFxIitAvzyVk.jpg)
如图添加相关控件:
![](http://bbs.esrichina-bj.cn/ESRI/attachments/forumid_25/20071113_17e1b8de042d59a9c2e5h2pBHRvNcGM0.jpg)
以下是vb.net代码:(参考Flyingis C#代码http://flyingis.cnblogs.com/)
在Button1_Click添加如下代码
Dim resource_index As Integer = 1
Dim targetlayername As String = "Country"
Dim datatable As System.Data.DataTable = Nothing
'直接获取MapResourceName为world的MapFunctionality,它的编号为1
Dim mf As ESRI.ArcGIS.ADF.Web.DataSources.IMapFunctionality = Map1.GetFunctionality(resource_index)
'先得到functionality,再获取resource
Dim gisresource As ESRI.ArcGIS.ADF.Web.DataSources.IGISResource = mf.Resource
Dim supported As Boolean = gisresource.SupportsFunctionality(GetType(ESRI.ArcGIS.ADF.Web.DataSources.IQueryFunctionality))
If supported = True Then
Dim qfunc As ESRI.ArcGIS.ADF.Web.DataSources.IQueryFunctionality
qfunc = gisresource.CreateFunctionality(GetType(ESRI.ArcGIS.ADF.Web.DataSources.IQueryFunctionality), Nothing)
Dim layerIds() As String = Nothing
Dim layerNames() As String = Nothing
qfunc.GetQueryableLayers(Nothing, layerIds, layerNames)
Dim spatialfilter As New ESRI.ArcGIS.ADF.Web.SpatialFilter()
spatialfilter.ReturnADFGeometries = False
spatialfilter.MaxRecords = 1000
spatialfilter.WhereClause = TextBox2.Text
datatable = qfunc.Query(Nothing, layerIds(3), spatialfilter)
End If
If Not datatable Is Nothing Then
Dim ds As New System.Data.DataSet()
ds.Tables.Add(datatable)
TreeViewPlus1.ShowClearAllButton = False
'//将结果绑定到TreeViewPlus控件上
TreeViewPlus1.BindToDataSet(ds)
TreeViewPlus1.Nodes(0).Expanded = True
End If
'查询结果高亮显示
'重新获得Map1控件所有的functionality
Dim getfunc As IEnumerable = Map1.GetFunctionalities()
Dim gResource As ESRI.ArcGIS.ADF.Web.DataSources.Graphics.MapResource = Nothing
Dim gFunc As IGISFunctionality = Nothing
For Each gFunc In getfunc
'找到名为"Selection"的MapResource
If gFunc.Resource.Name = "selection" Then
'down cast到ESRI.ArcGIS.ADF.Web.DataSources.Graphics.MapResource
gResource = gFunc.Resource
End If
Next
If gResource Is Nothing Then
Return
End If
Dim gLayer As ESRI.ArcGIS.ADF.Web.Display.Graphics.ElementGraphicsLayer = Nothing
Dim dTable As System.Data.DataTable = Nothing
For Each dTable In gResource.Graphics.Tables
If TypeOf dTable Is ESRI.ArcGIS.ADF.Web.Display.Graphics.ElementGraphicsLayer Then
gLayer = dTable
End If
Next
If gLayer Is Nothing Then
gLayer = New ESRI.ArcGIS.ADF.Web.Display.Graphics.ElementGraphicsLayer()
gResource.Graphics.Tables.Add(gLayer)
End If
'清除已有数据
gLayer.Clear()
Dim drs As Data.DataRowCollection = datatable.Rows
Dim shpind As Integer = -1
Dim i As Integer = 0
For i = 0 To (datatable.Columns.Count - 1)
If datatable.Columns(i).DataType Is GetType(ESRI.ArcGIS.ADF.Web.Geometry.Geometry) Then
shpind = i
End If
Next
'Throw an exception
Dim ex0 As New Exception("No geometry available in datatable")
Try
Dim dr As Data.DataRow
For Each dr In drs
Dim geom As ESRI.ArcGIS.ADF.Web.Geometry.Geometry = dr(shpind)
'创建一个GraphicElement
Dim ge As New ESRI.ArcGIS.ADF.Web.Display.Graphics.GraphicElement(geom, System.Drawing.Color.Yellow)
ge.Symbol.Transparency = 50.0
'将GraphicElement添加到ElementGraphicsLayer中
gLayer.Add(ge)
Next
Catch ex As Exception
Throw ex
End Try
If (Map1.ImageBlendingMode = ImageBlendingMode.WebTier) Then
Map1.Refresh()
ElseIf (Map1.ImageBlendingMode = ImageBlendingMode.Browser) Then
'只刷新Graphics Resource
Map1.RefreshResource(gResource.Name)
End If
效果图
![点击在新窗口查看全图
CTRL+鼠标滚轮放大或缩小](http://bbs.esrichina-bj.cn/ESRI/attachments/forumid_25/20071113_9cde67be1fb6f1aadfe1xcqRf8XDf077.jpg)
![点击在新窗口查看全图
CTRL+鼠标滚轮放大或缩小](http://bbs.esrichina-bj.cn/ESRI/attachments/forumid_25/20071113_f7709e8853f55a76426c0UpbQ3igX1AM.jpg)
![点击在新窗口查看全图
CTRL+鼠标滚轮放大或缩小](http://bbs.esrichina-bj.cn/ESRI/attachments/forumid_25/20071113_6261272ce488f1eff9acjmosWchZ1EHe.jpg)