ThinkGeo.com    |     Documentation    |     Premium Support

Custom error tiles

Hey,

Is it possible to use some custom error tile when remote WMS/WMTS/WFS service is down or there is no internet connection? So instead of map component drawing “red X” and/or writing error on map, we’d be using some predefined image?

I noticed that cache has NoDataTileImage property but it’s readonly and not sure if it’s even the thing I should be looking at…

Mikko,

What layers or overlays are you specifically using? I just want to make sure the method I’m thinking of works. I have the code below. The idea is if there is an error on a Layer or Overlay then we will call a DrawingException and DrawnException events. You can hook to the event and draw whatever you want on the canvas. What I am not sure about is that certain layers or overlays may not be respecting this or may have their own ways of representing this. What makes me suspect is that property you mentioned. You can try the code but I’m not 100% it will work. If not you can open a ticket and we can look at it in a more timely manner.

        wmsOverlay.DrawnException += WmsOverlay_DrawnException;

        private void WmsOverlay_DrawnException(object sender, DrawnExceptionTileOverlayEventArgs e)
        {
            e.Canvas.DrawArea(e.Canvas.CurrentWorldExtent, GeoBrushes.White, DrawingLevel.LevelOne);
            e.Canvas.DrawText("Error", new GeoFont("Arial", 20, DrawingFontStyles.Bold), GeoBrushes.Black, new ScreenPointF[] { new ScreenPointF(e.Canvas.Width / 2, e.Canvas.Height / 2) }, DrawingLevel.LevelOne);
        }
1 Like

Thanks, I’ll try that approach.

We are using WmsOverlay, WmtsTiledOverlay, WfsFeatureLayer+LayerOverlay (as there is no “WfsOverlay”) and ThinkGeoCloudRasterMapsOverlay.

It kind-of worked. Custom “error” is there but generated messages remain, too.

Even if you clear the canvas in DrawnException event handler the messages are still visible.

That is what I was seeing as well when I did my test. I wasn’t sure what exactly what layers or overlays you were using. We will track this down to see if we can ensure that the red drawing will respect the overriding drawing on an error.

What version are you on, 10 or 12?

Mikko,

I think I was able to track this down. It’s silly I didn’t think of this. The first thing you can do is to cancel the default drawing with e.Cancel = true. This causes the DrawExceptionCore not to be called so it should not write what you were seeing. Another point is I was looking into the code on how we draw the exception and I see that we were using the DrawingLevel.LabelLevel. In our drawing system we have a number of levels and the label level is always on top. The code I sent before was drawing on level one and then the DrawExceptionCore was drawing on top of that even though we thought we cleared the canvas. I think that you would not even have to cancel it if you drew on the LabelLevel in the DrawnException event.

This should apply to all of the overlays you were talking about because this is being drawn in a TileOverlay which they inherit from.

        private void WmsOverlay_DrawingException(object sender, DrawingExceptionTileOverlayEventArgs e)
        {
            e.Cancel = true;

            e.Canvas.DrawArea(e.Canvas.CurrentWorldExtent, GeoBrushes.White, DrawingLevel.LabelLevel);
            e.Canvas.DrawText("Error", new GeoFont("Arial", 20, DrawingFontStyles.Bold), GeoBrushes.Black, new ScreenPointF[] { new ScreenPointF(e.Canvas.Width / 2, e.Canvas.Height / 2) }, DrawingLevel.LabelLevel);
        }
1 Like

We are using 13 beta and trying to keep up with the latest (as long as there’s no breaking bugs).

Thanks for the example, it’s working just great!

Few problems still that I noticed.

If this is used with ThinkGeoCloudRasterMapsOverlay then “default” error message with red “X” is still drawn on the canvas.

When used with WmtsTiledOverlay async threads keep hitting the custom event handler (in a loop maybe?) but nothing is drawn. Only way to stop this is to cancel operation via e.Canvas.CancellationToken() but then map is left empty.

I will take a look, I didn’t test every overlay :slight_smile:. I suspect some of them are doing things differently. I’m just curious as to how you are simulating the error state, disconnecting it from the internet?

@David yes, by turning the WiFi adapter off. In our use case GIS solution is used in the forest so disconnects happen.

When I tested this further I’d say that

a) WMS: Works nicely and only displays overridden stuff on canvas
b) WMTS: Shows error thrown by component + overriden stuff
c) Cloud maps: same as WMTS

Anything developments regarding this issue?

Now when @Leo_Liu solved my problem with GeoPDFs, I’ll return here to ask where we are at :slight_smile:

Hi Mikko,

The problem was that e.cancel didn’t work in DrawingException of ThinkGeoCloudRasterMapsOverlay and WmtsTiledOverlay. I’ve fixed it in source code. Feel free to upgrade ThinkGeo.UI.Wpf to 13.0.0-beta355 or above.

Thanks,
Leo

1 Like

Will do. Seems like it’s not available in NuGet yet.

Hi Mikko,

It’ll take one or two days before it’s available.

Thanks,
Leo

Thanks, works like a charm.

You’re welcome. Let us know if you have more questions.

Thanks,
Leo