ThinkGeo.com    |     Documentation    |     Premium Support

Help with FeatureLayerWpfDrawingOverlay

Hello,

I currently have an application that plots points on a map. The points are currently in a layer, which is in LayerOverlay.

I’ve been trying to convert to using a FeatureLayerWpfDrawingLayer but have run into a problem.

Whenever I attempt to call MapView.RefreshAsync or _pointOVerlay.RefreshAsync() I get a NullReferenceException. The full stack trace is

at ThinkGeo.UI.Wpf.FeatureLayerWpfDrawingOverlay.zEc=.MoveNext()
at ThinkGeo.UI.Wpf.FeatureLayerWpfDrawingOverlay.qEE=.MoveNext()
at ThinkGeo.UI.Wpf.Overlay.Tkg=.MoveNext()
at ThinkGeo.UI.Wpf.Overlay.wkU=(Exception e, String memberName)
at ThinkGeo.UI.Wpf.Overlay.Tkg=.MoveNext()
at ThinkGeo.UI.Wpf.MapViewBase.7kc=.MoveNext()
at ThinkGeo.UI.Wpf.MapViewBase.8Ec=.MoveNext()
at ThinkGeo.UI.Wpf.MapViewBase.7Uc=.MoveNext()
at ThinkGeo.UI.Wpf.MapViewBase.7Ec=.MoveNext()
at ThinkGeo.UI.Wpf.MapViewBase.F0g=.MoveNext()
at ThinkGeo.UI.Wpf.MapViewBase.Fkg=.MoveNext()
at ADISSView.WPF.UI.Mapping.MapViewHostV2.d__12.MoveNext()

The relevent parts of my code are…

from the xaml.
<thinkgeo:MapView x:Name=“MapView” MapUnit=“Meter” Loaded=“MapView_OnLoaded”/>

from xaml.cs
private LayerOverlay _backgroundOverlay = new LayerOverlay();
private FeatureLayerWpfDrawingOverlay _pointOverlay = new FeatureLayerWpfDrawingOverlay();

private async void MapView_OnLoaded(object sender, RoutedEventArgs e) {
var basemapOverlay = new OpenStreetMapOverlay(…);

MapView.Overlays.Add("basemapOverlay", basemapOverlay);
MapView.Overlays.Add("backgroundOverlay", _backgroundOverlay);
MapView.Overlays.Add("pointOverlay", _pointOverlay);

await MapView.RefreshAsync();

CreateValueStyle();

}

public async Task PlotTrips(List tripsToPlot) {
var converter = new ProjectionConverter(4326, 3857);

foreach (var trip in tripsToPlot) {
    string layerName = $"trip-{trip.TripNumber}";

    if (_pointOverlay.FeatureLayers.Contains(layerName)) {
        continue;
    }

    var layer = new InMemoryFeatureLayer();

    converter.Open();

    foreach (var point in trip.Points) {
        var vertex = converter.ConvertToExternalProjection(point.CenterLon, point.CenterLat);
        var feature = new Feature(vertex);

        layer.InternalFeatures.Add(point.PointId.ToString(), feature);
    }

    converter.Close();

    layer.ZoomLevelSet.ZoomLevel01.DefaultPointStyle = PointStyle.CreateSimplePointStyle(PointSymbolType.Circle, GeoColors.Red, 5);
    layer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;

    _pointOverlay.FeatureLayers.Add(layerName, layer);
}

try {
    await MapView.RefreshAsync();
}
catch (Exception ex) {
    Console.WriteLine(ex.Message);
}

}

If I switch the overlay to a standared LayerOverlay (and adjust the code accordingly) it all works fine.
I’m just wondering if there’s something I’m missing.

Regards,

Aaron

Hi Aaron,

The issue was recreated and fixed in the latest beta122, can you pull the latest and have another try? We are aiming for having v14.5 released which will include all the bug fixes in the beta branch.

Thanks,
Ben

Thanks Ben.

Switching to the latest beta solved the problem.
It does seem that it is much slower when zooming in and out compared to the standard LayerOverlay.

As it’s beta I"m guessing there’s still work to be done. I’m just glad it’s working.

Regards,

Aaron

Hi Aaron,

When zooming in/out, FeatureLayerWpfDrawingOverlay renders all the features on the fly, while LayerOverlay just stretches the pre-rendered images, which means WpfDrawingOverlay will be slower when you have many features to render in the layer. I’d suggest avoiding displaying too many features, nor displaying complicated features on the map if possible. Just let us know the details of your project and we might provide more tricks about the performance.

Thanks,
Ben

Hello Ben,

Thanks for the feedback. This particular project is mostly just plotting simple markers on a map, but it could be anywhere from 1000 to 20,000+ markers. And unfortunately they do all need to be plotted.

Hi Aaron,

Here we created a sample with 20,000 markers in MarkerOverlay + Cluster, have a try and see if this is a better fit.

MarkerClusterSample_Post12344.zip (6.6 KB)

Thanks,
Ben