[OpenLayers-Users] Display a Attribute of a GML-File on label in OpenLayers

Xavier Mamano (jorix) xavier.mamano at gmail.com
Tue Mar 5 14:35:57 PST 2013


Hi,

Create a styleMap object as well:
var gmllayer = new OpenLayers.Layer.Vector("GML", { 
  ...
  styleMap: new OpenLayers.StyleMap({strokeColor:"#2C5C91",
    fillColor:"#2C5C91",strokeWidth:1,fillOpacity: 0.1, 
    label:"${name}",labelOutlineColor:"white",labelOutlineWidth:1 }),
  ...
});

Regards,

Xavier Mamano



Gau, Hans-Jürgen wrote
> hello,
>  
> sorry, I'm beginner...
> 
> I want to display attribute called 'name' of a GML file on the map as a
> label in the center of the polygon. I tried the following example with
> only one feature. The polygon is correctly displayed but instead of "name
> of polygon" "${name}" is displayed.
> 
> ...
> 		var gmllayer = new OpenLayers.Layer.Vector("GML", {
>                 protocol: new OpenLayers.Protocol.HTTP({
>                     url: "./gml/test.gml", 
>                     format: new OpenLayers.Format.GML({extractAttributes:
> true})   
> 					}),
> 				style: {strokeColor:"#2C5C91",
> fillColor:"#2C5C91",strokeWidth:1,fillOpacity: 0.1,
> 						label:"${name}",labelOutlineColor:"white",labelOutlineWidth:1 },
>                 strategies: [new OpenLayers.Strategy.Fixed()]
>             });
>         map.addLayer(gmllayer);
> ...
> 
> GML-File test.gml, you see tested with Atribute and element 'name'
> 
> ###Begin of GML-file
> 
> <?xml version="1.0" encoding="ISO-8859-1"?>
> <wfs:FeatureCollection  xmlns:wfs="http://www.opengis.net/wfs" 
> xmlns:gml="http://www.opengis.net/gml"
> xmlns:ogc="http://www.opengis.net/ogc"
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
>     
> <gml:featureMember  name="name of polygon">
>       
> <polygon fid="1" name="name of polygon">
>         
> <msGeometry  name="name of polygon">
>         
> <gml:Polygon srsName="EPSG:25832">
>           
> <gml:outerBoundaryIs  name="name of polygon">
>             
> <gml:LinearRing>
>               
> <gml:coordinates name="hoaoaoa!" >
> 657211.496206959,5852409.25758288 702139.320850297,5854075.33901891
> 700277.499102075,5898550.55493897 655763.294395135,5896890.64992756
> 657211.496206959,5852409.25758288 
> </gml:coordinates>
>             
> </gml:LinearRing>
>           
> </gml:outerBoundaryIs>
>         
> </gml:Polygon>
>         
> </msGeometry>
>         
> <ogc_fid>
> 1
> </ogc_fid>
>         
> <name>
> name of polygon
> </name>
>         
> <id>
> 1
> </id>
>       
> </polygon>
>     
> </gml:featureMember>
> </wfs:FeatureCollection>
> ###END of GML-file
> 
> 
> I've searched a lot on openlayers-website but nothing has helped me
> finally.
> 
> Best regards, hans
> _______________________________________________
> Users mailing list

> Users at .osgeo

> http://lists.osgeo.org/mailman/listinfo/openlayers-users





--
View this message in context: http://osgeo-org.1560.n6.nabble.com/Display-a-Attribute-of-a-GML-File-on-label-in-OpenLayers-tp5038568p5038655.html
Sent from the OpenLayers Users mailing list archive at Nabble.com.


More information about the Users mailing list