using System; using System.Windows.Forms; using ThinkGeo.MapSuite.Core; using ThinkGeo.MapSuite.DesktopEdition; using System.Threading; using System.Windows.Threading; using System.Collections.Generic; using System.Collections.ObjectModel; namespace CSharpWinformsSamples { public class DisplayShapeMap : UserControl { public DisplayShapeMap() { InitializeComponent(); repositioningThread = new Thread(new ThreadStart(ThreadStartingComputer)); repositioningThread.SetApartmentState(ApartmentState.STA); repositioningThread.Name = "ManageThread"; repositioningThread.Start(); } Thread repositioningThread; private DispatcherTimer dispather = new DispatcherTimer(); private DispatcherTimer dispather2 = new DispatcherTimer(); List points = new List(); List points2 = new List(); public bool finish = true; private void DisplayMap_Load(object sender, EventArgs e) { winformsMap1.MapUnit = GeographyUnit.DecimalDegree; winformsMap1.CurrentExtent = new RectangleShape(-118.098, 84.3, 118.098, -84.3); LayerOverlay staticOverlay = new LayerOverlay(); winformsMap1.Overlays.Add("staticOverlay", staticOverlay); Random radom = new Random(); for (int i = 0; i < 43000; i++) { points.Add(new PointShape(radom.Next(-180, 180), radom.Next(-90, 90)) { Id = i.ToString() }); } for (int i = 0; i < 4000; i++) { points2.Add(new PointShape(radom.Next(-180, 180), radom.Next(-90, 90)) { Id = i.ToString() }); } LayerOverlay overlay = new LayerOverlay(); for (int i = 0; i < 10; i++) { InMemoryFeatureLayer inmLayer = new InMemoryFeatureLayer(); inmLayer.Name = i.ToString(); inmLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20; if (i == 9) { inmLayer.ZoomLevelSet.ZoomLevel01.DefaultPointStyle = PointStyles.CreateSimplePointStyle(PointSymbolType.Circle, GeoColor.SimpleColors.Red, 3); } else { inmLayer.ZoomLevelSet.ZoomLevel01.DefaultPointStyle = PointStyles.CreateSimplePointStyle(PointSymbolType.Circle, GeoColor.SimpleColors.White, 3); } overlay.Layers.Add(i.ToString(), inmLayer); } winformsMap1.Overlays.Add("overlay", overlay); winformsMap1.Refresh(); dispather.Interval = TimeSpan.FromMilliseconds(1000); dispather.Tick += new EventHandler(timerScreenRefresh_Tick); dispather.Start(); dispather2.Interval = TimeSpan.FromMilliseconds(1000); dispather2.Tick += new EventHandler(timerScreenRefresh_Tick2); dispather2.Start(); } void timerScreenRefresh_Tick2(object sender, EventArgs e) { List tempPoints = points2; LayerOverlay ov = (LayerOverlay)winformsMap1.Overlays["overlay"]; Collection features = new Collection(); foreach (PointShape point in tempPoints) { Feature feature = new Feature(point.X, point.Y, point.Id + "plane"); feature.ColumnValues.Add("figure", point.Id); features.Add(feature); } for (int i = 0; i < 9; i++) { InMemoryFeatureLayer inmlayer = ov.Layers[i] as InMemoryFeatureLayer; lock (inmlayer) { inmlayer.InternalFeatures.Clear(); for (int n = 0; n < 4000; n++) { try { inmlayer.InternalFeatures.Add(features[n].Id, features[n]); } catch (System.Exception ex) { System.Diagnostics.Debug.WriteLine(ex); } } } } winformsMap1.Refresh(); } void timerScreenRefresh_Tick(object sender, EventArgs e) { List tempPoints = points; LayerOverlay ov = (LayerOverlay)winformsMap1.Overlays["overlay"]; Collection features = new Collection(); foreach (PointShape point in tempPoints) { Feature feature = new Feature(point.X, point.Y, point.Id + "plane"); feature.ColumnValues.Add("figure", point.Id); features.Add(feature); } InMemoryFeatureLayer inmlayer = ov.Layers[9] as InMemoryFeatureLayer; lock (inmlayer) { inmlayer.InternalFeatures.Clear(); for (int i = 0; i < features.Count; i++) { try { inmlayer.InternalFeatures.Add(features[i].Id, features[i]); } catch (System.Exception ex) { System.Diagnostics.Debug.WriteLine(ex); } } } winformsMap1.Refresh(); } private void ThreadStartingComputer() { while (finish) { foreach (PointShape point in points) { point.X = point.X + 0.2; } foreach (PointShape point in points2) { point.X = point.X - 0.1; } Thread.Sleep(500);//5????? } }