block by rveciana 3fa92915c4c2e67940fb88d698bb712b

Animated path using Canvas and point-at-length

Full Screen

Creating visualizations like this one but using canvas is possible.

Since the Canvas element hasn’t got the getTotalLength() method as it exists in SVG, I’m using the point-at-length library, that calculates exactly this.

The library is designed to be used only from nodejs, but using browserify (as in this post), this is not a ptoblem:

browserify index.js --standalone Points > point-at-length.js

In a previous version of the block, I created an SVG element to use the getTotalLength() method, which is much less elegant and can’t be used in a nodejs environment.

The library doesn’t give an exact value, I’ll have to investigate more…

The path is the Trans Mongolian train route taken from here but redrawn, since the original is a multi line.

index.html

point-at-length.js

transsiberian.dbf

transsiberian.json

transsiberian.prj

transsiberian.qpj

transsiberian.shp

transsiberian.shx