User Manual

Adding MSSQL Spatial LayerSources

Adding MSSQL Spatial tables as Mapzania LayerSources can take as little as one line of code in the startup section of your application. This is illustrated in the examples below:

Default Registration

To register all MSSQL Spatial tables in a database using default options add the code highlighted below to your startup code:


void Application_Start(object sender, EventArgs e)
{
	...

    // Obtain a connectionstring from ConfigurationManager (web.config)
    var connectionString = ConfigurationManager.ConnectionStrings["MY_CONNECTION"].ConnectionString;
    
    // Register the MSSQl Spatial database
    Mapzania.Services.RegisterMsSqlSpatialDatabase(connectionString);
    
    // Start Mapzania
    Mapzania.Services.Start(this);
    
    AreaRegistration.RegisterAllAreas();
    GlobalConfiguration.Configure(WebApiConfig.Register);
    RouteConfig.RegisterRoutes(RouteTable.Routes);
    BundleConfig.RegisterBundles(BundleTable.Bundles);
    ...
}

NOTE: It is important that the Mapzania.Services.RegisterMsSqlSpatialDatabase method be called before the Mapzania.Services.Start method. If this is not done, the MsSqlSpatial database will not be activated.

Registration with Options

To register all MSSQL Spatial tables in a database using custom options add the code highlighted below to your startup code:


void Application_Start(object sender, EventArgs e)
{
	...

    // Obtain a connectionstring from ConfigurationManager (web.config)
    var connectionString = ConfigurationManager.ConnectionStrings["MY_CONNECTION"].ConnectionString;
    
    // Set options for MSSQL Spatial LayerSources
    var options = new Platform.MsSqlSpatial.ProviderOptions {
        Prefix = "MYDB_",
        DefaultSRID = "EPSG:4283",
        DefaultIdColumnName = "MY_ID",
        DefaultGeometryColumnName = "MY_GEOMETRY"
    };
    
    // Register the MSSQl Spatial database
    Mapzania.Services.RegisterMsSqlSpatialDatabase(connectionString, options);
    
    // Start Mapzania
    Mapzania.Services.Start(this);
    
    AreaRegistration.RegisterAllAreas();
    GlobalConfiguration.Configure(WebApiConfig.Register);
    RouteConfig.RegisterRoutes(RouteTable.Routes);
    BundleConfig.RegisterBundles(BundleTable.Bundles);
    ...
}

See Mapzania.Services.RegisterMsSqlSpatialDatabase for reference documentation.