Inheritance: Style, ICloneable
        public void ReturnMaxColorForMaxValue()
        {
            var minVectorStyle = new VectorStyle { Fill = new SolidBrush(Color.Red) };
            var maxVectorStyle = new VectorStyle { Fill = new SolidBrush(Color.Blue) };

            var theme = new GradientTheme("red to blue", 10.0, 100.123, minVectorStyle, maxVectorStyle, null, null, null);

            var color = theme.GetFillColor(100.123);

            AssertColor(Color.Blue, color);
        }
Exemple #2
0
        public VectorStyle Clone()
        {
            VectorStyle vs = null;
            lock (_fillStyle)
            {
                vs = new VectorStyle()
                {
                    _fillStyle = _fillStyle.Clone() as Brush,
                    _lineOffset = _lineOffset,
                    _lineStyle = _lineStyle.Clone() as Pen,
                    _outline = _outline,
                    _outlineStyle = _outlineStyle.Clone() as Pen,
                    _PointBrush = _PointBrush.Clone() as Brush,
                    _PointSize = _PointSize,
                    _symbol = (_symbol != null ? _symbol.Clone() as Image : null),
                    _symbolOffset = new PointF(_symbolOffset.X, _symbolOffset.Y),
                    _symbolRotation = _symbolRotation,
                    _symbolScale = _symbolScale,
                    PointSymbolizer = PointSymbolizer,
                    LineSymbolizer = LineSymbolizer,
                    PolygonSymbolizer = PolygonSymbolizer

                };
            }
            return vs;
        }
Exemple #3
0
    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 = (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(0, 0);
            myMap.Zoom   = 360;
            //Create the map
            GenerateMap();
        }
    }
Exemple #4
0
 /// <summary>
 /// This method is used for determining the style
 /// It is used as a delegate for the CustomTheme class.
 /// </summary>
 /// <param name="row"></param>
 /// <returns></returns>
 private VectorStyle GetCountryStyle(FeatureDataRow row)
 {
     VectorStyle s = new VectorStyle();
     s.Fill = new SolidBrush(Color.Green);
     s.Symbol = GetPieChart(row);
     return s;
 }
Exemple #5
0
 /// <summary>
 /// This method is used for determining the style
 /// It is used as a delegate for the CustomTheme class.
 /// </summary>
 /// <param name="row"></param>
 /// <returns></returns>
 private SharpMap.Styles.VectorStyle GetCountryStyle(SharpMap.Data.FeatureDataRow row)
 {
     SharpMap.Styles.VectorStyle s = new SharpMap.Styles.VectorStyle();
     s.Fill   = new SolidBrush(Color.Green);
     s.Symbol = GetPieChart(row);
     return(s);
 }
Exemple #6
0
	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();
		}
	}
Exemple #7
0
	/// <summary>
	/// This method is used for determining the color of country based on attributes.
	/// It is used as a delegate for the CustomTheme class.
	/// </summary>
	/// <param name="row"></param>
	/// <returns></returns>
	private SharpMap.Styles.VectorStyle GetCountryStyle(SharpMap.Data.FeatureDataRow row)
	{
		SharpMap.Styles.VectorStyle style = new SharpMap.Styles.VectorStyle();
		switch (row["NAME"].ToString().ToLower())
		{
			case "denmark": //If country name is Danmark, fill it with green
				style.Fill = Brushes.Green;
				return style;
			case "united states": //If country name is USA, fill it with Blue and add a red outline
				style.Fill = Brushes.Blue;
				style.Outline = Pens.Red;
				return style;
			case "china": //If country name is China, fill it with red
				style.Fill = Brushes.Red;
				return style;
			default:
				break;
		}
		//If country name starts with S make it yellow
		if (row["NAME"].ToString().StartsWith("S"))
		{
			style.Fill = Brushes.Yellow;
			return style;
		}
		// If geometry is a (multi)polygon and the area of the polygon is less than 30, make it cyan
		else if (row.Geometry.GetType() == typeof(IMultiPolygon) && (row.Geometry as IMultiPolygon).Area < 30 ||
			row.Geometry.GetType() == typeof(IPolygon) && (row.Geometry as IPolygon).Area < 30 )
		{
			style.Fill = Brushes.Cyan;
			return style;
		}
		else //None of the above -> Use the default style
			return null;
	}
Exemple #8
0
 private static void UpdateMinMaxForPolygons(VectorStyle defaultStyle, VectorStyle minStyle, VectorStyle maxStyle, Color minColor, Color maxColor, float minOutlineSize, float maxOutlineSize)
 {
     minStyle.Fill = new SolidBrush(minColor);
     maxStyle.Fill = new SolidBrush(maxColor);
     minStyle.Outline = CreatePen(defaultStyle.Outline.Color, minOutlineSize, defaultStyle.Outline);
     maxStyle.Outline = CreatePen(defaultStyle.Outline.Color, maxOutlineSize, defaultStyle.Outline);
 }
Exemple #9
0
 private static void UpdateMinMaxForLineStrings(VectorStyle defaultStyle, int sizeMin, int sizeMax, VectorStyle minStyle, VectorStyle maxStyle, Color minColor, Color maxColor, float minOutlineSize, float maxOutlineSize, bool skipSizes)
 {
     minStyle.Line = CreatePen(minColor, skipSizes ? 4 : sizeMin, defaultStyle.Line);
     maxStyle.Line = CreatePen(maxColor, skipSizes ? 12 : sizeMax, defaultStyle.Line);
     minStyle.Outline = CreatePen(defaultStyle.Outline.Color, minOutlineSize, defaultStyle.Outline);
     maxStyle.Outline = CreatePen(defaultStyle.Outline.Color, maxOutlineSize, defaultStyle.Outline);
 }
Exemple #10
0
    private HtmlGenericControl LegendDiv(SharpMap.Layers.ILayer myLayer)
    {
        HtmlGenericControl legendDiv = new HtmlGenericControl("div");

        legendDiv.Style.Add("width", "2em");
        legendDiv.Style.Add("overflow", "hidden");
        legendDiv.Style.Add("position", "absolute");
        legendDiv.Style.Add("margin-left", "0.5em");
        legendDiv.Style.Add("margin-bottom", "0px");
        if (myLayer.GetType() == typeof(SharpMap.Layers.VectorLayer))
        {
            SharpMap.Layers.VectorLayer myVectorLayer = (myLayer as SharpMap.Layers.VectorLayer);

            SharpMap.Styles.VectorStyle myStyle = new SharpMap.Styles.VectorStyle();
            if (myVectorLayer.Theme != null)
            {
                if (myVectorLayer.Theme.GetType() == typeof(SharpMap.Rendering.Thematics.CustomTheme))
                {
                    SharpMap.Rendering.Thematics.CustomTheme myTheme = (myVectorLayer.Theme as SharpMap.Rendering.Thematics.CustomTheme);
                    myStyle = (myTheme.DefaultStyle as SharpMap.Styles.VectorStyle);
                }
                else if (myVectorLayer.Theme.GetType() == typeof(SharpMap.Rendering.Thematics.GradientTheme))
                {
                    SharpMap.Rendering.Thematics.GradientTheme myTheme = (myVectorLayer.Theme as SharpMap.Rendering.Thematics.GradientTheme);
                    myStyle = (myTheme.MinStyle as SharpMap.Styles.VectorStyle);
                }
            }
            else
            {
                myStyle = myVectorLayer.Style;
            }

            if (myStyle.Outline.Color.Name.ToString() != "Black")
            {
                string lineStyle = (myStyle.Outline.DashStyle.ToString() == "Dash") ? "dotted" : "solid";
                legendDiv.Style.Add("border", lineStyle + " " + myStyle.Outline.Width.ToString() + "px " + ColorToHex(myStyle.Outline.Color));
                legendDiv.Style.Add("height", "1em");
            }
            else
            {
                string lineStyle = (myStyle.Line.DashStyle.ToString() == "Dash") ? "dotted" : "solid";
                legendDiv.Style.Add("border-bottom", lineStyle + " " + myStyle.Line.Width.ToString() + "px " + ColorToHex(myStyle.Line.Color));
                legendDiv.Style.Add("height", "0.8em");
            }

            System.Drawing.SolidBrush fillBrush = (myVectorLayer.Style.Fill as System.Drawing.SolidBrush);
            if (fillBrush.Color.Name.ToString() != "Black")
            {
                HtmlGenericControl fillDiv = new HtmlGenericControl("div");
                fillDiv.Style.Add("border-left", "solid 2em " + ColorToHex(fillBrush.Color));
                fillDiv.Style.Add("height", "1.2em");
                fillDiv.Style.Add("overflow", "hidden");
                fillDiv.Style.Add("opacity ", ColorAlpha(fillBrush.Color) + "%");
                fillDiv.Style.Add("filter", "ALPHA(opacity=" + ColorAlpha(fillBrush.Color) + ")");
                legendDiv.Controls.Add(fillDiv);
            }
        }
        return(legendDiv);
    }
Exemple #11
0
 /// <summary>
 /// Initializes a new layer
 /// </summary>
 /// <param name="layername">Name of layer</param>
 public VectorLayer(string layername)
 {
     _Style = new VectorStyle();
     UpdateStyleGeometry();
     name = layername;
     // _SmoothingMode = SmoothingMode.AntiAlias;
     _SmoothingMode = SmoothingMode.HighSpeed;
 }
Exemple #12
0
 public FeatureEditor(ICoordinateConverter coordinateConverter, ILayer layer, IFeature feature, VectorStyle vectorStyle)
 {
     CoordinateConverter = coordinateConverter;
     Layer = layer;
     SourceFeature = feature;
     VectorStyle = vectorStyle;
     TopologyRules = new List<IFeatureRelationEditor>();
 }
Exemple #13
0
    /// <summary>
    /// This method is used for determining the style
    /// It is used as a delegate for the CustomTheme class.
    /// </summary>
    /// <param name="row"></param>
    /// <returns></returns>
    private SharpMap.Styles.VectorStyle GetCountryStyle(SharpMap.Data.FeatureDataRow row)
    {

        SharpMap.Styles.VectorStyle s = new SharpMap.Styles.VectorStyle();
        s.Fill = new SolidBrush(Color.Green);
        s.Symbol = GetPieChart(row);
        return s;
    }
 protected override void OnInitializeDefaultStyle()
 {
     Style = new VectorStyle
     {
         GeometryType = typeof(ILineString),
         Fill = new SolidBrush(Color.Tomato),
         Line = new Pen(Color.SteelBlue, 3)
     };
 }
Exemple #15
0
 public FeatureInteractor(ILayer layer, IFeature feature, VectorStyle vectorStyle, IEditableObject editableObject)
 {
     Layer = layer;
     SourceFeature = feature;
     VectorStyle = vectorStyle;
     FeatureRelationEditors = new List<IFeatureRelationInteractor>();
     EditableObject = editableObject;
     CreateTrackers();
 }
Exemple #16
0
        /// <summary>
        /// Factory method to create a random puntal style
        /// </summary>
        /// <returns>A puntal vector style</returns>
        public static VectorStyle CreateRandomPolygonalStyle()
        {
            var res = new VectorStyle();

            ClearPuntalStyle(res);
            ClearLinealStyle(res);
            RandomizePolygonalStyle(res);
            return(res);
        }
Exemple #17
0
 /// <summary>
 /// Utility function to randomize lineal settings
 /// </summary>
 /// <param name="res">The style to randomize</param>
 private static void RandomizeLinealStyle(VectorStyle res)
 {
     res.Line          = new Pen(CreateRandomKnownColor(_rnd.Next(67, 256)), _rnd.Next(1, 3));
     res.EnableOutline = _rnd.Next(0, 2) == 1;
     if (res.EnableOutline)
     {
         res.Outline = new Pen(CreateRandomKnownColor(_rnd.Next(67, 256)), _rnd.Next((int)res.Line.Width, 5));
     }
 }
Exemple #18
0
        public void GenerateThemeWithMaxDoubleAndMinDoubleValue()
        {
            var minVectorStyle = new VectorStyle { Fill = new SolidBrush(Color.Red) };
            var maxVectorStyle = new VectorStyle { Fill = new SolidBrush(Color.Blue) };

            var theme = new GradientTheme("red to blue", double.MinValue, double.MaxValue, minVectorStyle, maxVectorStyle, null, null, null);

            var color = theme.GetFillColor(100);

            AssertColor(Color.FromArgb(255, 127, 0, 127), color);
        }
Exemple #19
0
        public static CategorialTheme CreateCategorialTheme(string attribute, VectorStyle defaultStyle, ColorBlend blend, 
            int numberOfClasses, IList<IComparable> values, List<string> categories)
        {
            if (defaultStyle == null)
            {
                defaultStyle = new VectorStyle
                                   {
                                       GeometryType = typeof (IPolygon)
                                   };
            }

            var categorialTheme = new CategorialTheme(attribute, defaultStyle);

            for (int i = 0; i < numberOfClasses; i++)
            {
                string label = (categories != null)
                                   ? categories[i]
                                   : values[i].ToString();

                Color color = (numberOfClasses > 1)
                                  ? blend.GetColor((float) i/(numberOfClasses - 1))
                                  : ((SolidBrush) defaultStyle.Fill).Color;
                
                var vectorStyle = (VectorStyle) defaultStyle.Clone();

                if (defaultStyle.GeometryType == typeof(IPoint))
                {
                    vectorStyle.Fill = new SolidBrush(color);
                    vectorStyle.Line.Width = 16;
                    vectorStyle.Shape = defaultStyle.Shape;
                }
                else if ((defaultStyle.GeometryType == typeof(IPolygon)) || (defaultStyle.GeometryType == typeof(IMultiPolygon)))
                {
                    vectorStyle.Fill = new SolidBrush(color);
                }
                else if ((defaultStyle.GeometryType == typeof(ILineString)) || (defaultStyle.GeometryType == typeof(IMultiLineString)))
                {
                    vectorStyle.Line = new Pen(color, defaultStyle.Line.Width);
                }
                else
                {
                    vectorStyle.Fill = new SolidBrush(color);
                }

                CategorialThemeItem categorialThemeItem = (values[i] != null)
                                                              ? new CategorialThemeItem(label, vectorStyle, vectorStyle.LegendSymbol, values[i])
                                                              : new CategorialThemeItem(label, vectorStyle, vectorStyle.LegendSymbol);

                
                categorialTheme.AddThemeItem(categorialThemeItem);
            }

            return categorialTheme;
        }
Exemple #20
0
        /// <summary>
        /// Returns the style based on a feature
        /// </summary>
        /// <param name="attribute">Attribute to calculate color from</param>
        /// <returns>Color</returns>
        public SharpMap.Styles.IStyle GetStyle(FeatureDataRow attribute)
        {
            VectorStyle vs = new VectorStyle();

            if (!_brushes.ContainsKey(attribute.Geometry))
                _brushes[attribute.Geometry] = new SolidBrush(Color.FromArgb(rand.Next(255), rand.Next(255), rand.Next(255)));

            vs.Fill = _brushes[attribute.Geometry];
            vs.Outline = new Pen(Color.Black);
            vs.EnableOutline = true;
            return vs;
        }
        private static VectorStyle GetStyle()
        {
            VectorStyle style = new VectorStyle
                                    {
                                        Fill = Brushes.AntiqueWhite,
                                        Line = Pens.Red,
                                        EnableOutline = true,
                                        Outline = Pens.Black,
                                        Symbol = new Bitmap(10, 10)
                                    };

            return style;
        }
Exemple #22
0
        private void fetch_GeoData(DateTime date)
        {
            List <String> res = new List <String>();

            for (int i = 0; i < db.dates.Count; i++)
            {
                if (date.Year == db.dates[i].Year && date.Month == db.dates[i].Month && date.Day == db.dates[i].Day)
                {
                    res.Add(db.location[i]);
                }
            }

            int[] colorMap = new int[95];
            foreach (String s in res)
            {
                for (int i = 0; i < 95; i++)
                {
                    if (s == i.ToString())
                    {
                        colorMap[i]++;
                    }
                }
            }

            Dictionary <string, SharpMap.Styles.IStyle> styles = new Dictionary <string, IStyle>();
            VectorStyle def = new VectorStyle();

            def.Fill = new SolidBrush(Color.FromArgb(255, 255, 255));
            int maxCol = colorMap.Max() == 0 ? 1 : colorMap.Max();

            for (int i = 0; i < colorMap.Length; i++)
            {
                int col = colorMap[i] == 0 ? 1 : colorMap[i];
                SharpMap.Styles.VectorStyle detectedArea = new SharpMap.Styles.VectorStyle();
                detectedArea.Fill = new SolidBrush(Color.FromArgb((int)(255 * decimal.Divide(col, maxCol)), (int)(0 * decimal.Divide(col, maxCol)), (int)(0 * decimal.Divide(col, maxCol))));
                if (colorMap[i] > 0)
                {
                    styles.Add(i.ToString(), detectedArea);
                }
                else
                {
                    styles.Add(i.ToString(), def);
                }
            }

            vlay.DataSource = new SharpMap.Data.Providers.ShapeFile(@"..\..\Resources\map.shp", true);
            vlay.Theme      = new SharpMap.Rendering.Thematics.UniqueValuesTheme <string>("kode", styles, def);
            mapBox1.Map.Layers.Add(vlay);
            mapBox1.Map.ZoomToExtents();
            mapBox1.Refresh();
        }
Exemple #23
0
        /// <summary>
        /// returns  a Random VectorStyle with no symbols.
        /// 
        /// </summary>
        /// <returns></returns>
        public static IVectorStyle RandomVectorStyleNoSymbols()
        {
            VectorStyle vs = new VectorStyle();

            vs.EnableOutline = random.Next(0, 2) == 1;

            vs.Fill = RandomBrush();
            vs.Line = RandomPen();
            vs.Outline = RandomPen();



            return vs;
        }
        public static SharpDXVectorStyle FromVectorStyle(RenderTarget rt, Factory f, VectorStyle vs)
        {
            var res = new SharpDXVectorStyle
            {
                // Global
                Enabled = vs.Enabled,
                MinVisible = vs.MinVisible,
                MaxVisible = vs.MaxVisible,
            };

            // Point
            if (vs.PointColor != null)
            {
                res.PointColor = Converter.ToSharpDXBrush(rt, vs.PointColor);
                res.PointSize = vs.PointSize;
            }
            if (vs.Symbol != null)
            {
                res.Symbol = Converter.ToSharpDXBitmap(rt, vs.Symbol as System.Drawing.Bitmap, vs.SymbolScale);
                res.SymbolOffset = Converter.ToSharpDXPoint(vs.SymbolOffset);
                //res.SymbolScale = vs.SymbolScale;
                res.SymbolRotation = vs.SymbolRotation;
            }
            
            // Line
            if (vs.Line != null)
            {
                res.Line = Converter.ToSharpDXBrush(rt, vs.Line.Brush);
                res.LineWidth = vs.Line.Width;
                res.LineStrokeStyle = Converter.ToSharpDXStrokeStyle(f, vs.Line);
                res.LineOffset = vs.LineOffset;
            }
            if (vs.Outline != null)
            {
                res.EnableOutline = vs.EnableOutline;
                res.Outline = Converter.ToSharpDXBrush(rt, vs.Outline.Brush);
                res.OutlineWidth = vs.Outline.Width;
                res.OutlineStrokeStyle = Converter.ToSharpDXStrokeStyle(f, vs.Line);
            }
            
            // Fill
            if (vs.Fill != null)
            {
                res.Fill = Converter.ToSharpDXBrush(rt, vs.Fill);
            }

            return res;
        }
Exemple #25
0
        /// <summary>
        /// Utility function to randomize puntal settings
        /// </summary>
        /// <param name="res">The style to randomize</param>
        private static void RandomizePuntalStyle(VectorStyle res)
        {
            switch (_rnd.Next(2))
            {
            case 0:
                res.Symbol      = DefaultSymbol;
                res.SymbolScale = 0.01f * _rnd.Next(80, 200);
                break;

            case 1:
                res.Symbol     = null;
                res.PointColor = new SolidBrush(CreateRandomKnownColor(_rnd.Next(67, 256)));
                res.PointSize  = 0.1f * _rnd.Next(5, 20);
                break;
            }
        }
Exemple #26
0
        private static ILayer CreateLayer(string path, VectorStyle style)
        {
            FileInfo file = new FileInfo(path);
            if (!file.Exists)
                throw new FileNotFoundException("file not found", path);

            string full = file.FullName;
            string name = Path.GetFileNameWithoutExtension(full);
            ILayer layer = new VectorLayer(name, new ShapeFile(full, true))
            {
                SRID = 900913,
                CoordinateTransformation = LayerTools.Wgs84toGoogleMercator,
                Style = style,
                SmoothingMode = SmoothingMode.AntiAlias
            };
            return layer;
        }
Exemple #27
0
        /// <summary>
        /// Creates a <see cref="GradientTheme"/>
        /// </summary>
        /// <param name="attribute">Name of the feature attribute</param>
        /// <param name="defaultStyle">Default <see cref="VectorStyle"/> to base this theme on</param>
        /// <param name="blend"><see cref="ColorBlend"/> 
        ///   defining the min and max colors
        ///   Note: Silently assumes 2 Colors defined
        /// </param>
        /// <param name="minValue">Minimum value of the feature attribute values</param>
        /// <param name="maxValue">Maximum value of the feature attribute values</param>
        /// <param name="sizeMin">Minimum line/point size in pixels</param>
        /// <param name="sizeMax">Maximum line/point size in pixels</param>
        /// <param name="skipColors">Use the min and max colors (false) or the defaultStyle fill color (true)</param>
        /// <param name="skipSizes">Let the size of a point depend on the value (false) or use the defaultStyle size (true)</param>
        /// <param name="numberOfClasses">The number of classes (ThemeItems) to generate (default = 8)</param>
        /// <returns>A new <see cref="GradientTheme"/></returns>
        public static GradientTheme CreateGradientTheme(string attribute, VectorStyle defaultStyle, ColorBlend blend,
            double minValue, double maxValue, int sizeMin, int sizeMax, bool skipColors, bool skipSizes, int numberOfClasses = 8)
        {
            if (defaultStyle == null)
            {
                defaultStyle = new VectorStyle { GeometryType = typeof(IPolygon) };
            }

            Color minColor = (skipColors) ? ((SolidBrush)defaultStyle.Fill).Color : blend.GetColor(0);
            Color maxColor = (skipColors) ? ((SolidBrush)defaultStyle.Fill).Color : blend.GetColor(1);

            var deltaWidth = (defaultStyle.Outline.Width - defaultStyle.Line.Width);

            float minOutlineSize = deltaWidth + sizeMin;
            float maxOutlineSize = deltaWidth + sizeMax;

            // Use default styles if not working with VectorLayers (i.e. RegularGridCoverageLayers)
            var minStyle = (VectorStyle)defaultStyle.Clone();
            var maxStyle = (VectorStyle)defaultStyle.Clone();

            minStyle.GeometryType = defaultStyle.GeometryType;
            maxStyle.GeometryType = defaultStyle.GeometryType;

            if (defaultStyle.GeometryType == typeof(IPoint))
            {
                UpdateMinMaxForPoints(defaultStyle, sizeMin, sizeMax, minStyle, maxStyle, minColor, maxColor, skipSizes);
            }
            else if ((defaultStyle.GeometryType == typeof(IPolygon)) || (defaultStyle.GeometryType == typeof(IMultiPolygon)))
            {
                UpdateMinMaxForPolygons(defaultStyle, minStyle, maxStyle, minColor, maxColor, minOutlineSize, maxOutlineSize);
            }
            else if ((defaultStyle.GeometryType == typeof(ILineString)) || (defaultStyle.GeometryType == typeof(IMultiLineString)))
            {
                UpdateMinMaxForLineStrings(defaultStyle, sizeMin, sizeMax, minStyle, maxStyle, minColor, maxColor, minOutlineSize, maxOutlineSize, skipSizes);
            }
            else
            {
                //use for unknown geometry..
                minStyle.Fill = new SolidBrush(minColor);
                maxStyle.Fill = new SolidBrush(maxColor);
                minStyle.Outline = CreatePen(minColor, minOutlineSize, defaultStyle.Outline);
                maxStyle.Outline = CreatePen(maxColor, maxOutlineSize, defaultStyle.Outline);
            }

            return new GradientTheme(attribute, minValue, maxValue, minStyle, maxStyle, blend, blend, null, numberOfClasses);
        }
Exemple #28
0
        public VectorStyle Clone()
        {
            VectorStyle vs = null;

            lock (this)
            {
                vs = new VectorStyle();

                if (_fillStyle != null)
                {
                    vs._fillStyle = _fillStyle.Clone() as Brush;
                }
                else
                {
                    vs._fillStyle = null;
                }
                vs._lineOffset = _lineOffset;
                if (_lineStyle != null)
                {
                    vs._lineStyle = _lineStyle.Clone() as Pen;
                }

                vs._outline = _outline;

                if (_outlineStyle != null)
                {
                    vs._outlineStyle = _outlineStyle.Clone() as Pen;
                }

                if (_PointBrush != null)
                {
                    vs._PointBrush = _PointBrush.Clone() as Brush;
                }

                vs._PointSize        = _PointSize;
                vs._symbol           = (_symbol != null ? _symbol.Clone() as Image : null);
                vs._symbolOffset     = new PointF(_symbolOffset.X, _symbolOffset.Y);
                vs._symbolRotation   = _symbolRotation;
                vs._symbolScale      = _symbolScale;
                vs.PointSymbolizer   = PointSymbolizer;
                vs.LineSymbolizer    = LineSymbolizer;
                vs.PolygonSymbolizer = PolygonSymbolizer;
            }
            return(vs);
        }
Exemple #29
0
        private static void SetFillStyle(VectorStyle style, XmlNode fillSymbolizer, XmlNamespaceManager nsm)
        {
            string stroke           = string.Empty;
            string strokeWidth      = string.Empty;
            string strokeOpacity    = string.Empty;
            string strokeLinejoin   = string.Empty;
            string strokeLineCap    = string.Empty;
            string strokeDasharray  = string.Empty;
            string strokeDashOffset = string.Empty;
            string fill             = string.Empty;
            string fillOpacity      = string.Empty;
            string pointSymbolPath  = string.Empty;

            var polygonFillSymbols = fillSymbolizer.SelectNodes("sld:Fill/sld:CssParameter", nsm);

            if (polygonFillSymbols == null)
            {
                return;
            }

            foreach (XmlElement polygonFillSymbol in polygonFillSymbols)
            {
                if (polygonFillSymbol != null)
                {
                    switch (polygonFillSymbol.GetAttribute("name"))
                    {
                    //polygon
                    case "fill":
                        fill = polygonFillSymbol.InnerXml;
                        break;

                    case "fill-opacity":
                        fillOpacity = polygonFillSymbol.InnerXml;
                        break;
                    }
                }
            }

            SetStyle(style, stroke, strokeWidth, strokeOpacity, strokeLinejoin, strokeLineCap, strokeDasharray,
                     strokeDashOffset, fill, fillOpacity, pointSymbolPath);


            //Call down to stroke style
            SetStrokeStyle(style, fillSymbolizer, nsm);
        }
Exemple #30
0
    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);
    }
Exemple #31
0
        /// <summary>
        /// Modifies a Vectorstyle to "highlight" during operation (eg. moving features)
        /// </summary>
        /// <param name="vectorStyle"></param>
        /// <param name="good"></param>
        public static void PimpStyle(VectorStyle vectorStyle, bool good)
        {
            vectorStyle.Line.Color = Color.FromArgb(128, vectorStyle.Line.Color);
            SolidBrush solidBrush = vectorStyle.Fill as SolidBrush;
            if (null != solidBrush)
                vectorStyle.Fill = new SolidBrush(Color.FromArgb(127, solidBrush.Color));
            else // possibly a multicolor brush
                vectorStyle.Fill = new SolidBrush(Color.FromArgb(63, Color.DodgerBlue));
            if (null != vectorStyle.Symbol)
            {
                Bitmap bitmap = new Bitmap(vectorStyle.Symbol.Width, vectorStyle.Symbol.Height);
                Graphics graphics = Graphics.FromImage(bitmap);
                ColorMatrix colorMatrix;
                if (good)
                {
                    colorMatrix = new ColorMatrix(new float[][]
                    {
                        new float[] {1.0f, 0.0f, 0.0f, 0.0f, 0.0f}, // red scaling of 1
                        new float[] {0.0f, 1.0f, 0.0f, 0.0f, 0.0f}, // green scaling of 1
                        new float[] {0.0f, 0.0f, 1.0f, 0.0f, 0.0f}, // blue scaling of 1
                        new float[] {0.0f, 0.0f, 0.0f, 0.5f, 0.0f}, // alpha scaling of 0.5
                        new float[] {0.0f, 0.0f, 0.0f, 0.0f, 1.0f}
                    });
                }
                else
                {
                    colorMatrix = new ColorMatrix(new float[][]
                    {
                        new float[] {2.0f, 0.0f, 0.0f, 0.0f, 0.0f}, // red scaling of 2
                        new float[] {0.0f, 1.0f, 0.0f, 0.0f, 0.0f}, // green scaling of 1
                        new float[] {0.0f, 0.0f, 1.0f, 0.0f, 0.0f}, // blue scaling of 1
                        new float[] {0.0f, 0.0f, 0.0f, 0.5f, 0.0f}, // alpha scaling of 0.5
                        new float[] {1.0f, 0.0f, 0.0f, 0.0f, 1.0f}
                    });
                }

                ImageAttributes imageAttributes = new ImageAttributes();
                imageAttributes.SetColorMatrix(colorMatrix);
                graphics.DrawImage(vectorStyle.Symbol,
                    new Rectangle(0, 0, vectorStyle.Symbol.Width, vectorStyle.Symbol.Height), 0, 0,
                    vectorStyle.Symbol.Width, vectorStyle.Symbol.Height, GraphicsUnit.Pixel, imageAttributes);
                graphics.Dispose();
                vectorStyle.Symbol = bitmap;
            }
        }
Exemple #32
0
    private static SharpMap.Styles.VectorStyle GetFullStationStyle(SharpMap.Data.FeatureDataRow row)
    {
        SharpMap.Styles.VectorStyle style = new SharpMap.Styles.VectorStyle();
        string s1 = row["Oid"].ToString();
        string s2 = row["id"].ToString();

        if (Int32.Parse(s1) < 6)
        {
            style.PointColor = new SolidBrush(Color.DarkOrange);
            style.PointSize  = 20f;
        }
        else
        {
            style.PointColor = new SolidBrush(Color.DeepSkyBlue);
            style.PointSize  = 10f;
        }
        return(style);
    }
Exemple #33
0
    public static Map InitializeGradientMap(Size size)
    {
        //Initialize a new map based on the simple map
        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.
        VectorStyle min = new VectorStyle();
        VectorStyle max = new VectorStyle();
        //Create theme using a density from 0 (min) to 400 (max)
        GradientTheme 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;
        (map.Layers[0] as VectorLayer).Theme = popdens;

        //Lets scale the labels so that big countries have larger texts as well
        LabelStyle lblMin = new LabelStyle();
        LabelStyle lblMax = new 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 LabelLayer).Theme = 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
        VectorStyle citymin = new VectorStyle();
        VectorStyle citymax = new 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 VectorLayer).Theme = new GradientTheme("Population", 1000000, 5000000, citymin, citymax);

        //Turn off the river layer
        map.Layers[1].Enabled = false;
        return map;
    }
Exemple #34
0
        public static Map SqlServer()
        {
            const string connstr = "Data Source=.\\SQL2008R2;Initial Catalog=SampleData;Integrated Security=SSPI;";
            Map map = new Map(new Size(1, 1));            

            VectorStyle style0 = new VectorStyle { Line = new Pen(Color.DarkGray, 2) };
            VectorLayer layer0 = CreateLayer(connstr, "osm_boundaries", style0);
            map.Layers.Add(layer0);
            
            VectorStyle style1 = new VectorStyle { Line = new Pen(Color.DarkRed, 2.5f) };
            VectorLayer layer1 = CreateLayer(connstr, "osm_roads_major", style1);
            map.Layers.Add(layer1);

            VectorStyle style2 = new VectorStyle { Line = new Pen(Color.DarkBlue, 1.5f) };
            VectorLayer layer2 = CreateLayer(connstr, "osm_roads_minor", style2);
            map.Layers.Add(layer2);
            
            return map;
        }
        private static VectorLayer CreateLayer(string connstr, string name, VectorStyle style)
        {
            if (connstr == null)
                throw new ArgumentNullException("connstr");
            if (name == null)
                throw new ArgumentNullException("name");

            SqlServer2008 source = new SqlServer2008(connstr, name, "geom", "ID") { ValidateGeometries = true };
            ICoordinateTransformation transformation = ProjHelper.LatLonToGoogle();
            VectorLayer item = new VectorLayer(name, source)
            {
                SRID = 4326,
                TargetSRID = 900913,
                CoordinateTransformation = transformation,
                Style = style,
                SmoothingMode = SmoothingMode.AntiAlias,
            };
            return item;
        }
Exemple #36
0
        public override object Clone()
        {
            VectorStyle vectorStyle = new VectorStyle();

            vectorStyle.Shape     = Shape;
            vectorStyle.ShapeSize = ShapeSize;
            if ((_CustomSymbol) && (null != Symbol))
            {
                vectorStyle.Symbol = (Bitmap)Symbol.Clone();
            }

            vectorStyle.Line          = Line == null ? null : (Pen)Line.Clone();
            vectorStyle.Outline       = Outline == null ? null : (Pen)Outline.Clone();
            vectorStyle.EnableOutline = EnableOutline;
            vectorStyle.Fill          = Fill == null ? null : (Brush)Fill.Clone();
            vectorStyle.GeometryType  = GeometryType;

            return(vectorStyle);
        }
Exemple #37
0
        public static bool AreVectorStylesEqual(VectorStyle lhs, VectorStyle rhs)
        {
            AreStylesEqual(lhs, rhs);

            Assert.AreEqual(lhs.PointSize, rhs.PointSize);
            Assert.AreEqual(((SolidBrush)lhs.PointColor).Color, ((SolidBrush)rhs.PointColor).Color);

            SurrogatesTest.ComparePens(lhs.Line, rhs.Line, "Line");
            Assert.AreEqual(lhs.Line.PenType, rhs.Line.PenType);
            Assert.AreEqual(lhs.Line.Color, rhs.Line.Color);
            Assert.AreEqual(lhs.EnableOutline, rhs.EnableOutline);
            Assert.AreEqual(lhs.Outline.PenType, rhs.Outline.PenType);
            Assert.AreEqual(lhs.Outline.Color, rhs.Outline.Color);

            Assert.AreEqual(lhs.Fill.GetType(), rhs.Fill.GetType());

            //ToDo: Test more properties
            return true;
        }
Exemple #38
0
        public void EventBubbling()
        {
            VectorStyle style = new VectorStyle();
            VectorLayer vectorLayer = new VectorLayer("EventBubbling");
            vectorLayer.Style = style;
            int changeCount = 0;
            Post.Cast<VectorLayer, System.ComponentModel.INotifyPropertyChanged>(vectorLayer).PropertyChanged +=
                delegate(object sender, System.ComponentModel.PropertyChangedEventArgs e)
                {
                    Assert.AreEqual(e.PropertyName, "Line");
                    changeCount++;
                };

            Assert.AreEqual(0, changeCount);
            Pen pen1 = new Pen(new SolidBrush(Color.Yellow), 3);
            style.Line = pen1;
            Assert.AreEqual(1, changeCount);

        }
        private static IStyle GetVectorStyle(ICssStyleDeclaration csd)
        {
            // VectorStyle object rebuild. Deserializes:
            //   border-color     Line.Color
            //   border-width     Line.Width
            //   outline-color    Outline.Color
            //   outline-width    Outline.Width
            //   outline-style    EnableOutline
            //   background-color Fill
            VectorStyle vStyle = new VectorStyle();
            if (csd.GetPropertyValue("border-color") != string.Empty)
                vStyle.Line.Color = GetColorFromCss(csd, "border-color");
            if (csd.GetPropertyValue("border-width") != string.Empty)
                vStyle.Line.Width = float.Parse(csd.GetPropertyValue("border-width"));
            if (csd.GetPropertyValue("outline-color") != string.Empty)
                vStyle.Outline.Color = GetColorFromCss(csd, "outline-color");
            if (csd.GetPropertyValue("outline-width") != string.Empty)
                vStyle.Outline.Width = float.Parse(csd.GetPropertyValue("outline-width"));
            if (csd.GetPropertyValue("outline-style") != string.Empty)
                vStyle.EnableOutline = (csd.GetPropertyValue("outline-style") == "enabled" ? true : false);
            if (csd.GetPropertyValue("background-color") != string.Empty)
                vStyle.Fill = new SolidBrush(GetColorFromCss(csd, "background-color"));

            vStyle.Line.EndCap = (LineCap)Enum.Parse(typeof(LineCap), csd.GetPropertyValue(endcapName));

            if (csd.GetPropertyValue("geometry-type") != string.Empty)
            {
                vStyle.GeometryType = GetGeometryTypeFromCssString(csd);
            }

            if (csd.GetPropertyValue("symbol-shape") != string.Empty)
            {
                vStyle.Shape = (VectorStyle.ShapeType?) Enum.Parse(typeof(VectorStyle.ShapeType), csd.GetPropertyValue("symbol-shape"));
            }
            if (csd.GetPropertyValue("symbol") != string.Empty) 
            {
                // From a Codepage 1251-encoded string, convert to bytes and next to a Bitmap representing the symbol
                byte[] bytes = Convert.FromBase64String(csd.GetPropertyValue("symbol"));
                vStyle.Symbol = (Bitmap)TypeDescriptor.GetConverter(typeof(Bitmap)).ConvertFrom(bytes);
            }
            return vStyle;
        }
Exemple #40
0
        public void EventBubbling3()
        {
            int changeCount = 0;
            var map = new Map(new Size(2, 1));
            var style = new VectorStyle();
            var vectorLayer = new VectorLayer("EventBubbling") {Style = style};
            map.Layers.Add(vectorLayer);

            ((INotifyPropertyChanged)map).PropertyChanged +=
                delegate(object sender, PropertyChangedEventArgs e)
                    {
                        Assert.AreEqual(e.PropertyName, "Line");
                        changeCount++;
                    };

            Assert.AreEqual(0, changeCount);
            var pen1 = new Pen(new SolidBrush(Color.Yellow), 3);
            style.Line = pen1;
            Assert.AreEqual(1, changeCount);
        }
Exemple #41
0
        /// <summary>
        /// Utility function to randomize polygonal settings
        /// </summary>
        /// <param name="res"></param>
        private static void RandomizePolygonalStyle(VectorStyle res)
        {
            switch (_rnd.Next(3))
            {
            case 0:
                res.Fill = new SolidBrush(CreateRandomKnownColor(_rnd.Next(67, 256)));
                break;

            case 1:
                res.Fill = new HatchBrush((HatchStyle)_rnd.Next(0, 53),
                                          CreateRandomKnownColor(), CreateRandomKnownColor(_rnd.Next(67, 256)));
                break;

            case 2:
                var alpha = _rnd.Next(67, 256);
                res.Fill = new LinearGradientBrush(new Point(0, 0), new Point(_rnd.Next(5, 10), _rnd.Next(5, 10)),
                                                   CreateRandomKnownColor(alpha), CreateRandomKnownColor(alpha));
                break;
            }
        }
Exemple #42
0
    /// <summary>
    /// This method is used for determining the color of country based on attributes.
    /// It is used as a delegate for the CustomTheme class.
    /// </summary>
    /// <param name="row"></param>
    /// <returns></returns>
    private IVectorStyle GetCountryStyle(SharpMap.Data.FeatureDataRow row)
    {
        IVectorStyle style = new SharpMap.Styles.VectorStyle();

        switch (row["NAME"].ToString().ToLower())
        {
        case "denmark":     //If country name is Danmark, fill it with green
            style.Fill = Brushes.Green;
            return(style);

        case "united states":     //If country name is USA, fill it with Blue and add a red outline
            style.Fill    = Brushes.Blue;
            style.Outline = Pens.Red;
            return(style);

        case "china":     //If country name is China, fill it with red
            style.Fill = Brushes.Red;
            return(style);

        default:
            break;
        }
        //If country name starts with S make it yellow
        if (row["NAME"].ToString().StartsWith("S"))
        {
            style.Fill = Brushes.Yellow;
            return(style);
        }
        // If geometry is a (multi)polygon and the area of the polygon is less than 30, make it cyan
        else if (row.Geometry.GetType() == typeof(SharpMap.Geometries.MultiPolygon) && (row.Geometry as SharpMap.Geometries.MultiPolygon).Area < 30 ||
                 row.Geometry.GetType() == typeof(SharpMap.Geometries.Polygon) && (row.Geometry as SharpMap.Geometries.Polygon).Area < 30)
        {
            style.Fill = Brushes.Cyan;
            return(style);
        }
        else //None of the above -> Use the default style
        {
            return(null);
        }
    }
 public static IFeatureEditor Create(ICoordinateConverter coordinateConverter, ILayer layer, IFeature feature, VectorStyle vectorStyle)
 {
     if (null == feature)
         return null;
     // most specific type should be first
     if (feature is GridProfile)
         return new GridProfileEditor(coordinateConverter, layer, feature, vectorStyle);
     if (feature is RegularGridCoverageCell)
         return new RegularGridCoverageCellEditor(coordinateConverter, layer, feature, vectorStyle);
     if (feature.Geometry is ILineString)
         return new LineStringEditor(coordinateConverter, layer, feature, vectorStyle);
     if (feature.Geometry is IPoint)
         return new PointEditor(coordinateConverter, layer, feature, vectorStyle);
     // todo implement custom mutator for Polygon and MultiPolygon
     // LineStringMutator will work as long as moving is not supported.
     if (feature.Geometry is IPolygon)
         return new LineStringEditor(coordinateConverter, layer, feature, vectorStyle);
     if (feature.Geometry is IMultiPolygon)
         return new LineStringEditor(coordinateConverter, layer, feature, vectorStyle);
     return null;
     //throw new ArgumentException("Unsupported type " + feature.Geometry);
 }
Exemple #44
0
        public void EventBubbling()
        {
            var style = new VectorStyle();
            var vectorLayer = new VectorLayer("EventBubbling") { Style = style };
            var changeCount = 0;

            ((INotifyPropertyChanged)vectorLayer).PropertyChanged +=
                delegate(object sender, System.ComponentModel.PropertyChangedEventArgs e)
                {
                    Assert.AreEqual(e.PropertyName, "Line");
                    changeCount++;
                };


            Assert.AreEqual(0, changeCount);

            var pen1 = new Pen(new SolidBrush(Color.Yellow), 3);
            style.Line = pen1;

            Assert.AreEqual(1, changeCount);

        }
Exemple #45
0
        private static void SetSymbologyForRule(VectorStyle style, XmlElement rule, XmlNamespaceManager nsm)
        {
            var polygonSymbolizers = rule.SelectNodes("sld:PolygonSymbolizer", nsm);
            var lineSymbolizers    = rule.SelectNodes("sld:LineSymbolizer", nsm);
            var pointSymbolizers   = rule.SelectNodes("sld:PointSymbolizer", nsm);

            if (polygonSymbolizers != null)
            {
                if (polygonSymbolizers.Count > 0)
                {
                    foreach (XmlElement polygonSymbolizer in polygonSymbolizers)
                    {
                        SetFillStyle(style, polygonSymbolizer, nsm);
                    }
                }
            }

            if (lineSymbolizers != null)
            {
                if (lineSymbolizers.Count > 0)
                {
                    foreach (XmlElement lineSymbolizer in lineSymbolizers)
                    {
                        SetStrokeStyle(style, lineSymbolizer, nsm);
                    }
                }
            }

            if (pointSymbolizers != null)
            {
                if (pointSymbolizers.Count > 0)
                {
                    foreach (XmlElement pointSymbolizer in pointSymbolizers)
                    {
                        SetPointStyle(style, pointSymbolizer, nsm);
                    }
                }
            }
        }
        private VectorStyle CalculateVectorStyle(SharpMap.Styles.VectorStyle min, SharpMap.Styles.VectorStyle max, double value)
        {
            VectorStyle style = new VectorStyle();
            double      dFrac = Fraction(value);
            float       fFrac = Convert.ToSingle(dFrac);

            style.Enabled       = (dFrac > 0.5 ? min.Enabled : max.Enabled);
            style.EnableOutline = (dFrac > 0.5 ? min.EnableOutline : max.EnableOutline);
            if (_FillColorBlend != null)
            {
                style.Fill = new System.Drawing.SolidBrush(_FillColorBlend.GetColor(fFrac));
            }
            else if (min.Fill != null && max.Fill != null)
            {
                style.Fill = InterpolateBrush(min.Fill, max.Fill, value);
            }

            if (min.Line != null && max.Line != null)
            {
                style.Line = InterpolatePen(min.Line, max.Line, value);
            }
            if (_LineColorBlend != null)
            {
                style.Line.Color = _LineColorBlend.GetColor(fFrac);
            }

            if (min.Outline != null && max.Outline != null)
            {
                style.Outline = InterpolatePen(min.Outline, max.Outline, value);
            }
            style.MinVisible   = InterpolateDouble(min.MinVisible, max.MinVisible, value);
            style.MaxVisible   = InterpolateDouble(min.MaxVisible, max.MaxVisible, value);
            style.Symbol       = (dFrac > 0.5 ? min.Symbol : max.Symbol);
            style.SymbolOffset = (dFrac > 0.5 ? min.SymbolOffset : max.SymbolOffset);             //We don't interpolate the offset but let it follow the symbol instead
            style.SymbolScale  = InterpolateFloat(min.SymbolScale, max.SymbolScale, value);
            return(style);
        }
Exemple #47
0
        private void RenderGeometry(System.Drawing.Graphics g, Map map, Geometry feature, SharpMap.Styles.VectorStyle style)
        {
            switch (feature.GetType().FullName)
            {
            case "SharpMap.Geometries.Polygon":
                if (style.EnableOutline)
                {
                    SharpMap.Rendering.VectorRenderer.DrawPolygon(g, (Polygon)feature, style.Fill, style.Outline, _ClippingEnabled, map);
                }
                else
                {
                    SharpMap.Rendering.VectorRenderer.DrawPolygon(g, (Polygon)feature, style.Fill, null, _ClippingEnabled, map);
                }
                break;

            case "SharpMap.Geometries.MultiPolygon":
                if (style.EnableOutline)
                {
                    SharpMap.Rendering.VectorRenderer.DrawMultiPolygon(g, (MultiPolygon)feature, style.Fill, style.Outline, _ClippingEnabled, map);
                }
                else
                {
                    SharpMap.Rendering.VectorRenderer.DrawMultiPolygon(g, (MultiPolygon)feature, style.Fill, null, _ClippingEnabled, map);
                }
                break;

            case "SharpMap.Geometries.LineString":
                SharpMap.Rendering.VectorRenderer.DrawLineString(g, (LineString)feature, style.Line, map);
                break;

            case "SharpMap.Geometries.MultiLineString":
                SharpMap.Rendering.VectorRenderer.DrawMultiLineString(g, (MultiLineString)feature, style.Line, map);
                break;

            case "SharpMap.Geometries.Point":
                SharpMap.Rendering.VectorRenderer.DrawPoint(g, (Point)feature, style.Symbol, style.SymbolScale, style.SymbolOffset, style.SymbolRotation, map);
                break;

            case "SharpMap.Geometries.MultiPoint":
                SharpMap.Rendering.VectorRenderer.DrawMultiPoint(g, (MultiPoint)feature, style.Symbol, style.SymbolScale, style.SymbolOffset, style.SymbolRotation, map);
                break;

            case "SharpMap.Geometries.GeometryCollection":
                foreach (Geometries.Geometry geom in (GeometryCollection)feature)
                {
                    RenderGeometry(g, map, geom, style);
                }
                break;

            default:
                break;
            }
        }
Exemple #48
0
        /// <summary>
        /// Method to parse the vector styles from a <see cref="XmlDocument"/>
        /// </summary>
        /// <param name="doc">The xml document</param>
        /// <returns>A dictionary of vector styles</returns>
        public static IDictionary <string, VectorStyle> ParseFeatureStyle(XmlDocument doc)
        {
            var styles = new Dictionary <string, VectorStyle>();

            // Load SLD file
            var nt  = new NameTable();
            var nsm = new XmlNamespaceManager(nt);

            nsm.AddNamespace("sld", "http://www.opengis.net/sld");
            nsm.AddNamespace("ogc", "http://www.opengis.net/ogc");
            nsm.AddNamespace("xlink", "http://www.w3.org/1999/xlink");


            var sldConfig = new XmlDocument(nt);

            sldConfig.LoadXml(doc.OuterXml);

            var featureTypeStyleEls = sldConfig.SelectNodes("//sld:FeatureTypeStyle", nsm);

            if (featureTypeStyleEls == null)
            {
                return(null);
            }

            foreach (XmlElement featTypeStyle in featureTypeStyleEls)
            {
                var el       = (XmlElement)featTypeStyle.SelectSingleNode("sld:FeatureTypeName", nsm);
                var mainName = el != null ? el.InnerText : "";
                var rules    = featTypeStyle.SelectNodes("sld:Rule", nsm);

                if (rules != null)
                {
                    foreach (XmlElement rule in rules)
                    {
                        el = (XmlElement)rule.SelectSingleNode("sld:Name", nsm);
                        var name  = el != null ? el.InnerText : "";
                        var style = new VectorStyle();
                        SetSymbologyForRule(style, rule, nsm);
                        styles.Add(mainName + ":" + name, style);
                    }
                }
            }

            return(styles);


            //style.AreFeaturesSelectable
            //style.Enabled
            //style.EnableOutline
            //style.Fill
            //style.HighlightFill
            //style.HighlightLine
            //style.HighlightOutline
            //style.HighlightSymbol
            //style.Line
            //style.MaxVisible
            //style.MinVisible
            //style.Outline
            //style.RenderingMode
            //style.SelectFill
            //style.SelectLine
            //style.SelectOutline
            //style.SelectSymbol
        }
Exemple #49
0
        private static void SetStyle(
            VectorStyle style,
            string stroke,
            string strokeWidth,
            string strokeOpacity,
            string strokeLinejoin,
            string strokeLineCap,
            string strokeDasharray,
            string strokeDashOffset,
            string fill,
            string fillOpacity,
            string pointSymbolPath
            )
        {
            if (!String.IsNullOrEmpty(stroke))
            {
                var color   = ColorTranslator.FromHtml(stroke);
                var opacity = 255;
                var width   = 1f;

                if (!String.IsNullOrEmpty(strokeOpacity))
                {
                    opacity = Convert.ToInt32(Math.Round(Convert.ToDouble(strokeOpacity) / 0.0039215, 0));
                    if (opacity > 255)
                    {
                        opacity = 255;
                    }
                }

                if (!String.IsNullOrEmpty(strokeWidth))
                {
                    width = Convert.ToSingle(strokeWidth);
                }

                Brush brush = new SolidBrush(Color.FromArgb(opacity, Convert.ToInt32(color.R), Convert.ToInt32(color.G),
                                                            Convert.ToInt32(color.B)));
                var pen = new Pen(brush, width);

                if (!String.IsNullOrEmpty(strokeLinejoin))
                {
                    switch (strokeLinejoin.ToLower())
                    {
                    case "mitre":
                        pen.LineJoin = LineJoin.Miter;
                        break;

                    case "round":
                        pen.LineJoin = LineJoin.Round;
                        break;

                    case "bevel":
                        pen.LineJoin = LineJoin.Bevel;
                        break;

                        //case "miterclipped": // Not in SLD
                        //    pen.LineJoin = StyleLineJoin.MiterClipped;
                        //    break;
                    }
                }

                if (!String.IsNullOrEmpty(strokeLineCap))
                {
                    switch (strokeLineCap.ToLower())
                    {
                    case "butt":
                        pen.StartCap = LineCap.Flat;
                        pen.EndCap   = LineCap.Flat;
                        break;

                    case "round":
                        pen.StartCap = LineCap.Round;
                        pen.EndCap   = LineCap.Round;
                        break;

                    case "square":
                        pen.StartCap = LineCap.Square;
                        pen.EndCap   = LineCap.Square;
                        break;

                        // N.B. Loads of others not used in SLD
                    }
                }

                if (!String.IsNullOrEmpty(strokeDasharray))
                {
                    var numbers = strokeDasharray.Split(Char.Parse(" "));
                    Func <string[], float[]> processor = strings =>
                    {
                        var res = new float[strings.Length];
                        for (var i = 0; i < strings.Length; i++)
                        {
                            res[i] = float.Parse(strings[i]);
                        }
                        return(res.ToArray());
                    };
                    pen.DashPattern = processor(numbers);
                }

                if (!String.IsNullOrEmpty(strokeDashOffset))
                {
                    float dashOffset;
                    var   success = float.TryParse(strokeDashOffset, out dashOffset);
                    if (success)
                    {
                        pen.DashOffset = dashOffset;
                    }
                }

                // Set pen
                style.Line = pen;
            }

            if (!String.IsNullOrEmpty(fill))
            {
                Color color   = ColorTranslator.FromHtml(fill);
                int   opacity = 255;

                if (!String.IsNullOrEmpty(fillOpacity))
                {
                    opacity = Convert.ToInt32(Math.Round(Convert.ToDouble(fillOpacity) / 0.0039215, 0));
                    if (opacity > 255)
                    {
                        opacity = 255;
                    }
                }

                Brush brush =
                    new SolidBrush(Color.FromArgb(opacity, Convert.ToInt32(color.R), Convert.ToInt32(color.G),
                                                  Convert.ToInt32(color.B)));

                style.Fill = brush;
            }


            if (!String.IsNullOrEmpty(pointSymbolPath))
            {
                var source = new Uri(pointSymbolPath);

                if (source.IsFile && File.Exists(source.AbsolutePath))
                {
                    style.Symbol = new Bitmap(source.AbsolutePath);
                }
                else if (source.IsAbsoluteUri)
                {
                }
            }

            style.Enabled       = true;
            style.EnableOutline = true;
        }
Exemple #50
0
        private static void SetStrokeStyle(VectorStyle style, XmlNode strokeSymbolizer, XmlNamespaceManager nsm)
        {
            string stroke           = string.Empty;
            string strokeWidth      = string.Empty;
            string strokeOpacity    = string.Empty;
            string strokeLinejoin   = string.Empty;
            string strokeLineCap    = string.Empty;
            string strokeDasharray  = string.Empty;
            string strokeDashOffset = string.Empty;
            string fill             = string.Empty;
            string fillOpacity      = string.Empty;
            string pointSymbolPath  = string.Empty;

            var polygonStrokeSymbols = strokeSymbolizer.SelectNodes("sld:Stroke/sld:CssParameter", nsm);

            if (polygonStrokeSymbols == null)
            {
                return;
            }

            foreach (XmlElement polygonStrokeSymbol in polygonStrokeSymbols)
            {
                if (polygonStrokeSymbol != null)
                {
                    switch (polygonStrokeSymbol.GetAttribute("name"))
                    {
                    // line
                    case "stroke":
                        stroke = polygonStrokeSymbol.InnerXml;
                        break;

                    case "stroke-width":
                        strokeWidth = polygonStrokeSymbol.InnerXml;
                        break;

                    case "stroke-opacity":
                        strokeOpacity = polygonStrokeSymbol.InnerXml;
                        break;

                    case "stroke-linejoin":     //“mitre”, “round”, and “bevel”
                        strokeLinejoin = polygonStrokeSymbol.InnerXml;
                        break;

                    case "stroke-linecap":     //“butt”, “round”, and “square”.
                        strokeLineCap = polygonStrokeSymbol.InnerXml;
                        break;

                    case "stroke-dasharray":
                        strokeDasharray = polygonStrokeSymbol.InnerXml;
                        break;

                    case "stroke-dashoffset":
                        strokeDashOffset = polygonStrokeSymbol.InnerXml;
                        break;
                    }
                }
            }

            SetStyle(style, stroke, strokeWidth, strokeOpacity, strokeLinejoin, strokeLineCap, strokeDasharray,
                     strokeDashOffset, fill, fillOpacity, pointSymbolPath);
        }
Exemple #51
0
 /// <summary>
 /// Method to add a <see cref="VectorStyle"/>
 /// </summary>
 /// <param name="style"></param>
 public void AddStyle(VectorStyle style)
 {
     _styles.Add(style);
 }
Exemple #52
0
        public override void Render(System.Drawing.Graphics g, Map map)
        {
            if (map.Center == null)
            {
                throw (new ApplicationException("Cannot render map. View center not specified"));
            }

            g.SmoothingMode = this.SmoothingMode;
            SharpMap.Geometries.BoundingBox envelope = map.Envelope; //View to render
            if (this.CoordinateTransformation != null)
            {
                envelope = SharpMap.CoordinateSystems.Transformations.GeometryTransform.TransformBox(envelope, this.CoordinateTransformation.MathTransform.Inverse());
            }

            //List<SharpMap.Geometries.Geometry> features = this.DataSource.GetGeometriesInView(map.Envelope);

            if (this.DataSource == null)
            {
                throw (new ApplicationException("DataSource property not set on layer '" + this.LayerName + "'"));
            }

            //If thematics is enabled, we use a slighty different rendering approach
            if (this.Theme != null)
            {
                SharpMap.Data.FeatureDataSet ds = new SharpMap.Data.FeatureDataSet();
                this.DataSource.Open();
                this.DataSource.ExecuteIntersectionQuery(envelope, ds);
                this.DataSource.Close();

                SharpMap.Data.FeatureDataTable features = (SharpMap.Data.FeatureDataTable)ds.Tables[0];

                if (this.CoordinateTransformation != null)
                {
                    for (int i = 0; i < features.Count; i++)
                    {
                        features[i].Geometry = SharpMap.CoordinateSystems.Transformations.GeometryTransform.TransformGeometry(features[i].Geometry, this.CoordinateTransformation.MathTransform);
                    }
                }

                //Linestring outlines is drawn by drawing the layer once with a thicker line
                //before drawing the "inline" on top.
                if (Style.EnableOutline)
                {
                    //foreach (SharpMap.Geometries.Geometry feature in features)
                    for (int i = 0; i < features.Count; i++)
                    {
                        SharpMap.Data.FeatureDataRow feature = features[i];
                        //Draw background of all line-outlines first
                        if (feature.Geometry is SharpMap.Geometries.LineString)
                        {
                            SharpMap.Styles.VectorStyle outlinestyle1 = this.Theme.GetStyle(feature) as SharpMap.Styles.VectorStyle;
                            if (outlinestyle1.Enabled && outlinestyle1.EnableOutline)
                            {
                                SharpMap.Rendering.VectorRenderer.DrawLineString(g, feature.Geometry as LineString, outlinestyle1.Outline, map);
                            }
                        }
                        else if (feature.Geometry is SharpMap.Geometries.MultiLineString)
                        {
                            SharpMap.Styles.VectorStyle outlinestyle2 = this.Theme.GetStyle(feature) as SharpMap.Styles.VectorStyle;
                            if (outlinestyle2.Enabled && outlinestyle2.EnableOutline)
                            {
                                SharpMap.Rendering.VectorRenderer.DrawMultiLineString(g, feature.Geometry as MultiLineString, outlinestyle2.Outline, map);
                            }
                        }
                    }
                }

                for (int i = 0; i < features.Count; i++)
                {
                    SharpMap.Data.FeatureDataRow feature = features[i];
                    SharpMap.Styles.VectorStyle  style   = this.Theme.GetStyle(feature) as SharpMap.Styles.VectorStyle;
                    RenderGeometry(g, map, feature.Geometry, style);
                }
            }
            else
            {
                this.DataSource.Open();

                Collection <SharpMap.Geometries.Geometry> geoms = this.DataSource.GetGeometriesInView(envelope);
                this.DataSource.Close();

                if (this.CoordinateTransformation != null)
                {
                    for (int i = 0; i < geoms.Count; i++)
                    {
                        geoms[i] = SharpMap.CoordinateSystems.Transformations.GeometryTransform.TransformGeometry(geoms[i], this.CoordinateTransformation.MathTransform);
                    }
                }

                //Linestring outlines is drawn by drawing the layer once with a thicker line
                //before drawing the "inline" on top.
                if (this.Style.EnableOutline)
                {
                    foreach (SharpMap.Geometries.Geometry geom in geoms)
                    {
                        if (geom != null)
                        {
                            //Draw background of all line-outlines first
                            switch (geom.GetType().FullName)
                            {
                            case "SharpMap.Geometries.LineString":
                                SharpMap.Rendering.VectorRenderer.DrawLineString(g, geom as LineString, this.Style.Outline, map);
                                break;

                            case "SharpMap.Geometries.MultiLineString":
                                SharpMap.Rendering.VectorRenderer.DrawMultiLineString(g, geom as MultiLineString, this.Style.Outline, map);
                                break;

                            default:
                                break;
                            }
                        }
                    }
                }

                for (int i = 0; i < geoms.Count; i++)
                {
                    if (geoms[i] != null)
                    {
                        RenderGeometry(g, map, geoms[i], this.Style);
                    }
                }
            }


            base.Render(g, map);
        }
Exemple #53
0
 /// <summary>
 /// Utility function to modify <paramref name="style"/> in order to prevent drawing of any puntal components
 /// </summary>
 /// <param name="style">The style to modify</param>
 private static void ClearLinealStyle(VectorStyle style)
 {
     style.EnableOutline = false;
     style.Line          = Pens.Transparent;
     style.Outline       = Pens.Transparent;
 }