How the Map Is Drawn¶
Applies to: ThinkGeo 15 (
ThinkGeo.Core15.0.1 and later)
Platforms: WPF · WinForms · Blazor · .NET MAUI · WebApi
A ThinkGeo 15 map is a style document drawn over data sources. The document says what to draw and how; the sources say where the data comes from. This page gives you that model, the few lines that put a map on screen, and a table of which kind of data goes where. Everything else in the Guides builds on it.
The model¶
MapView the control: unit, extent, scale, mouse and touch
├── Basemap = GpuBasemap(MapStyle) everything that is drawn as the map
│ └── MapStyle the style document: sources + layers (+ images, glyphs, sprite)
│ ├── ThinkGeoVectorTileSource ThinkGeo Cloud vector tiles
│ ├── FeatureSourceVectorTileSource your files, databases and in-memory features, cut into tiles
│ ├── MbTilesVectorTileSource, PmTilesVectorTileSource offline vector tile archives
│ ├── RasterTileSource aerial imagery, WMS, WMTS, XYZ, raster archives and raster files
│ └── DynamicSource features that move every frame
└── Overlays what sits on the map and reacts to the user
├── SimpleMarkerOverlay, PopupOverlay UI elements pinned to a ground position
├── EditInteractiveOverlay, TrackInteractiveOverlay drawing, editing and measuring
└── LayerOverlay classic layers that have no style-document equivalent
- The
MapViewis the control. It owns the map unit, the extent and the scale, and it turns mouse and touch into panning, zooming, rotating and tilting. - The
Basemapdraws the map. It holds oneMapStyle, and aMapStyleis a style document: a list of sources (tile services, files, databases, archives) and a list of layers that say how the data in those sources is painted, in what order, and at which zoom levels. The basemap and your own data live in the same document, so one document describes the whole map. - The
Overlaysare for what is not part of the map picture: markers and popups made of UI elements, the overlays that let the user draw and edit shapes, and classic layers that the style document cannot express.
A MapStyle is a ThinkGeo.Core object, so the same document can be drawn by a WPF or WinForms MapView, by the Blazor MapView in the browser, by a MAUI MapView on iOS, Android and Windows, and onto a printed page.
A map in six lines¶
WPF is shown; WinForms is the same code with using ThinkGeo.UI.WinForms;.
using ThinkGeo.Core;
using ThinkGeo.Core.Styling;
using ThinkGeo.UI.Wpf;
private async void Map_Loaded(object sender, RoutedEventArgs e)
{
Map.MapUnit = GeographyUnit.Meter;
var cloud = new ThinkGeoVectorTileSource(cloudApiKey) { VectorTileCache = new FileTileCache(cacheFolder) };
Map.Basemap = new GpuBasemap(new MapStyle(ThinkGeoVectorStyles.Light, cloud));
Map.CenterPoint = new PointShape(-10777290, 3908740);
Map.CurrentScale = 9000;
await Map.RefreshAsync();
}
MapUnitisMeter: the map is in Web Mercator (EPSG:3857), the projection every tile source uses. Data in another projection gets aProjectionConverter; see Styling Your Data.ThinkGeoVectorTileSourceis where the basemap tiles come from. The key is a ThinkGeo Cloud API key from cloud.thinkgeo.com; it is not your ThinkGeo license key. The cache keeps downloaded tiles on disk.new MapStyle(ThinkGeoVectorStyles.Light, cloud)is the document: the Light preset is the address of a style on ThinkGeo's CDN, and the source it is given is the one its layers draw from.ThinkGeoVectorStyles.Darkis the other preset.Map.Basemap = new GpuBasemap(style)hands the document to the map.CenterPointandCurrentScale, orCurrentExtent, say where the map opens.RefreshAsync()draws.
The Desktop Quick Start walks through the same code in a new WPF or WinForms project.
The style document¶
The document follows the MapLibre Style Specification, an open format. ThinkGeo parses and draws it with its own engine. A document has:
- sources: where the data is. A source is a vector tile service, a file or table cut into tiles, a raster tile service, an archive.
- layers: how to draw it, in order. Each layer has a
type(fill,line,circle,symbol,raster,heatmap,fill-extrusion,hillshadeorbackground), thesource-layerit reads, an optionalfilter, a zoom range, andlayoutandpaintproperties. - images, glyphs and a sprite for icons, patterns and label text.
{
"layers": [
{ "type": "fill",
"source-layer": "Parks",
"paint": { "fill-color": "#2E4A3B", "fill-outline-color": "#4F7A5F" } },
{ "type": "symbol",
"source-layer": "Parks",
"layout": { "text-field": ["get", "NAME"], "text-font": ["Noto Sans Bold"], "text-size": 11 },
"paint": { "text-color": "#9AD3A8" } }
]
}
That is a complete document for ThinkGeo when it is handed to one source in code: version, sources, layer id and layer source are filled in for you. Several documents can be added to one MapStyle, and the later ones draw above the earlier ones. Style Documents explains the format; Basemaps covers the ThinkGeo Cloud styles and the other tile services.
Your data¶
A FeatureSource reads a file, a table or features built in code; a FeatureSourceVectorTileSource cuts what it reads into tiles; the document draws them by source-layer name. Reading the format is the only line that differs between a shapefile, a GeoJSON file, a database table or an in-memory list.
var parks = new FeatureSourceVectorTileSource();
parks.FeatureSources.Add(new ShapeFileFeatureSource(@"Data\Parks.shp")
{
ProjectionConverter = new ProjectionConverter(2276, 3857) // Texas state plane feet -> Web Mercator
});
var style = new MapStyle(ThinkGeoVectorStyles.Light, cloud);
style.AddStyle(parksJson, parks); // the document above; "source-layer": "Parks"
Map.Basemap = new GpuBasemap(style);
A source added without a key gets its file or table name as the source-layer; FeatureSources.Add("parks", source) names it yourself. Styling Your Data has the rules, labels and patterns.
Which way for which data¶
| Data | Where it goes |
|---|---|
| Basemaps, your files and databases, tile archives, map services | A source in the style document |
| Things that move every frame: vehicles, aircraft, a growing track | A DynamicSource in the style, updated one feature at a time |
| Feature state that changes over time | One layer per state, switched with MapStyle.SetLayerVisibility, or a DynamicSource. What a paint delegate returns for a feature is fixed when its tile is built, so a delegate cannot read a clock |
| Fields: a grid of values, wind, readings at points | GridSource, VectorFieldSource and PointValueSource, added with AddGridFill, AddVectorField and AddIsolines |
| Content made from the whole view, such as a graticule with labels at the screen edge | A classic overlay |
| UI elements and interaction: markers, popups, drawing, editing, measuring, scale bars, legends, north arrows | Overlays |
| Drawing only the classic layers do: S-52 nautical charts, raster tiles reprojected as they are read, the keyed commercial raster providers | A LayerOverlay above the basemap |
| Printing and export | MapStyleFeatureAsyncLayer draws a style document on any GeoCanvas, a PdfGeoCanvas included |
Changing the Map While It Runs covers the first three rows in detail.
Zoom and scale¶
The MapView thinks in scale: CurrentScale is the denominator of the map scale, and CurrentExtent and CenterPoint say what is on screen. A style document thinks in zoom levels, the Web Mercator zooms where 0 is the whole world and each level doubles the detail. MapView.ZoomScales is the list that ties the two together: the scale the map snaps to at each zoom. A layer's minzoom and maxzoom, and the ["zoom"] expression inside its paint, refer to those zoom levels.
Platforms¶
| Platform | Package | How the document is drawn | .NET |
|---|---|---|---|
| WPF | ThinkGeo.UI.Wpf | MapView.Basemap draws it on the GPU | .NET 8 or later. On .NET Framework 4.6.2 and later the same package has no Basemap; the map is drawn with the classic path |
| WinForms | ThinkGeo.UI.WinForms | MapView.Basemap, as in WPF | .NET 8 or later; .NET Framework as above |
| Blazor | ThinkGeo.UI.Blazor | VectorTileOverlay hands the document (Style or StyleJson) and your FeatureSources to MapLibre GL in the browser | .NET 8 and .NET 10 |
| .NET MAUI | ThinkGeo.UI.Maui | MapView.Basemap draws it on the GPU on iOS, Android and Windows, as in WPF; the app calls UseThinkGeoGpu() in MauiProgram.cs. The classic overlays are still available | .NET 10 |
| WebApi | ThinkGeo.UI.WebApi | Your endpoint serves vector tiles cut from your FeatureSources by a VectorTileOverlay, and the browser client, such as MapLibre, draws them from the document; or image tiles drawn on the server from classic layers | .NET 8 or later, and .NET Framework 4.6.2 or later |
The style-document renderer needs .NET 8 or later. A desktop project that must stay on .NET Framework uses the classic path, which is the same MapView with Overlays instead of a Basemap; see Classic Rendering. An application that already has classic FeatureLayers can bring them into a style with FeatureLayerTranslator; that page shows how.
When something does not show¶
- The map stays blank. Listen to
Basemap.TileLoadFailed: a tile that cannot be loaded (a wrong key, a server that does not answer, a file that is not there) is left out and raises the event with the exception. - The document has a mistake.
new MapStyle(json, …)andSetStyleAsyncthrow with the reason. The map keeps drawing the last document that worked. - Your data is not drawn. The
source-layerin the document must be the key the source was added under (the file or table name when it was added without one). Data in another projection needs aProjectionConverterto EPSG:3857. Afilterthat matches nothing draws nothing. - Your data appears only when zoomed in.
FeatureSourceVectorTileSource.MinDataZoomandMaxDataZoombound the zooms at which tiles are cut; pastMaxDataZoomthe covering tile is reused.