ThinkGeo.com    |     Documentation    |     Premium Support

How to add labels to InternalFeatures

I am plotting vehicle positions on a map pulled from a database, and under each I need a label displaying the name the car, for example "Bob's Car". I have looked in the documentation but it is not clear to me on how to do this. Here is some of my sample code:

  InMemoryFeatureLayer
            bitmapLayer = new InMemoryFeatureLayer();
            bitmapLayer.ZoomLevelSet.ZoomLevel01.DefaultPointStyle.PointType = PointType.Bitmap;
            bitmapLayer.ZoomLevelSet.ZoomLevel01.DefaultPointStyle.Image = new GeoImage(@"c:\MapIcons\charger.png");
            bitmapLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;
            bitmapLayer.ZoomLevelSet.ZoomLevel01.DefaultTextStyle = TextStyles.CreateSimpleTextStyle(null, "Arial", 9, DrawingFontStyles.Bold, GeoColor.SimpleColors.Black);
            winformsMap1.StaticOverlay.Layers.Add("BitmapLayer", bitmapLayer);
            // Plot single marker for testing
            bitmapLayer.InternalFeatures.Add("Bob's Car", new Feature(new PointShape(-85.1511, 33.6855)));
            winformsMap1.Refresh();



Steve,


This is actually fairly easy to setup, but the documentation is a bit sparse on setting this up.


First you need to setup Columns for your InMemoryLayer to contain your label information.


InMemoryFeatureLayer inMemoryLayer = new InMemoryFeatureLayer();

inMemoryLayer.Columns.Add(new FeatureSourceColumn("Label1"));



Next you need to create your new Feature and add the ColumnValue data for it.



Feature testFeature = new Feature(new PointShape(45, 45));

testFeature.ColumnValues.Add("Label1", "TEST LABEL");

inMemoryLayer.InternalFeatures.Add(testFeature);

inMemoryLayer.ZoomLevelSet.ZoomLevel01.DefaultTextStyle = TextStyles.City1("Label1");

inMemoryLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;


Note that if you setup a Column for your InMemoryLayer that all the InternalFeatures you add must have a ColumnValue specified for that Column. That is to say that you need to have either valid data or a blank string for the Label1 ColumnValue for all your features.