Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I need to show label of each feature based on attribute field value. I know that I can use ${attribute} notation for this purpose. But this approach works only if I make StyleMap and pass it to vector layer constructor. But in this case I can not modify style of each features separately. How I can make layer with labels and with not null value of style property of each feature? My current config:

var custom_style = {
    fill: true,
    fillColor: "#feb24c",
    fillOpacity: 0.2,
    strokeColor: '#3182bd',
    strokeWidth: 1
};

var l = new OpenLayers.Layer.Vector("Coverage", {
    strategies: [new OpenLayers.Strategy.BBOX()],
    protocol: new OpenLayers.Protocol.HTTP({
        url: "http://***:8088/collect",
        format: new ol.Format.GeoJSON()
    }),
    style: custom_style
});

If I add label: ${attribute} to custom_style object, then text ${attribute} will be shown on map, not value of attribute.

share|improve this question
    
are you having problems because some features have null value? –  neogeomat Oct 28 '13 at 13:54
add comment

1 Answer

In the case of the label, probably this may work:

label: '${attribute}'

Here I modified your code with it:

var custom_style = {
    fill: true,
    fillColor: "#feb24c",
    fillOpacity: 0.2,
    strokeColor: '#3182bd',
    strokeWidth: 1,
    label: '${attribute}'
};

var l = new OpenLayers.Layer.Vector("Coverage", {
    strategies: [new OpenLayers.Strategy.BBOX()],
    protocol: new OpenLayers.Protocol.HTTP({
        url: "http://***:8088/collect",
        format: new ol.Format.GeoJSON()
    }),
    style: custom_style
});
share|improve this answer
    
Unfortunately, this approach doesn't work as I mentioned above. –  drnextgis May 29 '13 at 1:54
    
could you post some images showing what you have and what you expect? –  Gery May 29 '13 at 10:44
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.