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 

ra 0 0 200 200
m 0 100
im /file
:Note - must end the script with a newline
 

 

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).

plot -s a.plt 
mount /srv/plot /mnt/plot
echo li 0 0 100 100 > /mnt/plot/ctl
echo erase > /mnt/plot/ctl

Usage as an interactive map.

 

OSM API

Tiles
https://tile.openstreetmap.org/zoom/x/y.png 
The World map at zoom 0
https://tile.openstreetmap.org/0/0/0.png 
 
Geocoding (Name to geographical co-ordinates)
https://nominatim.openstreetmap.org/search?q=hebbal&format=jsonv2&limit=1

Routing
http://router.project-osrm.org/route/v1/driving/77.5963454,13.1006982;77.5919,13.0382184?overview=full&geometries=geojson&steps=true 
 

 

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)  

ra 0 0 200 200

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
 
w 5
pe disc disc
li 120 120 180 180
pe disc arrow
li 180 180 180 120

Color codes: 

  1. 0-255 converts to color using cmap2rgba() - alpha is set to 255.
  2. Black (k, legacy z), Red (r), Green (g), Blue (b), Magenta (m), Yellow (y), Cyan (c), White (w)

 

Lessons Learnt

  1. plot squeezes the range into a square viewport. It's advisable to keep the range square as well to avoid confusion.
  2. 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

Popular posts from this blog

Plan 9 : The Infinity Notebook

Plan 9: Quick Boot with UEFI

Comics Builder in GNU Emacs