ThinkGeo.com    |     Documentation    |     Premium Support

Stop Drawing in ThinkGeoV12

How can I stop Overlay from drawing and close the FeatureLayer? I can see the same question is asked in Stop/Interrupt Drawing but I cannot implement that in v12.

When I did that, I faced with this exception:

   at System.Data.SqlClient.SqlDataReader.CheckDataIsReady(Int32 columnIndex, Boolean allowPartiallyReadColumn, Boolean permitAsync, String methodName)
   at System.Data.SqlClient.SqlDataReader.TryReadColumn(Int32 i, Boolean setTimeout, Boolean allowPartiallyReadColumn)
   at System.Data.SqlClient.SqlDataReader.GetValueInternal(Int32 i)
   at System.Data.SqlClient.SqlDataReader.GetValue(Int32 i)
   at ThinkGeo.Core.SqlServerFeatureSource.ByE=(SqlDataReader dataReader)
   at ThinkGeo.Core.SqlServerFeatureSource.EEk=(RectangleShape boundingBox, QueryType queryType, IEnumerable`1 returningColumnNames)
   at ThinkGeo.Core.FeatureSource.GetFeaturesForDrawing(RectangleShape boundingBox, Double screenWidth, Double screenHeight, IEnumerable`1 returningColumnNames)
   at ThinkGeo.Core.FeatureLayer.DrawCore(GeoCanvas canvas, Collection`1 labelsInAllLayers)
   at Core.Contract.Sources.ITNSqlFeatureLayer.DrawCore(GeoCanvas canvas, Collection`1 labelsInAllLayers) in D:\Source\repos\TRACC\Core.Contract\Sources\ITNSqlFeatureLayer.cs:line 30

Hey @Mahdi_Rastegari,

To stop an Overlay from drawing, it might be best to cancel it on the MapView instead of the Overlay because it’ll cancel sooner.

private void MapViewOnOverlayDrawing(object? sender, OverlayDrawingMapViewEventArgs e)
{
    if (e.Overlay.GetType() == typeof(LayerOverlay) && e.Overlay.Name == "MyLayerOverlay")
    {
        e.Cancel = true;
    }
}

If this doesn’t work for you, can you post the code you used to set it up here?

Thanks,
Kyle

@Kyle_Day
Unfortunately, It didn’t work for me.

this is some part of the code that I want to stop drawing…

            _overlayToCancel = overlay;
            foreach (var overlayLayer in overlay.Layers)
            {
                overlayLayer.Close();
            }
            overlay.Close();
            overlay.Dispose();
            Overlays.Remove(overlay);

And here is your suggestion:

        protected override void OnOverlayDrawing(OverlayDrawingMapViewEventArgs e)
        {
            if (e.Overlay == _overlayToCancel)
                e.Cancel = true;
            base.OnOverlayDrawing(e);
        }

The event ‘MapViewOnOverlayDrawing’ is not invoked during the drawing mode, I think it invoked at the first of drawing procedure.

Hi @Mahdi_Rastegari,

The “OnOverlayDrawing” event of MapView is only called when doing the map refresh, it should be mapView level event. The overlay has its own event to allow us to monitor its status:

  • Drawing - raises before the overlay is drawing
  • Drawn - raises after the overlay is drawn
  • DrawingAttribution - raises before the drawing overlay’s attribution
  • DrawnAttribution - raises after the drawing overlay’s attribution

To cancel the drawing of the overlay, we can use “Drawing” event, codes like below:

        LayerOverlay parksOverlay = new LayerOverlay();
        parksOverlay.Drawing += ParksOverlay_Drawing;
        mapView.Overlays.Add(parksOverlay);

An in the ParksOverlay_Drawing method, we can let “Cancel” as true to stop the drawing. Here is the code:

    private void ParksOverlay_Drawing(object sender, DrawingOverlayEventArgs e)
    {
        e.Cancel = true;
    }

Regards,
Johnny