This project has moved and is read-only. For the latest updates, please go here.

Invalidate region of Mapbox

Mar 28, 2014 at 2:00 PM

I'm trying to invalidate just a region of my mapbox using this code. I'm hoping to be able to just redraw a portion of the form in order to improve the performance (I'm having to flash icons which causes a lot of redraw calls, so just redrawing sections of screen would save a lot of time). this does not seem to work though. does sharpmap.Render use rectangles that are passed through from the invalidate function? If sharpmap does not support this, then should it?

var coordfact = new CoordinateTransformationFactory();
        var trans = coordfact.CreateFromCoordinateSystems(GeographicCoordinateSystem.WGS84,

        var topleft =
            _map.WorldToImage(trans.MathTransform.Transform(new Coordinate(lineGeom.EnvelopeInternal.MinX, lineGeom.EnvelopeInternal.MaxY)));
        var bottomRight =
            _map.WorldToImage(trans.MathTransform.Transform(new Coordinate(lineGeom.EnvelopeInternal.MaxX, lineGeom.EnvelopeInternal.MinY)));

        Console.WriteLine("topleft = " + topleft.ToString());
        Console.WriteLine("bottom right = " + bottomRight.ToString());

        mapBox1.Invalidate(new Rectangle((int)topleft.X, (int)topleft.Y, (int)(bottomRight.X-topleft.X  ), (int)(bottomRight.Y-topleft.Y )));
Mar 28, 2014 at 4:05 PM
If sharpmap does not support this, then should it?
It does not. It would be an improvement.

A new map image is created when you invoke MapBox.UpdateImage(bool forceRefresh). This method is private so we are free to change the signature, to e.g.
MapBox.UpdateImage(bool forceRefresh, Envelope bbox = null).
Furthermore we need to:
  • assign bbox = _map.Envelope; if the one passed was null
  • assign bbox = _map.Envelope.Intersection(bbox); if one was passed.
  • compute the offset in the image and take it into account it the GetImagesAsyncEnd function.
Now we can override Control.OnInvalidated(Rectangle invalidRect) and force the update of the partial image.
Mar 28, 2014 at 4:06 PM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.
Mar 28, 2014 at 4:57 PM
I normally call MapBox.Refresh.

Is MapBox.UpdateImage the prefered way of doing it?
Mar 31, 2014 at 8:04 AM
You cannot call UpdateImage directly, it is a private member of MapBox.
If you call MapBox.Refresh() it internally calls UpdateImage.

The approach outlined above doesn't work out because the ILayer.Render method takes Map as argument and not a specific viewport.