ThinkGeo.com    |     Documentation    |     Premium Support

Adding Overlay causes System.NullReferenceException error

Hello,

I am trying to load the map using MBTiles and am getting an error when the map is adding to the Overlays. The error is System.NullReferenceException. Using the Product Center 12 HowDoI example application I am using the exact steps and not sure as to why I am getting the error.

Thank you,
Eric

Here is my code in the Map2_Loaded function:

thinkGeoMBTilesFeatureLayer2 = new ThinkGeoMBTilesLayer(“MapData/Nevada.mbtiles”, new Uri(“MapData/thinkgeo-world-streets-lightCORE.json”, UriKind.Relative));
thinkGeoMBTilesFeatureLayer.BitmapTileCache = null;

        layerOverlay2.TileWidth = 512;
        layerOverlay2.TileHeight = 512;
        layerOverlay.DrawingQuality = DrawingQuality.HighSpeed;

        layerOverlay2.Layers.Add("MBFiles", thinkGeoMBTilesFeatureLayer2);

        mapView2.MapUnit = GeographyUnit.Meter;
        mapView2.ZoomLevelSet = new ThinkGeoCloudMapsZoomLevelSet();
        
        if (!mapView2.Overlays.Contains("MBFiles"))
        {
            // Error here
            mapView2.Overlays.Add("MBFiles", layerOverlay);
        }

        mapView2.Refresh();

Thanks Eric,
Most likely. The Nevada.mbtiles and thinkgeo-world-streets-lightCORE.json not in your current exe file folder. make sure the file in the correct location. In some our sample we set the data file as “Copy if newer”. The data will auto to copy to bin\debug folder. So if you are using another data file. Make sure the data file in the correct location. To verify this you could use the absolute path and try again.

Thanks

Frank

Hi Frank,

Thanks for the reply. I currently am using an absolute path to the files (pulled from the ViewModel) and that folder/files do currently exist.

Is there anything else that could be causing the Overlays.Add to give the NullReference error?

Thanks

I resolved the error by adding mapView.CurrentExtent
mapView.MapUnit = GeographyUnit.Meter;
mapView.ZoomLevelSet = new ThinkGeoCloudMapsZoomLevelSet(512);
mapView.CurrentExtent = new RectangleShape(-14180662, 5547256, -7832569, 1777465);

Eric,
I think I gave you the wrong direction. This turn out it is an issue in our sample style json file. More detail you can find in your another post.

Sorry for the misleading.

Thanks

Frank