openlayers/openlayers — pull request #504 by probins (2012-06-01 09:48:27+00:00)
Title: KML: export style

Builds on http://trac.osgeo.org/openlayers/ticket/2409 with the following additions/changes:
1. stores incoming document-level 'shared' styles and stylemaps so they can be output as input
2. if feature has attributes.styleUrl this will be output (and assumed to refer to a stored style)
3. if no styleUrl, Placemark style will be created specific to feature
4. named colors ('blue', 'red' etc) catered for by cross-reference object which developers can supply as they wish (I decided this was better than providing a large object with all colors, as most sites won't use most colors)

Open issues:
- shared styles are in Document element, which means the Folder element output at the moment is now redundant. I would prefer to get rid of this, but name/description are currently API properties. If people want to keep the Folder for bc, a possible compromise would be to add code not to output if name null
- as noted in the patch on trac, current OL code should be updated to kml 2.2. I'll look into this and put in separate pull request
- OL style (at least if you use the defaults) returns a symbolizer which caters for all geometry types. It would reduce the output file size if the feature style only output the style for the geometry type. I've left that for someone else to do if they like :-)

Tests which compare output will have to be changed, but I have left that pending decision on what to do with folder. I can add a few basic style output tests, but there are so many different variations and combinations that it's impossible to test everything.
I have tested with some test data of my own, plus with live data. I have also uploaded output to maps.google.com, made changes, downloaded to OL, changed, re-uploaded and back again, and have not noticed any problems. It would be good, though, if others could test this with their own data to see if there are issues.

I have changed vector-formats example as in trac patch, and you can use this for testing, though if you want to test the output of saved style elements you'll have to copy the saved styles from formats.in.kml to formats.out.kml