0

I am new to open layer map. I am trying to display a label on a marker by reading the label from a geojson file.

Here is the format of my geojson file:

{
    "type": "FeatureCollection",
    "features": [
        {"type":"Feature","properties":{"label":"1"}, "geometry":{"type":"Point", "coordinates":[-81, 42]}},
    ]
}

I tried to use attribute replacement to display the label. Here is the code:

var vector_style = new OpenLayers.Style({
        'fillColor': '#669933',
        'fillOpacity': .8,
        'strokeColor': '#aaee77',
        'strokeWidth': 3,
        'pointRadius': 8,
        'label': '${label}'
    });

However, all the other properties are shown except the label. Could you please tell me how I can display the label from the geojson file?

user1319894
  • 1
  • 2
  • 3

2 Answers2

2

You can try this approach:

var vector_template = {
        fillColor: '#669933',
        fillOpacity: .8,
        strokeColor: '#aaee77',
        strokeWidth: 3,
        pointRadius: 8,
        label: '${label}'
    }

var vector_style = new OpenLayers.Style(vector_template);

It works for me. Otherwise try changing label to something else.

0

Well, try:

'label': '${label}'
Odoakr
  • 382
  • 1
  • 13
  • 'label' might be a kind of key word... try to change it on something like 'displayLabel'... – Odoakr Aug 06 '12 at 13:56
  • It is still not working. Not matter what key words I used in the properties section, the label just did not show up on the map. – user1319894 Aug 06 '12 at 14:47