User Tools

Site Tools


map_suite_wms_server_edition_quick_start_guide

Map Suite WMS Server Edition Quick Start Guide

Note: The page was created before Map Suite 10. Map Suite 10.0 organized many classes into new namespaces and assemblies as well as had a few minor breaks in compatibility. The majority of previously built code should work without modification assuming the new namespaces are added. For guidance on upgrading your existing code, please check out MapSuite 10 Upgrade Guide.

The Map Suite WMS Server Edition illustrated QuickStart Guide will guide you through the process of building your own Web Map Service, creating a sample plugin, and will help you become familiar with Map Suite. This edition of the QuickStart Guide supports WMS Server Edition 7.0.0.0 and higher.

Welcome to Map Suite™ WMS Server Edition from ThinkGeo, a full-featured WMS Server that makes it easy for any Microsoft .NET developer to set up their own Web Map Service quickly and efficiently. Using the intuitive object model, even developers inexperienced in Geographic Information Systems (GIS) can start serving rich, professional-grade maps in minutes.

The purpose of this guide is to help you quickly get started building your own Web Map Service. Like any new software, there is some learning to be done along the way.

How do we start to learn to build up a Map Suite WMS Server? The best way is to make a demo with it.

Before we get started, make sure that you have installed the ThinkGeo Product Center and that you have either started an evaluation or activated a full license of Map Suite Desktop Edition. By default, this will install the Map Suite Desktop Edition 9.0 assemblies to C:\Program Files (x86)\ThinkGeo\Map Suite 9.0\Map Suite WMS Server.

Download the Sample

Setting Up Your Environment

Let's create a new Class Library project in Microsoft Visual Studio (2012 or newer) and call it “HelloWmsPlugin” (see screenshots below). Set the Templates to “.NET Framework 4.0” for the project.

Note: Please make sure the name of the library is suffixed with “Plugin”.

The Class Library is created in a new solution called “HelloWmsPlugin”, which includes a default file named “Class1.cs”. Let's change its name, as well as the class name, from “Class1” to “Countries02Plugin”.

Right-click the “HelloWmsPlugin” project in Solution Explorer and select “Add Reference…” Next, navigate to the C:\Program Files (x86)\ThinkGeo\Map Suite 9.0\Map Suite WMS Server\Current Version\Managed Assemblies directory and add “WmsServerEdition.dll”, “MapSuiteCore.dll”, “GeoAPI.dll” and “MapSuiteCore.dll” to the project references. The references should then look like the image below.

Note: Although it is not a ThinkGeo assembly, you also need to add “WindowsBase.dll” to the references. WindowsBase can be found on the .NET tab of the Add Reference dialog. If you don't do this, you will get the following error when you compile the project: “The type 'System.Collections.Specialized.INotifyCollectionChanged' is defined in an assembly that is not referenced. You must add a reference to assembly 'WindowsBase, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'.”

Now, you are ready to set up your own WMS server using your own data. Our first step is to set a reference to the Map Suite Core and WmsServerEdition workspace at the very top of our code, as we will use many classes within them. We do this so that we do not have to use the fully qualified name of the Map Suite classes throughout our code. Set the reference like this:

using ThinkGeo.MapSuite.Core;
using ThinkGeo.MapSuite.WmsServerEdition;

Now let's look at the sample code to bring this concept to fruition. For the purposes of our demo application, we'll use map data covering the entire world in the “Countries02” Shapefile. We've included this sample data in the attached sample zip file; you can find it in the sample project folder at \HelloWmsPlugin\AppData.

Implementing a Sample Plugin

WmsLayerPlugin is an abstract class in the WmsServerEdition assembly. It is the main class for you to use when you implement your own WMS Server. Let's make our Countries02Plugin class inherited from WmsPlugin by adding the following code:

using ThinkGeo.MapSuite.Core;
using ThinkGeo.MapSuite.WmsServerEdition;
 
namespace HelloWmsPlugin
{
    public class Countries02Plugin: WmsLayerPlugin
    {
    }
}

Then, right-click on the abstract class name “WmsLayerPlugin” to show the menu, and then click “Implement Interface” to generate the code below automatically. It looks like the image that follows:

The next step is to implement all of the abstract methods. The majority of our sample code is placed in the GetMapConfigurationCoremethod. In this sample, we will add two layers: BackgroundLayer and WorldLayer. The following code shows how we accomplish this.

using ThinkGeo.MapSuite.Core;
using ThinkGeo.MapSuite.WmsServerEdition;
 
namespace HelloWmsPlugin
{
    public class Countries02Plugin : WmsLayerPlugin
    {
        protected override RectangleShape GetBoundingBoxCore(string crs)
        {
            return new RectangleShape(-126.826171875, 57.104766845702, -70.83984375, 18.960235595702);
        }
 
        protected override MapConfiguration GetMapConfigurationCore(string style, string crs)
        {
            // NOTE: Please make sure you are using the absolute file path name, also you can use the relative file path name, 
            // but please remeber the path is relative to the built .dll of the plugin 
            string worldLayerFilePath = @"C:\**\Web\HelloWmsPlugin\HelloWmsPlugin\AppData\Countries02.shp";
 
            BackgroundLayer backgroundLayer = new BackgroundLayer(new GeoSolidBrush(GeoColor.GeographicColors.ShallowOcean));
 
            ShapeFileFeatureLayer worldLayer = new ShapeFileFeatureLayer(worldLayerFilePath);
            worldLayer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle = AreaStyles.Country1;
            worldLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;
 
            MapConfiguration mapConfiguration = new MapConfiguration();
            mapConfiguration.Layers.Add("BackgroundLayer", backgroundLayer);
            mapConfiguration.Layers.Add("WorldLayer", worldLayer);
            return mapConfiguration;
        }
 
        protected override string GetNameCore()
        {
            return "Display A Simple Map";
        }
 
        protected override System.Collections.ObjectModel.Collection<string> GetProjectionsCore()
        {
            return new System.Collections.ObjectModel.Collection<string> { "EPSG:4326" };
        }
    }
}

Now, press F6 to compile and the “HelloWmsPlugin.dll” will be generated in the project's \bin\debug directory. This is your first WmsLayerPlugin which we will use later for a WMS Server.

Managing Your Plugins

Add the existing WmsPluginService Project where you can download it from worldmapwms service to the “HelloWmsPlugin” solution we just created, as illustrated by the screenshot below.

Important Notes: You may need to delete the files within the WmsLayerPlugins folder to remove any existing plugins. Also, if you are using Windows 7 or Windows Server 2008, you may need to copy the WmsPluginService Project to another folder where you have permission to write; otherwise you may not be able to compile the project properly.

Set the “WmsPluginService” project as the startup project and set “Default.aspx” as the startup page, press F5 to run your application and you'll see the WMS Server Admin page pictured below:

Copy “HelloWmsPlugin.dll” to the WmsPluginService\WmsLayerPlugins folder (which is specified by appSetting in “Web.config”; feel free to change it if you prefer) and then the default page should look like the screenshot below:

As you can see, your WmsPlugin has been loaded and is displaying on the management page. You can click the “Preview” link to open a new window and see the result as follows:

Viewing the WMS Server's Capabilities

On the top of the WMS Server default page, you'll see a link called “View Capabilites.” Click this link to view the current WMS Server Capabilities, which include the general information about the service itself and specific information about its available layers.

The WMS Server capabilities are displayed in XML format in your browser, similar to the screenshot below:

Adding Another Plugin

Let's build another demonstration plugin that will show how to use multiple projections and set a TileCache for a layer.

First, add a new class to the “HelloWmsPlugin” project and call it “WorldMapKitPlugin”. It will use the WorldMapKit Layer and supports two projections – EPSG: 4326 and EPSG: 900913. The implementation will be like this:

using System;
using System.Collections.ObjectModel;
using ThinkGeo.MapSuite.Core;
using ThinkGeo.MapSuite.WmsServerEdition;
 
namespace HelloWmsPlugin
{
    public class WorldMapKitPlugin : WmsLayerPlugin
    {
        protected override RectangleShape GetBoundingBoxCore(string crs)
        {
            RectangleShape extent = new RectangleShape(-131.22, 55.05, -54.03, 16.91);
            if (crs.Equals("EPSG:900913", StringComparison.OrdinalIgnoreCase))
            {
                extent = new RectangleShape(-13939426.6371, 6701997.4056, -7812401.86, 2626987.386962);
            }
            return extent;
        }
 
        protected override MapConfiguration GetMapConfigurationCore(string style, string crs)
        {
            WorldMapKitLayer worldMapKitLayer = new WorldMapKitLayer();
            switch (crs)
            {
                case "EPSG:4326":
                    break;
                case "EPSG:900913":
                    worldMapKitLayer.Projection = WorldMapKitProjection.SphericalMercator;
                    break;
            }
 
            MapConfiguration mapConfiguration = new MapConfiguration();
            mapConfiguration.Layers.Add("worldMapKitLayer", worldMapKitLayer);
            return mapConfiguration;
        }
 
        protected override GeographyUnit GetGeographyUnitCore(string crs)
        {
            GeographyUnit geographyUnit = GeographyUnit.DecimalDegree;
            switch (crs)
            {
                case "EPSG:4326":
                    break;
                case "EPSG:900913":
                    geographyUnit = GeographyUnit.Meter;
                    break;
            }
 
            return geographyUnit;
        }
 
        protected override string GetNameCore()
        {
            return "Map Suite World Map Kit";
        }
 
        protected override Collection<string> GetProjectionsCore()
        {
            Collection<string> projections = new Collection<string>();
            projections.Add("EPSG:4326");
            projections.Add("EPSG:900913");
            return projections;
 
        }
    }
}

After adding this class, rebuild the project and upload the new “HelloWmsPlugin.dll” to the WmsLayerPlugins folder mentioned in the previous section. Then, refresh the WMS Server management page and you will see two plugin items on the list. Mouse over each item's “Preview” link and you will see a small preview image on the left that gives you a general idea of what the plugin will look like.

Consuming the WMS on a Client App

The WMS Server now has been set up correctly. If you would like to consume it on a client application, please refer the code below.

Example 1: Using the default projection “EPSG: 4326” with “DEFAULT” style in Map Suite Web Edition.

using System;
using System.Web.UI;
using ThinkGeo.MapSuite.Core;
using ThinkGeo.MapSuite.WebEdition;
 
namespace WmsWebSmaple
{
    public partial class _Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                Map1.MapBackground.BackgroundBrush = new GeoSolidBrush(GeoColor.FromHtml("#E5E3DF"));
                Map1.CurrentExtent = new RectangleShape(-131.22, 55.05, -54.03, 16.91);
                Map1.MapUnit = GeographyUnit.DecimalDegree;
 
                WmsOverlay wmsOverlay = new WmsOverlay("WMS Overlay");
                wmsOverlay.Parameters.Add("LAYERS", "Map Suite World Map Kit");
                wmsOverlay.Parameters.Add("STYLES", "DEFAULT");
 
                //Here you add your WMS Server uri
                wmsOverlay.ServerUris.Add(new Uri("http://localhost:62626/WmsHandler.axd"));
                Map1.CustomOverlays.Add(wmsOverlay);
            }
        }
    }
}

Example 2: Using the projection “EPSG: 900913” with “DEFAULT” style in Map Suite Web Edition.

using System;
using System.Web.UI;
using ThinkGeo.MapSuite.Core;
using ThinkGeo.MapSuite.WebEdition;
 
namespace WmsWebSmaple
{
    public partial class _Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                Map1.MapBackground.BackgroundBrush = new GeoSolidBrush(GeoColor.FromHtml("#E5E3DF"));
                Map1.CurrentExtent = new RectangleShape(-13939426.6371, 6701997.4056, -7812401.86, 2626987.386962);
                Map1.MapUnit = GeographyUnit.Meter;
 
                WmsOverlay wmsOverlay = new WmsOverlay("WMS Overlay");
                wmsOverlay.Parameters.Add("LAYERS", "Map Suite World Map Kit");
                wmsOverlay.Parameters.Add("STYLES", "DEFAULT");
                wmsOverlay.Parameters.Add("SRS", "EPSG:900913");
 
                //Here you add your WMS Server uri
                wmsOverlay.ServerUris.Add(new Uri("http://localhost:62626/WmsHandler.axd"));
                Map1.CustomOverlays.Add(wmsOverlay);
            }
        }
    }
}

Example 3: Using the projection “EPSG: 4326” with “DEFAULT” style in Map Suite Desktop Edition.

using System;
using System.Windows.Forms;
using ThinkGeo.MapSuite.Core;
using ThinkGeo.MapSuite.DesktopEdition;
 
namespace WMSDesktopEditionSample
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
 
        private void Form1_Load(object sender, EventArgs e)
        {
            winformsMap1.BackgroundOverlay.BackgroundBrush = new GeoSolidBrush(GeoColor.GeographicColors.ShallowOcean);
            winformsMap1.MapUnit = GeographyUnit.DecimalDegree;
            winformsMap1.CurrentExtent = new RectangleShape(-126.826171875, 57.104766845702, -70.83984375, 18.960235595702);
 
            TiledWmsLayer tiledWmsLayer = new TiledWmsLayer(new Uri("http://localhost:62626/WmsHandler.axd"));
            tiledWmsLayer.ActiveLayerNames.Add("Display A Simple Map");
            tiledWmsLayer.ActiveStyleNames.Add("DEFAULT");
 
            LayerOverlay staticOverlay = new LayerOverlay();
            staticOverlay.Layers.Add("SimpleWmsLayerPlugin", tiledWmsLayer);
            winformsMap1.Overlays.Add(staticOverlay);
 
            winformsMap1.Refresh();
        }
    }
}

Summary

You have now explored the basics of using Map Suite WMS Server Edition and are able to start adding this functionality into your own applications. Let's recap what we have learned about the object relationships and how the pieces of Map Suite work together:

  1. A WMS plugin assembly contains one or more public classes, and each of them should inherit from the WmsLayerPlugin abstract class. A WMS plugin assembly should have a name that ends with “plugin”.
  2. You must implement the GetMapConfigurationCore method, which is used to define your own layers.
  3. You must implement the GetBoundingBoxCore method, which returns the boundingBox of all the layers you defined.
  4. You need to implement the GetNameCore method to specify the name of a WMS layer.
  5. You need to implement the GetProjectionsCore method, which is used to add the projection string code (such as “EPSG: 4326”) that you want to support.
  6. Each public class inherited from the WmsLayerPlugin abstract class represents one Layer element in the WMS specification.
  7. All custom WmsPlugin DLLs need to be copied to a specified directory, which can be changed in the “Web.config” file.

Download Sample Code From This Exercise (1.75 MB)

map_suite_wms_server_edition_quick_start_guide.txt · Last modified: 2017/03/17 05:11 by tgwikiupdate