ThinkGeo.com    |     Documentation    |     Premium Support

Text overlay that stays with polygons

 


Hi,


In the application that I am working on we use a satellite image map. On that image map we put a layer of polygons lines and rectangles to display vehicles and display the vehicle states. (I am still not sure there is enough control of the color of the individual polygons colors) So far all is moving forward. Now we want to display an ID number on the vehicle that is visible at ZoomLevel14 to ZoomLevel20 and have it track the vehicle (which is a group of polygons)


I tried to use the RotatingTextStyle example but when I executed this line of code. 


 



VehicleOverlay.Columns.Add(new FeatureSourceColumn(vehicleid + "_name"));


The I could no longer refresh my StaticOverlay no longer had a name. ??? So when I executed this line


the application threw an exception. 



winformsMap1.Refresh(winformsMap1.Overlays[


"VehicleOverlay"]);   


 


I have so much to learn. Hope you can help even though this is a very small snipet of code but why would the name of the overlay be altered by adding this columns ?


 



I answered my own question. I was able to do this by combining to menthods.  
  
 First for the layers ----  
  
 inMemoryLayer.ZoomLevelSet.ZoomLevel01.DefaultTextStyle.PointPlacement = PointPlacement.UpperCenter; 
 inMemoryLayer.ZoomLevelSet.ZoomLevel01.DefaultTextStyle.OverlappingRule = LabelOverlappingRule.NoOverlapping; 
 inMemoryLayer.ZoomLevelSet.ZoomLevel01.DefaultTextStyle.DuplicateRule = LabelDuplicateRule.NoDuplicateLabels; 
 inMemoryLayer.ZoomLevelSet.ZoomLevel01.DefaultTextStyle = new TextStyle("YourColName", new GeoFont("Arial", 10), new GeoSolidBrush(GeoColor.SimpleColors.Yellow));          
 … 
 Add your geometry  
 … 
  
 Then to get a label to show up on the polygon you need to create an event handler and add it to your inMemoryFeatureLayer 
 inMemoryLayer.FeatureSource.CustomColumnFetch += new EventHandler<CustomColumnFetchEventArgs>(FeatureSource_CustomColumnFetch);    
  
  
      // call back for labels. 
      void FeatureSource_CustomColumnFetch(object sender, CustomColumnFetchEventArgs e) 
      {         
       if (e.ColumnName = "YourColName")   
         { 
          e.ColumnValue = "DisplayText";   // label that will be displayed 
         } 
      }  
  
  


 If you want to display the labels and the symbols for the vehicles, you need to create two InMemoryFeatureLayers. One for the geometry of the features (symbols) and another one for the labels. You can look at the sample code below. If you want to update the position of the vehicles, you need to edit the shape of the features. We have some projects in the Code Community that show how to do that such as the last one code.thinkgeo.com/projects/show/centeringtolerance. Here a point based feature is updated, but the same principle applies for polygons or lines.


I hope that from the Code Community project and the sample code, you will have a better idea on how to proceed for your own needs.


 



//InMemoryFeatureLayer for the geometry of the features
            InMemoryFeatureLayer inMemoryFeatureLayer = new InMemoryFeatureLayer();
            inMemoryFeatureLayer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle = AreaStyles.CreateSimpleAreaStyle(GeoColor.StandardColors.Red, GeoColor.StandardColors.Black);
            inMemoryFeatureLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;

            //InMemoryFeatureLayer for the label of the features
            InMemoryFeatureLayer labelInMemoryFeatureLayer = new InMemoryFeatureLayer();
            labelInMemoryFeatureLayer.Open();
            labelInMemoryFeatureLayer.Columns.Add(new FeatureSourceColumn("VehicleName"));
            labelInMemoryFeatureLayer.Close();
            labelInMemoryFeatureLayer.ZoomLevelSet.ZoomLevel01.DefaultTextStyle = TextStyles.LocalRoad2("VehicleName");
            labelInMemoryFeatureLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;


            Feature newFeature = new Feature(myPolygonShape);
            newFeature.ColumnValues["VehicleName"] = "My Vehicle"; 
 
            inMemoryFeatureLayer.Open();
            inMemoryFeatureLayer.EditTools.BeginTransaction();
            inMemoryFeatureLayer.EditTools.Add(newFeature);
            inMemoryFeatureLayer.EditTools.CommitTransaction();
            inMemoryFeatureLayer.Close();

            labelInMemoryFeatureLayer.Open();
            labelInMemoryFeatureLayer.EditTools.BeginTransaction();
            labelInMemoryFeatureLayer.EditTools.Add(newFeature);
            labelInMemoryFeatureLayer.EditTools.CommitTransaction();
            labelInMemoryFeatureLayer.Close();

            LayerOverlay vehicleOverlay = new LayerOverlay();
            vehicleOverlay.Layers.Add("Vehicle", inMemoryFeatureLayer);
            vehicleOverlay.Layers.Add("VehicleLabel", labelInMemoryFeatureLayer);

            winformsMap1.Overlays.Add(vehicleOverlay);

            winformsMap1.Refresh(vehicleOverlay);


Seems like it could all be done in one layer.   
 Here is  piece I did not see anywhere else  
  
 Feature newFeature = new Feature(myPolygonShape); 
 newFeature.ColumnValues["VehicleName"] = "My Vehicle";  
  
 Thanks Val.  


Rob, 
  
 Hope it’s working with you, thank Val’s sharing. 
  
 The code is about adding value to the specific column, it will be used for TextStyle which will get the column value by the column name as text to draw on the map.  
 If I misunderstood, please let me know. 
  
 Thanks 
 James

My mind is trying to understand why I have to tie a labels to data columns with values in them. I have static labels not dynamic. That said I am going to work my way through it. Getting the correct size via the zoom levels seems difficult. It doesnt seem linear.  


Concerning your comment on getting the correct size of the labels thru the zoom levels, i let you know that you can implement your own type of TextStyle with the size dependent on the scale for example. In the Code Community, we have a couple of project that show how to do that. 
  I suggest you check that out. 
  
 code.thinkgeo.com/projects/show/scalingtextstyle  
  
 Also, there is project that shows how to have a labels displaying at real world size. You might that this interesting. 
  
 code.thinkgeo.com/projects/show/worldsizedtextstyle

Thanks a bunch Val. I am going through the projects and looking at the code.  
 I really feel like I am missing some fundamentals or some documentation. I can’t seem to connect the dots properly on how this stuff goes together. There are LayerOverlay’s and InMemoryFeatureLayer’s and Data Columns ?? and Features and FeatureSource that tie text together in some way to a data column to control what shows up on the screen. The more I need to customize the more lost I am feeling.

Bob, 
  
 I will try and write up a nice description but for now I would suggest you check out a couple of learning videos we have put together. 
  
 The key ones would be (in my suggested order) 
  
 1. Integrating Custom Data Formats (This will teach you about feature sources, features, and some layers) 
 2. Creating Custom Styles (this will teach you about styles and also about data columns etc) 
 3. Exploring Layers (this will teach you about layers in more detail and about layers without features) 
  
 gis.thinkgeo.com/Products/GISComponentsforNETDevelopers/MapSuiteDesktopEdition/Videos/tabid/679/Default.aspx 
  
 David