for (int i = 0; i < MAX_TARGETS; i++) { if (!(hideUnknownTracks && targets<i>.trackClass == trackClassificationEnum.UNKNOWN)) { if ((targets<i>.timeLapseComms < TARGET_DROP_TIMEOUT && targets<i>.trackStatus == trackStatusEnum.TARGET_ACTIVE) || i == selectedIconTrackIndex) {
If I comment the "add lineshape feature" line, the code works fine showing tracks from our AIS receiver, otherwise I get the error after building up enough track history.
I know this is a pretty inefficient way to do this, but until I get a better understanding of MapSuite, this is how I can best understand what is going on.
I cannot compile your code successfully because of some variables are not defined, so I cannot reproduce your problem exactly, I just made a simple sample and try to reproduce the exception what you occurred, the sample code is very easy, here is the code below:
private void button1_Click(object sender, EventArgs e) { Collection<Vertex> verteices1 = new Collection<Vertex>(); verteices1.Add(new Vertex(0.2, 0.5)); verteices1.Add(new Vertex(0.8, 60.2)); verteices1.Add(new Vertex(1.8, 70.1)); LineShape lineShape2 = new LineShape(verteices1); Feature feature = new Feature(lineShape2); InMemoryFeatureLayer inMemoryLayer = new InMemoryFeatureLayer(); inMemoryLayer.InternalFeatures.Add("Test", feature); inMemoryLayer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle.FillSolidBrush.Color = GeoColor.FromArgb(100, GeoColor.StandardColors.RoyalBlue); inMemoryLayer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle.OutlinePen.Color = GeoColor.StandardColors.Blue; inMemoryLayer.ZoomLevelSet.ZoomLevel01.DefaultLineStyle.OuterPen = new GeoPen(GeoColor.FromArgb(200, GeoColor.StandardColors.Red), 5); inMemoryLayer.ZoomLevelSet.ZoomLevel01.DefaultPointStyle.SymbolPen = new GeoPen(GeoColor.FromArgb(255, GeoColor.StandardColors.Green), 8); inMemoryLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;
LayerOverlay staticOverlay = new LayerOverlay(); staticOverlay.Layers.Add("InMemoryFeatureLayer", inMemoryLayer); winformsMap1.Overlays.Add(staticOverlay); winformsMap1.CurrentExtent = new RectangleShape(0, 100, 100, 0); winformsMap1.Refresh(); }
According to my test, it can work fine, I cannot find out any exceptions, please review your code or send us a complete sample so that we can reproduce this problem exactly,
Getting my code to run as it does here might be tricky, so I cut the code out of the timer event and placed a simplified version of it into the initialization section and I get the same exception. I think if I can figure out why it fails here, it will shed light on why it fails in the timer as well.
// Something bad gets done to the map in here winformsMap.Overlays["Tracks|Friendly"].Lock.EnterWriteLock(); LayerOverlay trackLayerOverlay = (LayerOverlay)winformsMap.Overlays["Tracks|Friendly"]; InMemoryFeatureLayer trackInMemoryFeatureLayer = (InMemoryFeatureLayer)trackLayerOverlay.Layers[0];
Feature feature = new Feature(new LineShape("LINESTRING(-76.286 36.827, -76.100 36.600)")); trackInMemoryFeatureLayer.InternalFeatures.Add("ID", feature); winformsMap.Overlays["Tracks|Friendly"].Lock.ExitWriteLock(); // end of bad stuff
winformsMap.Refresh(); // Exception thrown from here
I would like to know if you get the same exception with this code that I do. (The code in the last post I made) If you are missing something, let me know. I am not making any progress as I don't understand what the exception is trying to tell me.
Thanks for your response. I am ashamed with my misunderstanding and I should have tried your code.
I think the problem is when the feature is added, the corresponding column value was not added which will be used for labeling. I change a bit for the code and have a try on the following code, it should work. // INIT ThinkGeo MapSuite try { winformsMap1.MapUnit = GeographyUnit.DecimalDegree; winformsMap1.BackgroundOverlay.BackgroundBrush = new GeoSolidBrush(GeoColor.GeographicColors.DeepOcean); winformsMap1.CenterAt(new PointShape(-76.286, 36.827)); winformsMap1.ZoomToScale(winformsMap1.ZoomLevelSet.ZoomLevel11.Scale);
worldMapKitRenderLayer = new WorldMapKitRenderLayer(@"D:\data\ThinkGeo\ThinkGeoWorldMapKit"); worldMapKitRenderLayer.LoadLayers();
LayerOverlay worldMapKitRenderLayerOverlay = new LayerOverlay(); worldMapKitRenderLayerOverlay.Layers.Add(worldMapKitRenderLayer); winformsMap1.Overlays.Add(worldMapKitRenderLayerOverlay);
InMemoryFeatureLayer tracksFriendlyInMemoryFeatureLayer = new InMemoryFeatureLayer(); tracksFriendlyInMemoryFeatureLayer.Open(); tracksFriendlyInMemoryFeatureLayer.Columns.Add(new FeatureSourceColumn("Label")); tracksFriendlyInMemoryFeatureLayer.Close(); tracksFriendlyInMemoryFeatureLayer.ZoomLevelSet.ZoomLevel01.DefaultTextStyle = new TextStyle("Label", new GeoFont("Verdana", 10, DrawingFontStyles.Bold), new GeoSolidBrush(GeoColor.StandardColors.White)); tracksFriendlyInMemoryFeatureLayer.ZoomLevelSet.ZoomLevel01.DefaultTextStyle.BestPlacement = true; tracksFriendlyInMemoryFeatureLayer.ZoomLevelSet.ZoomLevel01.DefaultTextStyle.PointPlacement = PointPlacement.CenterRight; tracksFriendlyInMemoryFeatureLayer.ZoomLevelSet.ZoomLevel01.DefaultTextStyle.HaloPen = new GeoPen(GeoColor.StandardColors.Black, 1); tracksFriendlyInMemoryFeatureLayer.ZoomLevelSet.ZoomLevel01.DefaultLineStyle.OuterPen = new GeoPen(GeoColor.StandardColors.DarkGreen, 2); tracksFriendlyInMemoryFeatureLayer.ZoomLevelSet.ZoomLevel01.DefaultPointStyle = new PointStyle(PointSymbolType.Square, new GeoSolidBrush(GeoColor.StandardColors.Green), new GeoPen(GeoColor.StandardColors.DarkGreen, 2), 10); tracksFriendlyInMemoryFeatureLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;
LayerOverlay tracksFriendlyLayerOverlay = new LayerOverlay(); tracksFriendlyLayerOverlay.Layers.Add(tracksFriendlyInMemoryFeatureLayer);
// Something bad gets done to the map in here winformsMap1.Overlays["Tracks|Friendly"].Lock.EnterWriteLock(); LayerOverlay trackLayerOverlay = (LayerOverlay)winformsMap1.Overlays["Tracks|Friendly"]; InMemoryFeatureLayer trackInMemoryFeatureLayer = (InMemoryFeatureLayer)trackLayerOverlay.Layers[0];
Feature feature = new Feature(new LineShape("LINESTRING(-76.286 36.827, -76.100 36.600)")); feature.ColumnValues.Add("Label", "Add Label Here"); trackInMemoryFeatureLayer.InternalFeatures.Add("ID", feature); winformsMap1.Overlays["Tracks|Friendly"].Lock.ExitWriteLock(); // end of bad stuff
winformsMap1.Refresh(); // Exception thrown from here } catch (Exception Exception) { //log.Enqueue("Problem initializing mapping tools: " + Exception.Message); System.Diagnostics.Debug.WriteLine(Exception.Message); }