/// <summary> /// Load dummy pushpins at design-time /// </summary> /// <param name="layer">The layer to which the downloaded pushpins will be associated.</param> /// <param name="pushpins">The PushpinModel collection to be populated.</param> public static void LoadPushpinsAsync(LayerModel layer, Collection<PushpinModel> pushpins) { PushpinModel pushpin1 = new PushpinModel { Guid = Guid.NewGuid().ToString(), Description = "Design-Time Description", Layer = layer, Location = new GeoCoordinate(48.8925, 2.3449) }; PushpinModel pushpin2 = new PushpinModel { Guid = Guid.NewGuid().ToString(), Description = "Design-Time Description", Layer = layer, Location = new GeoCoordinate(48.8875, 2.3882) }; PushpinModel pushpin3 = new PushpinModel { Guid = Guid.NewGuid().ToString(), Description = "Design-Time Description", Layer = layer, Location = new GeoCoordinate(48.8766, 2.3555) }; PushpinModel pushpin4 = new PushpinModel { Guid = Guid.NewGuid().ToString(), Description = "Design-Time Description", Layer = layer, Location = new GeoCoordinate(48.8641, 2.3977) }; PushpinModel pushpin5 = new PushpinModel { Guid = Guid.NewGuid().ToString(), Description = "Design-Time Description", Layer = layer, Location = new GeoCoordinate(48.8327, 2.3261) }; PushpinModel pushpin6 = new PushpinModel { Guid = Guid.NewGuid().ToString(), Description = "Design-Time Description", Layer = layer, Location = new GeoCoordinate(48.8166, 2.3605) }; pushpins.Add(pushpin1); pushpins.Add(pushpin2); pushpins.Add(pushpin3); pushpins.Add(pushpin4); pushpins.Add(pushpin5); pushpins.Add(pushpin6); }
/// <summary> /// Helper method to asynchronously load pushpins associated with the supplied layer and populate the pushpins collection supplied as a parameter. /// </summary> /// <param name="layer">The layer to which the downloaded pushpins will be associated.</param> /// <param name="pushpins">The PushpinModel collection to be populated.</param> public static void LoadPushpinsAsync(LayerModel layer, Collection<PushpinModel> pushpins) { LayerAndPushpin layerAndPushpin = new LayerAndPushpin { LayerModel = layer, PushpinModels = pushpins }; WebClient client = new WebClient(); client.DownloadStringCompleted += new DownloadStringCompletedEventHandler(LoadPushpinsAsync_DownloadStringCompleted); client.DownloadStringAsync(new Uri(layer.Link), layerAndPushpin); }
private static void LoadLayersAsync_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e) { WebClient client = sender as WebClient; Collection<LayerModel> layers = e.UserState as Collection<LayerModel>; if (layers == null) { throw new ArgumentNullException("layers", "The layers parameter provided to the LoadLayersAsync method is null."); } if (e.Error != null) { throw e.Error; } XElement root = XElement.Parse(e.Result); XNamespace atom = "http://www.w3.org/2005/Atom"; var entries = from entry in root.Descendants(atom + "entry") select new { Id = entry.Element(atom + "id").Value, Title = entry.Element(atom + "title").Value, Summary = entry.Element(atom + "summary").Value, Link = entry.Elements(atom + "link").First(elm => elm.Attribute("type").Value == "application/vnd.google-earth.kml+xml").Attribute("href").Value, ImageLink = entry.Elements(atom + "link").First(elm => elm.Attribute("type").Value == "image/png").Attribute("href").Value }; BackgroundWorker worker = new BackgroundWorker(); worker.DoWork += (send, evt) => { foreach (var entry in entries) { LayerModel model = new LayerModel { Id = entry.Id, Title = entry.Title, Summary = entry.Summary, Link = entry.Link, ImageLink = entry.ImageLink.StartsWith("http") ? entry.ImageLink : App.OdafWebsiteUrl + "/" + entry.ImageLink }; Deployment.Current.Dispatcher.BeginInvoke(() => { layers.Add(model); }); } }; worker.RunWorkerAsync(); }