Plan 9: Tiled Map
Use plot(1) to display tiled maps. The zoom factor decides the grid dimension.
osm.js: Download tile images from OpenStreetMaps using hget. Cache the images. Convert the PNG image into Plan 9 format using png. Display the images using plot.
Plot script
Plot tries to center the drawing. Hence the origin is at the bottom with a slight offset from the left. However, image uses origin at the top left.
Interactive Plotting and Maps
Use plot command in server mode (-s option).
Usage as an interactive map.
OSM API
OpenStreetMap Routing
Text Formatting
Demo of some advanced features.
- Set pen color
- Align text around a point
- Set pen thickness
- Set start and end of the line. Available ends are square, disc and arrow.
- Use vec for polyline (a set of points connected with lines)
box 0 0 200 200
co red
fo /n/ttf/ArchitectsDaughter.ttf.26/font
line 100 0 100 200
m 100 100
te \RRight Aligned\n
te \CCenter Aligned\n
te \LLeft Aligned
pe disc disc
li 120 120 180 180
pe disc arrow
li 180 180 180 120
Color codes:
- 0-255 converts to color using cmap2rgba() - alpha is set to 255.
- Black (k, legacy z), Red (r), Green (g), Blue (b), Magenta (m), Yellow (y), Cyan (c), White (w)
Lessons Learnt
- plot squeezes the range into a square viewport. It's advisable to keep the range square as well to avoid confusion.
- Use unloadimage() (or any draw related operations in general) from the main thread ONLY.
Code
Plot: https://gitlab.com/atamariya/plan9front/-/blob/dev/sys/src/cmd/plot/
OSM: https://gitlab.com/atamariya/qjs/-/blob/plan9/osm.js

Comments
Post a Comment