/// <summary> /// Gets blocks from a KML file. /// </summary> /// <returns>The blocks.</returns> /// <param name="kml">Path to the KML file.</param> /// <param name="treeTypes">Existing Tree types.</param> public static List<Block> GetBlocks(string kml, List<TreeType> treeTypes) { var allTreeTypes = new List<TreeType>(); allTreeTypes.AddRange(treeTypes); var xml = XDocument.Parse(kml); var ns = xml.Root.Name.Namespace; var blocks = xml.Descendants(ns + "Placemark"); var resultList = new List<Block>(); foreach (var item in blocks) { var resultBlock = new Block(); resultBlock.BoundingCoordinates = new List<Position>(); var treetypeName = item.Descendants(ns + "SimpleData").FirstOrDefault(); var treetypeNameString = treetypeName != null ? treetypeName.Value : "NOTDEFINED"; if (allTreeTypes.All(treeType => treeType.Name != treetypeNameString)) { var gayTreeType = new TreeType(treetypeNameString, NewTreeTypeColor(allTreeTypes)); resultBlock.TreeType = gayTreeType; allTreeTypes.Add(gayTreeType); } else { resultBlock.TreeType = allTreeTypes[allTreeTypes.IndexOf(new TreeType(treetypeNameString))]; } var cords = item.Descendants(ns + "coordinates"); resultBlock.BoundingCoordinates = GetCoordinates(cords); resultList.Add(resultBlock); } return resultList; }
/// <summary> /// Block selected event. /// </summary> /// <param name="block">Block that raises the selected event.</param> public void BlockSelectedEvent(Block block) { if (this.BlockSelected != null) { FieldHelper.SelectedBlock = block; this.BlockSelected(this, new BlockSelectedEventArgs(block)); } }
/// <summary> /// Maps the tapped. /// </summary> /// <param name="sender">The sender of the tapped event inside the map.</param> /// <param name="e">The arguments of the map tapped event.</param> private void MapTapped(object sender, MapTappedEventArgs e) { var tappedField = this.CheckFieldClicked(e.Position); if (tappedField != null) { this.SelectedField = tappedField; } if (e.Zoomlevel > 15) { var tappedBlock = this.CheckBlockClicked(e.Position); if (tappedBlock != null) { this.selectedBlock = tappedBlock; var navigationPage = (NavigationPage)Application.Current.MainPage; var informationViewModel = new InformationViewModel(this.SelectedField, this.SelectedBlock); navigationPage.PushAsync(new BlockInformationContentPage(informationViewModel)); } } }
/// <summary> /// Initializes a new instance of the <see cref="TreeWatch.BlockSelectedEventArgs"/> class. /// </summary> /// <param name="block">Block that through the event.</param> public BlockSelectedEventArgs(Block block) { this.Block = block; }