Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
    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;
    }
Exemplo n.º 3
0
        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;
        }