private static void TestMaps(string name, Map m, Map mD) { Assert.NotNull(mD); Assert.AreEqual(m.Size, mD.Size); Assert.AreEqual(m.Layers.Count, mD.Layers.Count); var c = new LayerTest.VectorLayerEqualityComparer(); for (var i = 0; i < m.Layers.Count; i++) { Assert.IsTrue(c.Equals((VectorLayer)m.Layers[i], (VectorLayer)mD.Layers[i]), "Layer {0}, '{1}' Differs at {2}", i, m.Layers[i].LayerName, string.Join(", ", c.DifferAt)); } Assert.AreEqual(m.PixelAspectRatio, mD.PixelAspectRatio); Assert.AreEqual(m.PixelHeight, mD.PixelHeight); Assert.AreEqual(m.PixelWidth, mD.PixelWidth); Assert.AreEqual(m.PixelSize, mD.PixelSize); Assert.AreEqual(m.BackColor, mD.BackColor); Assert.IsTrue(m.Center.Equals(mD.Center)); Assert.IsTrue(m.GetExtents().Equals(mD.GetExtents())); Assert.IsTrue(m.Envelope.Equals(mD.Envelope)); Assert.AreEqual(m.Decorations.Count, mD.Decorations.Count); Assert.AreEqual(m.SRID, mD.SRID); Assert.AreEqual(m.Zoom, mD.Zoom); Assert.DoesNotThrow(() => m.GetMap().Save(name + "-S.bmp")); Assert.DoesNotThrow(() => mD.GetMap().Save(name + "-D.bmp")); }
public void GetExtents_ValidDatasource() { Map map = new Map(new Size(400, 200)); VectorLayer vLayer = new VectorLayer("Geom layer", CreateDatasource()); map.Layers.Add(vLayer); BoundingBox box = map.GetExtents(); Assert.AreEqual(new BoundingBox(0, 50, 0, 346.3493254), box); }
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; }
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); }