openlayers/openlayers — pull request #247 by probins (2012-02-26 17:50:56+00:00)
Title: KML: write attributes; add option for kvp attributes

A follow-up to #100.

1. Adds a new kvpAttributes property to determine whether extendedData nodes should create kvp (so compatible with other formats) or object (as at present) attributes. For BC (and to pass all the tests), I've made the default for this false.
2. Adds a new buildExtendedData method to output feature attributes as extendedData Data nodes. This does not use kvpAttributes, but tests whether the attribute value is an object or not.

This can be tested very simply with examples/vector-formats.html. I've tried all the variations I can think of, and they all seem to be correct.

The compatibility issue is not as simple as I thought at first, as GeoJSON attributes too can be objects, as in prop1 in the final feature in the sample at http://geojson.org/geojson-spec.html
If you feed this sample into examples/vector-formats.html you will see that GML and GeoRSS aren't catering for this, but outputting [object Object]. At least GeoJSON is handling it correctly :-) What I've done is allow for extendedData-type objects, but just output empty nodes for any other objects. I doubt whether this issue occurs very often, so it's probably not worth spending much time on.

Because parseAttributes() is not differentiating between Data and SimpleData elements, any schema info is lost on output. You could I suppose set keepData on the format, and fish that out of there, but then lots of other elements are lost too. If you want full editing of kml, you should use Google Earth, not OL :-)

I should probably add some new tests, and also add something to the release notes. Anything else?