[OpenLayers-Users] Is there a way to assign a dynamic label on vector layer?

Mark K. Zanfardino mzanfardino at gmail.com
Mon Aug 1 21:01:08 EDT 2011


I have a vector layer that is generated via a WFS layer. I'd like to 
label the vectors according to a field in the source WFS protocol.  My 
layer is currently defined as follows (note that I have used the 
substitution "${name}" in the label parameter).  Currently this renders 
the vectors with the label as "undefined".  I'd like to use the name 
field from the data source as the label for the vectors.  Please let me 
know if I can provide more detail.

tens = new OpenLayers.Layer.Vector("TENS (Vector)",
     {
       styleMap: new OpenLayers.StyleMap({
         fillColor: '#faff6a',
         fillOpacity: 0.5,
         strokeColor: '#000000',
         strokeOpacity: 0.5,
         strokeWidth: 1,
         pointRadius: 4,
         label : "${name}"
       }),
       strategies: [new OpenLayers.Strategy.BBOX()],
       protocol: new OpenLayers.Protocol.WFS({
           srsName: "EPSG:4326",
           url: mapPath,
           featureType: "tenszones",
           featurePrefix: "ms",
               geometryName: "msGeometry"
       }),
       filter: new OpenLayers.Filter.Comparison({
           type: OpenLayers.Filter.Comparison.NOT_EQUAL_TO,
           property: "name",
           value: "Countywide"
       }),
       filter: new OpenLayers.Filter.Comparison({
           type: OpenLayers.Filter.Comparison.LIKE,
           property: "name",
           value: "DOW*"
       })},
       {
           isBaseLayer: false,
           buffer: 0
   });



More information about the Users mailing list