public void AddMapbox(SharpMap.Forms.MapBox map) { layerbase = new List <string>(); this.map = map; map.Refresh(); baselayer = new SharpMap.Layers.VectorLayer("States"); baselayer.DataSource = new SharpMap.Data.Providers.ShapeFile(@"../../../../map/SZ_DISTR/SZ_DISTR.shp", true); //构造土地样式 VectorStyle style1 = new VectorStyle(); style1.Fill = new SolidBrush(Color.FromArgb(176, 170, 170)); VectorStyle style2 = new VectorStyle(); style2.Fill = new SolidBrush(Color.FromArgb(153, 153, 153)); VectorStyle style3 = new VectorStyle(); style3.Fill = new SolidBrush(Color.FromArgb(192, 192, 192)); VectorStyle style4 = new VectorStyle(); style4.Fill = new SolidBrush(Color.FromArgb(204, 204, 204)); //创建地图 Dictionary <string, SharpMap.Styles.IStyle> styles = new Dictionary <string, IStyle>(); styles.Add("罗湖区", style1); styles.Add("福田区", style2); styles.Add("盐田区", style3); styles.Add("龙岗区", style2); styles.Add("宝安区", style1); styles.Add("坪山新区", style4); styles.Add("南山区", style3); styles.Add("龙华新区", style4); styles.Add("大鹏新区", style2); styles.Add("光明新区", style3); //分配主题 baselayer.Theme = new SharpMap.Rendering.Thematics.UniqueValuesTheme <string>("DISTRICT", styles, style1); map.Map.Layers.Add(baselayer); layerbase.Add(baselayer.LayerName); map.Map.ZoomToExtents(); map.Refresh(); map.ActiveTool = SharpMap.Forms.MapBox.Tools.Pan; }
public static void InitializeBackgroundMap(ref SharpMap.Forms.MapBox mapBox1) { string GSHHGFileName = @"d:\Users\dwoodall\Documents\GSHHG\gshhg-shp-2.3.5-1\GSHHS_shp\f\GSHHS_f_L1.shp"; // this is the default area to be displayed. do not make it bigger unless you want to wait forever for it to render GeoAPI.Geometries.Envelope envelope = new GeoAPI.Geometries.Envelope(-75.0d, -80.0d, 23.0d, 28.0d); //ShapeFile GSHHGData = new ShapeFile(GSHHGFileName); SharpMap.Layers.VectorLayer GSHHGLayer = new SharpMap.Layers.VectorLayer("GSHHG"); GSHHGLayer.DataSource = new SharpMap.Data.Providers.ShapeFile(GSHHGFileName, true); if (!GSHHGLayer.DataSource.IsOpen) { GSHHGLayer.DataSource.Open(); } //Create the style for Land SharpMap.Styles.VectorStyle landStyle = new SharpMap.Styles.VectorStyle(); landStyle.Fill = new System.Drawing.SolidBrush(S52.colorMaptoRGBI(S52.ColorName.LANDF)); landStyle.Outline = new System.Drawing.Pen(System.Drawing.Color.Black); //Create the style for Water SharpMap.Styles.VectorStyle waterStyle = new SharpMap.Styles.VectorStyle(); waterStyle.Fill = new System.Drawing.SolidBrush(S52.colorMaptoRGBI(S52.ColorName.DEPMD)); //Create the default style SharpMap.Styles.VectorStyle defaultStyle = new SharpMap.Styles.VectorStyle(); defaultStyle.Fill = new System.Drawing.SolidBrush(System.Drawing.Color.Red); //Create the theme items Dictionary <string, SharpMap.Styles.IStyle> styles = new Dictionary <string, SharpMap.Styles.IStyle>(); styles.Add("land", landStyle); styles.Add("water", waterStyle); styles.Add("default", defaultStyle); GSHHGLayer.Style = landStyle; GSHHGLayer.Style.EnableOutline = true; mapBox1.BackColor = S52.colorMaptoRGB(S52.ColorName.UINFB); mapBox1.Map.Layers.Add(GSHHGLayer); mapBox1.Map.ZoomToExtents(); mapBox1.Refresh(); GeoAPI.CoordinateSystems.Transformations.ICoordinateTransformationFactory ctFact = new ProjNet.CoordinateSystems.Transformations.CoordinateTransformationFactory(); GSHHGLayer.CoordinateTransformation = ctFact.CreateFromCoordinateSystems(ProjNet.CoordinateSystems.GeographicCoordinateSystem.WGS84, ProjNet.CoordinateSystems.ProjectedCoordinateSystem.WebMercator); GSHHGLayer.ReverseCoordinateTransformation = ctFact.CreateFromCoordinateSystems(ProjNet.CoordinateSystems.ProjectedCoordinateSystem.WebMercator, ProjNet.CoordinateSystems.GeographicCoordinateSystem.WGS84); //mapBox1.Map.BackgroundLayer.Add(new SharpMap.Layers.TileAsyncLayer( // new BruTile.Web.OsmTileSource(), "OSM")); //mapBox1.Map.ZoomToBox(envelope); mapBox1.Map.ZoomToExtents(); mapBox1.Refresh(); mapBox1.ActiveTool = SharpMap.Forms.MapBox.Tools.Pan; }