ThinkGeo.com    |     Documentation    |     Premium Support

Ms14 trackoverlay

Hi,

From the demo sample https://docs.thinkgeo.com/products/desktop-maps/quickstart-winforms/ I try to set a TrackOverlay but got the following error :
System.Collections.Generic.KeyNotFoundException: ‘The given key ‘TrackInteractiveOverlay’ was not present in the dictionary.’

here is the code, I just added the line about the trackoverlay at the end

private async void Form_Load(object? sender, EventArgs e)
{
// Set the map’s unit of measurement to meters(Spherical Mercator)
mapView.MapUnit = GeographyUnit.Meter;

// Add Cloud Maps as a background overlay
var thinkGeoCloudVectorMapsOverlay = new ThinkGeoCloudVectorMapsOverlay
{
ClientId = “AOf22-EmFgIEeK4qkdx5HhwbkBjiRCmIDbIYuP8jWbc~”,
ClientSecret = “xK0pbuywjaZx4sqauaga8DMlzZprz0qQSjLTow90EhBx5D8gFd2krw~~”,
MapType = ThinkGeoCloudVectorMapsMapType.Light,
TileCache = new FileRasterTileCache(@".\cache", “thinkgeo_vector_light”)
};
mapView.Overlays.Add(thinkGeoCloudVectorMapsOverlay);

// Set the map extent
mapView.CurrentExtent = MaxExtents.ThinkGeoMaps;

mapView.TrackOverlay = new TrackInteractiveOverlay();

await mapView.RefreshAsync();
}

I am using the last 14 beta096, this kind of code was working in MS12

Hi,

Thanks for reporting this. In ThinkGeo UI 14, the TrackOverlay is automatically created inside the MapView , so you don’t need to add or manage it yourself. To enable drawing, you only need to set its TrackMode . For example:

mapView.TrackOverlay.TrackMode = TrackMode.Line;

That single line is enough to activate drawing.

If you also want to capture the shape once the user finishes drawing, you can handle the TrackEnded event like this:

mapView.TrackOverlay.TrackEnded += (s, e) =>
{
    var shape = e.TrackShape;
    // Do something with the drawn shape here
};

So the key change is:

  • Don’t add your own TrackInteractiveOverlay to the overlays collection.
  • Simply use the built-in mapView.TrackOverlay and set its TrackMode .

This way, you won’t see the KeyNotFoundException anymore, and the drawing should work immediately without needing to pan or resize.

Kind regards,
Rui

Hi Rui,

Thank you for sharing the code snippet. Before V14, we used our own CustomTrackInteractiveOverlay. If I understand correctly, now I should use the built-in TrackOverlay and subscribe to its events in order to to implement my own logic, right ?

How could I achieve something similar to this :

protected override InteractiveResult MouseClickCore(InteractionArguments interactionArguments)
      {
        if (interactionArguments.MouseButton != MapMouseButton.Right)
        {
          if (MapControler.snapMode)
          {
            PointShape point = new(interactionArguments.WorldX, interactionArguments.WorldY);
            PointShape closestPoint = getClosestPointTo(point);

            if (closestPoint != null)
            {
              interactionArguments.WorldX = closestPoint.X;
              interactionArguments.WorldY = closestPoint.Y;
            }
          }

          return base.MouseClickCore(interactionArguments);
        }

        RemoveLastVertexAdded();
        return new InteractiveResult();
      }

Hi Judicael,

We’ve recreated your issue and have it fixed in the latest beta, can you pull the latest (ThinkGeo.UI.WinForms 14.4.0-beta100) and have another try?

Thanks,
Ben