Have questions? Call us toll-free at 1-866-847-7510 (outside North America, call 1-785-727-4133)

Map Suite WMS Server Edition Quick Start Guide

From ThinkGeo Wiki

Jump to: navigation, search
Info Balloon

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 6.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.

(For the purposes of this guide, let's assume we have installed Map Suite WMS Server Evaluation Edition 6.0 to the default folder: C:\Program Files\ThinkGeo\Map Suite WMS Server Evaluation Edition 6.0.

Contents

Download the Sample

Download Download Sample Code From This Exercise (143 KB)

Setting Up Your Environment

Let's start with a new Class Library in the Visual Studio.NET 2008 IDE and call it "HelloWmsPlugin" (see screenshots below). Set the Templates to ".NET Framework 3.5" for the project.

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

QSG WMSServerEdition Img01.png


QSG WMSServerEdition Img02.png


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\ThinkGeo\Map Suite WMS Server Evaluation Edition 6.0\Developer Reference\WMS Server Edition directory and add "WmsServerEdition.dll", "MapSuiteCore.dll", "GeoAPI.dll" and "MapSuiteCore.dll" to the reference. The references should then look like the image below.

Note: If you are using MapSuiteCore.dll version 4.5.0.0 or later, 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=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'."

QSG WMSServerEdition Img03.png


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" shapefiles. We've included this sample data with Map Suite WMS Server Edition; you can find it in your installation folder at C:\Program Files\ThinkGeo\Map Suite WMS Server Evaluation Edition 6.0\HowDoISamples\CSharp Samples\SampleData.

QSG WMSServerEdition Img04.png


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:

QSG WMSServerEdition Img05.png


The next step is to implement all of the abstract methods. The majority of our sample code is placed in the GetMapConfigurationCore method. 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)
        {
              string worldLayerFilePath = @"C:\Program Files\ThinkGeo\Map Suite WMS Server Evaluation Edition 6.0\HowDoISamples\CSharp Samples\SampleData\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 located at C:\Program Files\ThinkGeo\Map Suite WMS Server Evaluation Edition 6.0\HowDoISamples\CSharp Samples\WmsPluginService 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.

QSG WMSServerEdition Img06.png


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:

QSG WMSServerEdition Img07.png


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:

QSG WMSServerEdition Img08.png


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:

QSG WMSServerEdition Img09.png


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.

QSG WMSServerEdition Img10.png


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

QSG WMSServerEdition Img11.png


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.

QSG WMSServerEdition Img12.png


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 Download Sample Code From This Exercise (143 KB)

Personal tools
Namespaces
Variants
Actions
Products
Data
Add Ons
Navigation
Toolbox
Learn More About Map Suite, Download a Free Trial, or Buy Now

GIS Developer Components for .NET
Map Suite Extensions & Add-Ons
Map Data Sets & Icons

Try Map Suite Free

Map Suite Online Store
sales@thinkgeo.com
1-866-847-7510 (Toll-Free)
1-785-727-4133 (Outside North America)

ThinkGeo LLC
2801 Network Blvd. Suite 215
Frisco, TX 75034
Map Suite Support Center