Fix polyline caching in PathVisualizer.

This was a typo/regression from #2223. Also added a test.

Fixes #2250