Exemplo 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 VectorStyle()
		{
			Outline = new StylePen(StyleColor.Black, 1);
			Line = new StylePen(StyleColor.Black, 1);
			Fill = new SolidStyleBrush(StyleColor.Black);
			EnableOutline = false;
		}
Exemplo 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 GeometryStyle()
 {
     Outline       = new StylePen(StyleColor.Black, 1);
     Line          = new StylePen(StyleColor.Black, 1);
     Fill          = new SolidStyleBrush(StyleColor.Black);
     EnableOutline = false;
 }
Exemplo n.º 3
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;
        }
        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);
            }
        }