Bruce Thomas

MapObjects, Databases, and Internet Connectivity

The King County GIS Center WWW map server has multiple browser windows allowing users to navigate a map image and query public agency databases associated with map features. A drop down list showing GIS layers on the map window identifies attributes in a data sheet window. This paper reviews the development of this map server design using MapObjects, MapObjects Internet Map Server (IMS), HTML, ECMAScript (JavaScript), Oracle, and Internet Information Server. In general, map servers are initialized with metadata about GIS layers, symbology, and available feature attributes before responding to browser clients. Each map server is supported by an ActiveX DLL developed by King County using Visual Basic 6. This DLL encapsulates the map server metadata in an object hierarchy along with MapObjects 2/IMS 2 functionality, ADO database connections, and HTML templates.


King County GIS Center Map Portal

The King County GIS Center has developed a web map portal, a series of inter-dependent and inter-linked map servers that allow spatial query of GIS themes maintained by King County. Each map server shares a common user interface, allowing a user to link between different map themes while maintaining a selected area of interest. An HTML interface maintains the area of interest through URL encoded map parameters.

The map portal is meant to serve basic desktop GIS needs of many county agencies in the near future by allowing users to perform spatial queries on map themes pre-defined by metadata. The map portal is extensible in the sense that new map themes and spatial queries can be added to the metadata for new map servers. Since the map portal is web based, only a web browser is required to access the map portal from the client's desktop.

Each map server is started with Active X components that read metadata about the contents of the map server. Each new map server is started by creating a new set of metadata and reading it with the map generator components. Once started, users can connect to the map server through the Internet. The contents of a map server can be adjusted by changing the metadata and restarting the map server.

The map portal is under final development at this time and some of this information may change in the near future. Please be sure to check the main page for the map portal at:

http://www.metrokc.gov/dias/its/gis/mapportal/index.htm

Map Portal Interface

The user interface is a panel that appears in the web browser as shown below. This map interface has several drop down menus and a tool bar above the map image and a location map on the left side. The user can find a map point by looking up an address or zooming and panning. The map portal includes several pre-defined map scales; these are represented by the button bar between the zoom in and zoom out buttons ( the + and - icons under the drop down that currently shows the 'King County' as the current map scale.) The drop down menu for 'Map Tools' is not fully functional at this time, but will be implemented in the near future.

test 6

The list under the location map shows the map theme and the map layers available for spatial query. Other map servers are listed under the 'Map Portals' drop down list. A dynamic scale bar appears below the map image. The map image shown above is a spatially registered key map that appears at the full county scale.

A separate browser window displays spatial query results. For instance, here is the query result for a user map click on a section of street in the map display. It reports the name, address range, and zip code for the street section.
 

Street Address Range
Street Name 77th Ave SE
Left From Address 2700
Left To Address 2898
Right From Address 2701
Right To Address 2899
Left Zipcode 98040
Right Zipcode 98040

This table would appear in a separate browser window that pops up after the user clicks on the street section to identify. This separate window is called a data sheet. Data sheets are discussed below.

Map Portal Architecture

The map servers are supported by Active X components, written in Visual Basic, that encapsulate the map server classes discussed below. The map server metadata contains enough information to instantiate objects from these Active X DLLs when the map server is started. Each class in turn depends upon some functionality from MapObjects, IMS, ADO, and other third party Active X components.

test 1

In general, web browsers connect to a web server that passes an HTTP request to the selected map server. The map server handles spatial operations by calling MapObjects methods, and passes database queries to an Oracle 7.3 database with an SQL command. The results are returned to the map server which generates a new HTML page which is returned to the client through the web server.

Metadata Collections

The map themes, base map layers, and data sheets for each map server are specified in metadata tables. Each map server contains lists of spatial layers, database connections, HTML templates, and links to other map servers. This metadata determines which map layers are displayed by a map server as well as the query results returned for each map server theme.

test 4

The diagram shows an Object Role Model (ORM) of the metadata collections for a map server. Each map server starts with a root object, identified by a unique tag. This root object reads the metadata to fill its collections. The metadata supplies the elements for each of these collections. For instance, a web map server with a given tag has a collection of URLs for the other web map servers that a user can link to from this map server.

Each web map server with a given tag also has a collection of layer sources, each identified by a unique tag. These map layers are drawn on the MapObjects map control, and some layers also allow spatial queries. A data sheet represents the HTML template for the results of a spatial query; each map server will have several of these data sheets, at least one for each layer with an available spatial query. Most spatial queries involve both map layers and database attributes associated with layer features. Each database connection for a map server is supported by an ADO Connection. The metadata for each database connection has enough information for the map server to create this ADO Connection in its own collection.

All of these collections are implemented with the Visual Basic collection data type. Each member of each collection is uniquely identified by an object tag.

Database Connections

When a map server has a spatial theme with attributes in a relational database such as Oracle 7.3, then the metadata must specify this association. The association between a map layer and its database attributes is supported by an ADO connection that remains open during the life-time of the map server.
 
test 3 Databases supply initial parameters for starting a web map server process.
Client requests map image and feature information from web server.
Server queries connected databases, makes map, and returns formatted results.
Databases respond to map server queries.

The sample VB code below shows how the map server performs an SQL query on a connected database for attributes of a selected map layer feature.
 

' VB Variables (in order of appearance):
'   oADOConn         ADO Connection object
'   oDatabase        object from database collection
'   oMORecordset     MapObjects Recordset object
'   oMOKey           MapObjects Field object
'   sLayerKeyName    name of key item in layer
'   sKeyValue        value of the key item for selected feature
'   sCriteria        portion of SQL query string
'   sDataKeyName     name of key item in database table
'   oADOCmd          ADO Command object
'   sTableName       name of database table with layer attributes
'   oADORecordset    ADO Recordset object

' 1. Get the open database connection

 Set oADOConn = oDatabase.ADOConnection

' 2. Set selected feature from map layer recordset.

 oMORecordset.MoveFirst

' 3. Make an SQL string with map layer key and database key.

 Set oMOKey = oMORecordset.Fields(sLayerKeyName)
 sKeyValue = oMOKey.ValueAsString
 sCriteria = sDataKeyName & " = '" & sKeyValue & "'"

' 4. Get the ADO recordset for the selected spatial feature

 Set oADOCmd = New ADODB.Command
 oADOCmd.CommandText = "SELECT * FROM " & sTableName & " WHERE " & sCriteria
 oADOCmd.CommandType = adCmdText
 Set oADOCmd.ActiveConnection = oADOConn
 Set oADORecordset = oADOCmd.Execute

' The database record in ADO Recordset now matches the map feature record

The ADO Connection object in step 1 points to the database with map layer attributes; the selected map feature is passed through a MapObjects Recordset object in step 2. The SQL query is started in step 3; it assumes that a key item exists in both the map layer and the database table. The value of the key item will be in the Fields collection of the MapObjects Recordset from step 2. The query on the database is completed in step 4 using an ADO Command object that returns an ADO Recordset. This ADO Recordset will have the attributes for the selected map feature. Since the key item should be unique in the related database table, there should only be one record in the ADO Recordset. Further processing on the fields of this recordset will yield the related attributes.

HTML Templates

The Unified Modeling Language (UML) diagram below shows the organization of VB classes that support the generation of HTML that a user sees in the web browser windows. All the HTML classes implement the HTMLSource interface. The HTMLSource interface allows easy construction of HTML content before passing it back to the client. The HTMLPage is the root class; it contains and organizes references to all the other HTML classes. The map server need only pass a collection of variables to the HTMLPage object, and it will construct the response to a client map request and return the new HTML map page to the client through the web server.

test 5

The HTMLLayerResult class in the lower right of the diagram constructs the results of a spatial query in a separate HTML page that is loaded in the data sheet browser window. The HTMLLayerResult class displays the collection of variables that contain the results of the spatial query against a map layer and its associated database connections. The map server data sheets are produced by the HTMLLayerResult class.

Map Server Model

Here is the UML overview of the map server class structure. Some subordinate classes have been left off the diagram to preserve clarity. The KGCMap class, in the center, is the root for every map server; MapFormX is a Visual Basic form module that contains the MapObjects Map control for the map server. Each map server instantiates its own set of classes as shown in this diagram and populates the properties from metadata. The metadata collections for map layers, database connections, and data sheets are represented by classes on the far right side of the diagram, along with a class that helps the map server start and the URL links to other map servers. The Generator module at the top middle is used to start map servers from the command line.

test 7

The left side of the diagram shows the HTMLPage class and the IMS WebLink control which is also contained on the MapFormX form. The MapForm interface, top left, represents the HTML FORM element that encapsulates a user's current map parameters as URL encoded name, value pairs. This URL encoded data is passed back to the map server with each client request for a map page.

Each map request raises an event that the KGCMap module responds to. The URL encoded parameters of each map request are used by the KGCMap module to generate a new map page according to the request. Each map server listens to a single IP port registered with IMS. Each map server is registered with a different IP port number. When one map server connects to another, it passes its URL encoded parameters through IMS to the other. Since all map servers in the map portal use the same URL encoded parameters, each map server can link to any of the others.

Client-Side JavaScript

Each map server is dependent upon JavaScript that runs on the client web browser. Client-side scripting serves two basic purposes: first, it controls the user interaction with the map panel in the web browser; and second, it helps formulate the URL encoded map parameters that are passed back to the map server with a client request. Further discussion of this client-side scripting is beyond the scope of this report.

Conclusion

Map Objects and Visual Basic are an excellent development combination for web map servers with database connections. The Microsoft ADO library provides simple and convenient objects for creating and using database connections with Map Objects in VB. The King County GIS Center has been able to include database connections associated with map layers, encapsulated in an Active X DLL for the map servers that support the King County GIS Center Map Portal.

This makes the map portal very extensible. By design, it is meant to easily implement new map servers by simply adding metadata for the new map servers and starting a new instance of the map generator components. This metadata defines not only the map layers that will display on the map, but also the attributes that will be displayed in a data sheet after running a spatial query that reads attributes from a connected database.

References

Goodman, Danny, Dynamic HTML:The Definitive Reference, O'Reilly, 1998
MapObjects Internet Map Server: Using MapObjects on the Internet, Esri, 1998.
MapObjects: Programmer's Reference, Esri, 1999.
Microsoft Software Developer's Network, 1999-2000.

Bruce Thomas
bruceth@microsoft.com
GIS Programmer, King County GIS Center
Seattle, Washington, USA