Пример #1
0
        public static SharpMap.Map GetMapForProviders(IEnumerable <SharpMap.Data.Providers.IProvider> providers)
        {
            var m = new SharpMap.Map();

            foreach (var provider in providers)
            {
                var l = new VectorLayer(provider.ConnectionID, provider)
                {
                    Style          = GetRandomVectorStyle(),
                    IsQueryEnabled = true
                };
                if (provider.GetFeatureCount() > 50000)
                {
                    m.BackgroundLayer.Add(AsyncLayerProxyLayer.Create(l, new Size(256, 128)));
                }
                else
                {
                    m.Layers.Add(l);
                }

                if (provider.GetFeatureCount() < 50000)
                {
                    var ll = new LabelLayer("Label " + provider.ConnectionID);
                    ll.DataSource = provider;

                    provider.Open();
                    var f = provider.GetFeature(1);
                    provider.Close();

                    ll.LabelColumn = f.Table.Columns[0].ColumnName;
                    ll.Style.CollisionDetection = false;
                    ll.Style.IgnoreLength       = true;

                    m.Layers.Add(ll);
                }
            }
            m.ZoomToExtents();
            return(m);
        }
Пример #2
0
        public static Map InitializeMap(float angle)
        {
            string wmsUrl = "http://resource.sgu.se/service/wms/130/brunnar";

            Map map = new Map();


            WmsLayer layWms = new WmsLayer("Brunnar", wmsUrl);

            layWms.AddLayer("grundvatten:SE.GOV.SGU.BRUNNAR.250K");
            //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 = 20000; //Set timeout to 5 seconds
            layWms.SRID    = 3006;

            map.BackgroundLayer.Add(AsyncLayerProxyLayer.Create(layWms, new Size(256, 256)));
            map.MaximumExtents = layWms.Envelope;

            //limit the zoom to 360 degrees width
            map.ZoomToExtents();
            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();
            map.Zoom = map.Envelope.Width / 3;
            return(map);
        }
Пример #3
0
        private static Map InitializeMapOrig(float angle)
        {
            //Initialize a new map of size 'imagesize'
            Map map = new Map();

            //Set up the countries layer
            VectorLayer layCountries = new VectorLayer("Countries");

            //Set the datasource to a shapefile in the App_data folder
            layCountries.DataSource = new ShapeFile("GeoData/World/countries.shp", true);
            //Set fill-style to green
            layCountries.Style.Fill = new SolidBrush(Color.FromArgb(64, Color.Green));
            //Set the polygons to have a black outline
            layCountries.Style.Outline       = Pens.Black;
            layCountries.Style.EnableOutline = true;
            layCountries.SRID = 4326;

            //Set up a river layer
            VectorLayer layRivers = new VectorLayer("Rivers");

            //Set the datasource to a shapefile in the App_data folder
            layRivers.DataSource = new ShapeFile("GeoData/World/rivers.shp", true);
            //Define a blue 1px wide pen
            layRivers.Style.Line = new Pen(Color.Blue, 1);
            layRivers.SRID       = 4326;

            //Set up a cities layer
            VectorLayer layCities = new VectorLayer("Cities");

            //Set the datasource to a shapefile in the App_data folder
            layCities.DataSource        = new ShapeFile("GeoData/World/cities.shp", true);
            layCities.Style.SymbolScale = 0.8f;
            layCities.MaxVisible        = 40;
            layCities.SRID = 4326;

            //Set up a country label layer
            LabelLayer layLabel = new LabelLayer("Country labels");

            layLabel.DataSource                = layCountries.DataSource;
            layLabel.Enabled                   = true;
            layLabel.LabelColumn               = "Name";
            layLabel.Style                     = new LabelStyle();
            layLabel.Style.ForeColor           = Color.White;
            layLabel.Style.Font                = new Font(FontFamily.GenericSerif, 12);
            layLabel.Style.BackColor           = new SolidBrush(Color.FromArgb(128, 255, 0, 0));
            layLabel.MaxVisible                = 90;
            layLabel.MinVisible                = 30;
            layLabel.Style.HorizontalAlignment = LabelStyle.HorizontalAlignmentEnum.Center;
            layLabel.SRID = 4326;
            layLabel.MultipartGeometryBehaviour = LabelLayer.MultipartGeometryBehaviourEnum.Largest;

            //Set up a city label layer
            LabelLayer layCityLabel = new LabelLayer("City labels");

            layCityLabel.DataSource                = layCities.DataSource;
            layCityLabel.Enabled                   = true;
            layCityLabel.LabelColumn               = "Name";
            layCityLabel.Style                     = new LabelStyle();
            layCityLabel.Style.ForeColor           = Color.Black;
            layCityLabel.Style.Font                = new Font(FontFamily.GenericSerif, 11);
            layCityLabel.MaxVisible                = layLabel.MinVisible;
            layCityLabel.Style.HorizontalAlignment = LabelStyle.HorizontalAlignmentEnum.Left;
            layCityLabel.Style.VerticalAlignment   = LabelStyle.VerticalAlignmentEnum.Bottom;
            layCityLabel.Style.Offset              = new PointF(3, 3);
            layCityLabel.Style.Halo                = new Pen(Color.Yellow, 2);
            layCityLabel.TextRenderingHint         = TextRenderingHint.AntiAlias;
            layCityLabel.SmoothingMode             = SmoothingMode.AntiAlias;
            layCityLabel.SRID        = 4326;
            layCityLabel.LabelFilter = LabelCollisionDetection.ThoroughCollisionDetection;
            layCityLabel.Style.CollisionDetection = true;

            //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.BackgroundLayer.Add(AsyncLayerProxyLayer.Create(layCountries));
            map.Layers.Add(layRivers);
            map.Layers.Add(layCities);
            map.Layers.Add(layLabel);
            map.Layers.Add(layCityLabel);


            //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;

            return(map);
        }