MySQL supports spatial extensions to enable the generation, storage, and analysis of geographic features. Additional information is available at


AspMap supports the Geometry data type. The MySqlLayer class can be used to access and edit such spatial data. A sample table in a MySQL database may look as the following:

NAME            TYPE
ID              int(11) AUTO_INCREMENT
GEOM              geometry
CITY_NAME        varchar(40)
STATE_NAME      varchar(25)
POPULATION      decimal(9,0)



The GEOM field stores shapes in the MySQL Geometry data format. The GEOM field has a spatial index (SPATIAL KEY GEOM) which is required to speed up spatial queries (for fast map rendering).


The ADO.NET framework does not have a built-in provider for MySQL. The MySQL Connector/Net provider (or any other MySQL provider) is required. The Connector/Net provider can be downloaded at


Create a MySqlLayer object and pass the connection string, table name and GEOM field to its constructor. It is also necessary to specify the FieldList property if you need attribute data for labeling or editing.


Add the MySqlLayer to the Map control using the AddLayer method:

Imports MySql.Data
Imports AspMap
Imports AspMap.Data

Dim connectionString As String = "Server=localhost;Database=DB;Uid=username;Pwd=password;"
Dim tableName As String = "cities"
Dim providerName As String = "MySql.Data.MySqlClient"

Dim mySqlLayer As MySqlLayer 

mySqlLayer = New MySqlLayer(providerName, connectionString, tableName, "GEOM")
mySqlLayer.FieldList = "ID, CITY_NAME, POPULATION"

Dim layer As Layer = map.AddLayer(mySqlLayer)


The MySqlLayer class supports editing of data as described in the Editing Spatial and Attribute Data topic.


Note: If you use only database layers in your application, it must be necessary to specify the extent of each database layer. By default, the extent is set to (-180,90,180,-90) where the units are decimal degrees. The extent of a database layer can be set via the Extent property. If an incorrect extent is set, the database layer will not be visible.



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