ThinkGeo.com    |     Documentation    |     Premium Support

Application crash when using bing maps with no internet connection

When using Aerial/Hybrid for Bing map the application will crash if there is no internet connection

I have duplicated this issue using BackgroundMapSwitchingSample-ForWpf sample code. I switched to bing aerial maps, switch off my wifi and pan to a new area and receive the following exception:

Unhandled Exception:
Unhandled Exception: System.Net.WebException: The remote name could not be resolved: ‘ecn.t2.tiles.virtualearth.net
at ThinkGeo.MapSuite.Wpf.Tile.DrawException(GeoCanvas geoCanvas, Exception exception)
at ThinkGeo.MapSuite.Wpf.Tile.Draw(GeoCanvas geoCanvas)
at ThinkGeo.MapSuite.Wpf.Tile.hFY=(Object status)
at System.Threading.QueueUserWorkItemCallback.WaitCallback_Context(Object state)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem()
at System.Threading.ThreadPoolWorkQueue.Dispatch()
at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback()

This is the same issue that is occurring in our application.

Hi Richard,

Upgrade your packages into the latest version and set this property can solve it:

bingMapsOverlay.DrawingExceptionMode = Drawing.DrawingExceptionMode.DrawException;

Regards,

Ethan

Thanks that resolved the issue for WPF. I performed similar tests in iOS and it works fine with or without the drawingExceptionMode being set there. I switched to OpenStreet maps it works with or without that setting in WPF, but in iOS it fails in the same manner as noted above with or without the DrawingExceptionMode being set. I am using the latest prerelease code for iOS.

Hi Richard,

You means the DrawingExceptionMode don’t works for OpenStreetMap in IOS version right?

The draw exception mode for layer and overlay works follow different way, could you please show us your code about how to reproduce it, so our developer can look into it.

Regards,

Don

Here is the code that I use to initialize the OSMLayer

                 >    LayerOverlay OSMOverlay = new LayerOverlay();
                    OpenStreetMapLayer osml = new OpenStreetMapLayer();
                    osml.ZoomlevelSet = new OpenStreetMapsZoomLevelSet();
                    osml.DrawingExceptionMode = DrawingExceptionMode.DrawException;
                    OSMOverlay.Layers.Add(osml);
                    mapOverlays.Insert(1, OSMOverlay);
                    BaseMapOverlay = OSMOverlay;
                    OSMOverlay.DrawingExceptionMode = DrawingExceptionMode.DrawException;

If need be I can create a sample application. Here is the Exception I am receiving in iOS

2018-11-01 13:49:17.124 ByersOneView.iOS[1073:1267194] Unhandled managed exception:
Error: NameResolutionFailure (System.Net.WebException)
at ThinkGeo.MapSuite.Layers.OpenStreetMapLayer.aic= (System.Int32 startTileX, System.Int32 startTileY, System.Int32 endTileX, System.Int32 endTileY, System.Int32 zoomlevelNumber, System.Double scale) [0x002dd] in :0
at ThinkGeo.MapSuite.Layers.OpenStreetMapLayer.DrawCore (ThinkGeo.MapSuite.Drawing.GeoCanvas canvas, System.Collections.ObjectModel.Collection1[T] labelsInAllLayers) [0x00585] in <be05304ee62349c9bcd1fda39982b7eb>:0 at ThinkGeo.MapSuite.Layers.Layer.DSQ= (ThinkGeo.MapSuite.Drawing.GeoCanvas canvas, System.Collections.ObjectModel.Collection1[T] labelsInAllLayers) [0x0004a] in :0
at ThinkGeo.MapSuite.Layers.Layer.Draw (ThinkGeo.MapSuite.Drawing.GeoCanvas canvas, System.Collections.ObjectModel.Collection`1[T] labelsInAllLayers) [0x00088] in :0
at T
hinkGeo.MapSuite.iOS.LayerTileView.DrawCore (ThinkGeo.MapSuite.Drawing.GeoCanvas geoCanvas) [0x000ad] in <124b302a64884ef1b52b43431083d18a>:0
at ThinkGeo.MapSuite.iOS.TileView.Draw (ThinkGeo.MapSuite.Drawing.GeoCanvas geoCanvas) [0x00000] in <124b302a64884ef1b52b43431083d18a>:0
at ThinkGeo.MapSuite.iOS.LayerOverlay.DrawTileCore (ThinkGeo.MapSuite.Drawing.GeoCanvas geoCanvas, ThinkGeo.MapSuite.iOS.TileView tile) [0x000f6] in <124b302a64884ef1b52b43431083d18a>:0
at ThinkGeo.MapSuite.iOS.TileOverlay.DrawTile (ThinkGeo.MapSuite.iOS.TileView tile, ThinkGeo.MapSuite.iOS.MapArguments mapArguments) [0x00184] in <124b302a64884ef1b52b43431083d18a>:0
at ThinkGeo.MapSuite.iOS.TileOverlay.nEQ= (ThinkGeo.MapSuite.iOS.TileOverlay+DrawingOperation op) [0x0004d] in <124b302a64884ef1b52b43431083d18a>:0
at ThinkGeo.MapSuite.iOS.TileOverlay+DrawingOperation.Main () [0x0000e] in <124b302a64884ef1b52b43431083d18a>:0

Hi Richard,

Thanks for your code, it looks for IOS this function have some issue, our developer will look into it.

Any update I will let you know.

Regards,

Ethan

Hi Richard,

Our developer should fix it, please get this package from Nuget when it’s availabe: https://www.nuget.org/packages/ThinkGeo.MapSuite/11.0.0-beta088

Regards,

Ethan

This fix worked for WPF, however the same issue exists on Android

Hi Richard,

That’s caused by different reason, our developer hadn’t found a good solution for that, so here is a workaround for your scenario.

    public class CustomBingMapsOverlay : BingMapsOverlay
{
    public CustomBingMapsOverlay(string applicationId) : base(applicationId)
    {
    }

    protected override void DrawExceptionCore(GeoCanvas geoCanvas, Exception ex)
    {
        try
        {
            base.DrawExceptionCore(geoCanvas, ex);
        }
        catch (Exception)
        {
        }
    }
}

CustomBingMapsOverlay baseOverlay = new CustomBingMapsOverlay("Your application ID");

It can solve the crash problem on Android.

Wish that’s helpful.

Regards,

Ethan

This did get past the crashing issue with Bing maps

Also the crash also occurs when you zoom in far enough so that there are no map tiles for that zoom extent.

Is there a way to tell the overlay to stretch the current bing map tile if there are either no more tiles present due to zooming in past the available tiles.

Hi Richard,

I think our BingMapsOverlay in WPF edition default support that.

And here is the test code:

        private void map_Loaded(object sender, RoutedEventArgs e)
    {
        map.MapUnit = GeographyUnit.Meter;

        foreach (ZoomLevel level in new BingMapsZoomLevelSet().GetZoomLevels())
        {
            map.ZoomLevelSet.CustomZoomLevels.Add(level);
        }
        
        map.ZoomLevelSet.CustomZoomLevels.Add(new ZoomLevel(500));
        map.ZoomLevelSet.CustomZoomLevels.Add(new ZoomLevel(200));
        map.ZoomLevelSet.CustomZoomLevels.Add(new ZoomLevel(100));
        map.ZoomLevelSet.CustomZoomLevels.Add(new ZoomLevel(50));
        map.ZoomLevelSet.CustomZoomLevels.Add(new ZoomLevel(25));
        map.ZoomLevelSet.CustomZoomLevels.Add(new ZoomLevel(10));

        map.MinimumScale = 1;

        BingMapsOverlay worldOverlay = new BingMapsOverlay("Your Bing Key");
        map.Overlays.Add(worldOverlay);



        map.CurrentExtent = new RectangleShape(-10776628.6977434, 3865917.20402557, -10776524.9811327, 3865842.85614905);
        map.Refresh();
    }

Regards,

Ethan

My apoloigies – I posted this in the wrong forum – my issue is with Android not WPF. I will post this in the correct forum.

Hi Richard,

Thanks to let us know that.

It looks our Android edition don’t support that for BingMapsOverlay, I think you can try to use LayerOverlay and BingMapsLayer to see whether it works.

Regards,

Ethan

Is it not supported or is because of the exception that gets thrown when no map tiles are found? If I did not have the work around with the CustomBingOverlay in it as noted above the application would crash because of a null pointer. When I zoom in the map scales the bing overlay which then disappears when it looks like its going out to acquire new tiles. At this point I am simply wondering why it would behave the same as WPF, the fact that is stretches the map during the transition indicates that it should be capable of doing so.

In the past it has been my experience that the bingmaplayer is slower than using the BingMapOverlay so I don’t see that as a long term solution – I will check out that mechanism to see if its something that I can use for the immediate future,

Hi Richard,

I build the test sample and check it again, it looks my previous reply is not exact.

If you don’t set custom zoomlevels, the map won’t throw exception when you zoom into deeper, and it will strech the map.

But if you set custom zoomlevel to deeper, you will get the exception there it should make your application get crash.

The Android is based on Xamarin, and some feature is not implemented just the same like WPF edition.

And in Android edition, the Overlay+BingLayer is slower than BingOverlay, that’s because they are in fact follow different tile matrix by default, the first solution get more calculation.

Here is the simplest code, you can see when you zoom in, the exception is not thrown and the tile map get stretch.

        protected override void OnCreate(Bundle bundle)
    {
        base.OnCreate(bundle);
        SetContentView(Resource.Layout.Main);

        MapView mapView = FindViewById<MapView>(Resource.Id.MapView);
        mapView.MapUnit = GeographyUnit.Meter;

        mapView.CurrentExtent = new RectangleShape(-11243423.7023786, 4768592.21409415, -11243022.114298, 4768003.21824261);

        BingMapsOverlay bing = new BingMapsOverlay("your key");

        mapView.Overlays.Add("bing1", bing);
        
        mapView.Refresh();
    }

Regards,

Ethan