/// <summary> /// Creates an instance of this class /// </summary> public MagnifierTool(MapBox parentMapBox) : base("Magnifier", "A tool to magnify the portion of the map below the cursor") { _parentMapBox = parentMapBox; _parentMapBox.MapChanged += HandleMapChanged; Map = _parentMapBox.Map; MagnificationFactor = 1.10; Offset = new Size(5,5); _magnified = new PictureBox(); _magnified.Size = new Size(75, 75); _magnified.BorderStyle = BorderStyle.FixedSingle; _magnified.Visible = false; _parentMapBox.Controls.Add(_magnified); Map = _parentMapBox.Map; _map = Map.Clone(); _map.Size = _magnified.Size; _map.Zoom = _map.Size.Width*(Map.Envelope.Width/Map.Size.Width) / _magnification; _map.Center = _map.Center; _magnified.Image = _map.GetMap(); Enabled = true; var ms = Assembly.GetExecutingAssembly().GetManifestResourceStream("WinFormSamples.Magnifier.cur"); if (ms != null) Cursor = new Cursor(ms); }
public void setup() { Desc = Helper.Description(); Assert.That(Desc, Is.Not.Null); Map = Helper.Default(); Assert.That(Map, Is.Not.Null); }
public static Map InitializeMap() { string wmsUrl = "http://www2.demis.nl/mapserver/request.asp"; SharpMap.Map map = new SharpMap.Map(); SharpMap.Layers.WmsLayer layWms = new SharpMap.Layers.WmsLayer("Demis Map", wmsUrl); layWms.SpatialReferenceSystem = "EPSG:4326"; layWms.AddLayer("Bathymetry"); 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 SharpMap.Geometries.Point(0, 0); return map; }
public static SharpMap.Map InitializeGoogleMap(GoogleMapType mt) { SharpMap.Map map = new SharpMap.Map(); GoogleRequest req; ITileSource tileSource; TileAsyncLayer tileLayer; if (mt == (GoogleMapType.GoogleSatellite | GoogleMapType.GoogleLabels)) { req = new GoogleRequest(GoogleMapType.GoogleSatellite); tileSource = new GoogleTileSource(req); tileLayer = new TileAsyncLayer(tileSource, "TileLayer - " + GoogleMapType.GoogleSatellite); map.Layers.Add(tileLayer); req = new GoogleRequest(GoogleMapType.GoogleLabels); tileSource = new GoogleTileSource(req); mt = GoogleMapType.GoogleLabels; } else { req = new GoogleRequest(mt); tileSource = new GoogleTileSource(req); } tileLayer = new TileAsyncLayer(tileSource, "TileLayer - " + mt); map.BackgroundLayer.Add(tileLayer); map.ZoomToBox(tileLayer.Envelope); return(map); }
private Map InitialiseMapAndLayers() { // plug in Web Mercator var pcs = ProjNet.CoordinateSystems.ProjectedCoordinateSystem.WebMercator; SharpMap.Session.Instance.CoordinateSystemRepository.AddCoordinateSystem(3857, pcs); Map m = new SharpMap.Map(new System.Drawing.Size(1440, 1080)) { BackColor = System.Drawing.Color.LightSkyBlue }; m.SRID = 3857; // add 3 layers: WGS84 with 2 diagonal lines, Ind75 with North-South line, and Ind75Utm47N with East-West Line // Mid-point of all lines is the same point (to within a few mm), creating a symetrical 8-pointed star when correctly transformed. // Datum Shift from Wgs84 to Ind75 in study area is in vicinity of 350-400m, so any GCS mis-match is immediately apparent. var vlWgs84 = CreateLayerWgs84(); var envWgs84 = vlWgs84.DataSource.GetExtents(); var vlInd75 = CreateLayerInd75(); var envInd75 = vlInd75.DataSource.GetExtents(); var vlInd75Utm47N = CreateLayerInd75Utm47N(); var envInd75Utm47N = vlInd75Utm47N.DataSource.GetExtents(); m.Layers.Add(vlWgs84); m.Layers.Add(vlInd75); m.Layers.Add(vlInd75Utm47N); return(m); }
public void MapSridEqualsFactorySrid() { var m = new Map(); Assert.AreEqual(m.SRID, m.Factory.SRID); m.SRID = 10; Assert.AreEqual(m.SRID, m.Factory.SRID); }
protected void Page_Load(object sender, EventArgs e) { //Set up the map. We use the method in the App_Code folder for initializing the map and alter it afterwards myMap = MapHelper.InitializeMap(new System.Drawing.Size((int)imgMap.Width.Value, (int)imgMap.Height.Value)); //Remove the river layer and label-layers myMap.Layers.RemoveAt(4); myMap.Layers.RemoveAt(3); myMap.Layers.RemoveAt(1); //Create Pie Layer SharpMap.Layers.VectorLayer pieLayer = new SharpMap.Layers.VectorLayer("Pie charts"); pieLayer.DataSource = (myMap.Layers[0] as SharpMap.Layers.VectorLayer).DataSource; CustomTheme<IVectorStyle> iTheme = new CustomTheme<IVectorStyle>(GetCountryStyle); pieLayer.Theme = iTheme; myMap.Layers.Add(pieLayer); 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(); myMap.Center = new SharpMap.Geometries.Point(10, 50); myMap.Zoom = 60; //Create the map GenerateMap(); } }
public static Map InitializeMap() { string wmsUrl = "http://www2.demis.nl/mapserver/request.asp"; SharpMap.Map map = new SharpMap.Map(); SharpMap.Layers.WmsLayer layWms = new SharpMap.Layers.WmsLayer("Demis Map", wmsUrl); layWms.SpatialReferenceSystem = "EPSG:4326"; layWms.AddLayer("Bathymetry"); 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 SharpMap.Geometries.Point(0, 0); return(map); }
public static Map CreateMap() { const string getCapabilitiesURI = "http://www2.dmsolutions.ca/cgi-bin/mswfs_gmap?request=GetCapabilities&service=WFS&VERSION=1.0.0"; Map demoMap = new SharpMap.Map(new Size(600, 600)); demoMap.MinimumZoom = 0.005; demoMap.BackColor = Color.White; SharpMap.Layers.VectorLayer layer1 = new SharpMap.Layers.VectorLayer("prov_land"); WFS prov1 = new WFS(getCapabilitiesURI, "", "prov_land", WFS.WFSVersionEnum.WFS1_1_0); layer1.Style.Fill = new SolidBrush(Color.IndianRed); // States //// Options // Defaults: MultiGeometries: true, QuickGeometries: false, GetFeatureGETRequest: false // Render with validation... prov1.QuickGeometries = false; // Important when connecting to an UMN MapServer //!!!prov1.GetFeatureGETRequest = true; // Ignore multi-geometries... prov1.MultiGeometries = false; layer1.DataSource = prov1; demoMap.Layers.Add(layer1); demoMap.ZoomToBox(new SharpMap.Geometries.BoundingBox(-3546709.473205, -869773.355764, 4444893.074820, 3923457.184829)); return demoMap; }
public static Map InitializeMap() { const string getCapabilitiesURI = "http://steven:8080/eWaterWfsConnector/wfs"; Map map = new SharpMap.Map(new System.Drawing.Size(600, 600)); map.MinimumZoom = 0.005; map.BackColor = System.Drawing.Color.White; SharpMap.Layers.VectorLayer layer1 = new SharpMap.Layers.VectorLayer("test"); WFS prov1 = new WFS(getCapabilitiesURI, "", "Well", WFS.WFSVersionEnum.WFS1_0_0); prov1.QuickGeometries = false; // Important when connecting to an UMN MapServer prov1.GetFeatureGETRequest = true; // Ignore multi-geometries... prov1.MultiGeometries = false; layer1.DataSource = prov1; map.Layers.Add(layer1); map.ZoomToBox(new SharpMap.Geometries.BoundingBox(574290, 4275299, 702273, 4386402)); return map; }
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 static Map CreateMap() { const string getCapabilitiesURI = "http://192.168.25.120:8080/deegree-wfs/services"; Map map = new SharpMap.Map(new Size(600, 600)); map.MinimumZoom = 0.005; map.BackColor = Color.White; SharpMap.Layers.VectorLayer layer1 = new SharpMap.Layers.VectorLayer("Springs"); WFS prov1 = new WFS(getCapabilitiesURI, "app1", "Springs", WFS.WFSVersionEnum.WFS1_1_0); prov1.QuickGeometries = false; // Important when connecting to an UMN MapServer prov1.GetFeatureGETRequest = true; // Ignore multi-geometries... prov1.MultiGeometries = false; layer1.DataSource = prov1; map.Layers.Add(layer1); map.ZoomToBox(new SharpMap.Geometries.BoundingBox(574290, 4275299, 702273, 4386402)); return map; }
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; }
internal static Map Default() { string currdir = Directory.GetCurrentDirectory(); Trace.WriteLine(String.Format("Current directory: {0}", currdir)); Map map = new Map(new Size(1, 1)); IDictionary<string, LayerData> dict = Nyc; foreach (string layer in dict.Keys) { string format = String.Format(@"WMS\Server\data\{0}", layer); string path = Path.Combine(currdir, format); if (!File.Exists(path)) throw new FileNotFoundException("file not found", path); string name = Path.GetFileNameWithoutExtension(layer); LayerData data = dict[layer]; ShapeFile source = new ShapeFile(path, true); VectorLayer item = new VectorLayer(name, source) { SRID = 4326, Style = (VectorStyle)data.Style, SmoothingMode = Smoothing.AntiAlias }; map.Layers.Add(item); } return map; }
protected void Page_Load(object sender, EventArgs e) { //Set up the map. We use the method in the App_Code folder for initializing the map myMap = MapHelper.InitializeMap(new System.Drawing.Size((int)imgMap.Width.Value,(int)imgMap.Height.Value)); //Set a gradient theme on the countries layer, based on Population density SharpMap.Rendering.Thematics.CustomTheme iTheme = new SharpMap.Rendering.Thematics.CustomTheme(GetCountryStyle); SharpMap.Styles.VectorStyle defaultstyle = new SharpMap.Styles.VectorStyle(); defaultstyle.Fill = Brushes.Gray; iTheme.DefaultStyle = defaultstyle; (myMap.Layers[0] as SharpMap.Layers.VectorLayer).Theme = iTheme; //Turn off the river layer and label-layers myMap.Layers[1].Enabled = false; myMap.Layers[3].Enabled = false; myMap.Layers[4].Enabled = false; if (Page.IsPostBack) { //Page is post back. Restore center and zoom-values from viewstate myMap.Center = (ICoordinate)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(); myMap.Center = GeometryFactory.CreateCoordinate(0, 0); myMap.Zoom = 360; //Create the map GenerateMap(); } }
protected override void OnRenderInternal(Map map, IPolygon polygon, IGraphics g) { IPoint pt = polygon.Centroid; Point renderingOrigin = Point.Truncate(Transform.WorldtoMap(pt.Coordinate, map)); g.RenderingOrigin = new PointStruct(renderingOrigin.X, renderingOrigin.Y); base.OnRenderInternal(map, polygon, g); }
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; }
public static SharpMap.Map InitializeGoogleMap(GoogleMapType mt) { SharpMap.Map map = new SharpMap.Map(); GoogleRequest req; ITileSource tileSource; TileAsyncLayer tileLayer; if (mt == (GoogleMapType.GoogleSatellite | GoogleMapType.GoogleLabels)) { req = new GoogleRequest(GoogleMapType.GoogleSatellite); tileSource = new GoogleTileSource(req); tileLayer = new TileAsyncLayer(tileSource, "TileLayer - " + GoogleMapType.GoogleSatellite); map.Layers.Add(tileLayer); req = new GoogleRequest(GoogleMapType.GoogleLabels); tileSource = new GoogleTileSource(req); mt = GoogleMapType.GoogleLabels; } else { req = new GoogleRequest(mt); tileSource = new GoogleTileSource(req); } tileLayer = new TileAsyncLayer(tileSource, "TileLayer - " + mt); map.BackgroundLayer.Add(tileLayer); map.ZoomToBox(tileLayer.Envelope); return map; }
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; }
private void HandleMapChanged(object sender, EventArgs e) { _map = Map.Clone(); _map.Size = _magnified.Size; _map.Zoom = _map.Size.Width * (Map.Envelope.Width / Map.Size.Width) / _magnification; _map.Center = _map.Center; //_magnified.Image = _map.GetMap(); }
protected override void OnRender(IGraphics g, Map map) { Brush brush = new SolidBrush(OpacityColor(Color.Red)); RectangleF rect = g.Clip; g.FillRectangle(brush, (int) rect.X, (int) rect.Y, (int) rect.Width, (int) rect.Height); }
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); }
/// <summary> /// Initializes a new mapControl /// </summary> public MapBox() { SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.OptimizedDoubleBuffer | ControlStyles.ResizeRedraw | ControlStyles.UserPaint, true); DoubleBuffered = true; _Map = new SharpMap.Map(ClientSize); m_ActiveTool = Tools.None; LostFocus += new EventHandler(MapBox_LostFocus); _legend = new MapLegend(this); }
private static Map InitializeMapOsm() { Map map = new Map(); TileLayer tileLayer = new TileLayer(new OsmTileSource(), "TileLayer - OSM"); map.Layers.Add(tileLayer); map.ZoomToBox(tileLayer.Envelope); return map; }
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; }
public MainForm() { InitializeComponent(); ICoordinateSequenceFactory<BufferedCoordinate2D> coordSeqFactory = new BufferedCoordinate2DSequenceFactory(); _geometryFactory = new GeometryFactory<BufferedCoordinate2D>(coordSeqFactory); _map = new Map(_geometryFactory); registerLayerFactories(); mapViewControl1.Map = _map; }
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; } }
public void GetLayerByName_Indexer() { Map map = new Map(); map.Layers.Add(new VectorLayer("Layer 1")); map.Layers.Add(new VectorLayer("Layer 3")); map.Layers.Add(new VectorLayer("Layer 2")); ILayer layer = map.Layers["Layer 2"]; Assert.IsNotNull(layer); Assert.AreEqual("Layer 2", layer.LayerName); }
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"; TiledWmsLayer tiledWmsLayer = new TiledWmsLayer("Metacarta", url); tiledWmsLayer.TileSetsActive.Add(tiledWmsLayer.TileSets["basic"].Name); map.Layers.Add(tiledWmsLayer); map.ZoomToBox(new SharpMap.Geometries.BoundingBox(-180.0, -90.0, 180.0, 90.0)); return map; }
private void radioButton2_MouseUp(object sender, MouseEventArgs e) { var rb = sender as RadioButton; if (rb == null) { return; } if (e.Button != MouseButtons.Right) { return; } SharpMap.Map map = null; switch (rb.Name) { case "radioButton2": // ShapeFile map = Samples.ShapefileSample.InitializeMap(tbAngle.Value, GetOpenFileName("Shapefile|*.shp")); break; case "radioButton5": // Ogr map = Samples.OgrSample.InitializeMap(tbAngle.Value, GetOpenFileName("Ogr Datasource|*.*")); break; case "radioButton6": // Gdal map = Samples.GdalSample.InitializeMap(tbAngle.Value, GetOpenFileName("Gdal Datasource|*.*")); break; case "radioButton9": // spatialite map = Samples.SpatiaLiteSample.InitializeMap(tbAngle.Value, GetOpenFileName("SpatiaLite 2|*.db;*.sqlite")); break; } if (map == null) { return; } //Add checked Map decorations foreach (ListViewItem checkedItem in lvwDecorations.CheckedItems) { Type mdType; if (MapDecorationTypes.TryGetValue(checkedItem.Text, out mdType)) { IMapDecoration md = Activator.CreateInstance(mdType) as IMapDecoration; map.Decorations.Add(md); } } mapBox1.Map = map; }
public void TestCoordinateSystemForMap(int srid) { var map = new Map(new Size(200, 150)) { SRID = srid }; ICoordinateSystem cs = null; Assert.DoesNotThrow( () => cs = map.GetCoordinateSystem()); Assert.NotNull(cs); Assert.AreEqual("EPSG", cs.Authority); #if DotSpatialProjections Assert.AreEqual((long)srid, cs.Authority); #else Assert.AreEqual((long)srid, cs.AuthorityCode); #endif }
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); }
protected void Page_Load(object sender, EventArgs e) { int Width = 0; int Height = 0; double centerX = 0; double centerY = 0; double Zoom = 0; string[] Layer; //Parse request parameters if (!int.TryParse(Request.Params["WIDTH"], out Width)) { throw(new ArgumentException("Invalid parameter")); } if (!int.TryParse(Request.Params["HEIGHT"], out Height)) { throw (new ArgumentException("Invalid parameter")); } if (!double.TryParse(Request.Params["ZOOM"], System.Globalization.NumberStyles.Float, numberFormat_EnUS, out Zoom)) { throw (new ArgumentException("Invalid parameter")); } if (!double.TryParse(Request.Params["X"], System.Globalization.NumberStyles.Float, numberFormat_EnUS, out centerX)) { throw (new ArgumentException("Invalid parameter")); } if (!double.TryParse(Request.Params["Y"], System.Globalization.NumberStyles.Float, numberFormat_EnUS, out centerY)) { throw (new ArgumentException("Invalid parameter")); } //Params OK SharpMap.Map map = InitializeMap(new System.Drawing.Size(Width, Height)); map.Center = new GeoAPI.Geometries.Coordinate(centerX, centerY); map.Zoom = Zoom; //Generate map System.Drawing.Bitmap img = (System.Drawing.Bitmap)map.GetMap(); //Stream the image to the client Response.ContentType = "image/png"; System.IO.MemoryStream MS = new System.IO.MemoryStream(); img.Save(MS, System.Drawing.Imaging.ImageFormat.Png); // tidy up img.Dispose(); byte[] buffer = MS.ToArray(); Response.OutputStream.Write(buffer, 0, buffer.Length); }
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"); }
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"); }
public static SharpMap.Map InitializeWmsMap(System.Drawing.Size size) { HttpContext.Current.Trace.Write("Initializing Wms map..."); //Initialize a new map of size 'imagesize' SharpMap.Map map = new SharpMap.Map(size); SharpMap.Layers.WmsLayer layWms = GetWmsLayer(); //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"), true); //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.Yellow; layCountries.Style.EnableOutline = true; layCountries.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, 8); 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; //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(layWms); map.Layers.Add(layCountries); map.Layers.Add(layLabel); //limit the zoom to 360 degrees width map.MaximumZoom = 360; map.BackColor = Color.LightBlue; map.Zoom = 360; map.Center = new SharpMap.Geometries.Point(0, 0); HttpContext.Current.Trace.Write("Map initialized"); return(map); }
private SharpMap.Layers.ILayer toggleLayer(string id, SharpMap.Map map) { string[] layerId = id.Split(new char[] { '_' }); if (layerId.Length <= 1) { return(map.Layers[Int32.Parse(layerId[0])]); } SharpMap.Layers.LayerGroup myGroup = (map.Layers[Int32.Parse(layerId[0])] as SharpMap.Layers.LayerGroup); for (int i = 1; i < layerId.Length - 1; i++) { myGroup = (myGroup.Layers[Int32.Parse(layerId[i])] as SharpMap.Layers.LayerGroup); } return(myGroup.Layers[Int32.Parse(layerId[layerId.Length - 1])]); }
public 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 SharpMap.Data.Providers.ShapeFile datasource = new SharpMap.Data.Providers.ShapeFile(HttpContext.Current.Server.MapPath(@"~\App_data\USA\states.shp"), true); layCountries.DataSource = datasource; datacoordsys = datasource.CoordinateSystem; //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.CoordinateTransformation = GetTransform(ddlProjection.SelectedValue); if (layCountries.CoordinateTransformation != null) { litInputCoordsys.Text = layCountries.CoordinateTransformation.TargetCS.WKT; litCoordsys.Text = layCountries.CoordinateTransformation.SourceCS.WKT; litTransform.Text = layCountries.CoordinateTransformation.MathTransform.WKT; } else { litInputCoordsys.Text = datasource.CoordinateSystem.WKT; litCoordsys.Text = "None"; litTransform.Text = "None"; } SharpMap.Layers.VectorLayer layGrid = new SharpMap.Layers.VectorLayer("Grid"); //Set the datasource to a shapefile in the App_data folder layGrid.DataSource = new SharpMap.Data.Providers.ShapeFile(HttpContext.Current.Server.MapPath(@"~\App_data\USA\latlong.shp"), true); layGrid.CoordinateTransformation = layCountries.CoordinateTransformation; layGrid.Style.Line = new Pen(Color.FromArgb(127, 255, 0, 0), 1); //Add the layers to the map object. map.Layers.Add(layCountries); map.Layers.Add(layGrid); map.BackColor = Color.LightBlue; HttpContext.Current.Trace.Write("Map initialized"); return(map); }
public static SharpMap.Map InitializeGradientMap(System.Drawing.Size size) { //Initialize a new map based on the simple map SharpMap.Map map = InitializeMap(size); //Set a gradient theme on the countries layer, based on Population density //First create two styles that specify min and max styles //In this case we will just use the default values and override the fill-colors //using a colorblender. If different line-widths, line- and fill-colors where used //in the min and max styles, these would automatically get linearly interpolated. SharpMap.Styles.VectorStyle min = new SharpMap.Styles.VectorStyle(); SharpMap.Styles.VectorStyle max = new SharpMap.Styles.VectorStyle(); //Create theme using a density from 0 (min) to 400 (max) IGradientThemeGdi <IVectorStyle> popdens = new GradientThemeIVectorStyle("PopDens", 0, 400, min, max); //We can make more advanced coloring using the ColorBlend'er. //Setting the FillColorBlend will override any fill-style in the min and max fills. //In this case we just use the predefined Rainbow colorscale popdens.FillColorBlend = SharpMap.Rendering.Thematics.ColorBlend.Rainbow5; (map.Layers[0] as SharpMap.Layers.VectorLayer).Theme = popdens; //Lets scale the labels so that big countries have larger texts as well SharpMap.Styles.LabelStyle lblMin = new SharpMap.Styles.LabelStyle(); SharpMap.Styles.LabelStyle lblMax = new SharpMap.Styles.LabelStyle(); lblMin.ForeColor = Color.Black; lblMin.Font = new Font(FontFamily.GenericSerif, 6); lblMax.ForeColor = Color.Blue; lblMax.BackColor = new SolidBrush(Color.FromArgb(128, 255, 255, 255)); lblMin.BackColor = lblMax.BackColor; lblMax.Font = new Font(FontFamily.GenericSerif, 9); (map.Layers[3] as ILabelLayer).Theme = new GradientThemeILabelStyle("PopDens", 0, 400, lblMin, lblMax); //Lets scale city icons based on city population //cities below 1.000.000 gets the smallest symbol, and cities with more than 5.000.000 the largest symbol SharpMap.Styles.VectorStyle citymin = new SharpMap.Styles.VectorStyle(); SharpMap.Styles.VectorStyle citymax = new SharpMap.Styles.VectorStyle(); citymin.Symbol = new Bitmap(HttpContext.Current.Server.MapPath(@"~\App_data\icon.png")); citymin.SymbolScale = 0.5f; citymax.Symbol = new Bitmap(HttpContext.Current.Server.MapPath(@"~\App_data\icon.png")); citymax.SymbolScale = 1f; (map.Layers[2] as SharpMap.Layers.VectorLayer).Theme = new GradientThemeIVectorStyle("Population", 1000000, 5000000, citymin, citymax); //Turn off the river layer map.Layers[1].Enabled = false; return(map); }
protected void Page_Load(object sender, EventArgs e) { //Set up the map. We use the method in the App_Code folder for initializing 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.Zoom = 80; myMap.Center = new SharpMap.Geometries.Point(-95, 37); //Create the map GenerateMap(); } }
protected void Page_Load(object sender, EventArgs e) { //Set up the map. We use the method in the App_Code folder for initializing the map myMap = MapHelper.InitializeMap(new System.Drawing.Size((int)imgMap.Width.Value, (int)imgMap.Height.Value)); SharpMap.Layers.VectorLayer GeomLayer = this.CreateGeometryLayer(); SharpMap.Layers.LabelLayer layGeomProviderLabel = new SharpMap.Layers.LabelLayer("LabelOfTheCityMayence"); layGeomProviderLabel.DataSource = GeomLayer.DataSource; layGeomProviderLabel.Enabled = true; layGeomProviderLabel.LabelColumn = "Name"; layGeomProviderLabel.Style = new SharpMap.Styles.LabelStyle(); layGeomProviderLabel.Style.ForeColor = System.Drawing.Color.AliceBlue; layGeomProviderLabel.Style.Font = new System.Drawing.Font("ArialB", 14); layGeomProviderLabel.Style.Offset = new System.Drawing.PointF(4, 4); layGeomProviderLabel.Style.HorizontalAlignment = SharpMap.Styles.LabelStyle.HorizontalAlignmentEnum.Left; layGeomProviderLabel.Style.VerticalAlignment = SharpMap.Styles.LabelStyle.VerticalAlignmentEnum.Bottom; layGeomProviderLabel.SRID = 4326; myMap.Layers.Add(GeomLayer); myMap.Layers.Add(layGeomProviderLabel); myMap.Center = new SharpMap.Geometries.Point(8, 50); myMap.Zoom = 10; 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(); //or center on 0,0 and zoom to full earth (360 degrees) //myMap.Center = new SharpMap.Geometries.Point(0,0); //myMap.Zoom = 360; //Create the map GenerateMap(); } }
protected void imgMap_Click(object sender, ImageClickEventArgs e) { //Set center of the map to where the client clicked //We set up a simple empty map so we can use the ImageToWorld() method for easy conversion from Image to World coordinates SharpMap.Map myMap = new SharpMap.Map(new Size(Convert.ToInt32(imgMap.Width.Value), Convert.ToInt32(imgMap.Height.Value))); myMap.Center = Center; myMap.Zoom = Zoom; Center = myMap.ImageToWorld(new System.Drawing.Point(e.X, e.Y)); //Set zoom value if any of the zoom tools were selected if (rblMapTools.SelectedValue == "0") //Zoom in { Zoom = Zoom * 0.5; } else if (rblMapTools.SelectedValue == "1") //Zoom out { Zoom = Zoom * 2; } //Create the map GenerateMap(); }
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(); } }
protected void Page_Load(object sender, EventArgs e) { //Set up the map. We use the method in the App_Code folder for initializing the map myMap = MapHelper.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 = (ICoordinate)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(); //or center on 0,0 and zoom to full earth (360 degrees) //myMap.Center = new SharpMap.Geometries.Point(0,0); //myMap.Zoom = 360; //Create the map GenerateMap(); } }
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; }
private Map InitMap() { var res = new SharpMap.Map() { SRID = 3857, BackColor = System.Drawing.Color.AliceBlue, }; //Lisbon... var mathTransform = LayerTools.Wgs84toGoogleMercator.MathTransform; var geom = GeometryTransform.TransformBox( new Envelope(-9.205626, -9.123736, 38.690993, 38.740837), mathTransform); //geom.ExpandBy(2500); res.ZoomToBox(geom); res.Decorations.Add(new NorthArrow { ForeColor = Color.DarkSlateBlue }); return(res); }
/// <summary> /// Initialise the map component. /// </summary> private static Map InitMap() { var result = new SharpMap.Map(); result.BackColor = Color.LightBlue; result.Center = new Coordinate(0, 0); result.SRID = 3857; BruTile.Cache.FileCache fileCache = new BruTile.Cache.FileCache(Path.Combine(Path.GetTempPath(), "OSM Map Tiles"), "png", new TimeSpan(100, 0, 0, 0)); TileLayer baseLayer = new TileLayer(BruTile.Predefined.KnownTileSources.Create(BruTile.Predefined.KnownTileSource.OpenStreetMap, persistentCache: fileCache, userAgent: "APSIM Next Generation"), "OpenStreetMap"); result.BackgroundLayer.Add(baseLayer); result.MaximumZoom = baseLayer.Envelope.Width; // This layer is used only as a sort of backup in case the BruTile download times out // or is otherwise unavailable. // It should normally be invisible, as it will be covered by the BruTile tile layer. string apsimx = PathUtilities.GetAbsolutePath("%root%", null); string shapeFileName = Path.Combine(apsimx, "ApsimNG", "Resources", "world", "countries.shp"); if (File.Exists(shapeFileName)) { VectorLayer layWorld = new VectorLayer("Countries"); layWorld.DataSource = new ShapeFile(shapeFileName, true); layWorld.Style = new VectorStyle(); layWorld.Style.EnableOutline = true; // Color background = Colour.FromGtk(MainWidget.GetBackgroundColour(StateFlags.Normal)); // Color foreground = Colour.FromGtk(MainWidget.GetForegroundColour(StateFlags.Normal)); // layWorld.Style.Fill = new SolidBrush(background); // layWorld.Style.Outline.Color = foreground; layWorld.CoordinateTransformation = latLonToMetres; result.BackgroundLayer.Insert(0, layWorld); } return(result); }
public override Texture LoadFile(QuadTile qt) { //获取切片的本地路径 string filePath = GetLocalPath(qt); qt.ImageFilePath = filePath; Texture texture = null; string ddsPath = filePath; //判断是否是DDS文件 if (World.Settings.ConvertDownloadedImagesToDds) { ddsPath = Path.GetDirectoryName(filePath) + "\\" + Path.GetFileNameWithoutExtension(filePath) + ".dds"; } filePath = ddsPath; //判断磁盘上,是否有当前文件,若有,则直接读取,若没有,则重新加载 if (!File.Exists(filePath)) { //动态读取Tiff影像中的值 SharpMap.Map map = new SharpMap.Map(); for (int i = 0; i < Layers.Length; i++) { SharpMap.Layers.VectorLayer shapeLayer = new SharpMap.Layers.VectorLayer(Path.GetFileNameWithoutExtension(Layers[i])); shapeLayer.DataSource = new SharpMap.Data.Providers.ShapeFile(Layers[i], true); //设置Polygon的填充色,默认为透明 shapeLayer.Style.Fill = new SolidBrush(fillColor); //设置Polygon的边框色 shapeLayer.Style.Outline = outlineColor; shapeLayer.Style.EnableOutline = true; shapeLayer.Style.Line = lineColor; shapeLayer.SRID = 4326; shapeLayer.Enabled = true; map.Layers.Add(shapeLayer); } //设置Map的背景色为透明色 map.BackColor = System.Drawing.Color.Transparent; //图像的formate System.Drawing.Imaging.ImageCodecInfo imageEncoder = GetEncoderInfo(formate); //图片的大小 map.Size = new System.Drawing.Size(m_textureSizePixels, m_textureSizePixels); //请求图像的范围 string bboxString = ""; bboxString = qt.West.ToString() + "," + qt.South.ToString() + "," + qt.East.ToString() + "," + qt.North.ToString(); SharpMap.Geometries.BoundingBox bbox = this.ParseBBOX(bboxString); //判断图像的拉伸范围 map.PixelAspectRatio = ((double)m_textureSizePixels / (double)m_textureSizePixels) / (bbox.Width / bbox.Height); map.Center = bbox.GetCentroid(); map.Zoom = bbox.Width; //获得当前请求的图片 System.Drawing.Image img = map.GetMap(); if (!Directory.Exists(Path.GetDirectoryName(filePath))) { Directory.CreateDirectory(Path.GetDirectoryName(filePath)); } //保存到本地磁盘 img.Save(filePath); } //设置是否显示图片的无效值 if (qt.QuadTileSet.HasTransparentRange) { texture = ImageHelper.LoadTexture(filePath, qt.QuadTileSet.ColorKey, qt.QuadTileSet.ColorKeyMax); } else { texture = ImageHelper.LoadTexture(filePath, qt.QuadTileSet.ColorKey); } //判断,是否转化为dds文件 if (World.Settings.ConvertDownloadedImagesToDds) { ConvertImage(texture, filePath); } //返回当前纹理 return(texture); }
private void radioButton2_MouseUp(object sender, MouseEventArgs e) { var rb = sender as RadioButton; if (rb == null) { return; } if (e.Button != MouseButtons.Right) { return; } SharpMap.Map map = null; switch (rb.Name) { case "radioButton2": // ShapeFile map = Samples.ShapefileSample.InitializeMap(tbAngle.Value, GetOpenFileName("Shapefile|*.shp")); break; case "radioButton5": // Ogr map = Samples.OgrSample.InitializeMap(tbAngle.Value, GetOpenFileName("Ogr Datasource|*.*")); break; case "radioButton6": // Gdal if ((Control.ModifierKeys & Keys.Control) == Keys.Control) { string cn = InputBox( "Please enter connection string.\n" + "For e.g. PostGis Rasters sth. like 'PG:host=... port=... dbname=... schema=... table=... column=...'", @"GDAL Raster Layer Connection", _gdalConnection); if (string.IsNullOrEmpty(cn)) { return; } map = Samples.GdalSample.InitializeMap(tbAngle.Value, new [] { cn }); _gdalConnection = cn; } else { map = Samples.GdalSample.InitializeMap(tbAngle.Value, GetOpenFileName("Gdal Datasource|*.*")); } break; case "radioButton9": // spatialite map = Samples.SpatiaLiteSample.InitializeMap(tbAngle.Value, GetOpenFileName("SpatiaLite 2|*.db;*.sqlite")); break; } if (map == null) { return; } //Add checked Map decorations foreach (ListViewItem checkedItem in lvwDecorations.CheckedItems) { Type mdType; if (MapDecorationTypes.TryGetValue(checkedItem.Text, out mdType)) { IMapDecoration md = Activator.CreateInstance(mdType) as IMapDecoration; map.Decorations.Add(md); } } mapBox1.Map = map; }
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); }
private void LoadParcels(List <PointD> pt, Color color, string labelname) { SharpMap.Map map = new SharpMap.Map(); List <GeoAPI.Geometries.Coordinate> vertices = new List <GeoAPI.Geometries.Coordinate>(); foreach (PointD i in pt) { GeoAPI.Geometries.Coordinate p = new GeoAPI.Geometries.Coordinate(); p.X = i.X; p.Y = i.Y; vertices.Add(p); } GeoAPI.Geometries.Coordinate l = new GeoAPI.Geometries.Coordinate(); l.X = pt[0].X; l.Y = pt[0].Y; vertices.Add(l); //Collection<GeoAPI.Geometries.IGeometry> geom = new Collection<GeoAPI.Geometries.IGeometry>(); GeometryFactory gf = new NetTopologySuite.Geometries.GeometryFactory(); GeoAPI.Geometries.ILinearRing shell = gf.CreateLinearRing(vertices.ToArray()); GeoAPI.Geometries.IPolygon polygon = gf.CreatePolygon(shell, null); SharpMap.Data.Providers.GeometryProvider geomProvider = new SharpMap.Data.Providers.GeometryProvider(polygon); SharpMap.Layers.VectorLayer layerParcels = new SharpMap.Layers.VectorLayer("Parcels"); SharpMap.Styles.VectorStyle style = new SharpMap.Styles.VectorStyle(); style.Fill = new SolidBrush(Color.FromArgb(200, color)); style.Outline = new Pen(new SolidBrush(color)); layerParcels.Style = style; layerParcels.Style.EnableOutline = true; layerParcels.DataSource = geomProvider; layerParcels.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias; mapBox1.ActiveTool = SharpMap.Forms.MapBox.Tools.Pan; var fdt = new SharpMap.Data.FeatureDataTable(); fdt.Columns.Add(new System.Data.DataColumn("id", typeof(uint))); fdt.Columns.Add(new System.Data.DataColumn("label", typeof(string))); var fdr = (SharpMap.Data.FeatureDataRow)fdt.NewRow(); fdr.ItemArray = new object[] { 1, labelname }; fdr.Geometry = polygon; fdt.AddRow(fdr); var dataprovider = new SharpMap.Data.Providers.GeometryFeatureProvider(fdt); var ll = new SharpMap.Layers.LabelLayer("llayer"); ll.DataSource = dataprovider; ll.LabelColumn = "label"; ll.Style.Font = new Font("Eurostile Extended", 16, FontStyle.Bold); mapBox1.Map.Layers.Add(layerParcels); mapBox1.Map.Layers.Add(ll); mapBox1.Map.ZoomToExtents(); mapBox1.Refresh(); }
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 void CargarDatos() { string ambito = string.Empty; if (this._uge.GetType() == typeof(BaseOrg)) { ambito = AdministradorPreferencias.Read(PrefsGlobal.OrgName); } else if (this._uge.GetType() == typeof(Zona)) { ambito = (this._uge as Zona).Denominacion; } else if (this._uge.GetType() == typeof(Edificio)) { ambito = (this._uge as Edificio).Denominacion; } else if (this._uge.GetType() == typeof(PlantaBase)) { ambito = string.Format("{0} en {1}", (this._uge as PlantaBase).Planta.ToString(), AdministradorPreferencias.Read(PrefsGlobal.OrgName)); } else if (this._uge.GetType() == typeof(PlantaZona)) { ambito = (this._uge as PlantaZona).Planta.ToString() + " en " + (this._uge as PlantaZona).Zona.Denominacion; } else if (this._uge.GetType() == typeof(PlantaEdificio)) { ambito = (this._uge as PlantaEdificio).Denominacion; } this.Text = string.Format("SIGUANETDesktop TreeMAP ({0}) - {1}", ambito, this._tituloForm); this.cbPaletaDinamica.DataSource = Enum.GetNames(typeof(TipoPaleta)); this.cbPaletaDinamica.SelectedItem = Enum.GetName(typeof(TipoPaleta), TipoPaleta.predeterminada); this.cbPaletaDinamica.DropDownStyle = ComboBoxStyle.DropDownList; this.tpLeyenda.Enabled = false; this.tpPDF.Enabled = false; this.tsbPDFLeyenda.Checked = this.PDFLeyenda; if (this._ds != null) { if (this._ds.Tables.Count > 0) { this.dg.DataSource = this._ds.Tables[0]; this.tslNumFilas.Text = string.Format("{0} registros", this._ds.Tables[0].Rows.Count); } } this.listInfo.GridLines = true; this.listInfo.Groups.Add(this._lvgGeneral); this.listInfo.Groups.Add(this._lvgLugar); this.listInfo.Groups.Add(this._lvgAdscripcion); this.listInfo.Groups.Add(this._lvgUso); this.listInfo.Groups.Add(this._lvgOcupacion); this.listInfo.Groups.Add(this._lvgPersonal); this.listInfo.Items.Add(this._lviCodEstancia); this.listInfo.Items.Add(this._lviDenoEstancia); this.listInfo.Items.Add(this._lviSuperficie); this.listInfo.Items.Add(this._lviCodZona); this.listInfo.Items.Add(this._lviNomZona); this.listInfo.Items.Add(this._lviCodEdificio); this.listInfo.Items.Add(this._lviNomEdificio); this.listInfo.Items.Add(this._lviPlanta); this.listInfo.Items.Add(this._lviCodDpto); this.listInfo.Items.Add(this._lviNomDpto); this.listInfo.Items.Add(this._lviCodActividad); this.listInfo.Items.Add(this._lviDescriActividad); this.listInfo.Items.Add(this._lviNumOcupantes); this._lviCodEstancia.Group = this._lvgGeneral; this._lviDenoEstancia.Group = this._lvgGeneral; this._lviSuperficie.Group = this._lvgGeneral; this._lviCodZona.Group = this._lvgLugar; this._lviNomZona.Group = this._lvgLugar; this._lviCodEdificio.Group = this._lvgLugar; this._lviNomEdificio.Group = this._lvgLugar; this._lviPlanta.Group = this._lvgLugar; this._lviCodDpto.Group = this._lvgAdscripcion; this._lviNomDpto.Group = this._lvgAdscripcion; this._lviCodActividad.Group = this._lvgUso; this._lviDescriActividad.Group = this._lvgUso; this._lviNumOcupantes.Group = this._lvgOcupacion; this.toolStrip1.Enabled = false; this.Mapa = new SharpMap.Map(this.miVMapa.Size); this.Mapa.BackColor = Color.White; this.Mapa.MapRendered += new SharpMap.Map.MapRenderedEventHandler(MapRender); this.nodoBaseOrg.Tag = new BaseOrg(); int i = 0; if (this._consulta == null) { List <PlantaEdificio> lpe = null; if (this._uge is BaseOrg) { lpe = (this._uge as BaseOrg).ObtenerPlantasEdificio(); } else if (this._uge is PlantaBase) { lpe = (this._uge as PlantaBase).ObtenerPlantasEdificio(); } else if (this._uge is Zona) { lpe = (this._uge as Zona).ObtenerPlantasEdificio(); } else if (this._uge is Edificio) { lpe = (this._uge as Edificio).ObtenerPlantas(); } else if (this._uge is PlantaZona) { lpe = (this._uge as PlantaZona).ObtenerPlantasEdificio(); } else if (this._uge is PlantaEdificio) { lpe = new List <PlantaEdificio>(); lpe.Add((PlantaEdificio)this._uge); } if (lpe != null) { EventoInicioModulo(lpe.Count); foreach (PlantaEdificio pe in lpe) { TreeNode NodoEdificio = GUIUtils.obtenerNodoEdificio(pe, nodoBaseOrg); TreeNode nodoPlanta = new TreeNode(pe.Codigo); nodoPlanta.Tag = pe; NodoEdificio.Nodes.Add(nodoPlanta); EventoPasoModulo(++i); } } } else if (this._consulta is List <Estancia> ) { EventoInicioModulo((this._consulta as List <Estancia>).Count); foreach (Estancia e in (List <Estancia>) this._consulta) { TreeNode NodoPlanta = GUIUtils.obtenerNodoPlanta(e, nodoBaseOrg); TreeNode nodoEstancia = new TreeNode(e.Codigo); nodoEstancia.Tag = e; NodoPlanta.Nodes.Add(nodoEstancia); EventoPasoModulo(++i); } } else if (this._consulta is List <Ubicacion> ) { EventoInicioModulo((this._consulta as List <Ubicacion>).Count); foreach (Ubicacion u in (List <Ubicacion>) this._consulta) { TreeNode NodoPlanta = GUIUtils.obtenerNodoPlanta(u.Estancia, nodoBaseOrg); TreeNode nodoUbicacion = new TreeNode(u.Persona.ToString()); nodoUbicacion.Tag = u; NodoPlanta.Nodes.Add(nodoUbicacion); EventoPasoModulo(++i); } } this.twNavegador.Nodes.Add(this.nodoBaseOrg); }
public static Map InitializeMapPostGis(Size size) { HttpContext.Current.Trace.Write("Initializing map..."); string connectionString = ConfigurationManager.ConnectionStrings["postgis"].ConnectionString; //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 new MsSqlSpatialProvider layCountries.DataSource = new SharpMap.Data.Providers.PostGIS(connectionString, "countries", "wkb_geometry", "ogc_fid"); //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; //Set up a river layer SharpMap.Layers.VectorLayer layRivers = new SharpMap.Layers.VectorLayer("Rivers"); //Set the datasource to a new MsSqlSpatialProvider layRivers.DataSource = new SharpMap.Data.Providers.PostGIS(connectionString, "rivers", "wkb_geometry", "ogc_fid"); //Define a blue 1px wide pen layRivers.Style.Line = new Pen(Color.Blue, 1); //Set up a river layer SharpMap.Layers.VectorLayer layCities = new SharpMap.Layers.VectorLayer("Cities"); //Set the datasource to a new MsSqlSpatialProvider layCities.DataSource = new SharpMap.Data.Providers.PostGIS(connectionString, "cities", "wkb_geometry", "ogc_fid");; //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; //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.MaxVisible = 90; layLabel.MinVisible = 30; layLabel.MultipartGeometryBehaviour = SharpMap.Layers.LabelLayer.MultipartGeometryBehaviourEnum.Largest; layLabel.LabelFilter = SharpMap.Rendering.LabelCollisionDetection.ThoroughCollisionDetection; layLabel.PriorityColumn = "popdens"; 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.Style.HorizontalAlignment = SharpMap.Styles.LabelStyle.HorizontalAlignmentEnum.Center; layLabel.Style.CollisionDetection = true; //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.PriorityColumn = "population"; layCityLabel.PriorityDelegate = delegate(SharpMap.Data.FeatureDataRow fdr) { Int32 retVal = 10000000 * (Int32)((String)fdr["capital"] == "Y" ? 1 : 0); return(retVal + Convert.ToInt32(fdr["population"])); }; layCityLabel.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias; layCityLabel.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias; layCityLabel.LabelFilter = SharpMap.Rendering.LabelCollisionDetection.ThoroughCollisionDetection; layCityLabel.Style = new SharpMap.Styles.LabelStyle(); layCityLabel.Style.ForeColor = Color.Black; layCityLabel.Style.Font = new Font(FontFamily.GenericSerif, 11); layCityLabel.Style.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.Style.CollisionDetection = true; //Add the layers to the map object. //The order we add them in are the order they are drawn, so we add the rivers last to put them on top map.Layers.Add(layCountries); map.Layers.Add(layRivers); map.Layers.Add(layCities); map.Layers.Add(layLabel); map.Layers.Add(layCityLabel); //limit the zoom to 360 degrees width map.MaximumZoom = 360; map.BackColor = Color.LightBlue; map.Zoom = 360; map.Center = new Point(0, 0); HttpContext.Current.Trace.Write("Map initialized"); return(map); }
protected void Page_Load(object sender, EventArgs e) { int Width = 0; int Height = 0; double centerX = 0; double centerY = 0; double Zoom = 0; string[] Layer; //Parse request parameters if (!int.TryParse(Request.Params["WIDTH"], out Width)) { throw(new ArgumentException("Invalid parameter")); } if (!int.TryParse(Request.Params["HEIGHT"], out Height)) { throw (new ArgumentException("Invalid parameter")); } if (!double.TryParse(Request.Params["ZOOM"], System.Globalization.NumberStyles.Float, numberFormat_EnUS, out Zoom)) { throw (new ArgumentException("Invalid parameter")); } if (!double.TryParse(Request.Params["X"], System.Globalization.NumberStyles.Float, numberFormat_EnUS, out centerX)) { throw (new ArgumentException("Invalid parameter")); } if (!double.TryParse(Request.Params["Y"], System.Globalization.NumberStyles.Float, numberFormat_EnUS, out centerY)) { throw (new ArgumentException("Invalid parameter")); } if (Request.Params["MAP"] == null) { throw (new ArgumentException("Invalid parameter")); } if (!string.IsNullOrEmpty(Request.Params["Layers"])) { Layer = Request.Params["Layers"].Split(new char[] { ',' }); } else { throw (new ArgumentException("Invalid parameter")); } string colors = Request.Params["Colors"]; string colorsLine = Request.Params["ColorsLine"]; //Params OK SharpMap.Map map = InitializeMap(Request.Params["MAP"], new System.Drawing.Size(Width, Height), colors, colorsLine); if (map == null) { throw (new ArgumentException("Invalid map")); } //toggle layers if (Layer[0] != "none") { for (int i = 0; i < Layer.Length; i++) { toggleLayer(Layer[i], map).Enabled = false; } } //Set visible map extents map.Center = new GeoAPI.Geometries.Coordinate(centerX, centerY); map.Zoom = Zoom; //Generate map System.Drawing.Bitmap img = (System.Drawing.Bitmap)map.GetMap(); //Stream the image to the client Response.ContentType = "image/png"; System.IO.MemoryStream MS = new System.IO.MemoryStream(); img.Save(MS, System.Drawing.Imaging.ImageFormat.Png); // tidy up img.Dispose(); byte[] buffer = MS.ToArray(); Response.OutputStream.Write(buffer, 0, buffer.Length); }
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); }