Skip to content

DisplayingVectorGraphics

Colin Zwiebel edited this page Jul 19, 2011 · 1 revision

Displaying Vector Graphics

It would be useful to display vector graphics in browser for system map purposes. This is a no easy task, however. Research on the best approach to displaying vector graphics follows.

Requirements

  • Display vectors within OTP technologies (OpenLayers)

  • Retain compatibility with all major browser (excluding IE6)

  • Penalties for flash and plugins (generally not compatible with OpenLayers, anyway)

Option 1: SVG display libraries

Ample

http://www.amplesdk.com/examples/svg/

Looks interesting. This one is a SVG2VML conversion, but browser-side. Might work. I imagine it would require modification of OpenLayers/ImageLayer.

svgweb

http://code.google.com/p/svgweb/

This one has some spiffy videos behind it, but suffers from the major problem of flash. It renders svg through flash in IE. OpenLayers places the base layer (divs/img elements) below feature layers (IE, the symbols, labels). This layering would not be possible if the symbol layers were flash objects.

Raphael

Another "svg in IE" type thing. Raphael adds a cross-platform, scene-graphed canvas-like object you can draw in using Javascript. It might be a good choice, except, again, it will require modification of OpenLayers ImageLayer to work. And it can't do SVG! You have to use Raphael drawing commands. Transforming SVG to that stuff is possible, but again, we're not saving our selves a format conversion or using a forward-looking open-standard.

Display of SVG in IE would probably be possible with Ample. It would be my best bet. However, still have to fix the FF issue (dunno why it doesn't work), and Ample won't help there (generates VML for IE, Firefox thinks VML is as crazy as you and I do).

Option 2: SVG to VML Conversion

Original attempt was a PHP app called "vector converter" (http://vectorconverter.sf.net) but its dated (as is VML) and requires PHP4. Getting it tow work is a trick, and the online version of the converter:

http://www.new-ural.net/

doesn't appear to work. Grr.

Vector Converter, has problems. To begin with, the project requires php4. It has an include to wrap it into php5, and I couldn't get it to work without php4. Even then it only works with very simple graphics. I suspect more sophisticated SVGs contain advanced elements or tranforms it dislikes. Vector Converter is based on XSLT, so if we had to perform this conversion a lot, I would just take the transforms from the project, and use something like lxml and python to apply the transforms. Documents might need a little pre-processing to make them simple and standard enough for the Vecter Converter XSL transforms to work properly.

Looking into VML more, its a strange, integrated XML format. It does not use xhtml tags. This is important because the OpenLayers ImageLayer works by creating divs and img elements and moving them around for the panning effect. Point ImageLayer at an SVG and it just sticks it in the src attribute. Modifying ImageLayer to use <v:group> elements would be more work. This is pretty much a deal breaker.

That and VML is being depricated. According to the Microsoft VML to SVG Migration Guide:

http://www.microsoft.com/downloads/details.aspx?FamilyID=2e8d87f2-c6ce-491f-a8e1-3413e0cff24a&displaylang=en

"Microsoft expects web sites to transition to SVG in the future"

Whether Microsoft expects to transition to actually supporting SVG is another story.

Another format option is XAML. Another Microsoft meta-lanuage vector format (because there clearly are not enough of these!). This one they made after SVG, because following an open standard would just be insanity (to be fair, VML could have become an intenet standard, but the W3C came up with SVG instead).

Anyway, XAML is very SVG-like. Only with SilverLight can IE display XAML. This is a problem. Its the good old IE6 problem. People without administrator privlidges cannot install SilverLight. They also will not be able to updgrade to IE v2000 (in which MS finally gets around to supporting SVG). So dealbreaker for XAML. People who want to use OpenTripPlanner in a jiffy will not want to have to install SilverLight. So this is not a good option.

Option 3: GeoSpatial Vector formats

Look like the way to go. OpenLayers can already do them and display properly in IE. No need to install SilverLight or other crap. And as a bonus, because they would be real OL features, selection and hover-over events are possible. The big con is 1) probably have to be converted by hand 2) KML may not be as versatile as SVG and may not look exactly the same as the provided system map. For our purposes, probably alright.

Straight Line Approximation

KML doesn't support curves (splines, Belzier curves). Symbols, etc need straight-line approximations.

Using Inkscape, I applied the "Modify Path -> add Nodes" extension, requiring 2 segments every 3 pixels. Then I selected each path and chose "make segments into lines". Straightening isn't technically required. Instead, you could just take the path data (IE, ) and treat the "curve to," "Belzier curve to," commands as line-to commands. Straightening does clean up the path data.

Unfortunately, Inkscape does not have a macro function, so these tasks were manual.

System Map Shop Future:

Doing a lot of conversions, I would write an Inkscape extension that applies the "add Nodes" and straighten extensions to all elements in a document. Or if illustrator can do the job, use that.

Automated Conversion to KML

This Java util exists and may be promising. For now, I'm just trying to do a proof-of-concept. Style KML like the original map. But keep it in mind for the future:

https://bitbucket.org/tbrugz/kmlutils/wiki/Home

Clone this wiki locally