[OpenLayers-Dev] rule based stylemapsand attribute object-values

Richard Duivenvoorde rdmailings at duif.net
Mon Mar 7 16:31:48 EST 2011


Richard Duivenvoorde wrote:
> Trying and debugging rulebased stylemaps like
> http://openlayers.org/dev/examples/stylemap.html
> 
> with a vector layer build from a KML I encounter the problem that the
> attribute values(!) of the vector layer are not literals/numbers, but
> objects with two members: 'value' and 'displayName'
> 
> it looks like the OpenLayers.Style.createLiteral (in
> OpenLayers.Style.js) is not working with that.
> 
> 1) what is a normal value for attributes: always literals, or is it
> supposed to be either a literal or an object (I mean is it a quirck of
> the KML format parser or is that a normal convention)
> 
> 2) should the createLiteral handle object values for attributes?

ok, my 'problem' is that the KML parser always(!) makes an object of the
attribute value when the placemarks in the KML contain 'Extended data'
nodes. By the way this KML is made by just creating a simple shapefile
(WITH some attributes) and export that one to KML
giving rise to something like:

<Placemark>
	<name>Start</name>
	<ExtendedData><SchemaData schemaUrl="#points">
		<SimpleData name="name">Start</SimpleData>
		<SimpleData name="icon">1</SimpleData>
		<SimpleData name="info"></SimpleData>
		<SimpleData name="page">start.html</SimpleData>
	</SchemaData></ExtendedData>
<Point><coordinates>4.635989855901445,52.38715008076877</coordinates></Point>
</Placemark>

The OL kml parser has code below to parse that data and always makes an
object ('ed') of it instead of the literal value:

parseExtendedData: function(node) {
        var attributes = {};
        ...
        var simpleDataNodes = node.getElementsByTagName("SimpleData");
        for (i = 0, len = simpleDataNodes.length; i < len; i++) {
            var ed = {};
            data = simpleDataNodes[i];
            key = data.getAttribute("name");
            ed['value'] = this.getChildValue(data);
            ed['displayName'] = key;
            attributes[key] = ed;
        }
        return attributes;
    },


It's easy to patch (for myself), but question is: do we want to have
attributes which have object values with as only 'extra' and member
displayName, which is exact the same as the key(!)?

Are there any other parsers which parse attribute values as objects?

Regards,

Richard


More information about the Dev mailing list