ThinkGeo.com    |     Documentation    |     Premium Support

LayerOverlay Draw to Bitmap

Scenario:

I have a local RasterTileCache that I am displaying using a LayerOverlay with IsCacheOnly set to true and the TileCache set appropriately. There are no layers. The user will not have access to the TileCache source data.

Question:

How do I have the LayerOverlay draw to a GeoCanvas?

Goal:

I want a bitmap/png of the current map extent to save to a file.

Additional Information:

There is no draw method for the overlay, and there is no layer to draw. I have tried to use MBTilesLayer, but that is expecting a Vector Tile Cache to draw. It does not draw from the RasterTileCache when I try to draw it on the canvas. I have tried to use a CloudRasterLayer, but it gives me an unauthorized exception most of the time. Plus, the tile cache is local, and when I have gotten the CloudRaster layer to draw, it has had holes in the image – meaning that the drawing was incomplete plus it was not the extent that the canvas was set for. My other layers draw as expected.

I nearly forgot to add. I have tried to override the RasterTileCache, but the merge bitmaps is not exposed to me in the Blazor edition like it was in the WPF/Desktop edition.

Thanks for any help that you can offer.

Hi Brandon,

Our developer build a sample for your requirement:

DrawingToGeoCanvas.zip (2.1 MB)

Please try it and please feel free to let us know If we misunderstand anything.

Regards,

Ethan

ModFiles.zip (1.2 KB)

Ethan,

Thanks for the code. I had actually tried something very similar. I modified your sample to what my case is. When I use your sample, it works as expected, but with my settings, it does not.

I modified the Index.Razor, and I enclosed the png. The size limit doesn’t allow me to upload the entire project.

Hi Brandon,

Thanks for your update, our developer look into your scenario and here is a new sample project.

DrawingToGeoCanvas.zip (1.6 MB)

Please view it and I hope that helps resolve the issue for you.

Regards,

Ethan

Ethan,

I appreciate the updated code, but unfortunately, it produces the same result - a blank file.

Hi Brandon,

Could you please try to debug code, and add a break point in CustomLayerOverlay class to see whether it hit?

I download the new package again, and run it in an clean machine, the result is correct.

As below is my test result:

If you found anything I missed when test please let me know.

Regards,

Ethan

Is that a shp file that you are trying to show me that displays?

If so, we agree that one works. My scenario is an overlay with NO layers and IsCacheOnly=True and a Raster tile cache setup, which does not work.

A break point hits with a blank output.

Hi Brandon,

Our latest sample project don’t contains shape files, it only contains some cached images, and the IsCacheOnly is set equal true.

<CustomLayerOverlay Id="CustomOverlay" @ref="baseOverlay" IsCacheOnly="true" TileCache="@TileCache"></CustomLayerOverlay>

Could you please double check whether the file you downloaded is 1.55 MB? Because the new version project have the same name with old one.

Regards,

Ethan

Ethan,

That was my mistake. I used the right project this morning (I remember distinctly some of the new code), but I must have looked at the wrong output file. It works as expected. Thanks! :smiley: :smiley: :smiley:

Hi Brandon,

I am glad to hear that’s helpful.

Any question please let us know.

Regards,

Ethan