Beispiel #1
0
        public void TestSplitComplex()
        {
            // Test with a Document that already has a shared style to make
            // sure it's not disturbed. Also check with a Placemark that
            // doesn't have a style.
            const string InputKml =
                "<Document>" +
                "<StyleMap id='stylemap0'/>" +
                "<Placemark><name>no style</name></Placemark>" +
                "<Placemark>" +
                "<Style><LineStyle/></Style>" +
                "</Placemark>" +
                "<Placemark>" +
                "<name>has shared stylemap</name>" +
                "<styleUrl>#stylemap0</styleUrl>" +
                "</Placemark>" +
                "</Document>";

            const string ExpectedKml =
                "<Document>" +
                "<StyleMap id='stylemap0'/>" +
                "<Style id='_0'><LineStyle/></Style>" +
                "<Placemark><name>no style</name></Placemark>" +
                "<Placemark><styleUrl>#_0</styleUrl></Placemark>" +
                "<Placemark>" +
                "<name>has shared stylemap</name>" +
                "<styleUrl>#stylemap0</styleUrl>" +
                "</Placemark>" +
                "</Document>";

            CompareText(InputKml, ExpectedKml, e => StyleResolver.SplitStyles(e));
        }
Beispiel #2
0
        public void TestInlineStyleUrl()
        {
            var placemark = new Placemark
            {
                StyleUrl = new Uri("http://example.com/style.kml#cool-style")
            };

            Placemark output = StyleResolver.InlineStyles(placemark);

            Assert.That(output.StyleUrl, Is.EqualTo(placemark.StyleUrl));

            placemark.StyleUrl = new Uri("#non-existent-local-reference", UriKind.Relative);
            output             = StyleResolver.InlineStyles(placemark);
            Assert.That(output.StyleUrl, Is.EqualTo(placemark.StyleUrl));

            var document = new Document();

            document.AddStyle(new Style {
                Id = "non-existent-local-reference"
            });
            document.AddFeature(placemark);
            document = StyleResolver.InlineStyles(document);

            placemark = (Placemark)document.Features.ElementAt(0);
            Assert.That(placemark.StyleUrl, Is.Null);
        }
Beispiel #3
0
        public void TestSplitNoDocument()
        {
            // Make sure if there's no document then it's unaltered.
            const string Kml =
                "<Folder>" +
                "<name>f</name>" +
                "<Placemark>" +
                "<Style><IconStyle/></Style>" +
                "</Placemark>" +
                "</Folder>";

            CompareText(Kml, Kml, e => StyleResolver.SplitStyles(e)); // Input and the output should be the same
        }
Beispiel #4
0
        public static void Run()
        {
            KmlFile file = Program.OpenFile("Enter a file to inline the styles:");

            if (file == null)
            {
                return;
            }

            var inlined    = StyleResolver.InlineStyles(file.Root);
            var serializer = new Serializer();

            serializer.Serialize(inlined);
            Console.WriteLine(serializer.Xml);
        }
Beispiel #5
0
        public void TestInlineComplex()
        {
            using (Stream data = SampleData.CreateStream("Engine.Data.Style Data.kml"))
                using (Stream output = SampleData.CreateStream("Engine.Data.Style Output.kml"))
                {
                    var parser = new Parser();
                    parser.Parse(data);
                    Document actual = GetDocument((Document)(((Kml)parser.Root).Feature), "InlineStylesTest");

                    parser.Parse(output);
                    Document expected = GetDocument((Document)(((Kml)parser.Root).Feature), "InlineStylesTest");

                    actual = StyleResolver.InlineStyles(actual);
                    SampleData.CompareElements(expected, actual);
                }
        }
Beispiel #6
0
        void ArrangeRoot()
        {
            StyleResolver.Revalidate();
            if (StyleResolver.StyleRules.Count == 0)
            {
                throw new InvalidOperationException("The style system contains no style-rules. This will result in errors. Aborting!");
            }

            var screenSpace = Bounds;

            if (lastLayoutSize != screenSpace || Root.LayoutInvalid)
            {
                Root.InvalidateLayout();
                Root.Arrange(screenSpace);
                lastLayoutSize = screenSpace;
            }
        }
Beispiel #7
0
        public void TestSplitBasic()
        {
            const string InputKml =
                "<Document>" +
                "<Placemark>" +
                "<Style/>" +
                "</Placemark>" +
                "</Document>";

            const string ExpectedKml =
                "<Document>" +
                "<Style id='_0'/>" +
                "<Placemark>" +
                "<styleUrl>#_0</styleUrl>" +
                "</Placemark>" +
                "</Document>";

            CompareText(InputKml, ExpectedKml, e => StyleResolver.SplitStyles(e));
        }
Beispiel #8
0
        public void TestSplitUniqueId()
        {
            // Force a collision and make sure it overwrites the id
            const string InputKml =
                "<Document>" +
                "<Style id='_0'/>" +
                "<Placemark><Style id='my_id'/></Placemark>" +
                "</Document>";

            const string ExpectedKml =
                "<Document>" +
                "<Style id='_0'/>" +
                "<Style id='_1'/>" +
                "<Placemark>" +
                "<styleUrl>#_1</styleUrl>" +
                "</Placemark>" +
                "</Document>";

            CompareText(InputKml, ExpectedKml, e => StyleResolver.SplitStyles(e));
        }
Beispiel #9
0
        public void TestInlineUpdate()
        {
            var document = new Document();

            document.AddStyle(new Style {
                Id = "style0"
            });

            var create = new CreateCollection {
                document
            };

            var update = new Update();

            update.AddUpdate(create);

            Update output = StyleResolver.InlineStyles(update);

            // Make sure it didn't change anything
            SampleData.CompareElements(update, output);
        }
Beispiel #10
0
        public void TestInlineBasic()
        {
            // Build our Kml with a shared style
            const string InputKml =
                "<Document>" +
                "<Style id='_0' />" +
                "<Placemark>" +
                "<styleUrl>#_0</styleUrl>" +
                "</Placemark>" +
                "</Document>";

            const string ExpectedKml =
                "<Document>" +
                "<Placemark>" +
                "<StyleMap>" +
                "<Pair><key>normal</key><Style/></Pair>" +
                "<Pair><key>highlight</key><Style/></Pair>" +
                "</StyleMap>" +
                "</Placemark>" +
                "</Document>";

            CompareText(InputKml, ExpectedKml, e => StyleResolver.InlineStyles(e));
        }
Beispiel #11
0
        private static void RunTestCase(Document data, string id, StyleState state, Style expected)
        {
            var file    = KmlFile.Create(data, true);
            var feature = file.FindObject(id) as Feature;

            Assert.That(feature, Is.Not.Null); // Make sure the test data is ok

            Style style = StyleResolver.CreateResolvedStyle(feature, file, state);

            if (expected == null)
            {
                // Make sure everything is null
                Assert.That(style.Balloon, Is.Null);
                Assert.That(style.Icon, Is.Null);
                Assert.That(style.Label, Is.Null);
                Assert.That(style.Line, Is.Null);
                Assert.That(style.List, Is.Null);
                Assert.That(style.Polygon, Is.Null);
            }
            else
            {
                SampleData.CompareElements(expected, style);
            }
        }
Beispiel #12
0
 public UIStyle(IContentLoader contentLoader)
 {
     StyleSystem   = new StyleSystem(contentLoader);
     StyleResolver = new StyleResolver(StyleSystem);
 }
Beispiel #13
0
 public virtual void Resolve(StyleResolver <StyleData> resolver)
 {
     // noop
 }