WorldToImage() публичный Метод

Converts a point from world coordinates to image coordinates based on the current zoom, center and mapsize.
public WorldToImage ( SharpMap p ) : System.Drawing.PointF
p SharpMap Point in world coordinates
Результат System.Drawing.PointF
Пример #1
0
        private RectangleF EnvelopeToRect(BoundingBox env)
        {
            var p1 = _Map.WorldToImage(env.TopLeft);
            var p2 = _Map.WorldToImage(env.BottomRight);

            float width  = (float)(p2.X > p1.X ? p2.X - p1.X : p1.X - p2.X);
            float height = (float)(p2.Y > p1.Y ? p2.Y - p1.Y : p1.Y - p2.Y);

            return(new RectangleF(p1.X, p1.Y, width, height));
        }
Пример #2
0
        private static Map InitializeDXF(float angle)
        {
            Map map = new Map();
            //Set the datasource to a shapefile in the App_data folder
            Ogr provider;
            try
            {
                provider = new Ogr("GeoData/SampleDXF.dxf",0);
            }
            catch (TypeInitializationException ex)
            {
                if (ex.Message == "The type initializer for 'OSGeo.OGR.Ogr' threw an exception.")
                {
                    throw new Exception(
                        String.Format(
                            "The application threw a PINVOKE exception. You probably need to copy the unmanaged dll's to your bin directory. They are a part of fwtools {0}. You can download it from: http://home.gdal.org/fwtools/",
                            GdalRasterLayer.FWToolsVersion));
                }
                throw;
            }
            VectorLayer lay = new VectorLayer("SampleDXF", provider);
            map.Layers.Add(lay);
            map.ZoomToExtents();
            Matrix mat = new Matrix();
            mat.RotateAt(angle, map.WorldToImage(map.Center));
            map.MapTransform = mat;

            _ogrSampleDataset = "SampleDXF";
            return map;

        }
Пример #3
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;
        }
Пример #4
0
        public static Map InitializeMapOrig(float angle)
        {
            //Initialize a new map of size 'imagesize'
            Map map = new Map();

            //Set up the countries layer
            VectorLayer layRoads = new VectorLayer("Roads");
            //Set the datasource to a shapefile in the App_data folder
            layRoads.DataSource = new ShapeFile("GeoData/World/shp_textonpath/DeMo_Quan5.shp", false);
            (layRoads.DataSource as ShapeFile).Encoding = Encoding.UTF8;
            //Set fill-style to green
            layRoads.Style.Fill = new SolidBrush(Color.Yellow);
            layRoads.Style.Line = new Pen(Color.Yellow, 4);
            //Set the polygons to have a black outline
            layRoads.Style.Outline = new Pen(Color.Black, 5); ;
            layRoads.Style.EnableOutline = true;
            layRoads.SRID = 4326;

            //Set up a country label layer
            LabelLayer layLabel = new LabelLayer("Roads labels");
            layLabel.DataSource = layRoads.DataSource;
            layLabel.Enabled = true;
            layLabel.LabelColumn = "tenduong";
            layLabel.LabelFilter = SharpMap.Rendering.LabelCollisionDetection.ThoroughCollisionDetection;
            layLabel.Style = new LabelStyle();
            layLabel.Style.ForeColor = Color.White;
            layLabel.Style.Font = new Font(FontFamily.GenericSerif, 9f, FontStyle.Bold);
            layLabel.Style.Halo = new Pen(Color.Black, 2f);
            layLabel.Style.IsTextOnPath = true;
            layLabel.Style.CollisionDetection = true;
            //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;

          
            //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(layRoads);          
            map.Layers.Add(layLabel);        


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

            map.ZoomToExtents();

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

            return map;
        }
Пример #5
0
 public void WorldToMap_DefaultMap_ReturnValue()
 {
     Map map = new Map(new Size(500, 200));
     map.Center = new Point(23, 34);
     map.Zoom = 1000;
     PointF p = map.WorldToImage(new Point(8, 50));
     Assert.AreEqual(new PointF(242.5f, 92), p);
 }
Пример #6
0
 public void WorldToImage()
 {
     Map map = new Map(new Size(1000, 500));
     map.Zoom = 360;
     map.Center = new Point(0, 0);
     Assert.AreEqual(new PointF(500, 250), map.WorldToImage(new Point(0, 0)));
     Assert.AreEqual(new PointF(0, 0), map.WorldToImage(new Point(-180, 90)));
     Assert.AreEqual(new PointF(0, 500), map.WorldToImage(new Point(-180, -90)));
     Assert.AreEqual(new PointF(1000, 0), map.WorldToImage(new Point(180, 90)));
     Assert.AreEqual(new PointF(1000, 500), map.WorldToImage(new Point(180, -90)));
 }
Пример #7
0
        private static Map InitializeS57(float angle)
        {
            //Initialize a new map of size 'imagesize'
            Map map = new Map();

            //Set the datasource to a shapefile in the App_data folder
            Ogr provider;
            try
            {
                provider = new Ogr("GeoData/S57/US5TX51M.000");
            }
            catch (TypeInitializationException ex)
            {
                if (ex.Message == "The type initializer for 'OSGeo.OGR.Ogr' threw an exception.")
                {
                    throw new Exception(
                        String.Format(
                            "The application threw a PINVOKE exception. You probably need to copy the unmanaged dll's to your bin directory. They are a part of fwtools {0}. You can download it from: http://home.gdal.org/fwtools/",
                            GdalRasterLayer.FWToolsVersion));
                }
                throw;
            }

            VectorLayer lay;
            Random rnd = new Random(9);
            for (Int32 i = provider.NumberOfLayers - 1; i >= 0; i--)
            {
                Ogr prov = new Ogr("GeoData/S57/US5TX51M.000", i);
                if (!prov.IsFeatureDataLayer) continue;
                string name = prov.LayerName;
                System.Diagnostics.Debug.WriteLine(string.Format("Layer {0}: {1}", i, name));
                //if (provider.GeometryType )
                lay = new VectorLayer(string.Format("Layer_{0}", name), prov);
                if (prov.OgrGeometryTypeString.IndexOf("Polygon") > 0)
                {
                    lay.Style.Fill =
                        new SolidBrush(Color.FromArgb(150, Convert.ToInt32(rnd.NextDouble() * 255),
                                                      Convert.ToInt32(rnd.NextDouble() * 255),
                                                      Convert.ToInt32(rnd.NextDouble() * 255)));
                    lay.Style.Outline =
                        new Pen(
                            Color.FromArgb(150, Convert.ToInt32(rnd.NextDouble() * 255),
                                           Convert.ToInt32(rnd.NextDouble() * 255),
                                           Convert.ToInt32(rnd.NextDouble() * 255)),
                            Convert.ToInt32(rnd.NextDouble() * 3));
                    lay.Style.EnableOutline = true;
                }
                else
                {
                    lay.Style.Line =
                        new Pen(
                            Color.FromArgb(150, Convert.ToInt32(rnd.NextDouble()*255),
                                           Convert.ToInt32(rnd.NextDouble()*255), Convert.ToInt32(rnd.NextDouble()*255)),
                            Convert.ToInt32(rnd.NextDouble()*3));
                }
                map.Layers.Add(lay);
            }
            _ogrSampleDataset = "S-57";
            map.ZoomToExtents();

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

            return map;
        }
Пример #8
0
        private static Map InitializeMapinfo(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
            try
            {
                layCountries.DataSource = new Ogr("GeoData/MapInfo/countriesMapInfo.tab");
            }
            catch (TypeInitializationException ex)
            {
                if (ex.Message == "The type initializer for 'OSGeo.OGR.Ogr' threw an exception.")
                {
                    throw new Exception(
                        String.Format(
                            "The application threw a PINVOKE exception. You probably need to copy the unmanaged dll's to your bin directory. They are a part of fwtools {0}. You can download it from: http://home.gdal.org/fwtools/",
                            GdalRasterLayer.FWToolsVersion));
                }
                throw;
            }

            //Set fill-style to green
            layCountries.Style.Fill = new SolidBrush(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 Ogr("GeoData/MapInfo/riversMapInfo.tab");
            //Define a blue 1px wide pen
            layRivers.Style.Line = new Pen(Color.Blue, 1);
            layRivers.SRID = 4326;

            //Set up a river layer
            VectorLayer layCities = new VectorLayer("Cities");
            //Set the datasource to a shapefile in the App_data folder
            layCities.DataSource = new Ogr("GeoData/MapInfo/citiesMapInfo.tab");
            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 = TextRendering.AntiAlias;
            layCityLabel.SmoothingMode = Smoothing.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.Layers.Add(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.ZoomToExtents(); // = 360;
            map.Center = new Point(0, 0);

            _ogrSampleDataset = "MapInfo";

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

            return map;
        }
Пример #9
0
        private static Map InitializeMapWithSymbolizerLayers(float angle)
        {
            //Initialize a new map of size 'imagesize'
            Map map = new Map();

            //Set up the countries layer
            var layCountries = new SharpMap.Layers.Symbolizer.PolygonalVectorLayer(
                "Countries",
                new ShapeFileEx("GeoData/World/countries.shp", true),
                new BasicPolygonSymbolizer {Fill = new SolidBrush(Color.Green), Outline = Pens.Black,}
                ) {SRID = 4326};

            //Set up a river layer
            var symbolizer = new CachedLineSymbolizer();
            symbolizer.LineSymbolizeHandlers.AddRange( new [] {
                new PlainLineSymbolizeHandler { Line = new Pen(Color.Blue, 3) { LineJoin = LineJoin.Round } },
                new PlainLineSymbolizeHandler{ Line = new Pen(Color.Aqua, 1)}, });

            var layRivers = new SharpMap.Layers.Symbolizer.LinealVectorLayer("Rivers")
                                {
                                    //Set the datasource to a shapefile in the App_data folder
                                    DataSource = new ShapeFileEx("GeoData/World/rivers.shp", true),
                                    //Define a blue 2px wide pen
                                    Symbolizer = symbolizer,
                                    SRID = 4326
                                };

            //Set up a cities layer
            var layCities = new SharpMap.Layers.Symbolizer.PuntalVectorLayer("Cities")
                                {
                                    //Set the datasource to a shapefile in the App_data folder
                                    DataSource = new ShapeFileEx("GeoData/World/cities.shp", true),
                                    Symbolizer = new RasterPointSymbolizer() { Scale = 0.8f },
                                    MaxVisible = 40
                                } ;

            //Set up a country label layer
            var layLabel = new LabelLayer("Country labels")
                               {
                                   DataSource = layCountries.DataSource,
                                   Enabled = true,
                                   LabelColumn = "Name",
                                   Style =
                                       new LabelStyle
                                           {
                                               ForeColor = Color.White,
                                               Font = new Font(FontFamily.GenericSerif, 12),
                                               BackColor = new SolidBrush(Color.FromArgb(128, 255, 0, 0)),
                                               HorizontalAlignment = LabelStyle.HorizontalAlignmentEnum.Center
                                           },
                                   MaxVisible = 90,
                                   MinVisible = 30,
                                   SRID = 4326,
                                   MultipartGeometryBehaviour = LabelLayer.MultipartGeometryBehaviourEnum.Largest,

                               };

            //Set up a city label layer
            var layCityLabel = new LabelLayer("City labels")
                                   {
                                       DataSource = layCities.DataSource,
                                       Enabled = true,
                                       LabelColumn = "Name",
                                       TextRenderingHint = TextRenderingHint.AntiAlias,
                                       SmoothingMode = SmoothingMode.AntiAlias,
                                       SRID = 4326,
                                       LabelFilter = LabelCollisionDetection.ThoroughCollisionDetection,
                                       Style =
                                           new LabelStyle
                                               {
                                                   ForeColor = Color.Black,
                                                   Font = new Font(FontFamily.GenericSerif, 11),
                                                   HorizontalAlignment = LabelStyle.HorizontalAlignmentEnum.Left,
                                                   VerticalAlignment = LabelStyle.VerticalAlignmentEnum.Bottom,
                                                   Offset = new PointF(3, 3),
                                                   CollisionDetection = true,
                                                   Halo = new Pen(Color.Yellow, 2)
                                               }, 
                                       MaxVisible = layLabel.MinVisible,
                                   };

            //Setup River label
            var layRiverLabel = new LabelLayer("River labels")
                                   {
                                       DataSource = layRivers.DataSource,
                                       Enabled = true,
                                       LabelColumn = "Name",
                                       TextRenderingHint = TextRenderingHint.AntiAlias,
                                       SmoothingMode = SmoothingMode.AntiAlias,
                                       SRID = 4326,
                                       LabelFilter = LabelCollisionDetection.ThoroughCollisionDetection,
                                       MultipartGeometryBehaviour = LabelLayer.MultipartGeometryBehaviourEnum.All,
                                       Style =
                                           new LabelStyle
                                               {
                                                   ForeColor = Color.DarkBlue,
                                                   Font = new Font("Arial", 11),
                                                   HorizontalAlignment = LabelStyle.HorizontalAlignmentEnum.Center,
                                                   VerticalAlignment = LabelStyle.VerticalAlignmentEnum.Middle,
                                                   //CollisionDetection = true,
                                                   Halo = new Pen(Color.Azure, 2), 
                                                   IgnoreLength =  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.Layers.Add(layCountries);
            map.Layers.Add(layRivers);
            map.Layers.Add(layCities);
            map.Layers.Add(layRiverLabel);
            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;
        }
 public override void Render(Graphics graphics, Map map)
 {
     if ((!map.Size.IsEmpty && (map.Size.Width > 0)) && (map.Size.Height > 0))
     {
         Bitmap bmp = new Bitmap(map.Size.Width, map.Size.Height, PixelFormat.Format32bppArgb);
         Graphics g = Graphics.FromImage(bmp);
         g.Transform = graphics.Transform.Clone();
         Extent extent = new Extent(map.Envelope.Min.X, map.Envelope.Min.Y, map.Envelope.Max.X, map.Envelope.Max.Y);
         int level = Utilities.GetNearestLevel(this._source.Schema.Resolutions, map.PixelSize);
         //IList<TileInfo> tiles = this._source.Schema.GetTilesInView(extent, level);
         IList<TileInfo> tiles = (this._source.Schema as ArcGISTileCompactSchema).GetTilesInView(extent, level);
         IList<WaitHandle> waitHandles = new List<WaitHandle>();
         foreach (TileInfo info in tiles)
         {
             if (this._bitmaps.Find(info.Index) == null)
             {
                 if ((this._fileCache != null) && this._fileCache.Exists(info.Index))
                 {
                     this._bitmaps.Add(info.Index, this.GetImageFromFileCache(info) as Bitmap);
                 }
                 else
                 {
                     AutoResetEvent waitHandle = new AutoResetEvent(false);
                     waitHandles.Add(waitHandle);
                     ThreadPool.QueueUserWorkItem(new WaitCallback(this.GetTileOnThread), new object[] { this._source.Provider, info, this._bitmaps, waitHandle });
                 }
             }
         }
         foreach (WaitHandle handle in waitHandles)
         {
             handle.WaitOne();
         }
         foreach (TileInfo info in tiles)
         {
             Bitmap bitmap = this._bitmaps.Find(info.Index);
             if (bitmap != null)
             {
                 PointF min = map.WorldToImage(new SharpMap.Geometries.Point(info.Extent.MinX, info.Extent.MinY));
                 PointF max = map.WorldToImage(new SharpMap.Geometries.Point(info.Extent.MaxX, info.Extent.MaxY));
                 min = new PointF((float)Math.Round((double)min.X), (float)Math.Round((double)min.Y));
                 max = new PointF((float)Math.Round((double)max.X), (float)Math.Round((double)max.Y));
                 try
                 {
                     g.DrawImage(bitmap, new Rectangle((int)min.X, (int)max.Y, (int)(max.X - min.X), (int)(min.Y - max.Y)), 0, 0, this._source.Schema.Width, this._source.Schema.Height, GraphicsUnit.Pixel, this._imageAttributes);
                     continue;
                 }
                 catch (Exception)
                 {
                     continue;
                 }
             }
         }
         graphics.Transform = new Matrix();
         graphics.DrawImageUnscaled(bmp, 0, 0);
         graphics.Transform = g.Transform;
         g.Dispose();
     }
 }
Пример #11
0
        public static Map InitializeMap(float angle)
        {
            //Initialize a new map of size 'imagesize'
            Map map = new Map();

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

            //Set the datasource to a shapefile in the App_data folder
            layCountries.DataSource = new SharpMap.Data.Providers.OracleProvider("system", "metsys", "127.0.0.1",
                                                                         "COUNTRIES", "GEOM", "ID");
            //System.Diagnostics.Debug.WriteLine(layCountries.DataSource.GetGeometryByOid(101).ToString());

            //Set fill-style to green
            layCountries.Style.Fill = new SolidBrush(Color.Green);
            //Set the polygons to have a black outline
            layCountries.Style.Outline = Pens.Black;
            layCountries.Style.EnableOutline = true;

            //Set up a river layer
            VectorLayer layRivers = new SharpMap.Layers.VectorLayer("Rivers");
            //Set the datasource to a shapefile in the App_data folder
            layRivers.DataSource = new SharpMap.Data.Providers.OracleProvider("system", "metsys", "127.0.0.1", "RIVERS", "GEOM", "ID");
            //Define a blue 1px wide pen
            layRivers.Style.Line = new Pen(Color.Blue, 1);

            //Set up a river layer
            VectorLayer layCities = new VectorLayer("Cities");
            //Set the datasource to a shapefile in the App_data folder
            layCities.DataSource = new SharpMap.Data.Providers.OracleProvider("system", "metsys", "127.0.0.1", "CITIES", "GEOM", "ID");
            layCities.Style.SymbolScale = 0.8f;
            layCities.MaxVisible = 40;

            //Set up a country label layer
            LabelLayer layLabel = new LabelLayer("Country labels")
            {
                DataSource = layCountries.DataSource,
                Enabled = true,
                LabelColumn = "NAME",
                MaxVisible = 90,
                MinVisible = 30,
                MultipartGeometryBehaviour = LabelLayer.MultipartGeometryBehaviourEnum.Largest,
                LabelFilter = SharpMap.Rendering.LabelCollisionDetection.ThoroughCollisionDetection,
                PriorityColumn = "POPDENS",
                Style = new LabelStyle()
                {
                    ForeColor = Color.White,
                    Font = new Font(FontFamily.GenericSerif, 12),
                    BackColor = new SolidBrush(Color.FromArgb(128, 255, 0, 0)),
                    HorizontalAlignment = LabelStyle.HorizontalAlignmentEnum.Center,
                    CollisionDetection = true
                }
            };

            ////Set up a city label layer
            LabelLayer layCityLabel = new LabelLayer("City labels")
            {
                DataSource = layCities.DataSource,
                Enabled = true,
                LabelColumn = "NAME",
                PriorityColumn = "POPULATION",
                PriorityDelegate = delegate(GeoAPI.Features.IFeature fdr)
                {
                    Int32 retVal = 10000000 * ((String)fdr.Attributes["capital"] == "Y" ? 1 : 0);
                    return retVal + Convert.ToInt32(fdr.Attributes["population"]);
                },
                TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias,
                SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias,
                LabelFilter = SharpMap.Rendering.LabelCollisionDetection.ThoroughCollisionDetection,
                Style = new LabelStyle()
                {
                    ForeColor = Color.Black,
                    Font = new Font(FontFamily.GenericSerif, 11),
                    MaxVisible = layLabel.MinVisible,
                    HorizontalAlignment = LabelStyle.HorizontalAlignmentEnum.Left,
                    VerticalAlignment = LabelStyle.VerticalAlignmentEnum.Bottom,
                    Offset = new PointF(3, 3),
                    Halo = new Pen(Color.Yellow, 2),
                    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.Layers.Add(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.ZoomToExtents(); // = 360;

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

            return map;

        }
Пример #12
0
        public static Map InitializeMap(float angle)
        {
            //Initialize a new map based on the simple map
            Map map = new Map();

            //Set up 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.Green);
            //Set the polygons to have a black outline
            layCountries.Style.Outline = Pens.Black;
            layCountries.Style.EnableOutline = true;
            layCountries.SRID = 4326;
            map.Layers.Add(layCountries);

            //set up 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;
            map.Layers.Add(layCities);

            //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;
            map.Layers.Add(layLabel);

            //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;
            map.Layers.Add(layCityLabel);

            //Set a gradient theme on the countries layer, based on Population density
            //First create two styles that specify min and max styles
            //In this case we will just use the default values and override the fill-colors
            //using a colorblender. If different line-widths, line- and fill-colors where used
            //in the min and max styles, these would automatically get linearly interpolated.
            VectorStyle min = new VectorStyle();
            VectorStyle max = new VectorStyle();
            //Create theme using a density from 0 (min) to 400 (max)
            GradientTheme popdens = new GradientTheme("PopDens", 0, 400, min, max);
            //We can make more advanced coloring using the ColorBlend'er.
            //Setting the FillColorBlend will override any fill-style in the min and max fills.
            //In this case we just use the predefined Rainbow colorscale
            popdens.FillColorBlend = ColorBlend.Rainbow5;
            layCountries.Theme = popdens;

            //Lets scale the labels so that big countries have larger texts as well
            LabelStyle lblMin = new LabelStyle();
            LabelStyle lblMax = new LabelStyle();
            lblMin.ForeColor = Color.Black;
            lblMin.Font = new Font(FontFamily.GenericSerif, 6);
            lblMax.ForeColor = Color.Blue;
            lblMax.BackColor = new SolidBrush(Color.FromArgb(128, 255, 255, 255));
            lblMin.BackColor = lblMax.BackColor;
            lblMax.Font = new Font(FontFamily.GenericSerif, 9);
            layLabel.Theme = new GradientTheme("PopDens", 0, 400, lblMin, lblMax);

            //Lets scale city icons based on city population
            //cities below 1.000.000 gets the smallest symbol, and cities with more than 5.000.000 the largest symbol
            VectorStyle citymin = new VectorStyle();
            VectorStyle citymax = new VectorStyle();
            string iconPath = "Images/icon.png";
            if (!File.Exists(iconPath))
            {
                throw new Exception(
                    String.Format("Error file '{0}' could not be found, make sure it is at the expected location",
                                  iconPath));
            }

            citymin.Symbol = new Bitmap(iconPath);
            citymin.SymbolScale = 0.5f;
            citymax.Symbol = new Bitmap(iconPath);
            citymax.SymbolScale = 1f;
            layCities.Theme = new GradientTheme("Population", 1000000, 5000000, citymin, citymax);

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

            map.MaximumExtents = new Envelope(-20, 70, -65, 80);
            map.MaximumZoom = 30;

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

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

            return map;
        }
Пример #13
0
        public static Map InitializeMap(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 SpatiaLite(
                DataSource, "countries", "geom", "PK_UID");

            //Set fill-style to green
            layCountries.Style.Fill = new SolidBrush(Color.Green);
            //Set the polygons to have a black outline
            layCountries.Style.Outline = Pens.Black;
            layCountries.Style.EnableOutline = true;

            //Set up a river layer
            VectorLayer layRivers = new VectorLayer("Rivers");
            //Set the datasource to a shapefile in the App_data folder
            layRivers.DataSource = new SpatiaLite(
                DataSource, "rivers", "geom", "PK_UID");
            //Define a blue 3px wide pen
            layRivers.Style.Line = new Pen(Color.LightBlue, 2);
            layRivers.Style.Line.CompoundArray = new[] { 0.2f, 0.8f };
            layRivers.Style.Outline = new Pen(Color.DarkBlue, 3);
            layRivers.Style.EnableOutline = true;

            //Set up a cities layer
            VectorLayer layCities = new VectorLayer("Cities");
            //Set the datasource to the spatialite table
            layCities.DataSource = new SpatiaLite(
                DataSource, "cities", "geom", "PK_UID");
            layCities.Style.SymbolScale = 0.8f;
            layCities.MaxVisible = 40;

            //Set up a country label layer
            LabelLayer layLabel = new LabelLayer("Country labels") 
            {
                DataSource = layCountries.DataSource,
                LabelColumn = "NAME",
                MultipartGeometryBehaviour = LabelLayer.MultipartGeometryBehaviourEnum.Largest,
                LabelFilter = LabelCollisionDetection.ThoroughCollisionDetection,
                PriorityColumn = "POPDENS",
                Style = new LabelStyle
                {
                    ForeColor = Color.White,
                    Font = new Font(FontFamily.GenericSerif, 12),
                    BackColor = new SolidBrush(Color.FromArgb(128, 255, 0, 0)),
                    HorizontalAlignment = LabelStyle.HorizontalAlignmentEnum.Center,
                    MaxVisible = 90,
                    MinVisible = 30,
                    CollisionDetection = true
                }
            };

            //Set up a city label layer
            LabelLayer layCityLabel = new LabelLayer("City labels")
            {
                DataSource = layCities.DataSource,
                LabelColumn = "name",
                PriorityColumn = "population",
                PriorityDelegate = delegate(IFeature fdr) 
                { 
                    Int32 retVal = 10000000 * ( (String)fdr.Attributes["capital"] == "Y" ? 1 : 0 );
                    return  retVal + Convert.ToInt32(fdr.Attributes["population"]);
                },
                TextRenderingHint = TextRendering.AntiAlias,
                SmoothingMode = Smoothing.AntiAlias,
                LabelFilter = LabelCollisionDetection.ThoroughCollisionDetection,
                Style = new LabelStyle
                {
                    ForeColor = Color.Black,
                    Font = new Font(FontFamily.GenericSerif, 11),
                    MaxVisible = layLabel.MinVisible,
                    HorizontalAlignment = LabelStyle.HorizontalAlignmentEnum.Left,
                    VerticalAlignment = LabelStyle.VerticalAlignmentEnum.Bottom,
                    Offset = new PointF(3, 3),
                    Halo = new Pen(Color.Yellow, 2),
                    CollisionDetection = true
                }
            };

            LabelLayer layRiverLabels = new LabelLayer("RiverLabels");
            layRiverLabels.DataSource = layRivers.DataSource;
            layRiverLabels.LabelColumn = "Name";
            layRiverLabels.PriorityDelegate = GetRiverLength;
            layRiverLabels.Style = new LabelStyle
                                       {
                                           Font = new Font("Arial", 10, FontStyle.Bold),
                                           Halo = new Pen(Color.Azure, 2),
                                           ForeColor = Color.DarkCyan,
                                           IgnoreLength = true,
                                           Enabled = true,
                                           CollisionDetection = true,
                                          
                                       };
            layRiverLabels.LabelFilter = LabelCollisionDetection.ThoroughCollisionDetection;

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

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

            map.ZoomToExtents(); // = 360;

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

        }
Пример #14
0
        internal static Map InitializeMap(float angle, string[] filenames)
        {
            if (filenames == null)
                return null;

            Map map = new Map();

            try
            {
                foreach (string filename in filenames)
                {
                    string connectionString = string.Format("Data Source={0}", filename);
                    foreach (SpatiaLite provider in SpatiaLite.GetSpatialTables(connectionString))
                    {
                        map.Layers.Add(
                            new VectorLayer(
                                string.Format("{0} - {1}", provider.Table, provider.GeometryColumn), provider) { Style = LayerTools.GetRandomVectorStyle() });
                    }
                }
                if (map.Layers.Count > 0)
                {
                    map.ZoomToExtents();

                    Matrix mat = new Matrix();
                    mat.RotateAt(angle, map.WorldToImage(map.Center));
                    map.MapTransform = mat;
                    return map;
                }
            }
            catch (Exception ex)
            {
                Trace.WriteLine(ex.Message);
            }
            return null;
        }
Пример #15
0
        public static Map InitializeMap(float angle)
        {
            try
            {
                // WARNING
                // This sample needs the GeoServer WFS running on your local machine. 
                // It uses the GeoServer default sample data. Installing and starting it is all you need to do
                // http://docs.codehaus.org/display/GEOS/Download

                // Sample by Peter Robineau

                const string getCapabilitiesURI = "http://localhost:8080/geoserver/wfs";
                const string serviceURI = "http://localhost:8080/geoserver/wfs";

                Map map = new Map(new Size(600, 600));
                map.MinimumZoom = 0.005;
                map.BackColor = Color.White;

                VectorLayer layer1 = new VectorLayer("States");
                VectorLayer layer2 = new VectorLayer("SelectedStatesAndHousholds");
                VectorLayer layer3 = new VectorLayer("New Jersey");
                VectorLayer layer4 = new VectorLayer("Roads");
                VectorLayer layer5 = new VectorLayer("Landmarks");
                VectorLayer layer6 = new VectorLayer("Poi");

                // Demo data from Geoserver 1.5.3 and Geoserver 1.6.0 

                WFS prov1 = new WFS(getCapabilitiesURI, "topp", "states", WFS.WFSVersionEnum.WFS1_0_0);

                // Bypass 'GetCapabilities' and 'DescribeFeatureType', if you know all necessary metadata.
                WfsFeatureTypeInfo featureTypeInfo = new WfsFeatureTypeInfo(serviceURI, "topp", null, "states",
                                                                            "the_geom");
                // 'WFS.WFSVersionEnum.WFS1_1_0' supported by Geoserver 1.6.x
                WFS prov2 = new WFS(featureTypeInfo, WFS.WFSVersionEnum.WFS1_1_0);
                // Bypass 'GetCapabilities' and 'DescribeFeatureType' again...
                // It's possible to specify the geometry type, if 'DescribeFeatureType' does not...(.e.g 'GeometryAssociationType')
                // This helps to accelerate the initialization process in case of unprecise geometry information.
                WFS prov3 = new WFS(serviceURI, "topp", "http://www.openplans.org/topp", "states", "the_geom",
                                    GeometryTypeEnum.MultiSurfacePropertyType, WFS.WFSVersionEnum.WFS1_1_0);

                // Get data-filled FeatureTypeInfo after initialization of dataprovider (useful in Web Applications for caching metadata.
                WfsFeatureTypeInfo info = prov1.FeatureTypeInfo;

                // Use cached 'GetCapabilities' response of prov1 (featuretype hosted by same service).
                // Compiled XPath expressions are re-used automatically!
                // If you use a cached 'GetCapabilities' response make sure the data provider uses the same version of WFS as the one providing the cache!!!
                WFS prov4 = new WFS(prov1.GetCapabilitiesCache, "tiger", "tiger_roads", WFS.WFSVersionEnum.WFS1_0_0);
                WFS prov5 = new WFS(prov1.GetCapabilitiesCache, "tiger", "poly_landmarks", WFS.WFSVersionEnum.WFS1_0_0);
                WFS prov6 = new WFS(prov1.GetCapabilitiesCache, "tiger", "poi", WFS.WFSVersionEnum.WFS1_0_0);
                // Clear cache of prov1 - data providers do not have any cache, if they use the one of another data provider  
                prov1.GetCapabilitiesCache = null;

                //Filters
                IFilter filter1 = new PropertyIsEqualToFilter_FE1_1_0("STATE_NAME", "California");
                IFilter filter2 = new PropertyIsEqualToFilter_FE1_1_0("STATE_NAME", "Vermont");
                IFilter filter3 = new PropertyIsBetweenFilter_FE1_1_0("HOUSHOLD", "600000", "4000000");
                IFilter filter4 = new PropertyIsLikeFilter_FE1_1_0("STATE_NAME", "New*");

                // SelectedStatesAndHousholds: Green
                OGCFilterCollection filterCollection1 = new OGCFilterCollection();
                filterCollection1.AddFilter(filter1);
                filterCollection1.AddFilter(filter2);
                OGCFilterCollection filterCollection2 = new OGCFilterCollection();
                filterCollection2.AddFilter(filter3);
                filterCollection1.AddFilterCollection(filterCollection2);
                filterCollection1.Junctor = OGCFilterCollection.JunctorEnum.Or;
                prov2.OGCFilter = filterCollection1;

                // Like-Filter('New*'): Bisque
                prov3.OGCFilter = filter4;

                // Layer Style
                layer1.Style.Fill = new SolidBrush(Color.IndianRed); // States
                layer2.Style.Fill = new SolidBrush(Color.Green); // SelectedStatesAndHousholds
                layer3.Style.Fill = new SolidBrush(Color.Bisque); // e.g. New York, New Jersey,...
                layer5.Style.Fill = new SolidBrush(Color.LightBlue);

                // Labels
                // Labels are collected when parsing the geometry. So there's just one 'GetFeatureByOid' call necessary.
                // Otherwise (when calling twice for retrieving labels) there may be an inconsistent read...
                // If a label property is set, the quick geometry option is automatically set to 'false'.
                prov3.Label = "STATE_NAME";
                LabelLayer layLabel = new LabelLayer("labels");
                layLabel.DataSource = prov3;
                layLabel.Enabled = true;
                layLabel.LabelColumn = prov3.Label;
                layLabel.Style = new LabelStyle();
                layLabel.Style.CollisionDetection = false;
                layLabel.Style.CollisionBuffer = new SizeF(5, 5);
                layLabel.Style.ForeColor = Color.Black;
                layLabel.Style.Font = new Font(FontFamily.GenericSerif, 10);
                layLabel.MaxVisible = 90;
                layLabel.Style.HorizontalAlignment = LabelStyle.HorizontalAlignmentEnum.Center;
                // Options 
                // Defaults: MultiGeometries: true, QuickGeometries: false, GetFeatureGETRequest: false
                // Render with validation...
                prov1.QuickGeometries = false;
                // Important when connecting to an UMN MapServer
                prov1.GetFeatureGETRequest = true;
                // Ignore multi-geometries...
                prov1.MultiGeometries = false;

                // Quick geometries
                // We need this option for prov2 since we have not passed a featuretype namespace
                prov2.QuickGeometries = true;
                prov4.QuickGeometries = true;
                prov5.QuickGeometries = true;
                prov6.QuickGeometries = true;

                layer1.DataSource = prov1;
                layer2.DataSource = prov2;
                layer3.DataSource = prov3;
                layer4.DataSource = prov4;
                layer5.DataSource = prov5;
                layer6.DataSource = prov6;

                map.Layers.Add(layer1);
                map.Layers.Add(layer2);
                map.Layers.Add(layer3);
                map.Layers.Add(layer4);
                map.Layers.Add(layer5);
                map.Layers.Add(layer6);
                map.Layers.Add(layLabel);

                map.Center = new Point(-74.0, 40.7);
                map.Zoom = 10;
                // Alternatively zoom closer
                // demoMap.Zoom = 0.2;

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

                return map;
            }
            catch (WebException ex)
            {
                if ((ex.Message.Contains("(502) Bad Gateway")) ||
                    (ex.Message.Contains("Unable to connect to the remote server")))
                {
                    throw new Exception(
                        "The Wfs sample threw an exception. You probably need to install the GeoServer WFS to your local machine. You can get it from here: http://docs.codehaus.org/display/GEOS/Download. The exception message was: " +
                        ex.Message);
                }
                else throw;
            }
        }
Пример #16
0
        private static Map InitializeMapOsm(float angle)
        {
            //Transparent style
            VectorStyle transparentStyle = new VectorStyle();
            transparentStyle.Fill = Brushes.Transparent;
            transparentStyle.EnableOutline = true; //otherwise all the fancy theming stuff won't work!
            transparentStyle.Line.Brush = Brushes.Transparent;
            transparentStyle.Outline.Brush = Brushes.Transparent;
            transparentStyle.Symbol = null;

            VectorStyle transparentStyle2 = new VectorStyle();
            transparentStyle2.Fill = Brushes.Transparent;
            transparentStyle2.EnableOutline = true; //otherwise all the fancy theming stuff won't work!
            transparentStyle2.Line.Brush = Brushes.Transparent;
            transparentStyle2.Outline.Brush = Brushes.Transparent;
            transparentStyle2.Symbol = null;

            //Initialize a new map
            Map map = new Map();
            map.BackColor = Color.Cornsilk;

            var encoding = System.Text.Encoding.UTF8;

            //Set up the countries layer
            VectorLayer layNatural = new VectorLayer("Natural");
            //Set the datasource to a shapefile in the App_data folder
            layNatural.DataSource = new ShapeFile(string.Format("{0}/natural.shp", PathOsm), true) { Encoding = encoding };
            //Set default style to draw nothing
            layNatural.Style = transparentStyle;
            //Set theme
            ThemeViaDelegate theme = new ThemeViaDelegate(layNatural.Style, "type");
            theme.GetStyleFunction = delegate(FeatureDataRow row)
                                         {
                                             string caseVal = (String) row["type"];
                                             caseVal = caseVal.ToLowerInvariant();
                                             VectorStyle returnStyle = new VectorStyle();

                                             switch (caseVal)
                                             {
                                                 case "forest":
                                                     returnStyle.Fill = Brushes.ForestGreen;
                                                     returnStyle.EnableOutline = true;
                                                     returnStyle.Outline.Brush = Brushes.DarkGreen;
                                                     break;
                                                 case "water":
                                                     returnStyle.Fill = Brushes.Aqua;
                                                     returnStyle.EnableOutline = true;
                                                     returnStyle.Outline.Brush = Brushes.DarkBlue;
                                                     break;
                                                 case "riverbank":
                                                     returnStyle.Fill = Brushes.Peru;
                                                     returnStyle.EnableOutline = true;
                                                     returnStyle.Outline.Brush = Brushes.OrangeRed;
                                                     break;
                                                 case "park":
                                                     returnStyle.Fill = Brushes.PaleGreen;
                                                     returnStyle.EnableOutline = true;
                                                     returnStyle.Outline.Brush = Brushes.DarkGreen;
                                                     break;
                                                 default:
                                                     returnStyle = null;
                                                     break;
                                             }
                                             return returnStyle;
                                         };
            layNatural.Theme = theme;
            layNatural.SRID = 31466;

            VectorLayer layRoads = new VectorLayer("Roads");
            layRoads.DataSource = new ShapeFile(string.Format("{0}/roads.shp", PathOsm)) { Encoding = encoding };
            layRoads.DataSource.Open();
            _roadsExtents = layRoads.DataSource.GetExtents();
            //layRoads.DataSource.Close();
            layRoads.Style = transparentStyle;
            ThemeViaDelegate themeRoads = new ThemeViaDelegate(transparentStyle, "type");
            themeRoads.GetStyleFunction = delegate(FeatureDataRow row)
                                              {
                                                  VectorStyle returnStyle = new VectorStyle();

                                                  switch ((String)row["type"])
                                                  {
                                                      case "rail":
                                                          returnStyle.Fill = Brushes.White;
                                                          returnStyle.Line.DashPattern = new float[] { 4f, 4f };//;System.Drawing.Drawing2D.DashStyle.Dash;
                                                          returnStyle.Line.Width = 4;
                                                          returnStyle.EnableOutline = true;
                                                          returnStyle.Outline.Brush = Brushes.Black;
                                                          returnStyle.Outline.Width = 6;
                                                          break;
                                                      case "canal":
                                                          returnStyle.Fill = Brushes.Aqua;
                                                          returnStyle.Outline.Brush = Brushes.DarkBlue;
                                                          returnStyle.Outline.Width = 5;
                                                          break;
                                                      case "cycleway":
                                                      case "footway":
                                                      case "pedestrian":
                                                          returnStyle.Line.Brush = Brushes.DarkGray;
                                                          returnStyle.Line.DashStyle =
                                                              DashStyle.Dot;
                                                          returnStyle.Line.Width = 1;
                                                          returnStyle.MaxVisible = _roadsExtents.Width * 0.05d;
                                                          break;
                                                      case "living_street":
                                                      case "residential":
                                                          returnStyle.Line.Brush = Brushes.LightGoldenrodYellow;
                                                          returnStyle.Line.Width = 2;
                                                          returnStyle.EnableOutline = true;
                                                          returnStyle.Outline.Brush = Brushes.DarkGray;
                                                          returnStyle.Outline.Width = 4;
                                                          returnStyle.MaxVisible = _roadsExtents.Width * 0.15d;
                                                          break;
                                                      case "primary":
                                                          returnStyle.Line.Brush = Brushes.LightGoldenrodYellow;
                                                          returnStyle.Line.Width = 7;
                                                          returnStyle.EnableOutline = true;
                                                          returnStyle.Outline.Brush = Brushes.Black;
                                                          returnStyle.Outline.Width = 11;
                                                          break;
                                                      case "secondary":
                                                          returnStyle.Line.Brush = Brushes.LightGoldenrodYellow;
                                                          returnStyle.Line.Width = 6;
                                                          returnStyle.EnableOutline = true;
                                                          returnStyle.Outline.Brush = Brushes.Black;
                                                          returnStyle.MaxVisible = _roadsExtents.Width * 0.3d;
                                                          returnStyle.Outline.Width = 10;
                                                          break;
                                                      case "tertiary":
                                                          returnStyle.Line.Brush = Brushes.LightGoldenrodYellow;
                                                          returnStyle.Line.Width = 5;
                                                          returnStyle.EnableOutline = true;
                                                          returnStyle.Outline.Brush = Brushes.Black;
                                                          returnStyle.MaxVisible = _roadsExtents.Width * 0.6d;
                                                          returnStyle.Outline.Width = 9;
                                                          break;
                                                      case "path":
                                                      case "track":
                                                      case "unclassified":
                                                          returnStyle.Line.Brush = Brushes.DarkGray;
                                                          returnStyle.Line.DashStyle =
                                                              DashStyle.DashDotDot;
                                                          returnStyle.Line.Width = 1;
                                                          returnStyle.MaxVisible = _roadsExtents.Width * 0.025d;
                                                          break;
                                                      default:
                                                          returnStyle = null;
                                                          break;
                                                  }
                                                  return returnStyle;
                                              };
            layRoads.Theme = themeRoads;
            layRoads.SRID = 31466;

            VectorLayer layRail = new VectorLayer("Railways");
            layRail.DataSource = new ShapeFile(string.Format("{0}/railways.shp", PathOsm)) { Encoding = encoding };
            layRail.Style.Line.Brush = Brushes.White;
            layRail.Style.Line.DashPattern = new float[] {4f, 4f};//;System.Drawing.Drawing2D.DashStyle.Dash;
            layRail.Style.Line.Width = 4;
            layRail.Style.EnableOutline = true;
            layRail.Style.Outline.Brush = Brushes.Black;
            layRail.Style.Outline.Width = 6;

            VectorLayer layWaterways = new VectorLayer("Waterways");
            layWaterways.Style = transparentStyle;
            layWaterways.DataSource = new ShapeFile(string.Format("{0}/waterways.shp", PathOsm)) { Encoding = encoding };
            layRoads.Style = transparentStyle;
            ThemeViaDelegate themeWater = new ThemeViaDelegate(transparentStyle, "type");
            themeWater.GetStyleFunction = delegate(FeatureDataRow row)
            {
                VectorStyle returnStyle = new VectorStyle();
                returnStyle.Line.Brush = Brushes.Aqua;
                returnStyle.EnableOutline = true;
                Int32 lineWidth = 1;
                switch ((String)row["type"])
                {
                    case "canal":
                    case "derelict_canal":
                        lineWidth = 2;
                        break;
                    case "drain":
                        returnStyle.EnableOutline = false;
                        break;
                    case "stream":
                        lineWidth = 2;
                        break;
                    default:
                        //returnStyle = null;
                        break;
                }
                returnStyle.Line.Width = lineWidth;
                returnStyle.Outline.Brush = Brushes.DarkBlue;
                returnStyle.Outline.Width = lineWidth + 1;
                return returnStyle;
            };
            layWaterways.Theme = themeWater;
            layWaterways.SRID = 31466;

            VectorLayer layPoints = new VectorLayer("Points");
            layPoints.DataSource = new ShapeFile(string.Format("{0}/points.shp", PathOsm)) { Encoding = encoding };
            layPoints.Style = transparentStyle2;
            ThemeViaDelegate themePoints = new ThemeViaDelegate(transparentStyle2, "type");
            themePoints.GetStyleFunction = delegate(FeatureDataRow row)
            {
                VectorStyle returnStyle = new VectorStyle();
                switch ((String)row["type"])
                {
                    case "bank":
                        returnStyle.Symbol = new Bitmap("Images/Bank.gif");
                        break;
                    case "hospital":
                        returnStyle.Symbol = new Bitmap("Images/medical-facility.gif");
                        break;
                    case "hotel":
                        returnStyle.Symbol = new Bitmap("Images/hotel.gif");
                        break;
                    case "restaurant":
                    case "fast-food":
                        returnStyle.Symbol = new Bitmap("Images/restaurant.gif");
                        break;
                    case "parking":
                        returnStyle.Symbol = new Bitmap("Images/car.gif");
                        break;
                    default:
                        Bitmap tmp = new Bitmap(1,1);
                        tmp.SetPixel(0,0, Color.Transparent);
                        returnStyle.Symbol = tmp;
                        break;
                }
                return returnStyle;
            };
            layPoints.Theme = themePoints;
            layWaterways.SRID = 31466;

            var layLabel = new LabelLayer("Road Labels");
            layLabel.DataSource = layRoads.DataSource;
            layLabel.LabelColumn = "Name";

            //Add layers to Map
            map.Layers.Add(layNatural);
            map.Layers.Add(layWaterways);
            map.Layers.Add(layRail);
            map.Layers.Add(layRoads);
            map.Layers.Add(layPoints);
            map.Layers.Add(layLabel);

            ShapeProvider sp = new ShapeProvider(string.Format("{0}/obepath.shp", PathOsm)) { Encoding = encoding };
            VectorLayer vl = new VectorLayer("obepath", sp);
            vl.SRID = 31466;
            vl.Style.Symbol = new Bitmap("Images/car.gif");

            VariableLayerCollection.Interval = 500;
            map.VariableLayers.Add(vl);

            //Restrict zoom
            map.MaximumZoom = layRoads.Envelope.Width * 0.75d;
            map.Zoom = layRoads.Envelope.Width * 0.2d; ;
            map.Center = layRoads.Envelope.Centre;

            var disclaimer = new Disclaimer
                {
                    Font = new Font("Arial", 7f, FontStyle.Italic),
                    Text = "Geodata from OpenStreetMap (CC-by-SA)\nTransformed to Shapefile by geofabrik.de",
                    Anchor = MapDecorationAnchor.CenterBottom
                };
            map.Decorations.Add(disclaimer);
            transparentStyle2.MaxVisible = map.MaximumZoom*0.3;

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

            return map;
        }
Пример #17
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 ShapeFileEx("GeoData/World/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 = 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 ShapeFileEx("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 ShapeFileEx("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.Layers.Add(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;
        }