Exemple #1
0
 public ImageMapStyle(double minVis, double maxVis, bool enabled)
     : base(minVis, maxVis, enabled)
 {
     this._polyStyle = new PolygonStyle(minVis, maxVis, enabled);
     this._ps        = new PointStyle(5, minVis, maxVis, enabled);
     this._ls        = new LineStyle(5, minVis, maxVis, enabled);
 }
Exemple #2
0
        public void FromFeatureBasedMapData_WithMapPolygonData_ReturnsNewRemovableDataWithSameProperties()
        {
            // Setup
            const string name         = "test";
            var          mapFeatures  = new MapFeature[0];
            var          polygonStyle = new PolygonStyle
            {
                FillColor       = Color.AliceBlue,
                StrokeColor     = Color.DeepSkyBlue,
                StrokeThickness = 3
            };

            var mapData = new MapPolygonData(name, polygonStyle)
            {
                Features = mapFeatures
            };

            // Call
            var convertedData = RemovableMapDataConverter.FromFeatureBasedMapData(mapData) as RemovableMapPolygonData;

            // Assert
            Assert.NotNull(convertedData);
            Assert.AreEqual(name, convertedData.Name);
            Assert.AreEqual(polygonStyle, convertedData.Style);
            Assert.AreSame(mapFeatures, convertedData.Features);
        }
Exemple #3
0
        /// <summary/>
        protected void processPolygonStyle(XmlNode layerNode, PolygonStyle PolygonStyle)
        {
            XmlNode polygonStyle = tryGetNodeByName(layerNode.ChildNodes, "polygon_style");

            if (polygonStyle != null)
            {
                PolygonStyle.BorderWidth     = float.Parse(polygonStyle.Attributes["border_width"].Value, CultureInfo.InvariantCulture);
                PolygonStyle.BorderColor     = ColorTranslator.FromHtml(polygonStyle.Attributes["border_color"].Value);
                PolygonStyle.BorderDashStyle = (DashStyle)int.Parse(polygonStyle.Attributes["border_dash_style"].Value, CultureInfo.InvariantCulture);
                PolygonStyle.HatchStyle      = (HatchStyle)int.Parse(polygonStyle.Attributes["hatch_style"].Value, CultureInfo.InvariantCulture);
                if (polygonStyle.Attributes["border_dash_cap"] != null)
                {
                    PolygonStyle.BorderDashCap = (DashCap)int.Parse(polygonStyle.Attributes["border_dash_cap"].Value, CultureInfo.InvariantCulture);
                }
                PolygonStyle.UseHatch = polygonStyle.Attributes["use_hatch"].Value == "1";
                if (polygonStyle.Attributes["border_visible"] != null)
                {
                    PolygonStyle.BorderVisible = polygonStyle.Attributes["border_visible"].Value == "1";
                }
                PolygonStyle.FillForeColor = ColorTranslator.FromHtml(polygonStyle.Attributes["fill_fore_color"].Value);
                PolygonStyle.FillBackColor = ColorTranslator.FromHtml(polygonStyle.Attributes["fill_back_color"].Value);

                if (polygonStyle.Attributes["fill_transparent"] != null)
                {
                    PolygonStyle.FillBackColor = Color.FromArgb(int.Parse(polygonStyle.Attributes["fill_transparent"].Value, CultureInfo.InvariantCulture), PolygonStyle.FillBackColor);
                }

                if (polygonStyle.Attributes["fill_pattern"] != null)
                {
                    PolygonStyle.FillPattern = (BuiltInFillPatterns)int.Parse(polygonStyle.Attributes["fill_pattern"].Value, CultureInfo.InvariantCulture);
                }
            }
        }
Exemple #4
0
        public void Constructor_WithStyleAndMapTheme_ExpectedValues()
        {
            // Setup
            const string name  = "test data";
            var          style = new PolygonStyle
            {
                FillColor       = Color.Aqua,
                StrokeColor     = Color.DarkGoldenrod,
                StrokeThickness = 3
            };

            var mapTheme = new MapTheme <PolygonCategoryTheme>("attribute", new[]
            {
                new PolygonCategoryTheme(ValueCriterionTestFactory.CreateValueCriterion(),
                                         new PolygonStyle())
            });

            // Call
            var data = new MapPolygonData(name, style, mapTheme);

            // Assert
            Assert.AreEqual(name, data.Name);
            CollectionAssert.IsEmpty(data.Features);
            Assert.AreSame(style, data.Style);
            Assert.AreSame(mapTheme, data.Theme);
        }
        protected override IFeatureSymbolizer CreateSymbolizer(MapPolygonData mapData)
        {
            PolygonStyle polygonStyle = mapData.Style;

            return(new PolygonSymbolizer(polygonStyle.FillColor,
                                         GetStrokeColor(polygonStyle),
                                         polygonStyle.StrokeThickness));
        }
Exemple #6
0
        /// <summary>
        /// Creates a new instance of <see cref="PolygonCategoryTheme"/>.
        /// </summary>
        /// <param name="criterion">The criterion belonging to the category.</param>
        /// <param name="style">The <see cref="PolygonStyle"/> belonging to the category.</param>
        /// <exception cref="ArgumentNullException">Thrown when any parameter is <c>null</c>.</exception>
        public PolygonCategoryTheme(ValueCriterion criterion, PolygonStyle style) : base(criterion)
        {
            if (style == null)
            {
                throw new ArgumentNullException(nameof(style));
            }

            Style = style;
        }
Exemple #7
0
        /// <summary>
        /// Creates a new instance of <see cref="MapPolygonData"/>.
        /// </summary>
        /// <param name="name">The name of the <see cref="MapLineData"/>.</param>
        /// <param name="style">The default style of the data that is not categorized by the categories
        /// defined in <paramref name="mapTheme"/>.</param>
        /// <param name="mapTheme">The map theme belong to the data.</param>
        /// <exception cref="ArgumentException">Thrown when <paramref name="name"/> is
        /// <c>null</c> or only whitespace.</exception>
        /// <exception cref="ArgumentNullException">Thrown when <paramref name="style"/>
        /// is <c>null</c>.</exception>
        public MapPolygonData(string name, PolygonStyle style, MapTheme <PolygonCategoryTheme> mapTheme) : base(name, mapTheme)
        {
            if (style == null)
            {
                throw new ArgumentNullException(nameof(style));
            }

            Style = style;
        }
Exemple #8
0
        /// <summary>
        /// Creates a new instance of <see cref="MapPolygonData"/>.
        /// </summary>
        /// <param name="name">The name of the <see cref="MapPolygonData"/>.</param>
        /// <param name="style">The style of the data.</param>
        /// <exception cref="ArgumentException">Thrown when <paramref name="name"/> is
        /// <c>null</c> or only whitespace.</exception>
        /// <exception cref="ArgumentNullException">Thrown when <paramref name="style"/>
        /// is <c>null</c>.</exception>
        public MapPolygonData(string name, PolygonStyle style) : base(name)
        {
            if (style == null)
            {
                throw new ArgumentNullException(nameof(style));
            }

            Style = style;
        }
Exemple #9
0
        public void StrokeThickness_SetValidValue_ValueSet(int validValue)
        {
            // Setup
            var polygonStyle = new PolygonStyle();

            // Call
            polygonStyle.StrokeThickness = validValue;

            // Assert
            Assert.AreEqual(validValue, polygonStyle.StrokeThickness);
        }
        private static Color GetStrokeColor(PolygonStyle style)
        {
            Color strokeColor = style.StrokeColor;

            if (style.StrokeThickness == 0)
            {
                strokeColor = Color.Transparent;
            }

            return(strokeColor);
        }
        public void Constructor_WithStyle_ExpectedValues()
        {
            // Setup
            var style = new PolygonStyle();

            // Call
            var data = new RemovableMapPolygonData("test data", style);

            // Assert
            Assert.IsInstanceOf <MapPolygonData>(data);
            Assert.IsInstanceOf <IRemovable>(data);
        }
Exemple #12
0
        public void StrokeThickness_SetInvalidValue_ThrowsArgumentOutOfRangeException(int invalidValue)
        {
            // Setup
            var polygonStyle = new PolygonStyle();

            // Call
            TestDelegate test = () => polygonStyle.StrokeThickness = invalidValue;

            // Assert
            const string message = "De waarde voor lijndikte moet in het bereik [0, 48] liggen.";

            TestHelper.AssertThrowsArgumentExceptionAndTestMessage <ArgumentOutOfRangeException>(test, message);
        }
        public void Constructor_ExpectedValues()
        {
            // Setup
            ValueCriterion valueCriterion = ValueCriterionTestFactory.CreateValueCriterion();
            var            style          = new PolygonStyle();

            // Call
            var category = new PolygonCategoryTheme(valueCriterion, style);

            // Assert
            Assert.IsInstanceOf <CategoryTheme>(category);
            Assert.AreSame(valueCriterion, category.Criterion);
            Assert.AreSame(style, category.Style);
        }
Exemple #14
0
        public static void AddStylesForPolygon(Document document, string[] styleNames)
        {
            // adding a stylemap that can be referenced from the elements
            Color32[] polyColors   = { new Color32(80, 0, 0, 255), new Color32(255, 255, 255, 255) };
            Color32[] lineColors   = { new Color32(255, 0, 0, 255), new Color32(255, 255, 255, 255) };
            bool[]    polyFills    = { true, false };
            bool[]    polyOutlines = { true, true };
            // create two styles, both contain definitions for LineStyle and PolygonStyle

            for (int i = 0; i < styleNames.Length; i++)
            {
                StyleMapCollection smc = new StyleMapCollection();

                Style[] stylePolyAndLine = { new Style(), new Style() };

                PolygonStyle stPoly = new PolygonStyle();
                stPoly.Color     = polyColors[i];
                stPoly.ColorMode = ColorMode.Normal;
                stPoly.Fill      = polyFills[i];
                stPoly.Outline   = polyOutlines[i];

                LineStyle stLine = new LineStyle();
                stLine.Color     = lineColors[i];
                stLine.ColorMode = ColorMode.Normal;

                stylePolyAndLine[0].Id      = styleNames[i] + "_Normal";
                stylePolyAndLine[0].Polygon = stPoly;
                stylePolyAndLine[0].Line    = stLine;
                document.AddStyle(stylePolyAndLine[0]);

                stylePolyAndLine[1].Id      = styleNames[i] + "_High";
                stylePolyAndLine[1].Polygon = stPoly;
                stylePolyAndLine[1].Line    = stLine;
                document.AddStyle(stylePolyAndLine[1]);

                // create a StyleMap collection and add above Styles as a pair
                // with different Style States
                smc.Id = styleNames[i];
                Pair[] pr = { new Pair(), new Pair() };
                pr[0].State    = StyleState.Normal;
                pr[0].StyleUrl = new Uri("#" + styleNames[i] + "_Normal", UriKind.Relative);
                smc.Add(pr[0]);
                pr[1].State    = StyleState.Highlight;
                pr[1].StyleUrl = new Uri("#" + styleNames[i] + "_High", UriKind.Relative);
                smc.Add(pr[1]);
                // add the stylemap collection to the document (in the same way as a style)
                document.AddStyle(smc);
            }
        }
Exemple #15
0
        public void ConvertLayerProperties_MapPolygonDataWithThemeAndMetaDataNameNotInFeatures_OnlyAddsDefaultCategory()
        {
            // Setup
            const string metadataAttribute = "Meta";
            var          random            = new Random(21);
            var          theme             = new MapTheme <PolygonCategoryTheme>("Other Meta", new[]
            {
                new PolygonCategoryTheme(ValueCriterionTestFactory.CreateValueCriterion(),
                                         new PolygonStyle
                {
                    FillColor       = Color.FromKnownColor(random.NextEnum <KnownColor>()),
                    StrokeColor     = Color.FromKnownColor(random.NextEnum <KnownColor>()),
                    StrokeThickness = random.Next(1, 48)
                })
            });

            var polygonStyle = new PolygonStyle
            {
                FillColor       = Color.FromKnownColor(random.NextEnum <KnownColor>()),
                StrokeColor     = Color.FromKnownColor(random.NextEnum <KnownColor>()),
                StrokeThickness = random.Next(1, 48)
            };
            var mapPolygonData = new MapPolygonData("test", polygonStyle, theme)
            {
                Features = new[]
                {
                    CreateMapFeatureWithMetaData(metadataAttribute)
                }
            };

            var mapPolygonLayer = new MapPolygonLayer();

            var converter = new MapPolygonDataConverter();

            // Call
            converter.ConvertLayerProperties(mapPolygonData, mapPolygonLayer);

            // Assert
            IPolygonSymbolizer expectedSymbolizer = CreateExpectedSymbolizer(polygonStyle);

            IPolygonScheme appliedScheme = mapPolygonLayer.Symbology;

            Assert.AreEqual(1, appliedScheme.Categories.Count);

            IPolygonCategory baseCategory = appliedScheme.Categories[0];

            AssertAreEqual(expectedSymbolizer, baseCategory.Symbolizer);
            Assert.IsNull(baseCategory.FilterExpression);
        }
Exemple #16
0
        /// <summary/>
        protected void addPolygonStyleElement(PolygonStyle PolygonStyle, XmlDocument doc, XmlElement layerElement)
        {
            XmlElement polygonStyleElement = doc.CreateElement("polygon_style");

            layerElement.AppendChild(polygonStyleElement);
            addAttribute(polygonStyleElement, "border_width", PolygonStyle.BorderWidth.ToString(CultureInfo.InvariantCulture));
            addAttribute(polygonStyleElement, "border_color", ColorTranslator.ToHtml(PolygonStyle.BorderColor));
            addAttribute(polygonStyleElement, "border_visible", PolygonStyle.BorderVisible ? "1" : "0");
            addAttribute(polygonStyleElement, "border_dash_style", ((int)PolygonStyle.BorderDashStyle).ToString(CultureInfo.InvariantCulture));
            addAttribute(polygonStyleElement, "border_dash_cap", ((int)PolygonStyle.BorderDashCap).ToString(CultureInfo.InvariantCulture));
            addAttribute(polygonStyleElement, "hatch_style", ((int)PolygonStyle.HatchStyle).ToString(CultureInfo.InvariantCulture));
            addAttribute(polygonStyleElement, "use_hatch", PolygonStyle.UseHatch ? "1" : "0");
            addAttribute(polygonStyleElement, "fill_fore_color", ColorTranslator.ToHtml(PolygonStyle.FillForeColor));
            addAttribute(polygonStyleElement, "fill_back_color", ColorTranslator.ToHtml(PolygonStyle.FillBackColor));
            addAttribute(polygonStyleElement, "fill_pattern", ((int)PolygonStyle.FillPattern).ToString(CultureInfo.InvariantCulture));
            addAttribute(polygonStyleElement, "fill_transparent", PolygonStyle.FillBackColor.A.ToString(CultureInfo.InvariantCulture));
        }
Exemple #17
0
        public void Properties_SetValues_PropertyValuesAsExpected()
        {
            // Setup
            Color     fillColor   = Color.AliceBlue;
            Color     strokeColor = Color.Gainsboro;
            const int width       = 3;

            // Call
            var polygonStyle = new PolygonStyle
            {
                FillColor       = fillColor,
                StrokeColor     = strokeColor,
                StrokeThickness = width
            };

            // Assert
            Assert.AreEqual(fillColor, polygonStyle.FillColor);
            Assert.AreEqual(strokeColor, polygonStyle.StrokeColor);
            Assert.AreEqual(width, polygonStyle.StrokeThickness);
        }
Exemple #18
0
        public void Constructor_WithStyle_ExpectedValues()
        {
            // Setup
            const string name  = "test data";
            var          style = new PolygonStyle
            {
                FillColor       = Color.Aqua,
                StrokeColor     = Color.DarkGoldenrod,
                StrokeThickness = 3
            };

            // Call
            var data = new MapPolygonData(name, style);

            // Assert
            Assert.AreEqual(name, data.Name);
            CollectionAssert.IsEmpty(data.Features);
            Assert.AreSame(style, data.Style);
            Assert.IsNull(data.Theme);
        }
Exemple #19
0
        public void SetProperties_IndividualProperties_UpdateDataAndNotifyObservers()
        {
            // Setup
            var random = new Random(21);

            var mocks    = new MockRepository();
            var observer = mocks.StrictMock <IObserver>();

            observer.Expect(o => o.UpdateObserver()).Repeat.Times(3);
            mocks.ReplayAll();

            var mapData = new MapPolygonData("Name");

            mapData.Attach(observer);

            var categoryTheme = new PolygonCategoryTheme(ValueCriterionTestFactory.CreateValueCriterion(),
                                                         new PolygonStyle());

            var properties = new PolygonCategoryThemeProperties(categoryTheme, string.Empty, mapData);

            Color fillColor       = Color.FromKnownColor(random.NextEnumValue <KnownColor>());
            Color strokeColor     = Color.FromKnownColor(random.NextEnumValue <KnownColor>());
            int   strokeThickness = random.Next(1, 48);

            // Call
            properties.FillColor       = fillColor;
            properties.StrokeColor     = strokeColor;
            properties.StrokeThickness = strokeThickness;

            // Assert
            PolygonStyle actualStyle = categoryTheme.Style;

            Assert.AreEqual(fillColor, actualStyle.FillColor);
            Assert.AreEqual(strokeColor, actualStyle.StrokeColor);
            Assert.AreEqual(strokeThickness, actualStyle.StrokeThickness);

            mocks.VerifyAll();
        }
        public static Func<ExportContext, SharpKml.Dom.Style> CreateFromSharpmapStyle(IStyle sharpmapStyle)
        {
            if (sharpmapStyle == null)
                throw new ArgumentNullException("sharpmapStyle");

            var vectorStyle = sharpmapStyle as VectorStyle;
            if (vectorStyle == null) return null;

            SharpKml.Dom.Style style = null;

            var install = new Action<ExportContext>(context =>
            {
                style = new SharpKml.Dom.Style
                {
                    Id = sharpmapStyle.GetHashCode().ToString(CultureInfo.InvariantCulture)
                };

                if (vectorStyle.Line != null)
                {
                    var lineStyle = new LineStyle();
                    style.Line = lineStyle;

                    var color = vectorStyle.Line.Color;
                    lineStyle.Color = new Color32(color.A, color.B, color.G, color.R);
                    lineStyle.ColorMode = ColorMode.Normal;
                    lineStyle.Width = vectorStyle.Line.Width;
                }

                var solidColor = ConvertToColor32(vectorStyle.Fill);
                if (solidColor != null)
                {
                    var polygonStyle = new PolygonStyle();
                    style.Polygon = polygonStyle;

                    polygonStyle.Fill = true;
                    polygonStyle.Color = solidColor;
                }

                if (vectorStyle.Symbol == null)
                {
                    if (vectorStyle.PointSize > 0)
                    {
                        var iconStyle = new IconStyle();

                        var pointColor = vectorStyle.PointColor != null
                            ? ConvertToColor32(vectorStyle.PointColor) ?? new Color32(255, 0, 0, 0)
                            : new Color32(255, 0, 0, 0);

                        iconStyle.Color = pointColor;
                        iconStyle.ColorMode = ColorMode.Normal;
                        iconStyle.Icon = new IconStyle.IconLink(Pushpins.ShadedDot);
                        iconStyle.Scale = vectorStyle.PointSize / 6;

                        style.Icon = iconStyle;
                    }
                }
                else
                {
                    var additionalFile = SaveImagetoDisk(vectorStyle.Symbol);
                    Debug.Assert(additionalFile != null, "additionalFile != null");

                    context.AdditionalFiles.Add(additionalFile);

                    var iconStyle = new IconStyle
                    {
                        Icon = new IconStyle.IconLink(new Uri(context.IsKmz ? Path.GetFileName(additionalFile) : additionalFile, UriKind.Relative)),
                        Scale = vectorStyle.SymbolScale
                    };

                    style.Icon = iconStyle;
                }
            });

            EventHandler endedHandler = delegate { style = null; };

            return context =>
            {
                if (style == null && sharpmapStyle.Enabled)
                {
                    install(context);

                    context.Exporter.Ended -= endedHandler;
                    context.Exporter.Ended += endedHandler;
                }

                return style;
            };
        }
Exemple #21
0
 private static PolygonSymbolizer CreateExpectedSymbolizer(PolygonStyle expectedPolygonStyle)
 {
     return(new PolygonSymbolizer(expectedPolygonStyle.FillColor,
                                  expectedPolygonStyle.StrokeColor,
                                  expectedPolygonStyle.StrokeThickness));
 }
Exemple #22
0
        public void ConvertLayerProperties_MapPolygonDataWithThemeAndMetaDataNameInFeatures_ConvertDataToMapPolygonLayer()
        {
            // Setup
            const string metadataAttribute = "Meta";
            var          random            = new Random(21);

            var unequalCriterion = new ValueCriterion(ValueCriterionOperator.UnequalValue,
                                                      "unequal value");
            var equalCriterion = new ValueCriterion(ValueCriterionOperator.EqualValue,
                                                    "equal value");
            var theme = new MapTheme <PolygonCategoryTheme>(metadataAttribute, new[]
            {
                new PolygonCategoryTheme(equalCriterion, new PolygonStyle
                {
                    FillColor       = Color.FromKnownColor(random.NextEnum <KnownColor>()),
                    StrokeColor     = Color.FromKnownColor(random.NextEnum <KnownColor>()),
                    StrokeThickness = random.Next(1, 48)
                }),
                new PolygonCategoryTheme(unequalCriterion, new PolygonStyle
                {
                    FillColor       = Color.FromKnownColor(random.NextEnum <KnownColor>()),
                    StrokeColor     = Color.FromKnownColor(random.NextEnum <KnownColor>()),
                    StrokeThickness = random.Next(1, 48)
                })
            });

            var polygonStyle = new PolygonStyle
            {
                FillColor       = Color.FromKnownColor(random.NextEnum <KnownColor>()),
                StrokeColor     = Color.FromKnownColor(random.NextEnum <KnownColor>()),
                StrokeThickness = random.Next(1, 48)
            };
            var mapPolygonData = new MapPolygonData("test", polygonStyle, theme)
            {
                Features = new[]
                {
                    CreateMapFeatureWithMetaData(metadataAttribute)
                }
            };

            var mapPolygonLayer = new MapPolygonLayer();

            var converter = new MapPolygonDataConverter();

            // Call
            converter.ConvertLayerProperties(mapPolygonData, mapPolygonLayer);

            // Assert
            PolygonSymbolizer expectedSymbolizer = CreateExpectedSymbolizer(polygonStyle);

            IPolygonScheme appliedScheme = mapPolygonLayer.Symbology;

            Assert.AreEqual(3, appliedScheme.Categories.Count);

            IPolygonCategory baseCategory = appliedScheme.Categories[0];

            AssertAreEqual(expectedSymbolizer, baseCategory.Symbolizer);
            Assert.IsNull(baseCategory.FilterExpression);

            IPolygonCategory equalSchemeCategory = appliedScheme.Categories[1];
            string           expectedFilter      = $"[1] = '{equalCriterion.Value}'";

            Assert.AreEqual(expectedFilter, equalSchemeCategory.FilterExpression);
            PolygonStyle expectedCategoryStyle = theme.CategoryThemes.ElementAt(0).Style;

            expectedSymbolizer = CreateExpectedSymbolizer(expectedCategoryStyle);
            AssertAreEqual(expectedSymbolizer, equalSchemeCategory.Symbolizer);

            IPolygonCategory unEqualSchemeCategory = appliedScheme.Categories[2];

            expectedFilter = $"NOT [1] = '{unequalCriterion.Value}'";
            Assert.AreEqual(expectedFilter, unEqualSchemeCategory.FilterExpression);
            expectedCategoryStyle = theme.CategoryThemes.ElementAt(1).Style;
            expectedSymbolizer    = CreateExpectedSymbolizer(expectedCategoryStyle);
            AssertAreEqual(expectedSymbolizer, unEqualSchemeCategory.Symbolizer);
        }
Exemple #23
0
        public void GivenMapLayerWithScheme_WhenConvertingLayerFeatures_ThenClearsAppliedSchemeAndAppliesDefaultCategory()
        {
            // Given
            const string metadataAttribute = "Meta";

            var mocks       = new MockRepository();
            var categoryOne = mocks.Stub <IPolygonCategory>();
            var categoryTwo = mocks.Stub <IPolygonCategory>();

            mocks.ReplayAll();

            var mapPolygonLayer = new MapPolygonLayer
            {
                Symbology = new PolygonScheme
                {
                    Categories =
                    {
                        categoryOne,
                        categoryTwo
                    }
                }
            };

            var converter = new MapPolygonDataConverter();

            var random       = new Random(21);
            var polygonStyle = new PolygonStyle
            {
                FillColor       = Color.FromKnownColor(random.NextEnum <KnownColor>()),
                StrokeColor     = Color.FromKnownColor(random.NextEnum <KnownColor>()),
                StrokeThickness = random.Next(1, 48)
            };
            var theme = new MapTheme <PolygonCategoryTheme>(metadataAttribute, new[]
            {
                new PolygonCategoryTheme(ValueCriterionTestFactory.CreateValueCriterion(),
                                         new PolygonStyle
                {
                    FillColor       = Color.FromKnownColor(random.NextEnum <KnownColor>()),
                    StrokeColor     = Color.FromKnownColor(random.NextEnum <KnownColor>()),
                    StrokeThickness = random.Next(1, 48)
                })
            });
            var mapPolygonData = new MapPolygonData("test", polygonStyle, theme)
            {
                Features = new[]
                {
                    CreateMapFeatureWithMetaData(metadataAttribute)
                }
            };

            // When
            converter.ConvertLayerFeatures(mapPolygonData, mapPolygonLayer);

            // Then
            PolygonCategoryCollection categoryCollection = mapPolygonLayer.Symbology.Categories;

            Assert.AreEqual(1, categoryCollection.Count);

            PolygonSymbolizer expectedSymbolizer = CreateExpectedSymbolizer(polygonStyle);

            AssertAreEqual(expectedSymbolizer, categoryCollection.Single().Symbolizer);

            mocks.VerifyAll();
        }
 private static IFeatureCategory CreateCategory(PolygonStyle style)
 {
     return(new PolygonCategory(style.FillColor, GetStrokeColor(style), style.StrokeThickness));
 }
Exemple #25
0
 /// <summary>
 /// Creates a new instance of <see cref="RemovableMapPolygonData"/>.
 /// </summary>
 /// <param name="name">The name of the <see cref="RemovableMapPolygonData"/>.</param>
 /// <param name="style">The style of the data.</param>
 /// <exception cref="ArgumentException">Thrown when <paramref name="name"/> is
 /// <c>null</c> or only whitespace.</exception>
 /// <exception cref="ArgumentNullException">Thrown when <paramref name="style"/>
 /// is <c>null</c>.</exception>
 public RemovableMapPolygonData(string name, PolygonStyle style) : base(name, style)
 {
 }
Exemple #26
0
        private void writeKML(string filename)
        {
            SharpKml.Dom.AltitudeMode altmode = SharpKml.Dom.AltitudeMode.Absolute;

            if (MainV2.cs.firmware == MainV2.Firmwares.ArduPlane)
            {
                altmode = SharpKml.Dom.AltitudeMode.Absolute;
            }
            else if (MainV2.cs.firmware == MainV2.Firmwares.ArduCopter2)
            {
                altmode = SharpKml.Dom.AltitudeMode.RelativeToGround;
            }

            Color[] colours = { Color.Red, Color.Orange, Color.Yellow, Color.Green, Color.Blue, Color.Indigo, Color.Violet, Color.Pink };

            Document kml = new Document();

            Tour tour = new Tour()
            {
                Name = "First Person View"
            };
            Playlist tourplaylist = new Playlist();

            AddNamespace(kml, "gx", "http://www.google.com/kml/ext/2.2");

            Style style = new Style();

            style.Id   = "yellowLineGreenPoly";
            style.Line = new LineStyle(new Color32(HexStringToColor("7f00ffff")), 4);



            PolygonStyle pstyle = new PolygonStyle();

            pstyle.Color  = new Color32(HexStringToColor("7f00ff00"));
            style.Polygon = pstyle;

            kml.AddStyle(style);

            Style stylet = new Style();

            stylet.Id = "track";
            SharpKml.Dom.IconStyle ico = new SharpKml.Dom.IconStyle();
            LabelStyle             lst = new LabelStyle();

            lst.Scale         = 0;
            stylet.Icon       = ico;
            ico.Icon          = new IconStyle.IconLink(new Uri("http://earth.google.com/images/kml-icons/track-directional/track-none.png"));
            stylet.Icon.Scale = 0.5;
            stylet.Label      = lst;

            kml.AddStyle(stylet);

            // create sub folders
            Folder planes = new Folder();

            planes.Name = "Planes";
            kml.AddFeature(planes);

            Folder points = new Folder();

            points.Name = "Points";
            kml.AddFeature(points);


            // coords for line string
            CoordinateCollection coords = new CoordinateCollection();

            int      a          = 1;
            int      c          = -1;
            DateTime lasttime   = DateTime.MaxValue;
            DateTime starttime  = DateTime.MinValue;
            Color    stylecolor = Color.AliceBlue;
            string   mode       = "";

            if (flightdata.Count > 0)
            {
                mode = flightdata[0].mode;
            }
            foreach (CurrentState cs in flightdata)
            {
                progressBar1.Value = 50 + (int)((float)a / (float)flightdata.Count * 100.0f / 2.0f);
                progressBar1.Refresh();

                if (starttime == DateTime.MinValue)
                {
                    starttime = cs.datetime;
                    lasttime  = cs.datetime;
                }

                if (mode != cs.mode || flightdata.Count == a)
                {
                    c++;

                    LineString ls = new LineString();
                    ls.AltitudeMode = altmode;
                    ls.Extrude      = true;

                    ls.Coordinates = coords;

                    Placemark pm = new Placemark();

                    pm.Name     = c + " Flight Path " + mode;
                    pm.StyleUrl = new Uri("#yellowLineGreenPoly", UriKind.Relative);
                    pm.Geometry = ls;

                    SharpKml.Dom.TimeSpan ts = new SharpKml.Dom.TimeSpan();
                    ts.Begin = starttime;
                    ts.End   = cs.datetime;

                    pm.Time = ts;

                    // setup for next line
                    mode      = cs.mode;
                    starttime = cs.datetime;

                    stylecolor = colours[c % (colours.Length - 1)];

                    Style style2 = new Style();
                    style2.Line = new LineStyle(new Color32(stylecolor), 4);

                    pm.StyleSelector = style2;

                    kml.AddFeature(pm);

                    coords = new CoordinateCollection();
                }

                coords.Add(new Vector(cs.lat, cs.lng, cs.alt));

                SharpKml.Dom.Timestamp tstamp = new SharpKml.Dom.Timestamp();
                tstamp.When = cs.datetime;

                FlyTo flyto = new FlyTo();

                flyto.Duration = (cs.datetime - lasttime).TotalMilliseconds / 1000.0;

                flyto.Mode = FlyToMode.Smooth;
                SharpKml.Dom.Camera cam = new SharpKml.Dom.Camera();
                cam.AltitudeMode = altmode;
                cam.Latitude     = cs.lat;
                cam.Longitude    = cs.lng;
                cam.Altitude     = cs.alt;
                cam.Heading      = cs.yaw;
                cam.Roll         = -cs.roll;
                cam.Tilt         = (90 - (cs.pitch * -1));

                cam.GXTimePrimitive = tstamp;

                flyto.View = cam;
                //if (Math.Abs(flyto.Duration.Value) > 0.1)
                {
                    tourplaylist.AddTourPrimitive(flyto);
                    lasttime = cs.datetime;
                }


                Placemark pmplane = new Placemark();
                pmplane.Name = "Point " + a;



                pmplane.Time = tstamp;

                pmplane.Visibility = false;

                SharpKml.Dom.Location loc = new SharpKml.Dom.Location();
                loc.Latitude  = cs.lat;
                loc.Longitude = cs.lng;
                loc.Altitude  = cs.alt;

                if (loc.Altitude < 0)
                {
                    loc.Altitude = 0.01;
                }

                SharpKml.Dom.Orientation ori = new SharpKml.Dom.Orientation();
                ori.Heading = cs.yaw;
                ori.Roll    = -cs.roll;
                ori.Tilt    = -cs.pitch;

                SharpKml.Dom.Scale sca = new SharpKml.Dom.Scale();

                sca.X = 2;
                sca.Y = 2;
                sca.Z = 2;

                Model model = new Model();
                model.Location     = loc;
                model.Orientation  = ori;
                model.AltitudeMode = altmode;
                model.Scale        = sca;

                try
                {
                    Description desc = new Description();
                    desc.Text = @"<![CDATA[
              <table>
                <tr><td>Roll: " + model.Orientation.Roll.Value.ToString("0.00") + @" </td></tr>
                <tr><td>Pitch: " + model.Orientation.Tilt.Value.ToString("0.00") + @" </td></tr>
                <tr><td>Yaw: " + model.Orientation.Heading.Value.ToString("0.00") + @" </td></tr>
                <tr><td>Time: " + cs.datetime.ToString("HH:mm:sszzzzzz") + @" </td></tr>
              </table> ";
//            ]]>";

                    pmplane.Description = desc;
                }
                catch { }

                Link link = new Link();
                link.Href = new Uri("block_plane_0.dae", UriKind.Relative);

                model.Link = link;

                pmplane.Geometry = model;

                planes.AddFeature(pmplane);

                ///

                Placemark pmt = new Placemark();

                SharpKml.Dom.Point pnt = new SharpKml.Dom.Point();
                pnt.AltitudeMode = altmode;
                pnt.Coordinate   = new Vector(cs.lat, cs.lng, cs.alt);

                pmt.Name = "" + a;

                pmt.Description = pmplane.Description;

                pmt.Time = tstamp;

                pmt.Geometry = pnt;
                pmt.StyleUrl = new Uri("#track", UriKind.Relative);

                points.AddFeature(pmt);

                a++;
            }

            tour.Playlist = tourplaylist;

            kml.AddFeature(tour);

            Serializer serializer = new Serializer();

            serializer.Serialize(kml);


            //Console.WriteLine(serializer.Xml);

            StreamWriter sw = new StreamWriter(filename);

            sw.Write(serializer.Xml);
            sw.Close();

            // create kmz - aka zip file

            FileStream      fs        = File.Open(filename.Replace(Path.GetExtension(filename), ".kmz"), FileMode.Create);
            ZipOutputStream zipStream = new ZipOutputStream(fs);

            zipStream.SetLevel(9);             //0-9, 9 being the highest level of compression
            zipStream.UseZip64 = UseZip64.Off; // older zipfile

            // entry 1
            string   entryName = ZipEntry.CleanName(Path.GetFileName(filename)); // Removes drive from name and fixes slash direction
            ZipEntry newEntry  = new ZipEntry(entryName);

            newEntry.DateTime = DateTime.Now;

            zipStream.PutNextEntry(newEntry);

            // Zip the file in buffered chunks
            // the "using" will close the stream even if an exception occurs
            byte[] buffer = new byte[4096];
            using (FileStream streamReader = File.Open(filename, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
            {
                StreamUtils.Copy(streamReader, zipStream, buffer);
            }
            zipStream.CloseEntry();

            filename = Path.GetDirectoryName(Application.ExecutablePath) + Path.DirectorySeparatorChar + "block_plane_0.dae";

            // entry 2
            entryName         = ZipEntry.CleanName(Path.GetFileName(filename)); // Removes drive from name and fixes slash direction
            newEntry          = new ZipEntry(entryName);
            newEntry.DateTime = DateTime.Now;

            zipStream.PutNextEntry(newEntry);

            // Zip the file in buffered chunks
            // the "using" will close the stream even if an exception occurs
            buffer = new byte[4096];
            using (FileStream streamReader = File.OpenRead(filename))
            {
                StreamUtils.Copy(streamReader, zipStream, buffer);
            }
            zipStream.CloseEntry();


            zipStream.IsStreamOwner = true;     // Makes the Close also Close the underlying stream
            zipStream.Close();

            flightdata.Clear();
        }
Exemple #27
0
        /// <summary>
        /// 获取要素信息
        /// </summary>
        /// <returns></returns>
        private CMapFeatureInfo GetMapFeatureInfo()
        {
            CMapFeatureInfo fInfo = new CMapFeatureInfo();
            SFeature        sf    = new SFeature();

            sf.AttValue = new string[m_attStruct.FldNumber];
            for (int i = 0; i < m_attStruct.FldNumber; i++)
            {
                sf.AttValue[i] = m_textBoxArr[i].Text;
                switch (this.m_attStruct.FldType[i])
                {
                case "double":
                case "integer":
                case "long":
                case "short":
                    if (!CommFun.IsNumber(sf.AttValue[i]))
                    {
                        MessageBox.Show("字段【Fld_" + this.m_attStruct.FldName[i] + "】输入的数据格式不正确。请重新输入!", "提示", MessageBoxButton.OK);
                        return(null);
                    }
                    break;
                }
            }
            SFeatureGeometry sfGeo = null;
            SFclsGeomType    curFGeoType;

            if (m_targetGeo != null)
            {
                sfGeo = m_targetGeo as SFeatureGeometry;
                if (sfGeo == null) //add feature
                {
                    sfGeo = new SFeatureGeometry();
                    switch ((m_targetGeo as IWebGeometry).GetGeomType())
                    {
                    case WebGeomType.Point:
                        sf.ftype = SFclsGeomType.Pnt;
                        GPoint pnt = new GPoint();
                        pnt.Dot       = m_targetGeo as Dot_2D;
                        sfGeo.PntGeom = new GPoint[] { pnt };
                        break;

                    case WebGeomType.Line:
                        sf.ftype = SFclsGeomType.Lin;
                        GLine line = new GLine();
                        line.Line     = m_targetGeo as AnyLine;
                        sfGeo.LinGeom = new GLine[] { line };
                        break;

                    case WebGeomType.Polygon:
                        sf.ftype = SFclsGeomType.Reg;
                        GRegion polygon = new GRegion();
                        AnyLine circle  = new AnyLine();
                        circle.Arcs         = new Arc[1];
                        circle.Arcs[0]      = new Arc();
                        circle.Arcs[0].Dots = (m_targetGeo as ZDIMS.BaseLib.Polygon).Dots;
                        polygon.Rings       = new AnyLine[] { circle };
                        sfGeo.RegGeom       = new GRegion[] { polygon };
                        break;

                    default:
                        sfGeo = null;
                        break;
                    }
                }
            }
            curFGeoType = ActiveMapDoc.ActiveLayerGeoType;
            if (this.m_featureStyle == null)
            {
                this.m_featureStyle = new WebGraphicsInfo();
            }
            this.m_style.Update();
            switch (curFGeoType)
            {
            case SFclsGeomType.Pnt:
                this.m_featureStyle.InfoType = GInfoType.PntInfo;
                PointStyle newPntStyle = this.m_style as PointStyle;
                this.m_featureStyle.PntInfo = new CPointInfo();
                if (newPntStyle.patternAngle.Text == "")
                {
                    this.m_featureStyle.PntInfo.Angle = 0.0;
                }
                else
                {
                    this.m_featureStyle.PntInfo.Angle = Convert.ToDouble(newPntStyle.patternAngle.Text);
                }
                if (newPntStyle.patternColor._TextBoxInput.Text.Split(':')[0] == "")
                {
                    this.m_featureStyle.PntInfo.Color = 0;
                }
                else
                {
                    this.m_featureStyle.PntInfo.Color = Convert.ToInt32(newPntStyle.patternColor._TextBoxInput.Text.Split(':')[0]);
                }
                if (newPntStyle.patternHeight.Text == "")
                {
                    this.m_featureStyle.PntInfo.SymHeight = 0.0;
                }
                else
                {
                    this.m_featureStyle.PntInfo.SymHeight = Convert.ToDouble(newPntStyle.patternHeight.Text);
                }
                if (newPntStyle.patternID._TextBoxInput.Text.Split(':')[0] == "")
                {
                    this.m_featureStyle.PntInfo.SymID = 0;
                }
                else
                {
                    this.m_featureStyle.PntInfo.SymID = Convert.ToInt32(newPntStyle.patternID._TextBoxInput.Text.Split(':')[0]);
                }
                if (newPntStyle.patternWidth.Text == "")
                {
                    this.m_featureStyle.PntInfo.SymWidth = 0.0;
                }
                else
                {
                    this.m_featureStyle.PntInfo.SymWidth = Convert.ToDouble(newPntStyle.patternWidth.Text);
                }
                break;

            case SFclsGeomType.Lin:
                this.m_featureStyle.InfoType = GInfoType.LinInfo;
                LineStyle newLineStyle = this.m_style as LineStyle;
                this.m_featureStyle.LinInfo = new CLineInfo();
                if (newLineStyle.color._TextBoxInput.Text.Split(':')[0] == "")
                {
                    this.m_featureStyle.LinInfo.Color = 0;
                }
                else
                {
                    this.m_featureStyle.LinInfo.Color = Convert.ToInt32(newLineStyle.color._TextBoxInput.Text.Split(':')[0]);
                }
                if (newLineStyle.patternID._TextBoxInput.Text.Split(':')[0] == "")
                {
                    this.m_featureStyle.LinInfo.LinStyleID = 0;
                }
                else
                {
                    this.m_featureStyle.LinInfo.LinStyleID = Convert.ToInt32(newLineStyle.patternID._TextBoxInput.Text.Split(':')[0]);
                }
                if (newLineStyle.patternID2._TextBoxInput.Text.Split(':')[0] == "")
                {
                    this.m_featureStyle.LinInfo.LinStyleID2 = 0;
                }
                else
                {
                    this.m_featureStyle.LinInfo.LinStyleID2 = Convert.ToInt32(newLineStyle.patternID2._TextBoxInput.Text.Split(':')[0]);
                }
                if (newLineStyle.penWidth.Text == "")
                {
                    this.m_featureStyle.LinInfo.LinWidth = 0.0;
                }
                else
                {
                    this.m_featureStyle.LinInfo.LinWidth = Convert.ToDouble(newLineStyle.penWidth.Text);
                }
                if (newLineStyle.lineScaleX.Text == "")
                {
                    this.m_featureStyle.LinInfo.Xscale = 0.0;
                }
                else
                {
                    this.m_featureStyle.LinInfo.Xscale = Convert.ToDouble(newLineStyle.lineScaleX.Text);
                }
                if (newLineStyle.lineScaleY.Text == "")
                {
                    this.m_featureStyle.LinInfo.Yscale = 0.0;
                }
                else
                {
                    this.m_featureStyle.LinInfo.Yscale = Convert.ToDouble(newLineStyle.lineScaleY.Text);
                }
                break;

            case SFclsGeomType.Reg:
                this.m_featureStyle.InfoType = GInfoType.RegInfo;
                PolygonStyle newRegStyle = this.m_style as PolygonStyle;
                this.m_featureStyle.RegInfo = new CRegionInfo();
                if (newRegStyle.fillcolor._TextBoxInput.Text.Split(':')[0] == "")
                {
                    this.m_featureStyle.RegInfo.FillColor = 0;
                }
                else
                {
                    this.m_featureStyle.RegInfo.FillColor = Convert.ToInt32(newRegStyle.fillcolor._TextBoxInput.Text.Split(':')[0]);
                }
                if (newRegStyle.patternColor._TextBoxInput.Text.Split(':')[0] == "")
                {
                    this.m_featureStyle.RegInfo.PatColor = 0;
                }
                else
                {
                    this.m_featureStyle.RegInfo.PatColor = Convert.ToInt32(newRegStyle.patternColor._TextBoxInput.Text.Split(':')[0]);
                }
                if (newRegStyle.patternHeight.Text == "")
                {
                    this.m_featureStyle.RegInfo.PatHeight = 0.0;
                }
                else
                {
                    this.m_featureStyle.RegInfo.PatHeight = Convert.ToDouble(newRegStyle.patternHeight.Text);
                }
                if (newRegStyle.patternID._TextBoxInput.Text.Split(':')[0] == "")
                {
                    this.m_featureStyle.RegInfo.PatID = 0;
                }
                else
                {
                    this.m_featureStyle.RegInfo.PatID = Convert.ToInt32(newRegStyle.patternID._TextBoxInput.Text.Split(':')[0]);
                }
                if (newRegStyle.patternPenWidth.Text == "")
                {
                    this.m_featureStyle.RegInfo.OutPenWidth = 0.0;
                }
                else
                {
                    this.m_featureStyle.RegInfo.OutPenWidth = Convert.ToDouble(newRegStyle.patternPenWidth.Text);
                }
                if (newRegStyle.patternWidth.Text == "")
                {
                    this.m_featureStyle.RegInfo.PatWidth = 0.0;
                }
                else
                {
                    this.m_featureStyle.RegInfo.PatWidth = Convert.ToDouble(newRegStyle.patternWidth.Text);
                }
                break;
            }

            sf.fGeom              = sfGeo;
            sf.FID                = m_featureID;
            fInfo.GInfo           = this.m_featureStyle;
            fInfo.FSet            = sf;
            fInfo.LayerIndex      = ActiveMapDoc.ActiveLayerIndex;
            fInfo.MapName         = new COpenMap();
            fInfo.MapName.MapName = new string[] { ActiveMapDoc.MapDocName };
            return(fInfo);
        }
        public static Func <ExportContext, SharpKml.Dom.Style> CreateFromSharpmapStyle(IStyle sharpmapStyle)
        {
            if (sharpmapStyle == null)
            {
                throw new ArgumentNullException("sharpmapStyle");
            }

            var vectorStyle = sharpmapStyle as VectorStyle;

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

            SharpKml.Dom.Style style = null;

            var install = new Action <ExportContext>(context =>
            {
                style = new SharpKml.Dom.Style
                {
                    Id = sharpmapStyle.GetHashCode().ToString(CultureInfo.InvariantCulture)
                };

                if (vectorStyle.Line != null)
                {
                    var lineStyle = new LineStyle();
                    style.Line    = lineStyle;

                    var color           = vectorStyle.Line.Color;
                    lineStyle.Color     = new Color32(color.A, color.B, color.G, color.R);
                    lineStyle.ColorMode = ColorMode.Normal;
                    lineStyle.Width     = vectorStyle.Line.Width;
                }

                var solidColor = ConvertToColor32(vectorStyle.Fill);
                if (solidColor != null)
                {
                    var polygonStyle = new PolygonStyle();
                    style.Polygon    = polygonStyle;

                    polygonStyle.Fill  = true;
                    polygonStyle.Color = solidColor;
                }

                if (vectorStyle.Symbol == null)
                {
                    if (vectorStyle.PointSize > 0)
                    {
                        var iconStyle = new IconStyle();

                        var pointColor = vectorStyle.PointColor != null
                            ? ConvertToColor32(vectorStyle.PointColor) ?? new Color32(255, 0, 0, 0)
                            : new Color32(255, 0, 0, 0);

                        iconStyle.Color     = pointColor;
                        iconStyle.ColorMode = ColorMode.Normal;
                        iconStyle.Icon      = new IconStyle.IconLink(Pushpins.ShadedDot);
                        iconStyle.Scale     = vectorStyle.PointSize / 6;

                        style.Icon = iconStyle;
                    }
                }
                else
                {
                    var additionalFile = SaveImagetoDisk(vectorStyle.Symbol);
                    Debug.Assert(additionalFile != null, "additionalFile != null");

                    context.AdditionalFiles.Add(additionalFile);

                    var iconStyle = new IconStyle
                    {
                        Icon  = new IconStyle.IconLink(new Uri(context.IsKmz ? Path.GetFileName(additionalFile) : additionalFile, UriKind.Relative)),
                        Scale = vectorStyle.SymbolScale
                    };

                    style.Icon = iconStyle;
                }
            });

            EventHandler endedHandler = delegate { style = null; };

            return(context =>
            {
                if (style == null && sharpmapStyle.Enabled)
                {
                    install(context);

                    context.Exporter.Ended -= endedHandler;
                    context.Exporter.Ended += endedHandler;
                }

                return style;
            });
        }
Exemple #29
0
 public ImageMapStyle(double minVis, double maxVis, bool enabled)
     : base(minVis, maxVis, enabled)
 {
     this._polyStyle = new PolygonStyle(minVis, maxVis, enabled);
     this._ps = new PointStyle(5, minVis, maxVis, enabled);
     this._ls = new LineStyle(5, minVis, maxVis, enabled);
 }