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()); Console.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&REQUEST=GetCapabilities&</OnlineURL> <WmsUser>test</WmsUser> <WmsPassword>pw</WmsPassword> <WmsLayers>0,1,2</WmsLayers> </MapLayer> </Layers>")); ms.Close(); }
public static Map InitializeMap() { string wmsUrl = "http://www2.demis.nl/mapserver/request.asp"; SharpMap.Map map = new SharpMap.Map(); SharpMap.Layers.WmsLayer layWms = new SharpMap.Layers.WmsLayer("Demis Map", wmsUrl); layWms.SpatialReferenceSystem = "EPSG:4326"; layWms.AddLayer("Bathymetry"); 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 SharpMap.Geometries.Point(0, 0); return map; }
public static Map InitializeMap() { string wmsUrl = "http://www2.demis.nl/mapserver/request.asp"; SharpMap.Map map = new SharpMap.Map(); SharpMap.Layers.WmsLayer layWms = new SharpMap.Layers.WmsLayer("Demis Map", wmsUrl); layWms.SpatialReferenceSystem = "EPSG:4326"; layWms.AddLayer("Bathymetry"); 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 SharpMap.Geometries.Point(0, 0); return(map); }
public void TestIssue156(string url, SecurityProtocolType sptFail, SecurityProtocolType sptSucceed) { var spDefault = ServicePointManager.SecurityProtocol; SharpMap.Layers.WmsLayer wmsLayer = null; ServicePointManager.SecurityProtocol = sptFail; Assert.That(() => wmsLayer = new SharpMap.Layers.WmsLayer("WMSFAIL", url), Throws.InstanceOf <System.ApplicationException>()); ServicePointManager.SecurityProtocol = sptSucceed; Assert.That(() => wmsLayer = new SharpMap.Layers.WmsLayer("WMSSUCCED", url), Throws.Nothing); Assert.That(wmsLayer, Is.Not.Null, "wmsLayer null"); ServicePointManager.SecurityProtocol = spDefault; }
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 = System.Text.ASCIIEncoding.ASCII.GetString(ms.ToArray()); Console.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</OnlineURL> <WmsLayers>0,1,2</WmsLayers> </MapLayer> </Layers>")); ms.Close(); }
public void AddLayerFail() { SharpMap.Layers.WmsLayer layer = new SharpMap.Layers.WmsLayer("wms", "http://wms.iter.dk/example_capabilities_1_3_0.xml"); layer.AddLayer("NonExistingLayer"); }
public void AddLayerOK() { SharpMap.Layers.WmsLayer layer = new SharpMap.Layers.WmsLayer("wms", "http://wms.iter.dk/example_capabilities_1_3_0.xml"); layer.AddLayer("ROADS_1M"); }
public Form1() { InitializeComponent(); string currentDir = Directory.GetCurrentDirectory(); string tutFile = @"\ShapeFiles\states_ugl.shp"; string worldBorders = @"\ShapeFiles\TM_WORLD_BORDERS-0.3.shp"; List <string> texasShapeFiles = new List <string>(); SharpMap.Layers.VectorLayer vlay = new SharpMap.Layers.VectorLayer("world"); // Load information from ShapeFiles vlay.DataSource = new SharpMap.Data.Providers.ShapeFile(currentDir + worldBorders, true); //Create the style VectorStyle defaultStyle = new VectorStyle(); //Create the style for regions VectorStyle africa = new VectorStyle(); VectorStyle antartica = new VectorStyle(); VectorStyle australia = new VectorStyle(); VectorStyle northAmerica = new VectorStyle(); VectorStyle asia = new VectorStyle(); VectorStyle europe = new VectorStyle(); // Set Random Colors Random rnd = new Random(); // Add styles to List styles.Add(999, defaultStyle); styles.Add(0, antartica); styles.Add(2, africa); styles.Add(9, australia); styles.Add(19, northAmerica); styles.Add(142, asia); styles.Add(150, europe); foreach (KeyValuePair <int, IStyle> style in styles) { var o = style.Value as VectorStyle; o.EnableOutline = true; rnd.Next(0, 256); var r = rnd.Next(0, 256); var g = rnd.Next(0, 256); var b = rnd.Next(0, 256); o.Fill = new SolidBrush(Color.FromArgb(r, g, b)); } //Assign the theme vlay.Theme = new SharpMap.Rendering.Thematics.UniqueValuesTheme <int>("region", styles, defaultStyle); // Add the layer to the mapBox control mapBox1.Map.Layers.Add(vlay); // Get US Cities from WMS Server SharpMap.Layers.WmsLayer wmsL = new SharpMap.Layers.WmsLayer("US Cities", "http://sampleserver1.arcgisonline.com/ArcGIS/services/Specialty/ESRI_StatesCitiesRivers_USA/MapServer/WMSServer"); //Force PNG format. Else we can't see through wmsL.SetImageFormat("image/png"); //Force version 1.1.0 wmsL.Version = "1.1.0"; //Add layer named 2 in the service (Cities) wmsL.AddLayer("2"); //Set the SRID wmsL.SRID = 4326; mapBox1.Map.Layers.Add(wmsL); // mapBox1.Map.Layers.Add(vlay); mapBox1.Map.ZoomToExtents(); mapBox1.Refresh(); mapBox1.ActiveTool = SharpMap.Forms.MapBox.Tools.Pan; }