상속: BaseLayer
예제 #1
0
        public static ILayer Create()
        {
            var layer = new Layer("PointLayer");
            var pointWithDefaultSymbolStyle = new Feature { Geometry = new Point(1000000, 1000000)};
            pointWithDefaultSymbolStyle.Styles.Add(new SymbolStyle());
            var pointAsSmallBlackDot = new Feature { Geometry = new Point(1000000, 0)};

            pointAsSmallBlackDot.Styles.Add(new SymbolStyle
                {
                    SymbolScale = 2.0f,
                    Fill = new Brush { Color = null },
                    Outline = new Pen { Color = Color.Green}
                });

            pointAsSmallBlackDot.Styles.Add(new SymbolStyle
                {
                    SymbolScale = 0.5f,
                    Fill = new Brush { Color = Color.Black },
                });

            var pointWithlabelStyle = new Feature { Geometry = new Point(0, 1000000)};
            pointWithDefaultSymbolStyle.Styles.Add(new LabelStyle { Text = "Label" });

            layer.DataSource = new MemoryProvider(new[] { pointWithlabelStyle, pointWithDefaultSymbolStyle, pointAsSmallBlackDot });
            return layer;
        }
예제 #2
0
 public static ILayer AddLayerWithOnePolygon()
 {
     var layer = new Layer("LayerWithPolygon");
     layer.DataSource = new Mapsui.Providers.MemoryProvider(CreatePolygon());
     layer.Styles.Add(new VectorStyle());
     return layer;
 }
 public static Layer Create2()
 {
     var provider = CreateProvider2();
     var layer2 = new Layer("AGOL Landsat 1975");
     layer2.DataSource = provider;
     layer2.Enabled = false;
     return layer2;
 }
 public static Layer Create()
 {
     var provider = CreateProvider();
     var layer = new Layer("AGOL Landsat 2010");
     layer.DataSource = provider;
     layer.Enabled = false;
     return layer;
 }
예제 #5
0
 public static Layer CreateCountryLayer(IProvider countrySource)
 {
     var countries = new Layer("Countries");
     countries.DataSource = countrySource;
     countries.DataSource.SRID = 3785;
     countries.Styles.Add(CreateCountryTheme());
     return countries;
 }
예제 #6
0
 public static Layer CreateCityLayer(IProvider citySource)
 {
     var layCities = new Layer("Cities");
     layCities.DataSource = citySource;
     layCities.DataSource.SRID = 3785;
     layCities.Styles.Add(CreateCityTheme());
     layCities.MaxVisible = 10000000.0;
     return layCities;
 }
예제 #7
0
 public static ILayer CreateRandomPointLayer(BoundingBox envelope, int count = 25)
 {
     var pointLayer = new Layer("pointLayer")
         {
             DataSource = new MemoryProvider(GenerateRandomPoints(envelope, count)),
         };
     pointLayer.Styles.Add(new VectorStyle { Fill = new Brush(Color.White)});
     return pointLayer;
 }
예제 #8
0
        public static ILayer CreateRandomPolygonLayer(BoundingBox envelope, int count = 10)
        {
            var pointLayer = new Layer("pointLayer")
                {
                    DataSource = new MemoryProvider(GenerateRandomPolygons(envelope, count))
                };

            pointLayer.Styles.Add(new VectorStyle()
                {
                    Fill = new Brush(Color.Orange),
                    Outline = new Pen(Color.Red, 2)
                });
            return pointLayer;
        }
 public static ILayer Create()
 {
     var layer = new Layer("PointLayer WorldUnits");
     var netherlands = new Feature { Geometry = new Point(710000, 6800000)};
     
     const string resource = "Mapsui.Samples.Common.Images.netherlands.jpg";
     netherlands.Styles.Add(new SymbolStyle
     {
         Symbol = new Bitmap { Data = System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream(resource) },
         SymbolType = SymbolType.Rectangle,
         UnitType = UnitType.WorldUnit,
         SymbolRotation = 5f,
         SymbolScale = 1400,
         Width = 365,
         Height = 380
     });
     
     layer.DataSource = new MemoryProvider(new[] { netherlands });
     return layer;
 }
예제 #10
0
        public static Map InitializeMap()
        {
            try
            {
                // WARNING
                // This sample needs the GeoServer WFS running on your local machine. 
                // It uses the GeoServer default sample data. Installing and starting it is all you need to do
                // http://docs.codehaus.org/display/GEOS/Download

                // Sample by Peter Robineau

                const string getCapabilitiesUri = "http://localhost:8080/geoserver/wfs";
                const string serviceUri = "http://localhost:8080/geoserver/wfs";

                var map = new Map();
                map.BackColor = Color.White;

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

                // Demo data from Geoserver 1.5.3 and Geoserver 1.6.0 

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

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

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

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

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

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

                // Layer Style
                layer1.Styles.Add(new VectorStyle { Fill = new Brush { Color = Color.Red } });
                layer2.Styles.Add(new VectorStyle { Fill = new Brush { Color = Color.Green } }); // SelectedStatesAndHousholds
                layer3.Styles.Add(new VectorStyle { Fill = new Brush { Color = Color.Yellow } }); // e.g. New York, New Jersey,...
                layer5.Styles.Add(new VectorStyle { Fill = new Brush { Color = Color.Blue } });

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

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

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

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

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

                return map;
            }
            catch (WebException ex)
            {
                if ((ex.Message.Contains("(502) Bad Gateway")) ||
                    (ex.Message.Contains("Unable to connect to the remote server")))
                {
                    throw new Exception(
                        "The Wfs sample threw an exception. You probably need to install the GeoServer WFS to your local machine. You can get it from here: http://docs.codehaus.org/display/GEOS/Download. The exception message was: " +
                        ex.Message);
                }
                throw;
            }
        }
예제 #11
0
        public static Map InitializeMap()
        {
            //Initialize a new map based on the simple map
            var map = new Map();

            //Layer osm = new Layer("OSM");
            //string url = "http://labs.metacarta.com/wms-c/tilecache.py?version=1.1.1&request=GetCapabilities&service=wms-c";
            //var tileSources = TileSourceWmsC.TileSourceBuilder(new Uri(url), null);
            //var tileSource = new List<ITileSource>(tileSources).Find(source => source.Schema.Name == "osm-map");
            //osm.DataSource = new TileProvider(tileSource, "OSM");
            //map.Layers.Add(osm);

            //Set up countries layer
            var countryLayer = new Layer("Countries");
            //Set the datasource to a shapefile in the App_data folder
            countryLayer.DataSource = new ShapeFile("GeoData/World/countries.shp", true);
            countryLayer.DataSource.SRID = 4326;
            
            var style = new VectorStyle
            {
                Fill = new Brush { Color = Color.Green },
                Outline = new Pen { Color = Color.Black }
            };
            countryLayer.Styles.Add(style);
            map.Layers.Add(countryLayer);

            //set up cities layer
            var cityLayer = new Layer("Cities");
            //Set the datasource to a shapefile in the App_data folder
            cityLayer.DataSource = new ShapeFile("GeoData/World/cities.shp", true);
            cityLayer.DataSource.SRID = 4326;
            cityLayer.MaxVisible = 0.09;
            map.Layers.Add(cityLayer);

            //Set up a country label layer
            var countryLabelLayer = new LabelLayer("Country labels");
            countryLabelLayer.DataSource = countryLayer.DataSource;
            countryLabelLayer.DataSource.SRID = 4326;
            countryLabelLayer.Enabled = true;
            countryLabelLayer.MaxVisible = 0.18;
            countryLabelLayer.MinVisible = 0.054;
            countryLabelLayer.LabelColumn = "NAME";
            var labelStyle = new LabelStyle();
            labelStyle.ForeColor = Color.Black;
            labelStyle.Font = new Font { FontFamily = "GenericSerif", Size = 12 };
            labelStyle.BackColor = new Brush { Color = new Color { A = 128, R = 255, G = 255, B = 255 } };
            labelStyle.HorizontalAlignment = LabelStyle.HorizontalAlignmentEnum.Center;
            countryLabelLayer.MultipartGeometryBehaviour = LabelLayer.MultipartGeometryBehaviourEnum.Largest;
            countryLabelLayer.Styles.Add(labelStyle);
            map.Layers.Add(countryLabelLayer);

            //Set up a city label layer
            var cityLabelLayer = new LabelLayer("City labels");
            cityLabelLayer.DataSource = cityLayer.DataSource;
            cityLabelLayer.DataSource.SRID = 4326;
            cityLabelLayer.Enabled = true;
            cityLabelLayer.LabelColumn = "NAME";
            cityLabelLayer.MaxVisible = countryLabelLayer.MinVisible;
            cityLabelLayer.MinVisible = 0;
            cityLabelLayer.LabelFilter = LabelCollisionDetection.ThoroughCollisionDetection;
            var cityLabelStyle = new LabelStyle();
            cityLabelStyle.ForeColor = Color.Black;
            cityLabelStyle.Font = new Font { FontFamily = "GenericSerif", Size = 11 };
            cityLabelStyle.HorizontalAlignment = LabelStyle.HorizontalAlignmentEnum.Left;
            cityLabelStyle.VerticalAlignment = LabelStyle.VerticalAlignmentEnum.Bottom;
            cityLabelStyle.Offset = new Offset { X = 3, Y = 3 };
            cityLabelStyle.Halo = new Pen { Color = Color.Yellow, Width = 2 };
            cityLabelStyle.CollisionDetection = true;
            cityLabelLayer.Styles.Add(cityLabelStyle);
            map.Layers.Add(cityLabelLayer);

            //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.
            IStyle min = new Style();
            IStyle max = new Style();
            //Create theme using a density from 0 (min) to 400 (max)
            var popdens = new GradientTheme("PopDens", 0, 400, min, max);
            //We can make more advanced coloring using the ColorBlend'er.
            //Setting the FillColorBlend will override any fill-style in the min and max fills.
            //In this case we just use the predefined Rainbow colorscale
            popdens.FillColorBlend = ColorBlend.Rainbow5;
            countryLayer.Styles.Add(popdens);

            //Lets scale the labels so that big countries have larger texts as well
            var lblMin = new LabelStyle();
            var lblMax = new LabelStyle();
            lblMin.ForeColor = Color.Black;
            lblMin.Font = new Font { FontFamily = "Sans Serif", Size = 6 };
            lblMax.ForeColor = Color.Black;
            lblMax.BackColor = new Brush { Color = new Color { A = 128, R = 255, G = 255, B = 255 } };
            lblMin.BackColor = lblMax.BackColor;
            lblMax.Font = new Font { FontFamily = "Sans Serif", Size = 9 };
            countryLabelLayer.Styles.Add(new GradientTheme("PopDens", 0, 400, lblMin, lblMax));

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

            citymin.Symbol = new Bitmap { Data = new FileStream(iconPath, FileMode.Open, FileAccess.Read) };
            citymin.SymbolScale = 0.5f;
            citymax.Symbol = new Bitmap { Data = new FileStream(iconPath, FileMode.Open, FileAccess.Read) };
            citymax.SymbolScale = 1f;
            cityLayer.Styles.Add(new GradientTheme("Population", 1000000, 5000000, citymin, citymax));

            var geodanLayer = new Layer("Geodan");
            geodanLayer.DataSource = new MemoryProvider(new Point(4.9130567, 52.3422033));
            geodanLayer.Styles.Add(new SymbolStyle { Symbol = new Bitmap { Data = new FileStream(iconPath, FileMode.Open, FileAccess.Read) } });
            map.Layers.Add(geodanLayer);

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

            return map;
        }