Hi Yvo,
Based on your findings, I'm afraid that it might not be possible to use
information from ExtendedData for Styling out of the box.
However, you should be able to do it with a workaround: add an event
listener for the 'beforefeatureadded' event to your layer and manipulate
the feature attributes before the features get added to the layer.
You could add something like this to your layer definition (again:
untested):
...
eventListeners: {
'beforefeatureadded': function(evt) {
var a = evt.feature.attributes;
a.RiskAssessmentTotal = a.RiskAssessmentTotal.value;
return true;
}
}
...
This will overwrite the RiskAssessmentTotal attribute with the value you
want. You can then reference the attribute like any other:
"${RiskAssessmentTotal}".
Regards, Roald
On 31/12/10 02:43, Yvo Weidmann wrote:
Dear Roald
Thank you very much for your hint. So far it is not working. I implemented as
you recommended. But no marker is visible.
See below the code I am using (with OL 2.10). Additionally you can check the
example with the following link:
http://www.geoidee.ch/projects/FuE_OpenLayers/Styles/Styles.html
Links to the source are provided.
------------ Start KML Fragment ------------
...
<Placemark>
<name>Sadaqat</name>
<ExtendedData>
<Data name="RiskAssessmentTotal">
<value>10</value>
</Data>
</ExtendedData>
<Point><coordinates> 69.807899,38.843349,0.000000</coordinates></Point>
</Placemark>
...
------------ End KML Fragment --------------
------------ Start JScript Fragment --------
...
// Style with use of extended attributes of the KML file
var styleMapExtendedAttributes = new OpenLayers.StyleMap({'default':{
...
pointRadius: "${RiskAssessmentTotal.value}",
...
}});
// KML file with StyleMap based on extendedAttributes
var villages = new OpenLayers.Layer.GML("Villages", "Villages/doc_attr.kml",
{
format: OpenLayers.Format.KML,
formatOptions: {
extractStyles: false,
extractAttributes: true
},
styleMap: styleMapExtendedAttributes,
projection: map.displayProjection
});
// Adding layers to the map
map.addLayers([gsat, villages]);
...
------------ End JScript Fragment ----------
Thank you very much for any further ideas,
Yvo
---------------------------------------------------------
Yvo Weidmann
734003, 4 Farkhad Str.
Dushanbe
Republic of Tajikistan
Mobile +992 98 53 11 090
Skype yvo.weidmann
-----Original Message-----
From: Roald de Wit [mailto:[email protected]]
Sent: Thursday, December 30, 2010 2:46 AM
To: Yvo Weidmann
Cc: [email protected]
Subject: Re: [OpenLayers-Users] KML styling with ExtendedData
Hi Yvo,
Since version 2.8 OL is capable of parsing ExtendedData. The following
example shows how load a KML file in general:
http://openlayers.org/dev/examples/kml-layer.html
In your case, you need to set 'extractStyles' to false instead of true.
That way you can control the styling yourself. You can then use the
attributes from your features for styling, eg:
...
pointRadius: "${myValue.value}"
...
(note the .value after your variable name)
This is untested, so please report back if it doesn't work for you,
preferably with a complete example (posted to something like pastebin).
HTH,
Roald
On 28/12/10 20:56, Yvo Weidmann wrote:
Dear List
I am using a KML file which includes some ExtendedData. A single
placemark looks about that:
<Placemark>
<name>Sadaqat</name>
<ExtendedData>
<Data name="myValue">
<value>2</value>
</Data>
</ExtendedData>
<Point>
<coordinates> 69.807899,38.843349,0.000000</coordinates>
</Point>
</Placemark>
Is there a good example known, showing how to use elements /
attributes of ExtendedData for styling?
Looking forward to any hint,
Yvo
_______________________________________________
Users mailing list
[email protected]
http://lists.osgeo.org/mailman/listinfo/openlayers-users
_______________________________________________
Users mailing list
[email protected]
http://lists.osgeo.org/mailman/listinfo/openlayers-users