Advanced GPolyline usage
Interactivity and performance issues

Tech Tutorial @ Web2Open Berlin, 2007-11-07

Flo Ledermann - maptales.com

Background & Motivation

Working on Maptales (& predecessors) for ~2 years Personal background

Overview: GPolyline

2005

2007

Initial approach

What we wanted

Constraints

Our approach

Drawing lines with DIV's

Bresenham Algorithm

-> Computer Graphics 101, Google, Wikipedia)


Spacing the pixels

Cool: individual pixels can react to DOM events (mouseover, click)
used to implement editing, dragging, dropping and hovering

Apply Bresenham lines to Google Maps

Issues

Lines can get veeeeery long (in pixels) when zoomed in!
A single segment will always be at least 1 pixel when zoomed out

Clipping & Culling

Calculating intersections of lines with viewport boundaries is computationally expensive!

Cohen-Sutherland Clipping

Two-step approach
Not the fastest known clipping algorithm, but intuitive and good performance in JavaScript.

Simplification

Simple Approach: use binary search to eliminate segments which are too close

Overall Conclusions

Things changed

We decided to switch in June 2007, but

-> Hybrid version!

Hybrid polylines

Performance comparison

Very surprising!

Conclusions

Encoded GPolylines

Douglas-Peucker Algorithm

Need code on server (for uploaded GPS data)
and client (for updating edited lines)

Interactive GPolylines

GPolylines do not give you any events (mouseover, click, ...)
How to solve this?

Calculating point-line distance

http://local.wasp.uwa.edu.au/~pbourke/geometry/pointline/
We can do this (with some optimizations) in real time for segments within viewport!

Following lines

Clipping is not needed for GPolylines, but can be reused to

--> The final result

Try out our cool, editable polylines at maptales.com
Or view the screencast first.

Open Q&A



Thanks for your attention!


http://www.maptales.com
http://floledermann.blogspot.com