Beispiel #1
0
        private void CreateMap()
        {

            String BasePath = Server.MapPath(@"~\Shape");
            WebMap1.Projection = KnownCoordinateSystems.Projected.World.WebMercator;
            WebMap1.MapViewExtents = new Extent(-20037508.342789, -20037508.342789, 20037508.342789, 20037508.342789);


            WebMapClient client = new WebMapClient();


            WMTClient WMT1 = new WMTClient();
            WMT1.Create(WebServiceType.BingHybrid);
            
            
            string WMSServerWMS0 = "http://maps.ngdc.noaa.gov/soap/web_mercator/nos_hydro/MapServer/WMSServer";
            WMSClient WMS0 = new WMSClient();

            WMS0.ReadCapabilities(WMSServerWMS0);
            WMS0.CRS = "EPSG:3857";
            WMS0.Projection = KnownCoordinateSystems.Projected.World.WebMercator;


            string WMSServerWMS1 = "http://maps.ngdc.noaa.gov/soap/web_mercator/graticule/MapServer/WMSServer";

            WMSClient WMS1 = new WMSClient();

            WMS1.ReadCapabilities(WMSServerWMS1);
            WMS1.CRS = "EPSG:3857";
            WMS1.Projection = KnownCoordinateSystems.Projected.World.WebMercator;


            client.AddService(WMT1);
            client.AddService(WMS0);
            client.AddService(WMS1);

            WebMap1.Back = client;


            IMapFeatureLayer CountriesLayer = (IMapFeatureLayer)WebMap1.AddLayer(BasePath + @"\10m_admin_0_countries.shp");
            PolygonSymbolizer SymbCountries = new PolygonSymbolizer(Color.FromArgb(0, 191, 0));
            SymbCountries.SetFillColor(Color.Transparent);
            SymbCountries.OutlineSymbolizer = new LineSymbolizer(Color.Magenta, 1);
            CountriesLayer.Symbolizer = SymbCountries;


            IMapFeatureLayer Graticules30Layer = (IMapFeatureLayer)WebMap1.AddLayer(BasePath + @"\10m_graticules_30.shp");
            LineSymbolizer SymbGratitules30 = new LineSymbolizer(Color.Red, 1);
            Graticules30Layer.Symbolizer = SymbGratitules30;

            Graticules30Layer.IsVisible = false;



        }
        private static List <CustomSymbolizer> GetBasicPolygonSymbols()
        {
            List <CustomSymbolizer> lst = new List <CustomSymbolizer>();

            PolygonSymbolizer s1 = new PolygonSymbolizer();

            s1.SetFillColor(Color.Beige);
            lst.Add(new CustomSymbolizer(s1, "poly01", "polygon 1", "default"));

            PolygonSymbolizer s2 = new PolygonSymbolizer();

            s2.SetFillColor(Color.LightGreen);
            s2.SetOutlineWidth(2.0);
            s2.OutlineSymbolizer.SetFillColor(Color.Red);
            lst.Add(new CustomSymbolizer(s2, "poly02", "polygon 2", "category2"));

            return(lst);
        }
        /// <summary>
        /// Deserializes the layer.
        /// </summary>
        /// <param name="layer">The layer.</param>
        /// <param name="polyLayer">The poly layer.</param>
        internal static void DeserializeLayer(dynamic layer, MapPolygonLayer polyLayer)
        {
            if (UseAlternateParser(layer))
            {
                DeserializeLayerAlternateVersion(layer.ShapefileProperties, polyLayer);
                return;
            }
            var polySymbolizer = new PolygonSymbolizer();
            var outlineColor = LegacyDeserializer.GetColor(layer.ShapeFileProperties["OutLineColor"]);
            var outlineWidth = Convert.ToDouble(layer.ShapeFileProperties["LineOrPointSize"]);
            polySymbolizer.SetOutline(outlineColor, outlineWidth);
            if (Convert.ToBoolean(layer.ShapeFileProperties["DrawFill"]))
            {
                Color color = LegacyDeserializer.GetColor(layer.ShapeFileProperties["Color"]);
                float transparency = Convert.ToSingle(layer.ShapeFileProperties["TransparencyPercent"]);
                color = color.ToTransparent(transparency);
                polySymbolizer.SetFillColor(color);
            }
            else
            {
                polySymbolizer.SetFillColor(Color.Transparent);
            }

            polyLayer.Symbolizer = polySymbolizer;
            try
            {
                int fieldIndex = Convert.ToInt32(layer.ShapeFileProperties.Legend["FieldIndex"]);

                // we have to clear the categories or the collection ends up with a default item
                polyLayer.Symbology.Categories.Clear();

                foreach (var colorBreak in layer.ShapeFileProperties.Legend.ColorBreaks.Elements())
                {
                    PolygonCategory category;

                    string startValue = colorBreak["StartValue"];
                    string endValue = colorBreak["EndValue"];

                    if (startValue == endValue)
                    {
                        category = new PolygonCategory(LegacyDeserializer.GetColor(colorBreak["StartColor"]), LegacyDeserializer.GetColor(colorBreak["StartColor"]), 0);
                        category.FilterExpression = String.Format("[{0}] = '{1}'", polyLayer.DataSet.DataTable.Columns[fieldIndex].ColumnName, startValue);
                        category.LegendText = startValue;
                    }
                    else
                    {
                        category = new PolygonCategory(LegacyDeserializer.GetColor(colorBreak["StartColor"]), LegacyDeserializer.GetColor(colorBreak["EndColor"]), 0, GradientType.Linear, outlineColor, outlineWidth);
                        category.FilterExpression = String.Format("'{2}' >= [{0}] >= '{1}'", polyLayer.DataSet.DataTable.Columns[fieldIndex].ColumnName, startValue, endValue);
                        category.LegendText = String.Format("{0} - {1}", startValue, endValue);
                    }
                    category.LegendText = startValue;
                    category.LegendItemVisible = Convert.ToBoolean(colorBreak["Visible"]);
                    polyLayer.Symbology.AddCategory(category);
                }

                // it took too a lot of work to figure out that we would need to do this...
                polyLayer.ApplyScheme(polyLayer.Symbology);
            }
            catch (RuntimeBinderException)
            {
                // ignore and continue.
                // this means the legend is not available.
            }
        }
        private static void DeserializeLayerAlternateVersion(dynamic shapefileProperties, MapPolygonLayer polyLayer)
        {
            var polySymbolizer = new PolygonSymbolizer();
            var outlineColor = LegacyDeserializer.GetColor(shapefileProperties.DefaultDrawingOptions["LineColor"]);
            var outlineWidth = Convert.ToDouble(shapefileProperties.DefaultDrawingOptions["LineWidth"]);
            polySymbolizer.SetOutline(outlineColor, outlineWidth);
            if (Convert.ToBoolean(shapefileProperties.DefaultDrawingOptions["FillVisible"]))
            {
                Color color = LegacyDeserializer.GetColor(shapefileProperties.DefaultDrawingOptions["FillBgColor"]);
                float transparency = Convert.ToInt32(shapefileProperties.DefaultDrawingOptions["FillTransparency"]) / 255f;
                color = color.ToTransparent(transparency);
                polySymbolizer.SetFillColor(color);
            }
            else
            {
                polySymbolizer.SetFillColor(Color.Transparent);
            }

            polyLayer.Symbolizer = polySymbolizer;
        }
        private static List<CustomSymbolizer> getBasicPolygonSymbols()
        {
            List<CustomSymbolizer> lst = new List<CustomSymbolizer>();

            PolygonSymbolizer s1 = new PolygonSymbolizer();
            s1.SetFillColor(Color.Beige);
            lst.Add(new CustomSymbolizer(s1, "poly01", "polygon 1", "default"));

            PolygonSymbolizer s2 = new PolygonSymbolizer();
            s2.SetFillColor(Color.LightGreen);
            s2.SetOutlineWidth(2.0);
            s2.OutlineSymbolizer.SetFillColor(Color.Red);
            lst.Add(new CustomSymbolizer(s2, "poly02", "polygon 2", "category2"));

            return lst;
        }
 public IPolygonSymbolizer ToPolygonSymbolizer()
 {
     PolygonSymbolizer ps = new PolygonSymbolizer();
     ps.SetFillColor(this.Color.ToDrawingColor());
     ps.SetOutline(this.PolygonBorderColor.ToDrawingColor(), this.PolygonBorderSize);
     return ps;
 }