Esempio n. 1
0
 /// <summary>
 /// Initializes a new VectorStyle with default values.
 /// </summary>
 /// <remarks>
 /// Default style values when initialized:<br/>
 /// <list type="table">
 /// <item>
 /// <term>AreFeaturesSelectable</term>
 /// <description>True</description>
 /// </item>
 /// <item>
 /// <term>LineStyle</term>
 /// <description>1px solid black</description>
 /// </item>
 /// <item>
 /// <term>FillStyle</term>
 /// <description>Solid black</description>
 /// </item>
 /// <item>
 /// <term>Outline</term>
 /// <description>No Outline</description>
 /// </item>
 /// <item>
 /// <term>Symbol</term>
 /// <description>Null reference (uses the geometry renderer default)</description>
 /// </item>
 /// </list>
 /// </remarks>
 public GeometryStyle()
 {
     Outline       = new StylePen(StyleColor.Black, 1);
     Line          = new StylePen(StyleColor.Black, 1);
     Fill          = new SolidStyleBrush(StyleColor.Black);
     EnableOutline = false;
 }
Esempio n. 2
0
		/// <summary>
		/// Initializes a new VectorStyle with default values.
		/// </summary>
		/// <remarks>
		/// Default style values when initialized:<br/>
		/// <list type="table">
		/// <item>
		/// <term>AreFeaturesSelectable</term>
		/// <description>True</description>
		/// </item>
		/// <item>
		/// <term>LineStyle</term>
		/// <description>1px solid black</description>
		/// </item>
		/// <item>
		/// <term>FillStyle</term>
		/// <description>Solid black</description>
		/// </item>
		/// <item>
		/// <term>Outline</term>
		/// <description>No Outline</description>
		/// </item>
		/// <item>
		/// <term>Symbol</term>
		/// <description>Null reference (uses the geometry renderer default)</description>
		/// </item>
		/// </list>
		/// </remarks>
		public VectorStyle()
		{
			Outline = new StylePen(StyleColor.Black, 1);
			Line = new StylePen(StyleColor.Black, 1);
			Fill = new SolidStyleBrush(StyleColor.Black);
			EnableOutline = false;
		}
        public void RenderPathOutlineTest()
        {
            GdiVectorRenderer renderer = new GdiVectorRenderer();

            Point2D[] points = new Point2D[]
                {new Point2D(1, 0), new Point2D(0, 1), new Point2D(-1, 0), new Point2D(0, -1)};

            Path2D path = new Path2D(points, true);

            StylePen outline = new StylePen(new SolidStyleBrush(StyleColor.Blue), 1);
            StylePen highlight = new StylePen(new SolidStyleBrush(StyleColor.Red), 1);
            StylePen selected = new StylePen(new SolidStyleBrush(StyleColor.Green), 1);

            IEnumerable<GdiRenderObject> renderObjects = renderer.RenderPaths(
                new Path2D[] {path}, outline, highlight, selected, RenderState.Normal);

            IEnumerator<GdiRenderObject> enumertor = renderObjects.GetEnumerator();
            enumertor.MoveNext();
            GdiRenderObject ro = enumertor.Current;

            Assert.AreEqual(RenderState.Normal, ro.State);
            Assert.IsInstanceOfType(typeof (SolidBrush), ro.Fill);
            Assert.IsNotNull(ro.GdiPath);
            Assert.AreEqual(4, ro.GdiPath.PointCount);
            Assert.AreEqual(new RectangleF(-1, -1, 2, 2), ro.GdiPath.GetBounds());

            PathData data = ro.GdiPath.PathData;

            for (Int32 i = 0; i < 4; i++)
            {
                Assert.AreEqual(points[i].X, data.Points[i].X, _e);
                Assert.AreEqual(points[i].Y, data.Points[i].Y, _e);
            }

            Assert.AreEqual(0, data.Types[0]);
            Assert.AreEqual(1, data.Types[1]);
            Assert.AreEqual(1, data.Types[2]);
            Assert.AreEqual(129, data.Types[3]);

            Pen expectedOutline = new Pen(Brushes.Blue, 1.0f);
            Pen expectedHighlight = new Pen(Brushes.Red, 1.0f);
            Pen expectedSelected = new Pen(Brushes.Green, 1.0f);

            Assert.IsTrue(pensAreEqual(expectedOutline, ro.Outline));
            Assert.IsTrue(pensAreEqual(expectedHighlight, ro.HighlightOutline));
            Assert.IsTrue(pensAreEqual(expectedSelected, ro.SelectOutline));

            expectedOutline.Dispose();
            expectedHighlight.Dispose();
            expectedSelected.Dispose();
            renderer.Dispose();
        }
Esempio n. 4
0
        private void SetStyle(
            GeometryStyle 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))
            {
                Color color = ColorTranslator.FromHtml(stroke);
                int opacity = 255;
                double width = 1;

                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.ToDouble(strokeWidth);
                }

                StyleBrush brush =
                    new SolidStyleBrush(new StyleColor(Convert.ToInt32(color.B), Convert.ToInt32(color.G),
                                                       Convert.ToInt32(color.R), opacity));
                StylePen pen = new StylePen(brush, width);

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

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

                if (!String.IsNullOrEmpty(strokeLineCap))
                {
                    switch (strokeLineCap.ToLower())
                    {
                        case "butt":
                            pen.StartCap = StyleLineCap.Flat;
                            pen.EndCap = StyleLineCap.Flat;
                            break;
                        case "round":
                            pen.StartCap = StyleLineCap.Round;
                            pen.EndCap = StyleLineCap.Round;
                            break;
                        case "square":
                            pen.StartCap = StyleLineCap.Square;
                            pen.EndCap = StyleLineCap.Square;
                            break;

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

                if (!String.IsNullOrEmpty(strokeDasharray))
                {
                    string[] Numbers = strokeDasharray.Split(Char.Parse(" "));

                    IEnumerable<float> dbls = Processor.Select(Numbers, delegate(string o) { return float.Parse(o); });
                    pen.DashPattern = Enumerable.ToArray(dbls);
                }

                if (!String.IsNullOrEmpty(strokeDashOffset))
                {
                    float dashOffset;
                    bool success;
                    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;
                }

                StyleBrush brush =
                    new SolidStyleBrush(new StyleColor(Convert.ToInt32(color.B), Convert.ToInt32(color.G),
                                                       Convert.ToInt32(color.R), opacity));

                style.Fill = brush;
            }


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

                if (source.IsFile && File.Exists(source.AbsolutePath))
                {
                    Bitmap b = new Bitmap(source.AbsolutePath);

                    MemoryStream ms = new MemoryStream();
                    b.Save(ms, ImageFormat.Png);
                    ms.Seek(0, SeekOrigin.Begin);

                    style.Symbol = new Symbol2D(ms, new Size2D(12, 10));
                }
                else if (source.IsAbsoluteUri)
                {
                    ///TODO
                }
            }

            style.Enabled = true;
            style.EnableOutline = true;
        }
Esempio n. 5
0
 public static StylePen RandomPen()
 {
     StylePen p = new StylePen(RandomColor(), random.Next(1, 5))
                      {
                          Alignment = StylePenAlignment.Center,
                          LineJoin = StyleLineJoin.MiterClipped,
                          MiterLimit = 2,
                          StartCap = StyleLineCap.NoAnchor,
                          EndCap = StyleLineCap.NoAnchor
                      };
     return p;
 }
Esempio n. 6
0
        private StylePen interpolatePen(StylePen min, StylePen max, Double attr)
        {
            Double frac = fraction(attr);

            StyleColor color = StyleColor.Interpolate(min.BackgroundBrush.Color, max.BackgroundBrush.Color, frac);
            StylePen pen = new StylePen(color, interpolateDouble(min.Width, max.Width, attr));

            pen.MiterLimit = interpolateFloat(min.MiterLimit, max.MiterLimit, attr);
            pen.StartCap = (frac > 0.5 ? max.StartCap : min.StartCap);
            pen.EndCap = (frac > 0.5 ? max.EndCap : min.EndCap);
            pen.LineJoin = (frac > 0.5 ? max.LineJoin : min.LineJoin);
            pen.DashStyle = (frac > 0.5 ? max.DashStyle : min.DashStyle);

            if (min.DashStyle == LineDashStyle.Custom && max.DashStyle == LineDashStyle.Custom)
            {
                pen.DashPattern = (frac > 0.5 ? max.DashPattern : min.DashPattern);
            }

            pen.DashOffset = (frac > 0.5 ? max.DashOffset : min.DashOffset);
            pen.DashCap = (frac > 0.5 ? max.DashCap : min.DashCap);

            if (min.CompoundArray.Length > 0 && max.CompoundArray.Length > 0)
            {
                pen.CompoundArray = (frac > 0.5 ? max.CompoundArray : min.CompoundArray);
            }

            pen.Alignment = (frac > 0.5 ? max.Alignment : min.Alignment);
            //pen.CustomStartCap = (frac > 0.5 ? max.CustomStartCap : min.CustomStartCap);  //Throws ArgumentException
            //pen.CustomEndCap = (frac > 0.5 ? max.CustomEndCap : min.CustomEndCap);  //Throws ArgumentException
            return pen;
        }
        /// <summary>
        /// Creates a new GdiRenderObject instance.
        /// </summary>
        /// <param name="text">The text to draw.</param>
        /// <param name="font">The font to use to render the text.</param>
        /// <param name="bounds">The location and size to draw the text.</param>
        /// <param name="fill">
        /// The brush used to fill the path when the state is <see cref="RenderState.Normal"/>.
        /// </param>
        /// <param name="highlightFill">
        /// The brush used to fill the path when the state is <see cref="RenderState.Highlighted"/>.
        /// </param>
        /// <param name="selectFill">
        /// The brush used to fill the path when the state is <see cref="RenderState.Selected"/>.
        /// </param>
        /// <param name="outline">
        /// The pen used to outline the path when the state is <see cref="RenderState.Normal"/>.
        /// </param>
        /// <param name="highlightOutline">
        /// The pen used to outline the path when the state is <see cref="RenderState.Highlighted"/>.
        /// </param>
        /// <param name="selectOutline">
        /// The pen used to outline the path when the state is <see cref="RenderState.Selected"/>.
        /// </param>
        public CairoRenderObject(String text, FontFace font, Rectangle bounds,
                                 StyleBrush fill, StyleBrush highlightFill, StyleBrush selectFill,
                                 StylePen outline, StylePen highlightOutline, StylePen selectOutline)
        {
            _state = RenderState.Normal;
            Path = null;

            Image = null;
            Bounds = new Rectangle();
            AffineTransform = null;
            ColorTransform = null;

            Text = text;
            Font = font;
            Bounds = bounds;
            Fill = fill;
            HighlightFill = highlightFill;
            SelectFill = selectFill;
            Outline = outline;
            HighlightOutline = highlightOutline;
            SelectOutline = selectOutline;
            Line = null;
            HighlightLine = null;
            SelectLine = null;
        }
        /// <summary>
        /// Creates a new GdiRenderObject instance.
        /// </summary>
        /// <param name="image">The symbol to draw.</param>
        /// <param name="imageBounds">The location and size to draw the symbol.</param>
        /// <param name="transform">The affine transform applied to the symbol before drawing.</param>
        /// <param name="colorTransform">The color transform applied to the symbol before drawing.</param>
        public CairoRenderObject(Surface image, Rectangle imageBounds, CairoMatrix transform, CairoMatrix colorTransform)
        {
            _state = RenderState.Normal;
            Image = image;
            Bounds = imageBounds;
            AffineTransform = transform;
            ColorTransform = colorTransform;

            Path = null;
            Fill = null;
            HighlightFill = null;
            SelectFill = null;
            Line = null;
            HighlightLine = null;
            SelectLine = null;
            Outline = null;
            HighlightOutline = null;
            SelectOutline = null;

            Text = null;
            Font = null;
        }
        /// <summary>
        /// Creates a new CairoRenderObject instance.
        /// </summary>
        /// <param name="path">The path to draw.</param>
        /// <param name="fill">
        /// The brush used to fill the path when the state is <see cref="RenderState.Normal"/>.
        /// </param>
        /// <param name="highlightFill">
        /// The brush used to fill the path when the state is <see cref="RenderState.Highlighted"/>.
        /// </param>
        /// <param name="selectFill">
        /// The brush used to fill the path when the state is <see cref="RenderState.Selected"/>.
        /// </param>
        /// <param name="line">
        /// The pen used to draw a line when the state is <see cref="RenderState.Normal"/>.
        /// </param>
        /// <param name="highlightLine">
        /// The pen used to draw a line when the state is <see cref="RenderState.Highlighted"/>.
        /// </param>
        /// <param name="selectLine">
        /// The pen used to draw a line when the state is <see cref="RenderState.Selected"/>.
        /// </param>
        /// <param name="outline">
        /// The pen used to outline the path when the state is <see cref="RenderState.Normal"/>.
        /// </param>
        /// <param name="highlightOutline">
        /// The pen used to outline the path when the state is <see cref="RenderState.Highlighted"/>.
        /// </param>
        /// <param name="selectOutline">
        /// The pen used to outline the path when the state is <see cref="RenderState.Selected"/>.
        /// </param>
        public CairoRenderObject(Path2D path, StyleBrush fill, StyleBrush highlightFill, StyleBrush selectFill,
                                 StylePen line, StylePen highlightLine, StylePen selectLine,
                                 StylePen outline, StylePen highlightOutline, StylePen selectOutline)
        {
            _state = RenderState.Normal;
            Path = path;
            Fill = fill;
            HighlightFill = highlightFill;
            SelectFill = selectFill;
            Line = line;
            HighlightLine = highlightLine;
            SelectLine = selectLine;
            Outline = outline;
            HighlightOutline = highlightOutline;
            SelectOutline = selectOutline;

            Image = null;
            Bounds = new Rectangle();
            AffineTransform = new CairoMatrix();
            ColorTransform = null;

            Text = null;
            Font = null;
        }
        private static void setupMsSqlSpatial(Map m)
        {
            string[] layernames = new[]
                                      {"Rivers",
                                          "Countries"
                                          /*,
                                          "Cities"*/
                                      };

            string sridstr = SridMap.DefaultInstance.Process(4326, "");

            foreach (string lyrname in layernames)
            {
                string tbl = lyrname;


                AppStateMonitoringFeatureProvider provider = new AppStateMonitoringFeatureProvider(
                    new MsSqlSpatialProvider(
                        new GeometryServices()[sridstr],
                        ConfigurationManager.ConnectionStrings["db"].ConnectionString,
                        "st",
                        "dbo",
                        tbl,
                        "oid",
                        "Geometry")
                        {
                            DefaultProviderProperties
                                = new ProviderPropertiesExpression(
                                new ProviderPropertyExpression[]
                                    {
                                        new WithNoLockExpression(true)
                                    })
                        });


                GeoJsonGeometryStyle style = new GeoJsonGeometryStyle();

                switch (tbl)
                {
                    case "Rivers":
                        {
                            StyleBrush brush = new SolidStyleBrush(StyleColor.Blue);
                            StylePen pen = new StylePen(brush, 1);
                            style.Enabled = true;
                            style.EnableOutline = true;
                            style.Line = pen;
                            style.Fill = brush;
                            break;
                        }

                    case "Countries":
                        {
                            StyleBrush brush = new SolidStyleBrush(new StyleColor(0, 0, 0, 255));
                            StylePen pen = new StylePen(brush, 2);
                            style.Enabled = true;
                            style.EnableOutline = true;
                            style.Line = pen;
                            style.Fill = new SolidStyleBrush(StyleColor.Green);

                            break;
                        }

                    default:
                        {
                            style = RandomStyle.RandomGeometryStyle();
                            style.MaxVisible = 100000;
                            break;
                        }
                }


                /* include GeoJson styles */
                style.IncludeAttributes = false;
                style.IncludeBBox = true;
                style.PreProcessGeometries = false;
                style.CoordinateNumberFormatString = "{0:F}";
                GeometryLayer layer = new GeometryLayer(tbl, style, provider);
                layer.Features.IsSpatiallyIndexed = false;
                layer.AddProperty(AppStateMonitoringFeatureLayerProperties.AppStateMonitor, provider.Monitor);
                m.AddLayer(layer);
            }
        }
Esempio n. 11
0
 public static StylePen Convert(StylePen outline)
 {
     return outline;
 }