User Manual

Adding PostGIS LayerSources

Adding PostGIS 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 PostGIS 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 PostGIS Spatial database
    Mapzania.Services.RegisterPostGISDatabase(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.RegisterPostGisDatabase method be called before the Mapzania.Services.Start method. If this is not done, the PostGIS database will not be activated.

Registration with Options

To register all PostGIS 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.PosGIS.ProviderOptions {
        Prefix = "MYDB_",
        DefaultSRID = "EPSG:4283"
    };
    
    // Register the PostGIS database
    Mapzania.Services.RegisterPostGisDatabase(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.RegisterPostGisDatabase for reference documentation.