ThinkGeo.com    |     Documentation    |     Premium Support

Adding Custom Labels

How would I add a custom label to a feature in a newly added layer.


What I'm doing is merging features from several shape files together. Once the features are merged I'd like to add a label to the newly merged feature. The text is not in the associated data file. So how would I add a custom label? The examples I've seen here on the discussion forums appear to be for prior versions, not V3 beta. Although it's very likely that I'm just confused.


Bob Mc.



Bob, Thanks for the post!


There is a and example of something close to this in the sample application called "Add custom data to a vector layer" under the "Query Vector Layers" section at: 


websamples.thinkgeo.com/webeditionsamples/  (Note: the code to these sample applications are included with the eval download).


I don't think this sample does exactly what you want, but it shows how you can use the Custom Data feature of the control to do labeling and add other data isn't natively in the feature.  Once the custom data is added to the feature it can be labeled just like any other type of native data.


Let us know if you have any questions or run into any issues.


Thanks!


 



Thanks Batman,


What I tried was:


mapShapeLayer.Features(featureKey).ColumnValues.Add("MyCol", "colData")

mapShapeLayer.ZoomLevelSet.ZoomLevel01.DefaultTextStyle = TextStyles.City1("MyCol")

mapShapeLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20


which adds the column to the feature correctly but does not display the label.


Any thoughts on why?


Bob Mc.



Additional note: I tried this with an existing column in the feature as well, and no label. Apparently I’m missing something fundamental with displaying labels.

Additional additional note: 
 I tried loading a shape file into the StaticLayers collection and I was able to see layers. That was good. But it wiped out my Google Map background layer (bad). And the layer I really want to display labels for is a dynamic layer that I’m creating from several merged features from a shape file. It looks kind of like this: 
  
                 mapShapeLayer = New InMemoryLayer 
  
                 For Each Item I want to merge 
                     targetShape = CType(theFeature.GetShape, AreaBaseShape) 
                     mapShapeLayer.Open() 
                     mapShapeLayer.EditTools.BeginTransaction() 
                     mapShapeLayer.EditTools.Union(mapShapeLayer.Features.Item(firstKey).Id, targetShape) 
                     mapShapeLayer.EditTools.Delete(zipFeature.Id) 
                     Dim unionResults As TransactionResult = mapShapeLayer.EditTools.CommitTransaction() 
                     mapShapeLayer.Close() 
                 Next 
  
                 mapShapeLayer.Open() 
                 mapShapeLayer.Name = “Layer Name” 
                 mapShapeLayer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle.FillSolidBrush.Color = GeoColor.FromArgb(50, GeoColor.SimpleColors.LightRed) 
                 mapShapeLayer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle.OutlinePen.Color = GeoColor.FromArgb(255, GeoColor.SimpleColors.Black) 
  
                 mapShapeLayer.ZoomLevelSet.ZoomLevel01.DefaultTextStyle = TextStyles.City1(“LABEL_COL”) 
                 mapShapeLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20 
  
                 mapShapeLayer.Close() 
  
                 ctlDirMap.DynamicLayers.Add(“Layer Name”, mapShapeLayer) 
  
 Bob Mc.

Bob,


Atttached is some code that I added to the the end of the Page_Load event  in the CreateAnInMemoryVectorLayer sample app at under DataProviders section.  I believe this is pretty close to what you need.


Let me know if this helps and gets your labels displaying.


Thanks!



34-Code.txt (1.46 KB)

Thanks Batman. I was able to take your example and fit it to my situation and the labels are now displaying. Thanks! It looks like the fix was to add "FeatureColumns" to my new InMemoryLayer before merging other features.


Thanks again,


Bob Mc.


 



Glad I could be of help. 


Let us know if you run into anymore problems or have suggestions for enhancements.




Thanks!



Hello, 
  
 I want to display label on my features and I’ve got the same problem. 
 But in the last version, the InMemoryLabelLayer doesn’t exist anymore. How can I fix this problem ? 
  
 Thanks.

Pierre, 
  
 We’ve renamed InMemoryLayer to InMemoryFeatureLayer,  We didn’t have InMemoryLabelLayer, the FeatureLayer can render both features and labels. 
  
 Thanks, 
  
 Ben

Hello, 
  
 Thanks for your answer.

Always my pleasure. :-)