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'm coding with GeoExt and I have some problems trying to display the names of diferent features in a vector layer.

This is my code:

mapPanel = new GeoExt.MapPanel({
    map: map
});

legendPanel = new GeoExt.LegendPanel({
    defaults: {
            labelCls: 'mylabel',
            style: 'padding:5px'    
        },
    bodyStyle: 'padding:5px; border:1px solid #8db2e3; border-top-width:0px;border-left-width:0px;border-right-width:0px',
    width: 348,
    autoScroll: true
});

In my legend I have 6 sublayers and all of them are titled with "Untitled" + 1,2,3,4,5, ... I would like to change the name of these different features, removing Untitled 1, 2, 3, ...

Does anybody can help me to do that? I think it is easy but I don't know how.

Thanks in advance! Rafael

share|improve this question
    
I'm not sure what you meant. Features and layers in web mapping are completely different things. –  drnextgis Jan 25 '13 at 1:52
add comment

1 Answer 1

There may be an easier way of going about this - but the only way I have found to label vector layers in a GeoExt LegendPanel is to give them a style rule with a name. So for styles that dont require rules, i just add one elseFilter rule (so it will always match) and put the name of the layer / feature in its rule oject:

new OpenLayers.Style(
{ 
    graphicName: "circle"
},
{
    rules : [
        new OpenLayers.Rule({
            name: "Red Circle Feature", // <--- this is what will display in legend panel
            elseFilter: true,
            symbolizer: {
                pointRadius: 12,
                fillColor: "red",
                strokeColor: "black"                    
            }
        })
    ]
})
share|improve this answer
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.