StreetMap Template


 

Overview

The StreetMap template allows you to incorporate a street map of your region into your ASP.NET application. The template uses freely available map data from OpenStreetMap. The template uses map caching, and requires only a few lines of code. The template  has the following structure:

 

/App_Code/StreetMap.cs - the source code of the template
/App_Data/StreetMap - the map data directory
/App_Data/StreetMap/World.shp - the background map of the world
/TileCache - the tile cache directory

 

A sample that demonstrates the template can be found in the AspMap samples directory (StreetMap.aspx).

 

Map Data

The template uses a pre-defined set of shapefiles (.shp) converted from the OpenStreetMap XML files (.osm):

 

Buildings.shp - buildings
ID - OSM identifier (string)
NAME - the name of the feature (string)
TYPE - the type of the feature (string)

 

Natural.shp - lakes, forests
ID - OSM identifier  (string)
NAME - the name of the feature (string)
TYPE - the type of the feature (string)

 

Places.shp - cities, towns, villages and other populated places
ID - OSM identifier (string)
NAME - the name of the feature (string)
TYPE - the type of the feature (string)
POPULATION - population (integer)

 

Points.shp - points of interest
ID - OSM identifier (string)
NAME - the name of the feature (string)
TYPE - the type of the feature (string)

 

Railways.shp - railroads
ID - OSM identifier (string)
NAME - the name of the feature (string)
TYPE - the type of the feature (string)

 

Roads.shp - highways, streets
ID - OSM identifier (string)
NAME - the name of the feature (string)
TYPE - the type of the feature (string)
REF - primary road number (string)
ONEWAY - specifies a oneway road (integer 1/0)
BRIDGE - specifies a bridge (integer 1/0)
MAXSPEED - speed limit (integer)

 

Waterways.shp - rivers
ID - OSM identifier (string)
NAME - the name of the feature (string)
TYPE - the type of the feature (string)

Obtaining Map Data of Your Region

The shapefiles can be obtained from the following sources:

 

 

To install your own map data set:

 

  1. Download a .shp.zip file.

  2. Remove all the files except the world.shp/world.shx/world.dbf files from the /App_Data/StreetMap directory (the world shapefile is optional and is provided for a reference, it can be safely removed).

  3. Extract the .shp.zip file into the /App_Data/StreetMap directory.

 

It is recommended to build spatial indexes for large shapefiles for fast map rendereing. Spatial indexes can be built by the Spatial Index Bulder utility which is installed with AspMap.

Incorporating the Template into Your Project
  1. Copy the StreetMap.cs file to the /App_Code directory of your ASP.NET application.

  2. Copy the StreetMap directory to the /App_Data directory of your application.

  3. Create a /TileCache directory at the root directory of your application. If you run your application under IIS, grant the IUSR account read/write/modify permissions for the /TileCache directory to let AspMap manage the tile images in the directory.

  4. Add a Map control into your ASP.NET project as described in the AspMap documentation.

  5. Add the following code to the Page_Load method (see the StreetMap.aspx sample in the AspMap samples):

 

[C#]
protected void Page_Load(object sender, EventArgs e)
{
    Map1.ImageOpacity = 0.5;
    Map1.ImageFormat = ImageFormat.Png;

    StreetMap streetMap = new StreetMap("StreetMap", "~/TileCache", 1000);
        // "StreetMap" - tile layer ID and map data directory name
        // "~/TileCache" - a virtual path to the tile cache directory
        // 1000 - the maximum size of the tile cache directory in megabytes

    AspMap.Web.TileLayer tileLayer = streetMap.CreateTileLayer(Map1);

    if (tileLayer != null)
    {
       Map1.AddLayer(tileLayer);
    }
}

[VB.NET]
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
        Map1.ImageOpacity = 0.5
        Map1.ImageFormat = ImageFormat.Png

        Dim streetMap As StreetMap = New StreetMap("StreetMap", "~/TileCache", 1000)
                ' "StreetMap" - tile layer ID and map data directory name
                ' "~/TileCache" - a virtual path to the tile cache directory
                ' 1000 - the maximum size of the tile cache directory in megabytes

        AspMap.Web.TileLayer tileLayer = streetMap.CreateTileLayer(Map1)

        If tileLayer IsNot Nothing Then
           Map1.AddLayer(tileLayer)
        End If
End Sub

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