VisQuill on a map · Part 1 of 6
Map and graphic
A MapLibre map with a VisQuill graphic on top of it, and what it takes to make them work together.
Map and graphic
The base map comes from MapLibre, an open-source library for interactive
maps. VisQuill draws on top of it. The GDK has no map support of its own;
the small file map.ts connects the two.
createMap returns the MapLibre map and the VisQuill
graphic.
Two layers
The demo's div gets two children of the same size: one for the map, one for the graphic, which lies on top. The map shows the area between two corners, with 20 pixels of space around it.
The tiles come from OpenFreeMap. They need an internet connection, and the attribution in the corner must stay visible.
The worker
MapLibre reads its tiles in a web worker, a script that runs next to the
page. Vite, the build tool of this project, does not find the worker file
by itself. The ?worker&url import gives its URL, and
setWorkerUrl passes it to MapLibre.
No labels on the map
The base map has its own place names. They would compete with the names the graphic draws, so they are hidden once the map style is loaded.
Letting the pointer through
The graphic lies on top of the map and would catch every click and
drag. With pointer-events: none, all input goes through to
the map, so it can be panned and zoomed as usual. Visuals that should react
to the pointer, such as a handle, turn it back on in CSS.
From coordinates to pixels
toScreen turns a longitude and latitude into a pixel
position in the graphic; toGeo does the reverse. Both use
MapLibre's project and unproject. The result
changes whenever the map is panned or zoomed.
A point in pixels
The ring in the middle is placed in pixels, at the center of the graphic's frame. Pan the map: the ring stays where it is. It belongs to the graphic, not to a place on the map.
Removing the map
The map is not part of the graphic. run returns a function
that removes it; this page calls it when the demo is taken off the
page.
