user1319894
user1319894

Reputation: 1

open layer: display a label from properties in geojson file

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?

Upvotes: 0

Views: 2599

Answers (2)

Šarūnas Rimša
Šarūnas Rimša

Reputation: 21

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.

Upvotes: 2

Odoakr
Odoakr

Reputation: 382

Well, try:

'label': '${label}'

Upvotes: 0

Related Questions