ThinkGeo.com    |     Documentation    |     Premium Support

Error while loading JSON style with Vector .mbtiles file

Hello,

I’m trying to load a 450MB .mbtiles file coupled with a pre-delivered JSON-Style.
I’m using the following dataset:

And here below is my code, which throws a NullreferenceException (see below codebase) when trying to load the map/style.

Can you please tell me if I’m doing something wrong or if the library has some problems with the provided data?
I tested both json and .mbtiles with QGIS and Maptiler, and they work fine.

Thanks!

private void MapView_Loaded(object sender, RoutedEventArgs e)

    {
        // It is important to set the map unit first to either feet, meters or decimal degrees.
        mapView.MapUnit = GeographyUnit.Meter;
        // Create a new overlay that will hold our new layer
        LayerOverlay layerOverlay = new LayerOverlay();
        // Create the background world maps using vector tiles stored locally in our MBTiles file and also set the styling though a json file

        ThinkGeoMBTilesLayer mbTilesLayer = new ThinkGeoMBTilesLayer(                                                        @"E:\Desktop-Maps\ThinkGeoVectorTiles\Resources\ch.swisstopo.leichte-basiskarte.vt.mbtiles", new Uri(@"E:\Desktop-Maps\ThinkGeoVectorTiles\Resources\leichte-basiskarte.json"));

        mbTilesLayer.Projection = new Projection(2056);
        layerOverlay.Layers.Add(mbTilesLayer);

        try {
            layerOverlay.Open();
            // Add the overlay to the map
            mapView.Overlays.Add(layerOverlay);
            // Set the current extent of the map to an area in the data
            mapView.CurrentExtent = mbTilesLayer.GetBoundingBox();
            layerOverlay.Close();
        } catch(Exception ex) {
            Console.WriteLine(ex.StackTrace);
        }
        // Refresh the map.
        mapView.Refresh();
    }

An unhandled exception of type ‘System.ArgumentNullException’ occurred in ThinkGeo.Core.dll: ‘Value cannot be null.’
at System.ThrowHelper.ThrowArgumentNullException(ExceptionArgument argument)
at System.Collections.Generic.List1.InsertRange(Int32 index, IEnumerable1 collection)
at EhU=.9zI=.9TI=(JObject jsonObject)
at EhU=.9zI=.hxU=(JObject jsonObject)
at ThinkGeo.Core.StyleJsonDocument.Parse(Byte[] styleJsonBytes)
at ThinkGeo.Core.ThinkGeoMBTilesLayer.lCs=()
at ThinkGeo.Core.ThinkGeoMBTilesLayer.OpenCore()
at ThinkGeo.Core.Layer.Open()
at ThinkGeo.Core.LayerOverlay.OpenCore()
at ThinkGeo.Core.Overlay.Open()
at ThinkGeoVectorTiles.MainWindow.MapView_Loaded(Object sender, RoutedEventArgs e) in E:\POCS\Desktop-Maps\ThinkGeoVectorTiles\MainWindow.xaml.cs:line 46
at System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs)
at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
at System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args)
at System.Windows.UIElement.RaiseEvent(RoutedEventArgs e)
at System.Windows.BroadcastEventHelper.BroadcastEvent(DependencyObject root, RoutedEvent routedEvent)
at System.Windows.BroadcastEventHelper.BroadcastLoadedEvent(Object root)
at System.Windows.Media.MediaContext.FireLoadedPendingCallbacks()
at System.Windows.Media.MediaContext.FireInvokeOnRenderCallbacks()
at System.Windows.Media.MediaContext.RenderMessageHandlerCore(Object resizedCompositionTarget)
at System.Windows.Media.MediaContext.RenderMessageHandler(Object resizedCompositionTarget)
at System.Windows.Media.MediaContext.Resize(ICompositionTarget resizedCompositionTarget)
at System.Windows.Interop.HwndTarget.OnResize()
at System.Windows.Interop.HwndTarget.HandleMessage(WindowMessage msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Interop.HwndSource.HwndTargetFilterMessage(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)
at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)
at System.Windows.Threading.Dispatcher.LegacyInvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Int32 numArgs)
at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)

Hi Enea,

Thanks for your question, but the ThinkGeoMBTilesLayer is a custom format and does not work with other providers.

However, I know you’ve had questions in the past with the Swiss Topo data via WMTS and we’re looking into that further. I hope we can find a solution for you in the near future.

Thanks,
John

Hi Enea,

There’s a new build (13.2.0-beta019) that has a fix for your previous ticket you submitted regarding the WmtsLayer not working with the Swiss topo service. There was a {Time} parameter that the topo service used slightly different than other services we had seen in the past.

I hope this solution works and I’ll send a separate email with the sample code.

Thanks,
John