Web Map Service layer
The WmsLayer is currently very basic and doesn't support automatic fetching of the WMS Service Description. Instead you would have to add the nessesary parameters to the URL, and the WmsLayer will set the remaining BoundingBox property and proper requests that changes between the requests. See the example below.
Inheritance: SharpMap.Layers.Layer
        public void TestSerializeWmsLayerWithCredentials()
        {
            SharpMap.Map             m = new SharpMap.Map();
            SharpMap.Layers.WmsLayer l = new SharpMap.Layers.WmsLayer("testwms", "http://sampleserver1.arcgisonline.com/ArcGIS/services/Specialty/ESRI_StatesCitiesRivers_USA/MapServer/WMSServer", TimeSpan.MaxValue,
                                                                      System.Net.WebRequest.DefaultWebProxy, new NetworkCredential("test", "pw"));
            l.AddChildLayers(l.RootLayer, false);
            m.Layers.Add(l);
            MemoryStream ms = new MemoryStream();

            SharpMap.Serialization.MapSerialization.SaveMapToStream(m, ms);
            string txt = System.Text.ASCIIEncoding.ASCII.GetString(ms.ToArray());

            System.Diagnostics.Trace.WriteLine(txt);
            Assert.IsTrue(txt.Contains(@"<Layers>
    <MapLayer xsi:type=""WmsLayer"">
      <Name>testwms</Name>
      <MinVisible>0</MinVisible>
      <MaxVisible>1.7976931348623157E+308</MaxVisible>
      <OnlineURL>http://sampleserver1.arcgisonline.com/ArcGIS/services/Specialty/ESRI_StatesCitiesRivers_USA/MapServer/WMSServer?SERVICE=WMS&amp;REQUEST=GetCapabilities&amp;</OnlineURL>
      <WmsUser>test</WmsUser>
      <WmsPassword>pw</WmsPassword>
      <WmsLayers>0,1,2</WmsLayers>
    </MapLayer>
  </Layers>"));
            ms.Close();
        }
Ejemplo n.º 2
0
        public static Map InitializeMap(float angle)
        {
            string wmsUrl = "http://dev:8080/geoserver/ows?service=wms&version=1.1.1&request=GetCapabilities";

            Map map = new Map();

            WmsLayer layWms = new WmsLayer("Demis Map", wmsUrl);

            layWms.AddLayer("sf:roads");
            //layWms.AddLayer("Topography");
            //layWms.AddLayer("Hillshading");

            layWms.SetImageFormat(layWms.OutputFormats[0]);
            layWms.ContinueOnError = true;
                //Skip rendering the WMS Map if the server couldn't be requested (if set to false such an event would crash the app)
            layWms.TimeOut = 5000; //Set timeout to 5 seconds
            layWms.SRID = 4326;
            map.Layers.Add(layWms);

            //limit the zoom to 360 degrees width
            map.MaximumZoom = 360;
            map.BackColor = Color.LightBlue;

            map.Zoom = 360;
            map.Center = new Point(0, 0);

            Matrix mat = new Matrix();
            mat.RotateAt(angle, map.WorldToImage(map.Center));
            map.MapTransform = mat;

            map.ZoomToExtents();
            return map;
        }
Ejemplo n.º 3
0
        public void BgColor_NamedColor_SetUrlPropertyCorrectly()
        {
            var client = CreateClientFromXmlResult("wms.atlantedesertificazione.xml");

            var layer = new WmsLayer("wms", client) {BgColor = Color.Red, SRID = 0, Transparent = false};

            var url = layer.GetRequestUrl(new Envelope(1, 1, 1, 1), new Size(1, 1));
            var queryString = HttpUtility.ParseQueryString(url);

            Assert.That(queryString["BGCOLOR"], Is.EqualTo("FF0000"), 
                "Layer.BgColor does not produce a valid Url");
        }
 public void OneTimeSetUp()
 {
     try
     {
         var l = new SharpMap.Layers.WmsLayer("testwms",
                                              "http://sampleserver1.arcgisonline.com/ArcGIS/services/Specialty/ESRI_StatesCitiesRivers_USA/MapServer/WMSServer");
         l.Dispose();
     }
     catch (Exception e)
     {
         throw new IgnoreException("Creation of WMS Layer failed", e);
     }
 }
Ejemplo n.º 5
0
    public static SharpMap.Layers.WmsLayer GetWmsLayer()
    {
        string wmsUrl = "http://www2.demis.nl/mapserver/request.asp";

        SharpMap.Layers.WmsLayer layWms = new SharpMap.Layers.WmsLayer("Demis Map", wmsUrl);
        layWms.SpatialReferenceSystem = "EPSG:4326";
        layWms.AddLayer("Bathymetry");
        layWms.AddLayer("Ocean features");
        layWms.SetImageFormat(layWms.OutputFormats[0]);
        layWms.ContinueOnError = true; //Skip rendering the WMS Map if the server couldn't be requested (if set to false such an event would crash the app)
        layWms.TimeOut         = 5000; //Set timeout to 5 seconds
        layWms.SRID            = 4326;
        return(layWms);
    }
Ejemplo n.º 6
0
    /// <summary>
    /// Recursive function for retriving layer names
    /// </summary>
    /// <param name="layer"></param>
    /// <param name="layWms"></param>
    private void PrintLayers(Client.WmsServerLayer layer, WmsLayer layWms)
    {
        litLayers.Text += "<li>" + layer.Name;
        if (layWms.LayerList.Contains(layer.Name))
            litLayers.Text += " (Enabled)";
        litLayers.Text += "</li>";

        if (layer.ChildLayers != null && layer.ChildLayers.Length > 0)
        {
            litLayers.Text += "<ul>";
            foreach (Client.WmsServerLayer childlayer in layer.ChildLayers)
                PrintLayers(childlayer, layWms);
            litLayers.Text += "</ul>";
        }
    }
Ejemplo n.º 7
0
    public static SharpMap.Map InitializeWmsMap(System.Drawing.Size size)
    {
        HttpContext.Current.Trace.Write("Initializing Wms map...");

        //Initialize a new map of size 'imagesize'
        SharpMap.Map             map    = new SharpMap.Map(size);
        SharpMap.Layers.WmsLayer layWms = GetWmsLayer();
        //Set up the countries layer
        SharpMap.Layers.VectorLayer layCountries = new SharpMap.Layers.VectorLayer("Countries");
        //Set the datasource to a shapefile in the App_data folder
        layCountries.DataSource = new SharpMap.Data.Providers.ShapeFile(HttpContext.Current.Server.MapPath(@"~\App_data\countries.shp"), true);
        //Set fill-style to green
        layCountries.Style.Fill = new SolidBrush(Color.Green);
        //Set the polygons to have a black outline
        layCountries.Style.Outline       = System.Drawing.Pens.Yellow;
        layCountries.Style.EnableOutline = true;
        layCountries.SRID = 4326;

        //Set up a country label layer
        SharpMap.Layers.LabelLayer layLabel = new SharpMap.Layers.LabelLayer("Country labels");
        layLabel.DataSource                = layCountries.DataSource;
        layLabel.Enabled                   = true;
        layLabel.LabelColumn               = "Name";
        layLabel.Style                     = new SharpMap.Styles.LabelStyle();
        layLabel.Style.ForeColor           = Color.White;
        layLabel.Style.Font                = new Font(FontFamily.GenericSerif, 8);
        layLabel.Style.BackColor           = new System.Drawing.SolidBrush(Color.FromArgb(128, 255, 0, 0));
        layLabel.MaxVisible                = 90;
        layLabel.MinVisible                = 30;
        layLabel.Style.HorizontalAlignment = SharpMap.Styles.LabelStyle.HorizontalAlignmentEnum.Center;
        layLabel.SRID = 4326;

        //Add the layers to the map object.
        //The order we add them in are the order they are drawn, so we add the rivers last to put them on top
        map.Layers.Add(layWms);
        map.Layers.Add(layCountries);
        map.Layers.Add(layLabel);

        //limit the zoom to 360 degrees width
        map.MaximumZoom = 360;
        map.BackColor   = Color.LightBlue;

        map.Zoom   = 360;
        map.Center = new SharpMap.Geometries.Point(0, 0);

        HttpContext.Current.Trace.Write("Map initialized");
        return(map);
    }
Ejemplo n.º 8
0
 public static WmsLayer GetWmsLayer()
 {
     string wmsUrl = "http://www2.demis.nl/worldmap/wms.asp";
     WmsLayer layWms = new WmsLayer("Demis Map", wmsUrl);
     layWms.AddLayer("Bathymetry");
     //layWms.AddLayer("Coastlines");
     //layWms.AddLayer("Countries");
     //layWms.AddLayer("Rivers");
     //layWms.AddLayer("Streams");
     layWms.AddLayer("Ocean features");
     layWms.SetImageFormat(layWms.OutputFormats[0]);
     layWms.ContinueOnError = true;
         //Skip rendering the WMS Map if the server couldn't be requested (if set to false such an event would crash the app)
     layWms.TimeOut = 5000; //Set timeout to 5 seconds
     layWms.SRID = 4326;
     return layWms;
 }
Ejemplo n.º 9
0
    private void PrintWmsInfo()
    {
        SharpMap.Layers.WmsLayer layWms = MapHelper.GetWmsLayer();
        //Get request url for WMS
        hlWmsImage.NavigateUrl = layWms.GetRequestUrl(
            new SharpMap.Geometries.BoundingBox(Center.X - Zoom * 0.5, Center.Y - Zoom * 0.25,
                                                Center.X + Zoom * 0.5, Center.Y + Zoom * 0.25), new Size((int)imgMap.Width.Value, (int)imgMap.Height.Value));

        litLayers.Text  = "<p><b>WMS Title</b>: " + layWms.ServiceDescription.Title + "<br/>Abstract: <i>" + layWms.ServiceDescription.Abstract + "</i>";
        litLayers.Text += "<br/><b>WMS Layers:</b><br/>";

        foreach (SharpMap.Web.Wms.Client.WmsServerLayer layer in layWms.RootLayer.ChildLayers)
        {
            PrintLayers(layer, layWms);
        }
        litLayers.Text += "</ul></p>";
    }
Ejemplo n.º 10
0
    /// <summary>
    /// Recursive function for retriving layer names
    /// </summary>
    /// <param name="layer"></param>
    /// <param name="layWms"></param>
    private void PrintLayers(SharpMap.Web.Wms.Client.WmsServerLayer layer, SharpMap.Layers.WmsLayer layWms)
    {
        litLayers.Text += "<li>" + layer.Name;
        if (layWms.LayerList.Contains(layer.Name))
        {
            litLayers.Text += " (Enabled)";
        }
        litLayers.Text += "</li>";

        if (layer.ChildLayers != null && layer.ChildLayers.Length > 0)
        {
            litLayers.Text += "<ul>";
            foreach (SharpMap.Web.Wms.Client.WmsServerLayer childlayer in layer.ChildLayers)
            {
                PrintLayers(childlayer, layWms);
            }
            litLayers.Text += "</ul>";
        }
    }
        public void TestSerializeWmsLayer()
        {
            SharpMap.Map             m = new SharpMap.Map();
            SharpMap.Layers.WmsLayer l = new SharpMap.Layers.WmsLayer("testwms", "http://sampleserver1.arcgisonline.com/ArcGIS/services/Specialty/ESRI_StatesCitiesRivers_USA/MapServer/WMSServer");
            l.AddChildLayers(l.RootLayer, false);
            m.Layers.Add(l);
            MemoryStream ms = new MemoryStream();

            SharpMap.Serialization.MapSerialization.SaveMapToStream(m, ms);
            string txt = Encoding.ASCII.GetString(ms.ToArray());

            txt = txt.Replace("\r\n", "");
            System.Diagnostics.Trace.WriteLine(txt);
            Assert.IsTrue(txt.Contains(@"<Layers><MapLayer xsi:type=""WmsLayer"">
      <Name>testwms</Name>
      <MinVisible>0</MinVisible>
      <MaxVisible>1.7976931348623157E+308</MaxVisible>
      <OnlineURL>http://sampleserver1.arcgisonline.com/ArcGIS/services/Specialty/ESRI_StatesCitiesRivers_USA/MapServer/WMSServer?SERVICE=WMS&amp;REQUEST=GetCapabilities&amp;</OnlineURL>
      <WmsLayers>0,1,2</WmsLayers>
    </MapLayer>
  </Layers>"));
            ms.Close();
        }
Ejemplo n.º 12
0
 public void AddLayerOK()
 {
     WmsLayer layer = new WmsLayer("wms", "http://wms.iter.dk/example_capabilities_1_3_0.xml");
     layer.AddLayer("ROADS_1M");
 }
Ejemplo n.º 13
0
 public void AddLayerFail()
 {
     WmsLayer layer = new WmsLayer("wms", "http://wms.iter.dk/example_capabilities_1_3_0.xml");
     layer.AddLayer("NonExistingLayer");
 }
Ejemplo n.º 14
0
	public static SharpMap.Layers.WmsLayer GetWmsLayer()
	{
		string wmsUrl = "http://www2.demis.nl/mapserver/request.asp";
		SharpMap.Layers.WmsLayer layWms = new SharpMap.Layers.WmsLayer("Demis Map", wmsUrl);
		layWms.SpatialReferenceSystem = "EPSG:4326";		
		layWms.AddLayer("Bathymetry");
		layWms.AddLayer("Ocean features");
		layWms.SetImageFormat(layWms.OutputFormats[0]);
		layWms.ContinueOnError = true; //Skip rendering the WMS Map if the server couldn't be requested (if set to false such an event would crash the app)
		layWms.TimeOut = 5000; //Set timeout to 5 seconds
		layWms.SRID = 4326;
		return layWms;
	}
Ejemplo n.º 15
0
 private static void AddLayerToLegend(WmsLayer layer, LegendToolItem parent)
 {
     var title = layer.RootLayer.Name;
     var layerItem = parent.AddItem(title);
     if (layer.Theme != null && layer.Theme.ThemeItems != null)
     {
         AddThemeItemsAsLegendItems(layer.Theme.ThemeItems, layerItem, false);
     }
 }
Ejemplo n.º 16
0
        /// <summary>
        /// Add a list of wms layers to the map.
        /// </summary>
        /// <param name="wmsLayers"></param>
        public void AddWMSLayers(List<WMSInfo> wmsLayers)
        {
            wmsLayers = wmsLayers.OrderBy(layer => layer.zIndex).ToList();
            try
            {

                for (int i = 0; i < wmsLayers.Count; i++)
                {
                    string layername = "WMSLayer_" + i;
                    WmsLayer layer = new WmsLayer(layername, wmsLayers[i].url);

                    layer.SetImageFormat("image/png");
                    layer.BgColor = Color.White;
                    layer.Transparent = true;
                    layer.Version = "1.1.0";
                    layer.ContinueOnError = true;
                    for (int t = 0; t < wmsLayers[i].layers.Count; t++)
                    {
                        string sublayerName = "";
                        try
                        {
                            sublayerName = wmsLayers[i].workspacePrefix != null ?
                                           wmsLayers[i].workspacePrefix + ":" + wmsLayers[i].layers[t] :
                                           wmsLayers[i].layers[t];

                            if (sublayerName != "")
                            {
                                layer.AddLayer(sublayerName);
                            }
                        }
                        catch (Exception ex)
                        {
                            Logger.Fatal("WMS sublayer load error " + ex.Message, ex);
                        }
                    }

                    layer.SRID = wmsLayers[i].coordinateSystemId;
                    map.Layers.Add(layer);
                }
            }
            catch (Exception ex)
            {
                Logger.Fatal("WMS layer load error " + ex.Message, ex);
            }
        }