[OpenLayers-Users] KML and Attributs

Christopher Schmidt crschmidt at metacarta.com
Wed May 6 07:19:59 EDT 2009


On Wed, May 06, 2009 at 04:14:59AM -0700, zoggo wrote:
> 
> Hi,
> 
> I'm importing a kml text file a a layer in my map:
> 
> var Layer_Regionen = new OpenLayers.Layer.GML("KML",
> "geodaten/regionen.kml", {
> 	   projection: new OpenLayers.Projection("EPSG:4326"),
> 	   format: OpenLayers.Format.KML,
>        formatOptions: {
> 		    extractStyles: true,
> 		    extractAttributes: true
> 		}
> 	});
> 
> Later in the code I'd like to extract some of the attribute out of a feature
> the Layer 'Layer_Regionen'. But i only get a whole string like this:
> 
> "<center><table><tr><th colspan='2'
> align='center'><em>Attributes</em></th></tr><tr
> bgcolor='#E3E3F3'><th>SHAPE_Area</th><td>8.80217136597592</td></tr><tr
> bgcolor=''><th>region</th><td>14</td></tr><tr
> bgcolor='#E3E3F3'><th>SHAPE_Length</th><td>15.2328377860413</td></tr><tr
> bgcolor=''><th>OBJECTID</th><td>2</td></tr></table></center>"
> 
> I only need the attribut 'region' with the value '14'.
> 
> Could someone help me?

As far as OpenLayers is concerned, that is the attribute. This data is
ulikely to be structured in any more useful way. You'll need to use
regular rexpressions or something similar toparse the data out of that.

If the data is included in some other tag in the KML as well, such as
ExtendedData, you may have more options. you might check that first, but
I wouldn't be surprisd if it doesn't.

Regards,
-- 
Christopher Schmidt
MetaCarta



More information about the Users mailing list