private async Task AddGraphicsToGraphicsLayer() { for (int i = 0; i < 100; i++) { // time-consuming operation await Task.Delay(50); Graphic g = new Graphic() { Geometry = GetRandomPolygon(), }; MyGraphicsLayer.Graphics.Add(g); } }
for (int i = 0; i < 100; i++) { Graphic g = new Graphic() { Geometry = GetRandomPolygon(), }; graphics.Add(g); await Task.Delay(50); } MyGraphicsLayer.Graphics.AddRange(graphics);
private void Button_Click(object sender, RoutedEventArgs e) { try { var _ = AddGraphicsToGraphicsLayer(); } catch (System.Exception) { MessageBox.Show("Error"); } MessageBox.Show("Done"); } private async Task AddGraphicsToGraphicsLayer() { List<Graphic> graphics = new List<Graphic>(); for (int i = 0; i < 100; i++) { Graphic g = new Graphic() { Geometry = GetRandomPolygon(), }; graphics.Add(g); await Task.Delay(50); } MyGraphicsLayer.Graphics.AddRange(graphics); } Random random = new Random(); private Polygon GetRandomPolygon() { Polygon polygon = new Polygon(); ESRI.ArcGIS.Client.Geometry.PointCollection pointCollection = new ESRI.ArcGIS.Client.Geometry.PointCollection(); MapPoint mapPoint = new MapPoint(random.Next(-20000000, 20000000), random.Next(-20000000, 20000000)); MapPoint mapPoint2 = new MapPoint(random.Next(-20000000, 20000000), random.Next(-20000000, 20000000)); MapPoint mapPoint3 = new MapPoint(random.Next(-20000000, 20000000), random.Next(-20000000, 20000000)); pointCollection.Add(mapPoint); pointCollection.Add(mapPoint2); pointCollection.Add(mapPoint3); polygon.Rings.Add(pointCollection); return polygon; }
Aangemelde leden kunnen berichten plaatsen, updates volgen en meer. Nieuw hier? Registreer een gratis account.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.