ThinkGeo.com    |     Documentation    |     Premium Support

TrackMode not starting until map extent change

Hi,

I use this basic code to draw shapes. The only difference between this and your HowDoI samples is that I use an override on the TrackInteractiveOverlay to define a start and end vertices for a measuring tool.

The problem I am seeing is that once this code is run, if I click the map, the drawing doesn’t begin. Only when I pan or zoom on the map does the TrackMode actual start. Any ideas what is missing from the track overlay to get it to initialize?

CustomTrackInteractiveOverlay track = new CustomTrackInteractiveOverlay();

        WinMap.TrackOverlay = track;
        track.TrackShapeLayer.ZoomLevelSet = GeoHelper.SetZoomLevels(WinMap.ZoomLevelSet,
            track.TrackShapeLayer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle);
        track.TrackShapeLayer.FeatureSource.ProjectionConverter = new GdalProjectionConverter(FromCRS.Proj4, FromCRS.Proj4);

        if (WinMap.EditOverlay.GetType() == typeof(SnapOverlay))
        {
            track.TrackStarting += Track_TrackStarting;
            track.TrackEnding += Track_TrackEnding;
            track.VertexAdding += Track_VertexAdding;
        }

        // There is always track ended
        track.TrackEnded += Track_TrackEnded;

        switch (shapeType)
        {
            case WellKnownType.GeometryCollection:
                break;
            case WellKnownType.Invalid:
                break;
            case WellKnownType.Line:
                WinMap.TrackOverlay.TrackMode = TrackMode.StraightLine;
                track.TrackShapeLayer.ZoomLevelSet = GeoHelper.SetZoomLevels(WinMap.ZoomLevelSet,
                    GeoHelper.DefaultLineStyle);
                break;
            case WellKnownType.Multiline:
                WinMap.TrackOverlay.TrackMode = TrackMode.Line;
                track.TrackShapeLayer.ZoomLevelSet = GeoHelper.SetZoomLevels(WinMap.ZoomLevelSet,
                    GeoHelper.DefaultLineStyle);
                break;
            case WellKnownType.Multipoint:
                WinMap.TrackOverlay.TrackMode = TrackMode.Point;
                track.TrackShapeLayer.ZoomLevelSet = GeoHelper.SetZoomLevels(WinMap.ZoomLevelSet,
                    GeoHelper.DefaultPointStyle);
                break;
            case WellKnownType.Multipolygon:
                WinMap.TrackOverlay.TrackMode = TrackMode.Polygon;
                track.TrackShapeLayer.ZoomLevelSet = GeoHelper.SetZoomLevels(WinMap.ZoomLevelSet,
                    GeoHelper.DefaultAreaStyle);
                break;
            case WellKnownType.Point:
                WinMap.TrackOverlay.TrackMode = TrackMode.Point;
                // Points don't support track starting or vertex adding
                track.TrackStarting -= Track_TrackStarting;
                track.VertexAdding -= Track_VertexAdding;
                track.TrackShapeLayer.ZoomLevelSet = GeoHelper.SetZoomLevels(WinMap.ZoomLevelSet,
                    GeoHelper.DefaultPointStyle);
                break;
            case WellKnownType.Polygon:
                WinMap.TrackOverlay.TrackMode = TrackMode.Polygon;
                track.TrackShapeLayer.ZoomLevelSet = GeoHelper.SetZoomLevels(WinMap.ZoomLevelSet,
                    GeoHelper.DefaultAreaStyle);
                break;
            default:
                break;
        }

        WinMap.TrackOverlay.RefreshAsync();

Do you mean it will not have any issue if using the built in TrackInteractiveOverlay instead of CustomTrackInteractiveOverlay?

In that case, can you send us the source code of CustomTrackInteractiveOverlay?

Based on that thought, I did the following to the top of the code so I was not using the Custom overlay to see if the problem would resolve itself

        TrackInteractiveOverlay track = WinMap.TrackOverlay;

        //CustomTrackInteractiveOverlay track = new CustomTrackInteractiveOverlay();
        //WinMap.TrackOverlay = track;

Quite unexpectedly, it all seems to have gone haywire. I click the screen and no shape is being drawn, but I see a ton of errors going off in my diagnostics.

image

I just changed to this

TrackInteractiveOverlay track = new TrackInteractiveOverlay();
WinMap.TrackOverlay = track;

I no longer get all the exceptions and I can see the line being drawn on the map, but the problem with TrackMode not starting until I zoom or pan persists.

I couldn’t recreate the issue, but if you haven’t called mapView.RefreshAsync() before, can you call WinMap.RefreshAsync(WinMap.TrackOverlay); instead of WinMap.TrackOverlay.RefreshAsync();? I mentioned in another post that MapView.RefreshAsync() did some overlay initialization?

Hi Ben,

WinMap.RefreshAsync(WinMap.TrackOverlay) seems to have worked. Thanks!

I will have to keep in mind the two refresh methods do somewhat different things…

That’s Great! :grinning: