Skip to content

Basemaps

A basemap is a source in the style document plus the layers that draw it. ThinkGeo Cloud is the usual one; this page also covers raster tiles, other vector tile services, offline archives, a map with no basemap at all, and the order in which your own layers meet the basemap's.


ThinkGeo Cloud vector maps

var cloud = new ThinkGeoVectorTileSource(cloudApiKey)
{
    VectorTileCache = new FileTileCache(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "MyApp", "Tiles"))
};

Map.Basemap = new GpuBasemap(new MapStyle(ThinkGeoVectorStyles.Light, cloud));
  • ThinkGeoVectorStyles.Light and ThinkGeoVectorStyles.Dark are the two presets. Each is the address of a style document on ThinkGeo's CDN.
  • The API key comes from cloud.thinkgeo.com. It is not your ThinkGeo license key, and it is not the client ID and secret: those sign in the Cloud service clients (geocoding, routing, elevation) and the classic raster overlay, and they do not open the vector tiles.
  • VectorTileCache keeps downloaded tiles on disk. Point it at a folder your application can write to; the folder it is installed in usually is not one.

Customizing the Cloud style

The preset is an ordinary document. Download it from the address in ThinkGeoVectorStyles.Light, change colors, fonts, which layers show and at which zooms, and hand your copy to the same source; it fills your key into the tile addresses.

Map.Basemap = new GpuBasemap(new MapStyle(File.ReadAllText(@"Styles\my-light.json"), cloud));

To take only part of the style, name the layer types you want. This draws the Cloud roads and labels over aerial imagery:

var aerial = new ThinkGeoRasterTileSource(cloudApiKey, ThinkGeoCloudRasterMapsMapType.Aerial_V2_X1);

var style = new MapStyle()
    .AddRaster(aerial, sourceId: "aerial");
style.AddStyle(ThinkGeoVectorStyles.Light, cloud, StyleLayerType.Line, StyleLayerType.Symbol);
Map.Basemap = new GpuBasemap(style);

Raster tiles

A raster source is a picture per tile; the document has nothing to style, so one AddRaster is the whole basemap.

var style = new MapStyle().AddRaster(new ThinkGeoRasterTileSource(cloudApiKey, ThinkGeoCloudRasterMapsMapType.Aerial_V2_X1));
Source Tiles from
ThinkGeoRasterTileSource ThinkGeo Cloud raster maps: light, dark, aerial and hybrid
OpenStreetMapRasterTileSource openstreetmap.org
XyzRasterTileSource Any {z}/{x}/{y} tile server you have the address of
WmsRasterTileSource A WMS server, one GetMap request per tile
WmtsRasterTileSource A WMTS server, through its Web Mercator tile matrix set
ClassicRasterTileSource A raster file (GeoTIFF, JPEG 2000, MrSID, a JPEG with a world file) opened by a GdalRasterSource, warped to Web Mercator once and served as tiles
MbTilesRasterTileSource, PmTilesRasterTileSource Raster tile archives on disk

AddRaster takes an optional RasterPaint for opacity, color adjustments and resampling, and a StyleLayerSlot for where the image goes among the style's layers.

Resampling decides how a tile looks when it is drawn larger or smaller than its own pixels, between zoom levels or past the source's last zoom:

  • RasterResampling.Auto, the default from ThinkGeo 15.1, copies a tile pixel for pixel when it is drawn at its own size, give or take 5%, on a map that is neither rotated nor tilted, so the text and thin lines of a raster street map stay sharp. Otherwise it blends, as Linear does. On a display scaled to 125% or more, raster tiles are drawn larger than their own pixels, so there Auto blends.
  • RasterResampling.Linear always blends neighboring pixels. It was the default before 15.1.
  • RasterResampling.Nearest keeps every pixel square, for rasters whose colors are classes, such as land use, where blending would invent colors that mean nothing.

In a style JSON document it is the raster-resampling paint property, "linear" or "nearest"; leave it out for Auto.

style.AddRaster(landUse, new RasterPaint(1f, resampling: RasterResampling.Nearest));

The HowDoI samples Raster Map Providers, WMS, WMTS and Raster File Formats show each source with its own settings.


Other vector tile services

Any server that publishes Mapbox vector tiles with a style document works the same way as ThinkGeo Cloud: a VectorTileSource on the style's address, and the document drawn from it.

var source = new VectorTileSource("https://tiles.openfreemap.org/styles/liberty");
Map.Basemap = new GpuBasemap(new MapStyle("https://tiles.openfreemap.org/styles/liberty", source));

Keyed providers (MapTiler, Esri, TomTom, Stadia and others) take their key in the style address or in a request header; VectorTileSource.SendingHttpRequest lets you add one. The content must be licensed for a third-party renderer; see the note at the end of Style Documents.


Offline basemaps

A tile archive is a single file holding a whole tileset, so it travels with the application and needs no network.

var tiles = new PmTilesVectorTileSource(@"Data\frisco.pmtiles");
await tiles.OpenAsync();

Map.Basemap = new GpuBasemap(new MapStyle().AddStyle(@"Data\frisco-style.json", tiles));

// Open on the archive's bounds: its centre, at the scale that fits it on the map.
var bounds = tiles.GetBoundingBox();
Map.CenterPoint = bounds.GetCenterPoint();
Map.CurrentScale = MapUtil.GetScale(Map.MapUnit, bounds, Map.ActualWidth, Map.ActualHeight);   // WPF; WinForms: Map.Width, Map.Height
// .NET MAUI: Map.MapScale = MapUtil.GetScale(Map.MapUnit, bounds, Map.CanvasWidth, Map.CanvasHeight);
  • MbTilesVectorTileSource, PmTilesVectorTileSource and TgTilesVectorTileSource read vector archives. Open the archive first: that is where it reads its zoom range and bounds. A vector archive needs a document that names its source-layers; AddVectorTiles(tiles) with no layers draws every layer in a default look when you have none.
  • MbTilesRasterTileSource and PmTilesRasterTileSource read raster archives and go in with AddRaster.
  • Regional extracts of ThinkGeo's own street map are available as archives to licensed Maps Street customers from the HelpDesk; see Maps Street.

No basemap

A map of your own data alone needs only a background color:

var style = new MapStyle().SetBackground(GeoColor.FromHtml("#EAE8E2"));
style.AddStyle(myJson, myData);
Map.Basemap = new GpuBasemap(style);

Where your layers go

Documents draw in the order they are added, so AddStyle(ThinkGeoVectorStyles.Light, cloud) followed by AddStyle(myJson, myData) puts your data above everything of the basemap, labels included. To slot your layers in between, add them with a StyleLayerSlot:

Slot Your layers go
Bottom Under everything
AboveFills Above the land, water and building fills, under the roads
UnderLabels Above the roads, under the labels
Top Above everything (the default)
style.AddVectorTiles(wash, "wash", StyleLayerSlot.UnderLabels,
    StyleLayer.CreateFill("wash", "world", paint: (_, _) => new FillPaint(GeoColors.White, 0.45f)));

The HowDoI sample Insert a Layer Under the Labels draws a translucent wash above the roads and below the labels, a position no overlay can reach, because an overlay is always above the whole map. MoveLayer(layerId, beforeLayerId) moves a layer of the document afterwards.


Who disposes the sources

The map disposes what it holds. What you take off it, and what you made, is yours.

  • Disposing the map disposes its Basemap and every overlay in Overlays and InteractiveOverlays.
  • A basemap you replace, or take off with Map.Basemap = null, is not disposed. Like an overlay removed from Overlays, it is yours again: put it back later, or dispose it. It holds memory until you do.
  • A map never disposes a tile source you gave it, so the same source can go into the next basemap, a second map, or a query of your own.
The source Disposed by
One you made and handed in: to GpuBasemap's constructor, TileSources or RasterTileSources, to AddRaster, AddVectorTiles or AddStyle(json, source), or as the source of FeatureLayerTranslator.TranslateInto You, once nothing draws from it any more
One the style made from an address in its document, or for a classic layer it translated The style, when the last map drawing it is disposed
One the map made for itself The map

To change to another basemap, dispose the one it replaces. The sources you gave the old one stay open, for the new one or for you to dispose:

var previous = Map.Basemap;
Map.Basemap = new GpuBasemap(new MapStyle().AddVectorTiles(tiles));
previous?.Dispose();

// Later, when the map is closed. The map disposes the basemap it holds; the sources are yours.
Map.Dispose();
tiles.Dispose();

For another look at the same data, restyle the basemap with SetStyleAsync instead of replacing it. See Dynamic Styles.

A basemap draws on one map at a time. Putting one on a second map while the first still shows it throws InvalidOperationException, and a disposed basemap throws ObjectDisposedException.

A source that was already disposed is refused where it is handed in, with an ObjectDisposedException that names it. One disposed while a map still draws from it is reported once to Basemap.TileLoadFailed and not asked for tiles again.

A style that translated a classic layer itself cannot make those tiles again once its last map is disposed, and handing it to another map throws. To keep a translated layer across maps, translate it with TranslateInto into a FeatureSourceVectorTileSource of your own.

This is the rule of the GPU map on WPF, WinForms and .NET MAUI, of MapStyle, and of GpuTileRenderer. Classic rendering disposes overlays the same way, and its overlays release the layers and sources they hold.


On .NET MAUI

From ThinkGeo 15.1 the MAUI MapView has a Basemap on iOS, Android and Windows, and the code on this page works there as it is: MapView.Basemap = new GpuBasemap(style). The app must call UseThinkGeoGpu() on its builder in MauiProgram.cs, or the map has nothing to draw on; the Mobile Maps quick start shows it. Point a FileTileCache at FileSystem.Current.CacheDirectory. The classic overlays in the next section are still available on MAUI, drawn on top of the basemap.

On .NET Framework

Where there is no Basemap, the same ThinkGeo Cloud document is drawn on the CPU as a tiled overlay: new ThinkGeoVectorTileOverlay(cloudApiKey) in MapView.Overlays, with ThinkGeoVectorStyles.Dark or your own style address as its second argument, and ThinkGeoCloudRasterMapsOverlay for the raster maps. See Classic Rendering.