ThinkGeo.com    |     Documentation    |     Premium Support

InMemoryFeatureLayer not showing

I have some InMemoryFeatureLayers I’m trying to display. For some reason, they only show if I don’t have any other layers on the map. For instance, I have an Overlay containing a shapefile of the countries, and a background layer for the ocean. When I don’t add these to the map, the InMemoryFeatureLayer shows up fine. But when I do add them, the InMemoryFeatureLayer seems to be hidden behind the shapefile layers. How can I fix this?

In this case, the InMemoryFeatureLayer should just display some text at the given long/lat on the map.

Here’s my setup:

LayerOverlay textOverlay = new LayerOverlay(); //holds all the text labels
LayerOverlay worldOverlay = new LayerOverlay(); //holds the background world/ocean layer

private void Map1_Loaded(object sender, RoutedEventArgs e)
{
    Map1.MapUnit = GeographyUnit.DecimalDegree;
    
    ShapeFileFeatureLayer worldLayer = new ShapeFileFeatureLayer("filepath_to_countries.shp");
    AreaStyle areaStyle = new AreaStyle();
    areaStyle.FillSolidBrush = new GeoSolidBrush(GeoColor.FromArgb(255, 233, 232, 214));
    areaStyle.OutlinePen = new GeoPen(GeoColor.FromArgb(255, 118, 138, 69), 1);
    areaStyle.OutlinePen.DashStyle = LineDashStyle.Solid;
    worldLayer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle = areaStyle;
    worldLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;
    worldLayer.Name = "World Layer";

    worldOverlay.Layers.Add(new BackgroundLayer(new GeoSolidBrush(GeoColor.GeographicColors.ShallowOcean)));
    worldOverlay.Layers.Add("World Layer", worldLayer);
    InMemoryFeatureLayer textLayer = new InMemoryFeatureLayer();
    textLayer.Name = "Text Layer";
    textOverlay.Layers.Add("Text Layer", textLayer);

    Map1.Overlays.Add("World Overlay", worldOverlay);
    textOverlay.Name = "Text Overlay";
    Map1.Overlays.Add("Text Overlay", textOverlay);
}

//function that adds text as an inmemoryfeaturelayer
private void AddText()
{
    InMemoryFeatureLayer layer = textOverlay.Layers[0] as InMemoryFeatureLayer;
    Feature feature = new Feature(-100, 30);
    feature.ColumnValues.Add("TestLabel", "testText");
    layer.InternalFeatures.Add(feature);

    layer.ZoomLevelSet.ZoomLevel01.DefaultTextStyle = new TextStyle("textName", new GeoFont("arial", 20, DrawingFontStyles.Bold), new GeoSolidBrush(GeoColors.Red));

    layer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;

    textOverlay.Refresh();
}

Thanks,
Dan

Hi Dan,

I hadn’t found problem from your code and hadn’t reproduced that by my simple sample.

I guess that’s maybe related with some other reason for example dll version, data.

So could you please upload your test sample with data, so I can reproduce that first.

Regards,

Ethan

Sorry I can’t upload the complete code because it has some sensitive info, but the code I posted above is all the code related to the issue. I made a new application as well with just the above code, and it has the same problem. It’s only when I take away the “worldOverlay”, does the InMemoryFeatureLayer show up properly. Can’t figure out why.

I’m adding the files to this onedrive link: https://1drv.ms/f/s!Aumr3sAYPp0bjAeYKgvucakJ-AEQ The project solution and the shape file being used for the world layer are in the zip files.

How it works:

There’s a textbox at the top of the window. This takes a “command” of a certain format like this:

add text textlabel=long,lat,textToDisplay

So an example would be:

add text State=-100,30,Texas

If you copy and paste the above line in the textbox, and hit the button, the map should display “Texas” in red over the state of Texas. However, it doesn’t appear.

The main part is at line 171 at the AddText function.

Let me know if you have any questions, thanks!

Hi Dan,

We checked your code, you are setting the incorrect column when using text style:

Your source code:

layer.ZoomLevelSet.ZoomLevel01.DefaultTextStyle = new TextStyle("textName", new GeoFont("arial", 20, DrawingFontStyles.Bold), new GeoSolidBrush(GeoColors.Red));

The “textName” is a variable not a string, if you want to use string, please use “State” directly.
You should change your code as following statements:

layer.ZoomLevelSet.ZoomLevel01.DefaultTextStyle = new TextStyle(textName, new GeoFont("arial", 20, DrawingFontStyles.Bold), new GeoSolidBrush(GeoColors.Red));

Here is test result:

If you meet any issue, please let me know that.

Thanks
Mark

Works perfect now. Thank you very much!

Hi Dan,

Any question please let us know.

Regards,

Ethan