ZoomToExtents() public method

Zooms to the extents of all layers
public ZoomToExtents ( ) : void
return void
示例#1
0
        public static Map InitializeMap()
        {
            Map map = new Map();

            //string url = "http://labs.metacarta.com/wms-c/tilecache.py?version=1.1.1&request=GetCapabilities&service=wms-c";
            string url = "http://dev:8080/geoserver/gwc/service/wms?SERVICE=WMS&VERSION=1.1.1&REQUEST=getcapabilities&TILED=true";
            //string url = "http://dev:8080/geoserver/ows?service=wms&version=1.3.0&request=GetCapabilities&tiled=true";
            //TiledWmsLayer tiledWmsLayer = new TiledWmsLayer("Metacarta", url);
            //tiledWmsLayer.TileSetsActive.Add(tiledWmsLayer.TileSets["avalon"].Name);
            //map.Layers.Add(tiledWmsLayer);
            //map.ZoomToBox(new BoundingBox(-180.0, -90.0, 180.0, 90.0));

            //WmscRequest req;
            //ITileSource tileSource;
            TileAsyncLayer tileLayer;
            //BruTile.Web.TmsTileSource source2 = new TmsTileSource(url);

            var source = new List<ITileSource>(WmscTileSource.CreateFromWmscCapabilties(new System.Uri(url)));

            //            foreach (ITileSource src in source)
            //            {
                tileLayer = new TileAsyncLayer(source[16], "tileLayer" + source[16]);
                tileLayer.MapNewTileAvaliable += map.MapNewTileAvaliableHandler;
                map.BackgroundLayer.Add(tileLayer);
            //            }
            map.ZoomToExtents();

            return map;
        }
示例#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;
        }
示例#3
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;

        }
示例#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 ReSize(int x, int y)
        {
            _Map.Size = new Size(x, y);

            _Map.ZoomToExtents();
            GeoAPI.Geometries.Coordinate P1 = new GeoAPI.Geometries.Coordinate((140.0 + 6), (44.0 - 4)); //_Map.ImageToWorld(new PointF(100, 100));
            _Map.Zoom   = 90;
            _Map.Center = P1;

            zoom = _Map.Zoom;
        }
示例#6
0
    public static Map InitializeMap()
    {
      try
      {
        //Sample provided by Dan Brecht and Joel Wilson
        Map map = new Map();
        map.BackColor = Color.White;

        string relativePath = "GeoData/GeoTiff/";

        SharpMap.Layers.GdalRasterLayer layer;

        if (!File.Exists(relativePath + "format01-image_a.tif"))
        {
          throw new Exception("Make sure the data is in the relative directory: " + relativePath);
        }

        layer = new SharpMap.Layers.GdalRasterLayer("GeoTiffA", relativePath + "format01-image_a.tif");
        map.Layers.Add(layer);
        layer = new SharpMap.Layers.GdalRasterLayer("GeoTiffB", relativePath + "format01-image_b.tif");
        map.Layers.Add(layer);
        layer = new SharpMap.Layers.GdalRasterLayer("GeoTiffC", relativePath + "format01-image_c.tif");
        map.Layers.Add(layer);
        layer = new SharpMap.Layers.GdalRasterLayer("GeoTiffD", relativePath + "format01-image_d.tif");
        map.Layers.Add(layer);

        SharpMap.Layers.VectorLayer shapeLayer;

        if (!File.Exists(relativePath + "outline.shp"))
        {
          throw new Exception("Make sure the data is in the relative directory: " + relativePath);
        }

        shapeLayer = new SharpMap.Layers.VectorLayer("outline", new SharpMap.Data.Providers.ShapeFile(relativePath + "outline.shp"));
        shapeLayer.Style.Fill = Brushes.Transparent;
        shapeLayer.Style.Outline = Pens.Black;
        shapeLayer.Style.EnableOutline = true;
        shapeLayer.Style.Enabled = true;
        map.Layers.Add(shapeLayer);

        map.ZoomToExtents();

        return map;
      }
      catch (Exception ex)
      {
        if (ex.Message == "The type initializer for 'OSGeo.GDAL.GdalPINVOKE' 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/", SharpMap.Layers.GdalRasterLayer.FWToolsVersion));
        }
        throw;
      }

    }
示例#7
0
        public void TestMap1()
        {
            var m = new Map(_mapSize);
            m.Layers.Add(new VectorLayer("tmp", new GeometryProvider(
                new LineString(new [] {new Coordinate(0, 0), new Coordinate(10, 10), }))));

            m.ZoomToExtents();

            Map mD = null;
            Assert.DoesNotThrow(()=>mD=SandD(m, GetFormatter()));

            TestMaps("Test1", m, mD);
        }
示例#8
0
        public void TestMapDecorationTest()
        {
            var m = new Map(new Size(780, 540)) {BackColor = Color.White};
            var p = new GeometryProvider(new List<SharpMap.Geometries.Geometry>());
            var pts = new [] {new GeoPoint(0, 0), new GeoPoint(779, 539)};
            var ls = new SharpMap.Geometries.LineString(new List<GeoPoint>(pts));
            p.Geometries.Add(ls);
            m.Layers.Add(new VectorLayer("t",p));
            m.ZoomToExtents();

            m.Decorations.Add(new TestDecoration
                                  {
                                      Anchor = MapDecorationAnchor.LeftTop,
                                      BorderColor = Color.Green,
                                      BackgroundColor = Color.LightGreen,
                                      BorderWidth = 2,
                                      Location = new Point(10, 10),
                                      BorderMargin = new Size(5, 5),
                                      RoundedEdges = true,
                                      Opacity = 0.6f
                                  });

            m.Decorations.Add(new TestDecoration
            {
                Anchor = MapDecorationAnchor.RightTop,
                BorderColor = Color.Red,
                BackgroundColor = Color.LightCoral,
                BorderWidth = 2,
                Location = new Point(10, 10),
                BorderMargin = new Size(5, 5),
                RoundedEdges = true,
                Opacity = 0.2f
            });

            m.Decorations.Add(new ScaleBar
            {
                Anchor = MapDecorationAnchor.Default,
                BorderColor = Color.Blue,
                BackgroundColor = Color.CornflowerBlue,
                BorderWidth = 2,
                Location = new Point(10, 10),
                BorderMargin = new Size(5, 5),
                RoundedEdges = true,
                BarWidth = 4,
                ScaleText =ScaleBarLabelText.RepresentativeFraction,
                NumTicks = 2,
                Opacity = 1f
            });
            var bmp = m.GetMap();
            bmp.Save("TestMapDecorationTest.bmp");
        }
示例#9
0
        public void TestMapDecorationTest()
        {
            Map m = new Map(new Size(780, 540)) {BackColor = Color.White, SRID = 0};
            GeoPoint[] pts = new [] {new GeoPoint(0, 0), new GeoPoint(779, 539)};
            FeatureProvider p = new FeatureProvider(m.Factory.CreateLineString(pts));
            m.Layers.Add(new VectorLayer("t",p));
            m.ZoomToExtents();

            m.Decorations.Add(new TestDecoration
                                  {
                                      Anchor = MapDecorationAnchor.LeftTop,
                                      BorderColor = Color.Green,
                                      BackgroundColor = Color.LightGreen,
                                      BorderWidth = 2,
                                      Location = new Point(10, 10),
                                      BorderMargin = new Size(5, 5),
                                      RoundedEdges = true,
                                      Opacity = 0.6f
                                  });

            m.Decorations.Add(new TestDecoration
            {
                Anchor = MapDecorationAnchor.RightTop,
                BorderColor = Color.Red,
                BackgroundColor = Color.LightCoral,
                BorderWidth = 2,
                Location = new Point(10, 10),
                BorderMargin = new Size(5, 5),
                RoundedEdges = true,
                Opacity = 0.2f
            });

            m.Decorations.Add(new ScaleBar
            {
                Anchor = MapDecorationAnchor.Default,
                BorderColor = Color.Blue,
                BackgroundColor = Color.CornflowerBlue,
                BorderWidth = 2,
                Location = new Point(10, 10),
                BorderMargin = new Size(5, 5),
                RoundedEdges = true,
                BarWidth = 4,
                ScaleText =ScaleBarLabelText.RepresentativeFraction,
                NumTicks = 2,
                Opacity = 1f
            });
            Image bmp = m.GetMap();
            bmp.Save("TestMapDecorationTest.bmp");
        }
示例#10
0
        public void ShowMap(Map map)
        {
            MapControl.Map = map;

            map.ZoomToExtents();

            MapControl.MouseMove += delegate(object sender, MouseEventArgs e)
                                        {
                                            var point = map.ImageToWorld(new PointF(e.X, e.Y));
                                            coordinateLabel.Text = string.Format("{0}:{1}", point.X, point.Y);
                                        };

            WindowsFormsTestHelper.ShowModal(this);

            map.Dispose();
        }
示例#11
0
        public void TestGetMap()
        {
            var m = new Map(new Size(500, 300));
            m.BackColor = Color.White;

            var p = KmlProvider.FromKml(@"TestData\KML_Samples.kml");
            var l = new VectorLayer(p.ConnectionID, p);
            l.Theme = p.GetKmlTheme();

            m.Layers.Add(l);
            m.ZoomToExtents();
            m.Zoom *= 1.1;

            var img = m.GetMap();
            img.Save("KmlProviderImage.png", ImageFormat.Png);
        }
示例#12
0
 public void TestTransparency()
 {
     var tmpFile = GdiImageLayerTest.CreateImage(new Size(300, 300), new Point(10, 10));
     using(var l = new GdiImageLayer(tmpFile))
     using (var pl = new GdiImageLayerProxy<GdiImageLayer>(l, 0.3f))
     using (var m = new Map(new Size(450, 450)))
     {
         m.Layers.Add(pl);
         m.ZoomToExtents();
         using (var img = (Bitmap)m.GetMap())
         {
             var color = img.GetPixel(225, 225);
             Assert.LessOrEqual(Math.Abs((int)Math.Round(0.3f*255, MidpointRounding.AwayFromZero) - color.A),1);
         }
     }
     GdiImageLayerTest.DeleteTmpFiles(tmpFile);
 }
示例#13
0
 public void TestColorMap()
 {
     var tmpFile = GdiImageLayerTest.CreateImage(new Size(300, 300), new Point(10, 10));
     using (var l = new GdiImageLayer(tmpFile))
     using (var pl = new GdiImageLayerProxy<GdiImageLayer>(l, new ColorMap{OldColor = Color.Red, NewColor = Color.MistyRose}))
     using (var m = new Map(new Size(450, 450)))
     {
         m.Layers.Add(pl);
         m.ZoomToExtents();
         using (var img = (Bitmap)m.GetMap())
         {
             var color = img.GetPixel(225, 225);
             Assert.AreEqual(Color.MistyRose.ToArgb(), color.ToArgb());
         }
     }
     GdiImageLayerTest.DeleteTmpFiles(tmpFile);
 }
示例#14
0
        public void TestPlainPolygonSymbolizer()
        {
            ShapeFile provider = new ShapeFile(
                "..\\..\\..\\WinFormSamples\\GeoData\\World\\countries.shp", true);
            PolygonalVectorLayer l = new PolygonalVectorLayer("Countries", provider);
            l.Symbolizer = new ModifiedBasicPolygonSymbolizer
                {
                    Fill = new HatchBrush(
                            HatchStyle.WideDownwardDiagonal, 
                            Color.Red /*,
                            System.Drawing.Color.LightPink*/),
                    UseClipping = false,
                    //Outline = System.Drawing.Pens.AliceBlue
                };

            Map m = new Map(new Size(1440, 1080)) { BackColor = Color.Cornsilk };
            m.Layers.Add(l);

            m.ZoomToExtents();

            Stopwatch sw = new Stopwatch();
            Image img = m.GetMap();
            
            sw.Start();
            img = m.GetMap();
            img.Save("PolygonSymbolizer-1.bmp", ImageFormat.Bmp);
            sw.Stop();
            Console.WriteLine(string.Format("Rendering new method:{0}ms", sw.ElapsedMilliseconds));

            l.Symbolizer = new BasicPolygonSymbolizer()
            {
                Fill = new HatchBrush(
                        HatchStyle.WideDownwardDiagonal,
                        Color.Red/*,
                        System.Drawing.Color.LightPink*/),
                UseClipping = false,
                //Outline = System.Drawing.Pens.AliceBlue
            };

            sw.Reset(); sw.Start();
            img = m.GetMap();
            img.Save("PolygonSymbolizer-2.bmp", ImageFormat.Bmp);
            sw.Stop();
            Console.WriteLine(string.Format("Rendering new method:{0}ms", sw.ElapsedMilliseconds));
        
        }
示例#15
0
 protected void Page_Load(object sender, EventArgs e)
 {
     //Set up the map
     myMap = InitializeMap(new System.Drawing.Size((int)imgMap.Width.Value, (int)imgMap.Height.Value));
     if (Page.IsPostBack)
     {
         //Page is post back. Restore center and zoom-values from viewstate
         myMap.Center = (SharpMap.Geometries.Point)ViewState["mapCenter"];
         myMap.Zoom   = (double)ViewState["mapZoom"];
     }
     else
     {
         //This is the initial view of the map. Zoom to the extents of the map:
         myMap.ZoomToExtents();
         //Save the current mapcenter and zoom in the viewstate
         ViewState.Add("mapCenter", myMap.Center);
         ViewState.Add("mapZoom", myMap.Zoom);
         //Create the map
         CreateMap();
     }
 }
示例#16
0
        void Init(double lon, double lat, double size)
        {
            longitude = lon;
            latitude  = lat;
            zoom      = size;
            var t = DateTime.Now.Ticks;

            fileName       = $"{Path.GetTempPath()}[{t}]_Land";
            _Map           = new SharpMap.Map(new Size(800, 600));
            _Map.BackColor = Color.DarkBlue;

            var writer = new BinaryWriter(new FileStream($"{fileName}.shp", FileMode.Create));

            writer.Write(Properties.Resources.map_land);
            writer.Close();
            writer = new BinaryWriter(new FileStream($"{fileName}.dbf", FileMode.Create));
            writer.Write(Properties.Resources.map_landd);
            writer.Close();
            writer = new BinaryWriter(new FileStream($"{fileName}.shx", FileMode.Create));
            writer.Write(Properties.Resources.map_landx);
            writer.Close();
            VectorLayer baseLayer = new VectorLayer("行政区域");

            if (!File.Exists($"{fileName}.shp"))
            {
                throw new FileNotFoundException($"ファイル作成エラー {fileName}.shp");
            }
            Console.WriteLine(fileName);
            baseLayer.DataSource = new ShapeFile($"{fileName}.shp", true);
            baseLayer.Style.Fill = Brushes.GreenYellow;
            //地図にレイヤを追加
            _Map.Layers.Add(baseLayer);
            //地図全体が表示されるようにズーム率を設定
            _Map.ZoomToExtents();
            GeoAPI.Geometries.Coordinate P1 = new GeoAPI.Geometries.Coordinate((140.0 + 6), (44.0 - 4)); //_Map.ImageToWorld(new PointF(100, 100));
            _Map.Zoom   = 90;
            _Map.Center = P1;

            zoom = _Map.Zoom;
        }
示例#17
0
        public void TestBasicLineSymbolizer()
        {
            ShapeFile p = new ShapeFile(@"d:\\daten\GeoFabrik\\roads.shp", false);
            VectorLayer l = new VectorLayer("roads", p);
            //l.Style.Outline = new System.Drawing.Pen(System.Drawing.Color.Firebrick, 5);
            l.Style.Line = new Pen(Color.Gold, 1);
            l.Style.EnableOutline = false;
            Map m = new Map(new Size(1440, 1080)) { BackColor = Color.Cornsilk };
            m.Layers.Add(l);

            m.ZoomToExtents();

            Stopwatch sw = new Stopwatch();
            sw.Start();
            m.GetMap();

            sw.Stop();
            Console.WriteLine(string.Format("Rendering old method: {0}ms", sw.ElapsedMilliseconds));
            sw.Reset();
            sw.Start();
            Image bmp = m.GetMap();
            sw.Stop();
            Console.WriteLine(string.Format("Rendering old method: {0}ms", sw.ElapsedMilliseconds));
            bmp.Save("NDSRoads1.bmp");


            CachedLineSymbolizer cls = new CachedLineSymbolizer();
            //cls.LineSymbolizeHandlers.Add(new SharpMap.Rendering.Symbolizer.PlainLineSymbolizeHandler { Line = new System.Drawing.Pen(System.Drawing.Color.Firebrick, 5) });
            cls.LineSymbolizeHandlers.Add(new PlainLineSymbolizeHandler { Line = new Pen(Color.Gold, 1) });

            l.Style.LineSymbolizer = cls;
            sw.Reset(); sw.Start();
            bmp = m.GetMap();
            sw.Stop();
            Console.WriteLine(string.Format("Rendering new method: {0}ms", sw.ElapsedMilliseconds));
            bmp.Save("NDSRoads2.bmp");

        }
示例#18
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;
        }
示例#19
0
    public static SharpMap.Map InitializeMap(Size size, string colors, string colorsLine)
    {
        HttpContext.Current.Trace.Write("Initializing map...");

        //Initialize a new map of size 'imagesize'
        var map = new SharpMap.Map(size);

        var blackPen       = new Pen(Color.FromArgb(255, 0, 0, 0), 1);
        var blackPen2      = new Pen(Color.FromArgb(255, 0, 0, 0), 2);
        var greenPen       = new Pen(Color.FromArgb(255, 0, 255, 0), 1);
        var greenPenTransp = new Pen(Color.FromArgb(255, 0, 255, 0), 1);

        greenPenTransp.Color = Color.FromArgb(100, greenPenTransp.Color.R, greenPenTransp.Color.G, greenPenTransp.Color.B);
        var redPen            = new Pen(Color.FromArgb(255, 255, 0, 0), 1);
        var bluePen           = new Pen(Color.FromArgb(255, 0, 0, 255), 1);
        var violetPen         = new Pen(Color.FromArgb(255, 255, 0, 255), 1);
        var cyanPen           = new Pen(Color.FromArgb(255, 0, 255, 255), 1);
        var yellowPen         = new Pen(Color.FromArgb(255, 255, 255, 0), 1);
        var darkGrayPen       = new Pen(Color.DarkGray, 1);
        var darkGrayPenTransp = new Pen(Color.DarkGray, 1);

        darkGrayPenTransp.Color = Color.FromArgb(100, darkGrayPenTransp.Color.R, darkGrayPenTransp.Color.G, darkGrayPenTransp.Color.B);
        var lightBluePen            = new Pen(Color.LightBlue, 1);
        var lightGreenPen           = new Pen(Color.LightGreen, 1);
        var lightGrayPen            = new Pen(Color.FromArgb(255, 234, 234, 234));
        var darkGreenPen            = new Pen(Color.DarkGreen);
        var azurePen                = new Pen(Color.DarkKhaki);
        var lightGoldenrodYellowPen = new Pen(Color.LightGoldenrodYellow);

        Dictionary <string, Color> colorFill = new Dictionary <string, Color>();


        if (colors != null)
        {
            colors = colors.Replace(",", "");
            string[] parts = colors.Split('|');

            for (int i = 0; i < parts.Length; i++)
            {
                if (parts[i] != "")
                {
                    string[] pair = parts[i].Split('=');

                    try
                    {
                        colorFill.Add(pair[0], Color.FromName(pair[1]));
                    }
                    catch { }
                }
            }
        }
        else
        {
            colorFill["Lviv"]         = Color.FromArgb(255, 234, 234, 234);
            colorFill["Suburbs2"]     = lightGrayPen.Color;
            colorFill["Parks"]        = darkGreenPen.Color;
            colorFill["Suburbs1"]     = lightGrayPen.Color;
            colorFill["Homes"]        = azurePen.Color;
            colorFill["Proms"]        = darkGrayPen.Color;
            colorFill["FuelStations"] = Color.FromArgb(255, 234, 234, 234);
        }

        Dictionary <string, Color> colorLineDict = new Dictionary <string, Color>();


        if (colors != null)
        {
            colorsLine = colorsLine.Replace(",", "");
            string[] parts = colorsLine.Split('|');

            for (int i = 0; i < parts.Length; i++)
            {
                if (parts[i] != "")
                {
                    string[] pair = parts[i].Split('=');

                    try
                    {
                        colorLineDict.Add(pair[0], Color.FromName(pair[1]));
                    }
                    catch { }
                }
            }
        }
        else
        {
            colorLineDict["Lviv"]         = blackPen.Color;
            colorLineDict["Suburbs2"]     = blackPen.Color;
            colorLineDict["Parks"]        = blackPen.Color;
            colorLineDict["Suburbs1"]     = blackPen.Color;
            colorLineDict["Homes"]        = blackPen.Color;
            colorLineDict["Proms"]        = blackPen.Color;
            colorLineDict["FuelStations"] = blackPen.Color;
        }

        bool town = true;

        if (town)
        {
            var lvivBlockLayer = new VectorLayer("Lviv");
            lvivBlockLayer.DataSource = new ShapeFile(
                HttpContext.Current.Server.MapPath(
                    @"~\App_Data\maps_lviv_new\block.shp"), true);
            lvivBlockLayer.Style.Outline       = new Pen(colorLineDict["Lviv"]);
            lvivBlockLayer.Style.Fill          = new SolidBrush(colorFill["Lviv"]);
            lvivBlockLayer.Style.EnableOutline = true;
            map.Layers.Add(lvivBlockLayer);

            var suburbsLayer2 = new VectorLayer("Suburbs2");
            suburbsLayer2.DataSource = new ShapeFile(
                HttpContext.Current.Server.MapPath(@"~\App_Data\maps_lviv_new\LLSITY12.shp"), true);
            suburbsLayer2.Style.Outline       = new Pen(colorLineDict["Suburbs2"]);
            suburbsLayer2.Style.Fill          = new SolidBrush(colorFill["Suburbs2"]);
            suburbsLayer2.Style.EnableOutline = true;
            map.Layers.Add(suburbsLayer2);

            var parksLayer = new VectorLayer("Parks");
            parksLayer.DataSource = new ShapeFile(
                HttpContext.Current.Server.MapPath(@"~\App_Data\maps_lviv_new\LLVGREN1.shp"),
                true);
            parksLayer.Style.Outline       = new Pen(colorLineDict["Parks"]);
            parksLayer.Style.Fill          = new SolidBrush(colorFill["Parks"]);
            parksLayer.Style.EnableOutline = true;
            map.Layers.Add(parksLayer);

            var suburbsLayer1 = new VectorLayer("Suburbs1");
            suburbsLayer1.DataSource = new ShapeFile(
                HttpContext.Current.Server.MapPath(@"~\App_Data\maps_lviv_new\LLVELL12.shp"),
                true);
            suburbsLayer1.Style.Outline       = new Pen(colorLineDict["Suburbs1"]);
            suburbsLayer1.Style.Fill          = new SolidBrush(colorFill["Suburbs1"]);
            suburbsLayer1.Style.EnableOutline = true;
            map.Layers.Add(suburbsLayer1);

            //homes
            var homesLayer = new VectorLayer("Homes");
            homesLayer.DataSource = new ShapeFile(
                HttpContext.Current.Server.MapPath(@"~\App_Data\maps_lviv_new\LLVHOM12.shp"),
                true);
            homesLayer.Style.Outline       = new Pen(colorLineDict["Homes"]);
            homesLayer.Style.Fill          = new SolidBrush(colorFill["Homes"]);
            homesLayer.Style.EnableOutline = true;
            map.Layers.Add(homesLayer);

            //proms
            var promLayer = new VectorLayer("Proms");
            promLayer.DataSource = new ShapeFile(
                HttpContext.Current.Server.MapPath(@"~\App_Data\maps_lviv_new\LLVPROM.shp"), true);
            promLayer.Style.Outline       = new Pen(colorLineDict["Proms"]);
            promLayer.Style.Fill          = new SolidBrush(colorFill["Proms"]);
            promLayer.Style.EnableOutline = true;
            map.Layers.Add(promLayer);

            VectorLayer fuelStationLayer = new VectorLayer("FuelStations");
            fuelStationLayer.DataSource = new ShapeFile(
                HttpContext.Current.Server.MapPath(
                    @"~\App_Data\FuelStationsLayers\LvivCityCorr\fuel_stations_lviv.shp"),
                true);
            fuelStationLayer.Style.Outline       = new Pen(colorLineDict["FuelStations"]);
            fuelStationLayer.Style.Fill          = new SolidBrush(colorFill["FuelStations"]);
            fuelStationLayer.Style.EnableOutline = true;
            //fuelStationLayer.Style.PointColor = Brushes.AliceBlue;
            SharpMap.Rendering.Thematics.CustomTheme myTheme = new SharpMap.Rendering.Thematics.CustomTheme(GetFullStationStyle);
            fuelStationLayer.Theme = myTheme;
            map.Layers.Add(fuelStationLayer);

            //var tmp6 = new VectorLayer("Lviv"){DataSource = new ShapeFile(HttpContext.Current.Server.MapPath(@"~\App_Data\maps_lviv_new\LROAD12.shp"), true)};
            //tmp6.Style.Outline = waPen6;
            //tmp6.Style.Fill = new SolidBrush(Color.FromArgb(255, 234, 234, 234));
            //tmp6.Style.EnableOutline = true;
            //map.Layers.Add(tmp6);
        }
        else
        {
            var lvivRegioonLayer = new VectorLayer("Region");
            lvivRegioonLayer.DataSource = new ShapeFile(
                HttpContext.Current.Server.MapPath(
                    @"~\App_Data\Lviv_Region_Romik\lv_line.shp"), true);
            lvivRegioonLayer.Style.Outline       = blackPen2;
            lvivRegioonLayer.Style.Fill          = new SolidBrush(Color.FromArgb(255, 234, 234, 234));
            lvivRegioonLayer.Style.EnableOutline = true;
            map.Layers.Add(lvivRegioonLayer);

            var territoryLayer = new VectorLayer("Regions");
            territoryLayer.DataSource = new ShapeFile(
                HttpContext.Current.Server.MapPath(
                    @"~\App_Data\Lviv_Region_Romik\terrytor.shp"), true);
            territoryLayer.Style.Outline       = darkGrayPenTransp;
            territoryLayer.Style.Fill          = new SolidBrush(lightGoldenrodYellowPen.Color);
            territoryLayer.Style.EnableOutline = true;
            map.Layers.Add(territoryLayer);

            var lakesLayer = new VectorLayer("Lakes");
            lakesLayer.DataSource = new ShapeFile(
                HttpContext.Current.Server.MapPath(
                    @"~\App_Data\Lviv_Region_Romik\vodoimy.shp"), true);
            lakesLayer.Style.Outline       = blackPen;
            lakesLayer.Style.Fill          = new SolidBrush(bluePen.Color);
            lakesLayer.Style.EnableOutline = true;
            map.Layers.Add(lakesLayer);

            var punkLayer = new VectorLayer("Punks");
            punkLayer.DataSource = new ShapeFile(
                HttpContext.Current.Server.MapPath(
                    @"~\App_Data\Lviv_Region_Romik\nas_punk.shp"), true);
            punkLayer.Style.Outline       = blackPen;
            punkLayer.Style.Fill          = new SolidBrush(darkGrayPen.Color);
            punkLayer.Style.EnableOutline = true;
            map.Layers.Add(punkLayer);

            var railsLayer = new VectorLayer("Rails");
            railsLayer.DataSource = new ShapeFile(
                HttpContext.Current.Server.MapPath(
                    @"~\App_Data\Lviv_Region_Romik\zal_kol.shp"), true);
            //map.Layers.Add(railsLayer);

            var fuelStationLayer = new VectorLayer("FuelStations");
            fuelStationLayer.DataSource = new ShapeFile(
                HttpContext.Current.Server.MapPath(
                    @"~\App_Data\FuelStationsLayers\LvivObl\fuel_stations.shp"),
                true);
            fuelStationLayer.Style.PointColor = Brushes.AliceBlue;
            map.Layers.Add(fuelStationLayer);

            var roadsLayer = new VectorLayer("Roads");
            roadsLayer.Style.Outline = blackPen;
            roadsLayer.DataSource    = new ShapeFile(
                HttpContext.Current.Server.MapPath(
                    @"~\App_Data\Lviv_Region_Romik\meregi.shp"), true);
            map.Layers.Add(roadsLayer);
        }

        GeoAPI.Geometries.Envelope mapExtents = map.GetExtents();
        //SharpMap.Geometries.BoundingBox mapExtents = map.GetExtents();
        map.Zoom        = mapExtents.Width;
        map.MaximumZoom = mapExtents.Width;
        map.MinimumZoom = 2000;
        map.Center      = mapExtents.Centre;
        map.BackColor   = Color.White;
        map.ZoomToExtents();

        HttpContext.Current.Trace.Write("Map initialized");
        return(map);
    }
示例#20
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;
        }
示例#21
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;
        }
示例#22
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;

        }
示例#23
0
    public static SharpMap.Map InitializeMap(Size size, string colors, string colorsLine)
    {
        HttpContext.Current.Trace.Write("Initializing map...");

        //Initialize a new map of size 'imagesize'
        var map = new SharpMap.Map(size);

        var blackPen = new Pen(Color.FromArgb(255, 0, 0, 0), 1);
        var blackPen2 = new Pen(Color.FromArgb(255, 0, 0, 0), 2);
        var greenPen = new Pen(Color.FromArgb(255, 0, 255, 0), 1);
        var greenPenTransp = new Pen(Color.FromArgb(255, 0, 255, 0), 1);
        greenPenTransp.Color = Color.FromArgb(100, greenPenTransp.Color.R, greenPenTransp.Color.G, greenPenTransp.Color.B);
        var redPen = new Pen(Color.FromArgb(255, 255, 0, 0), 1);
        var bluePen = new Pen(Color.FromArgb(255, 0, 0, 255), 1);
        var violetPen = new Pen(Color.FromArgb(255, 255, 0, 255), 1);
        var cyanPen = new Pen(Color.FromArgb(255, 0, 255, 255), 1);
        var yellowPen = new Pen(Color.FromArgb(255, 255, 255, 0), 1);
        var darkGrayPen = new Pen(Color.DarkGray, 1);
        var darkGrayPenTransp = new Pen(Color.DarkGray, 1);
        darkGrayPenTransp.Color = Color.FromArgb(100, darkGrayPenTransp.Color.R, darkGrayPenTransp.Color.G, darkGrayPenTransp.Color.B);
        var lightBluePen = new Pen(Color.LightBlue, 1);
        var lightGreenPen = new Pen(Color.LightGreen, 1);
        var lightGrayPen = new Pen(Color.FromArgb(255, 234, 234, 234));
        var darkGreenPen = new Pen(Color.DarkGreen);
        var azurePen = new Pen(Color.DarkKhaki);
        var lightGoldenrodYellowPen = new Pen(Color.LightGoldenrodYellow);

        Dictionary<string, Color> colorFill = new Dictionary<string, Color>();

        if (colors != null)
        {
            colors = colors.Replace(",", "");
            string[] parts = colors.Split('|');

            for (int i = 0; i < parts.Length; i++)
            {
                if (parts[i] != "")
                {
                    string[] pair = parts[i].Split('=');

                    try
                    {
                        colorFill.Add(pair[0], Color.FromName(pair[1]));
                    }
                    catch { }
                }
            }
        }
        else
        {
            colorFill["Lviv"] = Color.FromArgb(255, 234, 234, 234);
            colorFill["Suburbs2"] = lightGrayPen.Color;
            colorFill["Parks"] = darkGreenPen.Color;
            colorFill["Suburbs1"] = lightGrayPen.Color;
            colorFill["Homes"] = azurePen.Color;
            colorFill["Proms"] = darkGrayPen.Color;
            colorFill["FuelStations"] = Color.FromArgb(255, 234, 234, 234);

        }

        Dictionary<string, Color> colorLineDict = new Dictionary<string, Color>();

        if (colors != null)
        {
            colorsLine = colorsLine.Replace(",", "");
            string[] parts = colorsLine.Split('|');

            for (int i = 0; i < parts.Length; i++)
            {
                if (parts[i] != "")
                {
                    string[] pair = parts[i].Split('=');

                    try
                    {
                        colorLineDict.Add(pair[0], Color.FromName(pair[1]));
                    }
                    catch { }
                }
            }
        }
        else
        {
            colorLineDict["Lviv"] = blackPen.Color;
            colorLineDict["Suburbs2"] = blackPen.Color;
            colorLineDict["Parks"] = blackPen.Color;
            colorLineDict["Suburbs1"] = blackPen.Color;
            colorLineDict["Homes"] = blackPen.Color;
            colorLineDict["Proms"] = blackPen.Color;
            colorLineDict["FuelStations"] = blackPen.Color;
        }

        bool town = true;
        if (town)
        {
            var lvivBlockLayer = new VectorLayer("Lviv");
            lvivBlockLayer.DataSource = new ShapeFile(
                HttpContext.Current.Server.MapPath(
                    @"~\App_Data\maps_lviv_new\block.shp"), true);
            lvivBlockLayer.Style.Outline = new Pen(colorLineDict["Lviv"]);
            lvivBlockLayer.Style.Fill = new SolidBrush( colorFill["Lviv"] );
            lvivBlockLayer.Style.EnableOutline = true;
            map.Layers.Add(lvivBlockLayer);

            var suburbsLayer2 = new VectorLayer("Suburbs2");
            suburbsLayer2.DataSource = new ShapeFile(
                HttpContext.Current.Server.MapPath(@"~\App_Data\maps_lviv_new\LLSITY12.shp"), true);
            suburbsLayer2.Style.Outline = new Pen(colorLineDict["Suburbs2"]);
            suburbsLayer2.Style.Fill = new SolidBrush(colorFill["Suburbs2"]);
            suburbsLayer2.Style.EnableOutline = true;
            map.Layers.Add(suburbsLayer2);

            var parksLayer = new VectorLayer("Parks");
            parksLayer.DataSource = new ShapeFile(
                HttpContext.Current.Server.MapPath(@"~\App_Data\maps_lviv_new\LLVGREN1.shp"),
                true);
            parksLayer.Style.Outline = new Pen(colorLineDict["Parks"]);
            parksLayer.Style.Fill = new SolidBrush(colorFill["Parks"]);
            parksLayer.Style.EnableOutline = true;
            map.Layers.Add(parksLayer);

            var suburbsLayer1 = new VectorLayer("Suburbs1");
            suburbsLayer1.DataSource = new ShapeFile(
                HttpContext.Current.Server.MapPath(@"~\App_Data\maps_lviv_new\LLVELL12.shp"),
                true);
            suburbsLayer1.Style.Outline = new Pen(colorLineDict["Suburbs1"]);
            suburbsLayer1.Style.Fill = new SolidBrush(colorFill["Suburbs1"]);
            suburbsLayer1.Style.EnableOutline = true;
            map.Layers.Add(suburbsLayer1);

            //homes
            var homesLayer = new VectorLayer("Homes");
            homesLayer.DataSource = new ShapeFile(
                HttpContext.Current.Server.MapPath(@"~\App_Data\maps_lviv_new\LLVHOM12.shp"),
                true);
            homesLayer.Style.Outline = new Pen(colorLineDict["Homes"]);
            homesLayer.Style.Fill = new SolidBrush(colorFill["Homes"]);
            homesLayer.Style.EnableOutline = true;
            map.Layers.Add(homesLayer);

            //proms
            var promLayer = new VectorLayer("Proms");
            promLayer.DataSource = new ShapeFile(
                HttpContext.Current.Server.MapPath(@"~\App_Data\maps_lviv_new\LLVPROM.shp"), true);
            promLayer.Style.Outline = new Pen(colorLineDict["Proms"]);
            promLayer.Style.Fill = new SolidBrush(colorFill["Proms"]);
            promLayer.Style.EnableOutline = true;
            map.Layers.Add(promLayer);

            VectorLayer fuelStationLayer = new VectorLayer("FuelStations");
            fuelStationLayer.DataSource = new ShapeFile(
                HttpContext.Current.Server.MapPath(
                    @"~\App_Data\FuelStationsLayers\LvivCityCorr\fuel_stations_lviv.shp"),
                true);
            fuelStationLayer.Style.Outline = new Pen(colorLineDict["FuelStations"]);
            fuelStationLayer.Style.Fill = new SolidBrush(colorFill["FuelStations"]);
            fuelStationLayer.Style.EnableOutline = true;
            //fuelStationLayer.Style.PointColor = Brushes.AliceBlue;
            SharpMap.Rendering.Thematics.CustomTheme myTheme = new SharpMap.Rendering.Thematics.CustomTheme(GetFullStationStyle);
            fuelStationLayer.Theme = myTheme;
            map.Layers.Add(fuelStationLayer);

            //var tmp6 = new VectorLayer("Lviv"){DataSource = new ShapeFile(HttpContext.Current.Server.MapPath(@"~\App_Data\maps_lviv_new\LROAD12.shp"), true)};
            //tmp6.Style.Outline = waPen6;
            //tmp6.Style.Fill = new SolidBrush(Color.FromArgb(255, 234, 234, 234));
            //tmp6.Style.EnableOutline = true;
            //map.Layers.Add(tmp6);
        }
        else
        {
            var lvivRegioonLayer = new VectorLayer("Region");
            lvivRegioonLayer.DataSource = new ShapeFile(
                HttpContext.Current.Server.MapPath(
                    @"~\App_Data\Lviv_Region_Romik\lv_line.shp"), true);
            lvivRegioonLayer.Style.Outline = blackPen2;
            lvivRegioonLayer.Style.Fill = new SolidBrush(Color.FromArgb(255, 234, 234, 234));
            lvivRegioonLayer.Style.EnableOutline = true;
            map.Layers.Add(lvivRegioonLayer);

            var territoryLayer = new VectorLayer("Regions");
            territoryLayer.DataSource = new ShapeFile(
                HttpContext.Current.Server.MapPath(
                    @"~\App_Data\Lviv_Region_Romik\terrytor.shp"), true);
            territoryLayer.Style.Outline = darkGrayPenTransp;
            territoryLayer.Style.Fill = new SolidBrush(lightGoldenrodYellowPen.Color);
            territoryLayer.Style.EnableOutline = true;
            map.Layers.Add(territoryLayer);

            var lakesLayer = new VectorLayer("Lakes");
            lakesLayer.DataSource = new ShapeFile(
                HttpContext.Current.Server.MapPath(
                    @"~\App_Data\Lviv_Region_Romik\vodoimy.shp"), true);
            lakesLayer.Style.Outline = blackPen;
            lakesLayer.Style.Fill = new SolidBrush(bluePen.Color);
            lakesLayer.Style.EnableOutline = true;
            map.Layers.Add(lakesLayer);

            var punkLayer = new VectorLayer("Punks");
            punkLayer.DataSource = new ShapeFile(
                HttpContext.Current.Server.MapPath(
                    @"~\App_Data\Lviv_Region_Romik\nas_punk.shp"), true);
            punkLayer.Style.Outline = blackPen;
            punkLayer.Style.Fill = new SolidBrush(darkGrayPen.Color);
            punkLayer.Style.EnableOutline = true;
            map.Layers.Add(punkLayer);

            var railsLayer = new VectorLayer("Rails");
            railsLayer.DataSource = new ShapeFile(
                HttpContext.Current.Server.MapPath(
                    @"~\App_Data\Lviv_Region_Romik\zal_kol.shp"), true);
            //map.Layers.Add(railsLayer);

            var fuelStationLayer = new VectorLayer("FuelStations");
            fuelStationLayer.DataSource = new ShapeFile(
                HttpContext.Current.Server.MapPath(
                    @"~\App_Data\FuelStationsLayers\LvivObl\fuel_stations.shp"),
                true);
            fuelStationLayer.Style.PointColor = Brushes.AliceBlue;
            map.Layers.Add(fuelStationLayer);

            var roadsLayer = new VectorLayer("Roads");
            roadsLayer.Style.Outline = blackPen;
            roadsLayer.DataSource = new ShapeFile(
                HttpContext.Current.Server.MapPath(
                    @"~\App_Data\Lviv_Region_Romik\meregi.shp"), true);
            map.Layers.Add(roadsLayer);

        }

        GeoAPI.Geometries.Envelope mapExtents = map.GetExtents();
        //SharpMap.Geometries.BoundingBox mapExtents = map.GetExtents();
        map.Zoom = mapExtents.Width;
        map.MaximumZoom = mapExtents.Width;
        map.MinimumZoom = 2000;
        map.Center = mapExtents.Centre;
        map.BackColor = Color.White;
        map.ZoomToExtents();

        HttpContext.Current.Trace.Write("Map initialized");
        return map;
    }
示例#24
0
 public void GetExtents_EmptyMap_ThrowInvalidOperationException()
 {
     Map map = new Map(new Size(2, 1));
     map.ZoomToExtents();
 }
示例#25
0
        public static Map GetMapForProviders(IEnumerable<IProvider> providers)
        {
            Map m = new Map();
            foreach (IProvider provider in providers)
            {
                VectorLayer l = new VectorLayer(provider.ConnectionID, provider)
                            {
                                Style = GetRandomVectorStyle()
                            };
                m.Layers.Add(l);
                LabelLayer ll = new LabelLayer("Label " + provider.ConnectionID);
                ll.DataSource = provider;

                provider.Open();
                IFeature f = provider.GetFeatureByOid(1);
                provider.Close();

                ll.LabelColumn = f.Factory.AttributesDefinition[1].AttributeName;
                ll.Style.CollisionDetection = false;
                ll.Style.IgnoreLength = true;

                m.Layers.Add(ll);
            }
            m.ZoomToExtents();
            return m;
        }
示例#26
0
        public void TestWarpedLineSymbolizer()
        {
            ShapeFile p = new ShapeFile(@"d:\\daten\GeoFabrik\\Aurich\\roads.shp", false);

            VectorLayer l = new VectorLayer("roads", p);

            CachedLineSymbolizer cls = new CachedLineSymbolizer();
            cls.LineSymbolizeHandlers.Add(new PlainLineSymbolizeHandler { Line = new Pen(Color.Gold, 2) });

            WarpedLineSymbolizeHander wls = new WarpedLineSymbolizeHander
                          {
                              Pattern =
                                  WarpedLineSymbolizer.
                                  GetGreaterSeries(3, 3),
                              Line = new Pen(Color.Firebrick, 1)
                              ,
                              Interval = 20
                          };
            cls.LineSymbolizeHandlers.Add(wls);
            l.Style.LineSymbolizer = cls;

            Map m = new Map(new Size(720, 540)) { BackColor = Color.Cornsilk };
            m.Layers.Add(l);

            m.ZoomToExtents();

            Stopwatch sw = new Stopwatch();

            sw.Start();
            Image bmp = m.GetMap();
            sw.Stop();
            Console.WriteLine(string.Format("Rendering new method: {0}ms", sw.ElapsedMilliseconds));
            bmp.Save("AurichRoads1.bmp");

            cls.LineSymbolizeHandlers[1] = new WarpedLineSymbolizeHander
                                               {
                                                   Pattern =
                                                       WarpedLineSymbolizer.
                                                       GetTriangle(4, 0),
                                                   Line = new Pen(Color.Firebrick, 1),
                                                   Fill = new SolidBrush(Color.Firebrick)
                                                   ,
                                                   Interval = 10
                                               };
            sw.Reset(); sw.Start();
            bmp = m.GetMap();
            sw.Stop();
            Console.WriteLine(string.Format("Rendering new method: {0}ms", sw.ElapsedMilliseconds));
            bmp.Save("AurichRoads2-0.bmp");

            cls.LineSymbolizeHandlers[1] = new WarpedLineSymbolizeHander
            {
                Pattern =
                    WarpedLineSymbolizer.
                    GetTriangle(4, 1),
                Line = new Pen(Color.Firebrick, 1),
                Fill = new SolidBrush(Color.Firebrick)
                ,
                Interval = 10
            };
            sw.Reset(); sw.Start();
            bmp = m.GetMap();
            sw.Stop();
            Console.WriteLine(string.Format("Rendering new method: {0}ms", sw.ElapsedMilliseconds));
            bmp.Save("AurichRoads2-1.bmp");
            cls.LineSymbolizeHandlers[1] = new WarpedLineSymbolizeHander
            {
                Pattern =
                    WarpedLineSymbolizer.
                    GetTriangle(4, 2),
                Line = new Pen(Color.Firebrick, 1),
                Fill = new SolidBrush(Color.Firebrick)
                ,
                Interval = 10
            };
            sw.Reset(); sw.Start();
            bmp = m.GetMap();
            sw.Stop();
            Console.WriteLine(string.Format("Rendering new method: {0}ms", sw.ElapsedMilliseconds));
            bmp.Save("AurichRoads2-2.bmp");

            cls.LineSymbolizeHandlers[1] = new WarpedLineSymbolizeHander
            {
                Pattern =
                    WarpedLineSymbolizer.
                    GetTriangle(4, 3),
                Line = new Pen(Color.Firebrick, 1),
                Fill = new SolidBrush(Color.Firebrick)
                ,
                Interval = 10
            };
            sw.Reset(); sw.Start();
            bmp = m.GetMap();
            sw.Stop();
            Console.WriteLine(string.Format("Rendering new method: {0}ms", sw.ElapsedMilliseconds));
            bmp.Save("AurichRoads2-3.bmp");


            //cls.LineSymbolizeHandlers[0] = cls.LineSymbolizeHandlers[1];
            cls.LineSymbolizeHandlers[1] = new WarpedLineSymbolizeHander
                                               {
                                                   Pattern =
                                                       WarpedLineSymbolizer.GetZigZag(4, 4),
                                                   Line = new Pen(Color.Firebrick, 1),
                                                   //Fill = new System.Drawing.SolidBrush(System.Drawing.Color.Firebrick)
                                               };
            sw.Reset(); sw.Start();
            bmp = m.GetMap();
            sw.Stop();
            Console.WriteLine(string.Format("Rendering new method: {0}ms", sw.ElapsedMilliseconds));
            bmp.Save("AurichRoads3.bmp");
        }
示例#27
0
    public static SharpMap.Map InitializeMapOgr(System.Drawing.Size size)
    {
        HttpContext.Current.Trace.Write("Initializing map...");

        //Initialize a new map of size 'imagesize'
        SharpMap.Map map = new SharpMap.Map(size);

        //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
        try
        {
            layCountries.DataSource = new SharpMap.Data.Providers.Ogr(HttpContext.Current.Server.MapPath(@"~\App_data\MapInfo\countriesMapInfo.tab"));
        }
        catch (Exception ex)
        {
            if (ex.GetType() == typeof(TypeInitializationException))
            {
                throw new Exception("Please copy the umanaged dll's into your bin folder from javascript:window.location.href='http://www.codeplex.com/SharpMap/Wiki/View.aspx?title=Extensions';.");
            }
        }

        //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.Black;
        layCountries.Style.EnableOutline = true;
        layCountries.SRID = 4326;

        //Set up a river layer
        SharpMap.Layers.VectorLayer layRivers = new SharpMap.Layers.VectorLayer("Rivers");
        //Set the datasource to a shapefile in the App_data folder
        layRivers.DataSource = new SharpMap.Data.Providers.Ogr(HttpContext.Current.Server.MapPath(@"~\App_data\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
        SharpMap.Layers.VectorLayer layCities = new SharpMap.Layers.VectorLayer("Cities");
        //Set the datasource to a shapefile in the App_data folder
        layCities.DataSource = new SharpMap.Data.Providers.Ogr(HttpContext.Current.Server.MapPath(@"~\App_data\MapInfo\citiesMapInfo.tab"));
        //Define a blue 1px wide pen
        //layCities.Style.Symbol = new Bitmap(HttpContext.Current.Server.MapPath(@"~\App_data\icon.png"));
        layCities.Style.SymbolScale = 0.8f;
        layCities.MaxVisible        = 40;
        layCities.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, 12);
        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;
        layLabel.MultipartGeometryBehaviour = SharpMap.Layers.LabelLayer.MultipartGeometryBehaviourEnum.Largest;

        //Set up a city label layer
        SharpMap.Layers.LabelLayer layCityLabel = new SharpMap.Layers.LabelLayer("City labels");
        layCityLabel.DataSource                = layCities.DataSource;
        layCityLabel.Enabled                   = true;
        layCityLabel.LabelColumn               = "Name";
        layCityLabel.Style                     = new SharpMap.Styles.LabelStyle();
        layCityLabel.Style.ForeColor           = Color.Black;
        layCityLabel.Style.Font                = new Font(FontFamily.GenericSerif, 11);
        layCityLabel.MaxVisible                = layLabel.MinVisible;
        layCityLabel.Style.HorizontalAlignment = SharpMap.Styles.LabelStyle.HorizontalAlignmentEnum.Left;
        layCityLabel.Style.VerticalAlignment   = SharpMap.Styles.LabelStyle.VerticalAlignmentEnum.Bottom;
        layCityLabel.Style.Offset              = new PointF(3, 3);
        layCityLabel.Style.Halo                = new Pen(Color.Yellow, 2);
        layCityLabel.TextRenderingHint         = System.Drawing.Text.TextRenderingHint.AntiAlias;
        layCityLabel.SmoothingMode             = SmoothingMode.AntiAlias;
        layCityLabel.SRID        = 4326;
        layCityLabel.LabelFilter = SharpMap.Rendering.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 SharpMap.Geometries.Point(0, 0);

        HttpContext.Current.Trace.Write("Map initialized");
        return(map);
    }
示例#28
0
    public static Map InitializeMapGdal(Size size)
    {
        HttpContext.Current.Trace.Write("Initializing map...");

        //Initialize a new map of size 'imagesize'
        Map map = new Map(size);

        //Set up the gdal layer
        LayerGroup g = new LayerGroup("OS");
        g.SRID = 27700;
        //D:\Raster\Ordnance Survey\OS Street View SM\data\sm
        System.IO.DirectoryInfo di = new System.IO.DirectoryInfo(HttpContext.Current.Server.MapPath(@"~\App_Data\Gdal"));
        foreach (System.IO.FileInfo fi in di.GetFiles("*.tif"))
        {
            try
            {
                SharpMap.Layers.GdalRasterLayer layer =
                    new SharpMap.Layers.GdalRasterLayer(
                        fi.Name, HttpContext.Current.Server.MapPath(@"~\App_Data\Gdal\" + fi.Name));
                //layer.SRID = 27700;
                g.Layers.Add(layer);
            }
            catch (TypeInitializationException ex)
            {
                if (ex.GetType() == typeof(TypeInitializationException))
                    throw new Exception(
                        "Please copy the umanaged dll's into your bin folder from javascript:window.location.href='http://www.codeplex.com/SharpMap/Wiki/View.aspx?title=Extensions';.");
            }
        }
        map.Layers.Add(g);
        map.ZoomToExtents();

        HttpContext.Current.Trace.Write("Map initialized");
        return map;
    }
示例#29
0
        public void GetMap_GeometryProvider_ReturnImage()
        {
            Map map = new Map(new Size(400, 200));
            VectorLayer vLayer = new VectorLayer("Geom layer", CreateDatasource());
            vLayer.Style.Outline = new Pen(Color.Red, 2f);
            vLayer.Style.EnableOutline = true;
            vLayer.Style.Line = new Pen(Color.Green, 2f);
            vLayer.Style.Fill = Brushes.Yellow;
            map.Layers.Add(vLayer);

            VectorLayer vLayer2 = new VectorLayer("Geom layer 2", vLayer.DataSource);
            vLayer2.Style.SymbolOffset = new PointF(3, 4);
            vLayer2.Style.SymbolRotation = 45;
            vLayer2.Style.SymbolScale = 0.4f;
            map.Layers.Add(vLayer2);

            VectorLayer vLayer3 = new VectorLayer("Geom layer 3", vLayer.DataSource);
            vLayer3.Style.SymbolOffset = new PointF(3, 4);
            vLayer3.Style.SymbolRotation = 45;
            map.Layers.Add(vLayer3);

            VectorLayer vLayer4 = new VectorLayer("Geom layer 4", vLayer.DataSource);
            vLayer4.Style.SymbolOffset = new PointF(3, 4);
            vLayer4.Style.SymbolScale = 0.4f;
            vLayer4.ClippingEnabled = true;
            map.Layers.Add(vLayer4);

            map.ZoomToExtents();

            Image img = map.GetMap();
            Assert.IsNotNull(img);
            map.Dispose();
            img.Dispose();
        }
示例#30
0
        public void TestCachedLineSymbolizerInTheme()
        {
            ShapeFile p = new ShapeFile(@"d:\\daten\GeoFabrik\\Aurich\\roads.shp", false);

            VectorLayer l = new VectorLayer("roads", p);
            ClsTheme theme = new ClsTheme(l.Style);
            l.Theme = theme;

            Map m = new Map(new Size(720, 540)) { BackColor = Color.Cornsilk };
            m.Layers.Add(l);

            m.ZoomToExtents();

            Stopwatch sw = new Stopwatch();

            sw.Start();
            Image bmp = m.GetMap();
            sw.Stop();
            Console.WriteLine(string.Format("Rendering new method: {0}ms", sw.ElapsedMilliseconds));
            bmp.Save("AurichRoads1Theme.bmp");
        }
示例#31
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;

        }
示例#32
0
    public static SharpMap.Map InitializeMap(System.Drawing.Size size)
    {
        HttpContext.Current.Trace.Write("Initializing map...");

        //Initialize a new map of size 'imagesize'
        SharpMap.Map map = new SharpMap.Map(size);

        //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"), false);

        //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.Black;
        layCountries.Style.EnableOutline = true;
        layCountries.SRID = 4326;

        //Set up a river layer
        SharpMap.Layers.VectorLayer layRivers = new SharpMap.Layers.VectorLayer("Rivers");
        //Set the datasource to a shapefile in the App_data folder
        layRivers.DataSource = new SharpMap.Data.Providers.ShapeFile(HttpContext.Current.Server.MapPath(@"~\App_data\rivers.shp"), false);
        //Define a blue 1px wide pen
        layRivers.Style.Line = new Pen(Color.Blue, 1);
        layRivers.SRID       = 4326;

        //Set up a river layer
        SharpMap.Layers.VectorLayer layCities = new SharpMap.Layers.VectorLayer("Cities");
        //Set the datasource to a shapefile in the App_data folder
        layCities.DataSource = new SharpMap.Data.Providers.ShapeFile(HttpContext.Current.Server.MapPath(@"~\App_data\cities.shp"), false);
        //Define a blue 1px wide pen
        //layCities.Style.Symbol = new Bitmap(HttpContext.Current.Server.MapPath(@"~\App_data\icon.png"));
        layCities.Style.SymbolScale = 0.8f;
        layCities.MaxVisible        = 40;
        layCities.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, 12);
        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;
        layLabel.MultipartGeometryBehaviour = SharpMap.Layers.LabelLayer.MultipartGeometryBehaviourEnum.Largest;

        //Set up a city label layer
        SharpMap.Layers.LabelLayer layCityLabel = new SharpMap.Layers.LabelLayer("City labels");
        layCityLabel.DataSource                = layCities.DataSource;
        layCityLabel.Enabled                   = true;
        layCityLabel.LabelColumn               = "Name";
        layCityLabel.Style                     = new SharpMap.Styles.LabelStyle();
        layCityLabel.Style.ForeColor           = Color.Black;
        layCityLabel.Style.Font                = new Font(FontFamily.GenericSerif, 11);
        layCityLabel.MaxVisible                = layLabel.MinVisible;
        layCityLabel.Style.HorizontalAlignment = SharpMap.Styles.LabelStyle.HorizontalAlignmentEnum.Left;
        layCityLabel.Style.VerticalAlignment   = SharpMap.Styles.LabelStyle.VerticalAlignmentEnum.Bottom;
        layCityLabel.Style.Offset              = new PointF(3, 3);
        layCityLabel.Style.Halo                = new Pen(Color.Yellow, 2);
        layCityLabel.TextRenderingHint         = System.Drawing.Text.TextRenderingHint.AntiAlias;
        layCityLabel.SmoothingMode             = SmoothingMode.AntiAlias;
        layCityLabel.SRID        = 4326;
        layCityLabel.LabelFilter = SharpMap.Rendering.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 = SharpMap.Converters.Geometries.GeometryFactory.CreateCoordinate(0, 0);

        HttpContext.Current.Trace.Write("Map initialized");
        return(map);
    }
示例#33
0
    public static Map InitializeMapOgr(Size size)
    {
        HttpContext.Current.Trace.Write("Initializing map...");

        //Initialize a new map of size 'imagesize'
        Map map = new Map(size);

        //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(HttpContext.Current.Server.MapPath(@"~\App_data\MapInfo\countriesMapInfo.tab"));
        }
        catch (TypeInitializationException ex)
        {
            if (ex.GetType() == typeof (TypeInitializationException))
                throw new Exception(
                    "Please copy the umanaged dll's into your bin folder from javascript:window.location.href='http://www.codeplex.com/SharpMap/Wiki/View.aspx?title=Extensions';.");
        }
        catch (Exception ex)
        {
            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(HttpContext.Current.Server.MapPath(@"~\App_data\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(HttpContext.Current.Server.MapPath(@"~\App_data\MapInfo\citiesMapInfo.tab"));
        //Define a blue 1px wide pen
        //layCities.Style.Symbol = new Bitmap(HttpContext.Current.Server.MapPath(@"~\App_data\icon.png"));
        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.ZoomToExtents(); // = 360;
        map.Center = new Point(0, 0);

        HttpContext.Current.Trace.Write("Map initialized");
        return map;
    }
示例#34
0
    public static SharpMap.Map InitializeMap(System.Drawing.Size size)
    {
			HttpContext.Current.Trace.Write("Initializing map...");
				
			//Initialize a new map of size 'imagesize'
			SharpMap.Map map = new SharpMap.Map(size);
					
			//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"), false);
			
			//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.Black;
			layCountries.Style.EnableOutline = true;
			layCountries.SRID = 4326;
			
			//Set up a river layer
			SharpMap.Layers.VectorLayer layRivers = new SharpMap.Layers.VectorLayer("Rivers");
			//Set the datasource to a shapefile in the App_data folder
			layRivers.DataSource = new SharpMap.Data.Providers.ShapeFile(HttpContext.Current.Server.MapPath(@"~\App_data\rivers.shp"), false);
			//Define a blue 1px wide pen
			layRivers.Style.Line = new Pen(Color.Blue,1);
			layRivers.SRID = 4326;

			//Set up a river layer
			SharpMap.Layers.VectorLayer layCities = new SharpMap.Layers.VectorLayer("Cities");
			//Set the datasource to a shapefile in the App_data folder
			layCities.DataSource = new SharpMap.Data.Providers.ShapeFile(HttpContext.Current.Server.MapPath(@"~\App_data\cities.shp"), false);
			//Define a blue 1px wide pen
			//layCities.Style.Symbol = new Bitmap(HttpContext.Current.Server.MapPath(@"~\App_data\icon.png"));
			layCities.Style.SymbolScale = 0.8f;
			layCities.MaxVisible = 40;
			layCities.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, 12);
			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;
			layLabel.MultipartGeometryBehaviour = SharpMap.Layers.LabelLayer.MultipartGeometryBehaviourEnum.Largest;

			//Set up a city label layer
			SharpMap.Layers.LabelLayer layCityLabel = new SharpMap.Layers.LabelLayer("City labels");
			layCityLabel.DataSource = layCities.DataSource;
			layCityLabel.Enabled = true;
			layCityLabel.LabelColumn = "Name";
			layCityLabel.Style = new SharpMap.Styles.LabelStyle();
			layCityLabel.Style.ForeColor = Color.Black;
			layCityLabel.Style.Font = new Font(FontFamily.GenericSerif, 11);
			layCityLabel.MaxVisible = layLabel.MinVisible;
			layCityLabel.Style.HorizontalAlignment = SharpMap.Styles.LabelStyle.HorizontalAlignmentEnum.Left;
			layCityLabel.Style.VerticalAlignment = SharpMap.Styles.LabelStyle.VerticalAlignmentEnum.Bottom;
			layCityLabel.Style.Offset = new PointF(3, 3);
			layCityLabel.Style.Halo = new Pen(Color.Yellow, 2);
			layCityLabel.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;
			layCityLabel.SmoothingMode = SmoothingMode.AntiAlias;
			layCityLabel.SRID = 4326;
			layCityLabel.LabelFilter = SharpMap.Rendering.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 = SharpMap.Converters.Geometries.GeometryFactory.CreateCoordinate(0,0);
				
			HttpContext.Current.Trace.Write("Map initialized");
			return map;
    }