Identifying Features Using the InfoWindow Tool


Objective: In this lesson, you will learn how to identify features using the InfoWindow tool.

 

The InfoWindow tool allows the user to click on a feature and see information about the feature in a popup window without reloading the page or the map image (the InfoWindow tool uses AJAX to send requests to the server):

 

To incorporate this functionality into your application, you need to do the following:

 

1. Add a MapToolButton control above the Map control on the form and call it infoWindowTool. Change the Map property to Map1, the MapTool property to InfoWindow, the ImageUrl property to "tools/infowindow.gif". 

Ê The InfoWindow tool allows you to pan the map (as the Pan tool) without changing the current map tool, this can be useful if you need to move the map slightly during identifying features.


2. Add an event handler for the InfoWindowTool event of Map1 and add the following code. The code uses the Identify method to find features. To display the results, the code uses a InfoWindow object that is passed into the InfoWindowTool event as the InfoWindowToolEventArgs.InfoWindow property.

Ê The InfoWindow class is derived from the Panel control and allows you to specify the appearance of the popup window.  Also, you can add Web controls to the InfoWindow class to display the found records inside the window.

 

Protected Sub Map1_InfoWindowTool(ByVal sender As Object, ByVal e As InfoWindowToolEventArgs) Handles Map1.InfoWindowTool

        Dim records As AspMap.Recordset = Map1.Identify(e.InfoPoint, 5)

        If (Not records.EOF) Then
            ' set the appearance of the InfoWindow object
            e.InfoWindow.Width = 300
            e.InfoWindow.Height = 120
            e.InfoWindow.HorizontalAlign = HorizontalAlign.Center
            e.InfoWindow.Font.Bold = True
            e.InfoWindow.ScrollBars = System.Web.UI.WebControls.ScrollBars.Auto

            ' create a DataGrid control to display the records
            Dim grid As DataGrid = New DataGrid()
            grid.DataSource = records
            grid.DataBind()

            ' add the DataGrid control to the InfoWindow object
            e.InfoWindow.Controls.Add(grid)

            ' set the content of the InfoWindow object
            If records.Layer.LabelField.Length > 0 Then
                e.InfoWindow.Content = records(records.Layer.LabelField).ToString()
            Else
                e.InfoWindow.Content = records(0).ToString()
            End If
        End If
End Sub

 

3. Compile and run the application, after selecting the InfoWindow tool and clicking on a feature, your map should look similar to the image below:

 

 

 

© 2018 VDS Technologies
Converted from CHM to HTML with chm2web Standard 2.85 (unicode)