private static void RunTestCase(TestCase test, KmlFile file) { // Need to create a file from the element for Process to use, // making sure we pass a copy not the real thing! var target = KmlFile.Create(file.FindObject(test.Target).Clone(), false); // Update is stored as an orphan of the parent folder var update = (Update)(file.FindObject(test.Input).Orphans.ElementAt(0)); var expected = file.FindObject(test.Output).Children.ElementAt(0); update.Process(target); SampleData.CompareElements(expected, target.Root.Children.ElementAt(0)); }
public void should_load_track_geometry() { using (var stream = SampleData.CreateStream("Engine.Data.Tracks.kml")) { KmlFile file = KmlFile.Load(stream); var placemark = file.FindObject("geoffrey") as Placemark; var track = placemark.Geometry as Track; Assert.That(track, Is.Not.Null); Assert.That(track.When.Count(), Is.EqualTo(track.Coordinates.Count())); } }
private static void RunTestCase(TestCase test, KmlFile file) { Element GetFirstFeature(KmlFile kml, string id) { return(((Container)kml.FindObject(id)).Features.First()); } // Need to create a file from the element for Process to use, // making sure we pass a copy not the real thing! var target = KmlFile.Create(file.FindObject(test.Target).Clone(), false); // Update is stored as an orphan of the parent folder var update = (Update)file.FindObject(test.Input).Orphans.First(); update.Process(target); Element expected = GetFirstFeature(file, test.Output); SampleData.CompareElements(expected, GetFirstFeature(target, test.Target)); }
private static void RunTestCase(KmlFile file, string id, BoundingBox box) { Feature feature = file.FindObject(id) as Feature; Assert.That(feature, Is.Not.Null); // Verify the test data var bounds = feature.CalculateBounds(); Assert.That(bounds, Is.Not.Null); Assert.That(bounds.East, Is.EqualTo(box.East)); Assert.That(bounds.North, Is.EqualTo(box.North)); Assert.That(bounds.South, Is.EqualTo(box.South)); Assert.That(bounds.West, Is.EqualTo(box.West)); }
private static void ProcessChange(ChangeCollection change, KmlFile file) { foreach (var source in change) { if (source.TargetId != null) { KmlObject target = file.FindObject(source.TargetId); if (target != null) { target.Merge(source); target.TargetId = null; // Merge copied the TargetId from the source, but target shouldn't have it set } } } }
private static void ProcessCreate(CreateCollection create, KmlFile file) { foreach (var source in create) { if (source.TargetId != null) { Container target = file.FindObject(source.TargetId) as Container; if (target != null) // Make sure it was found and that the target was a Container { foreach (var feature in source.Features) { var clone = feature.Clone(); // We never give the original source. target.AddFeature(clone); file.AddFeature(clone); } } } } }
private static void RunTestCase(Document data, string id, StyleState state, Style expected) { KmlFile file = KmlFile.Create(data, true); Feature feature = file.FindObject(id) as Feature; Assert.That(feature, Is.Not.Null); // Make sure the test data is ok var 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); } }
private static void ProcessDelete(DeleteCollection delete, KmlFile file) { foreach (var source in delete) { if (source.TargetId != null) { Feature feature = file.FindObject(source.TargetId) as Feature; if (feature != null) { // Remove the Feature from the parent, which is either // a Container or Kml Container container = feature.Parent as Container; if (container != null) { container.RemoveFeature(source.TargetId); } else { Kml kml = feature.Parent as Kml; if (kml != null) { kml.Feature = null; } } // Also remove it from the file file.RemoveFeature(feature); } } } }