I need to use Jquery to handle other elements on the webpage. I tried to put labels on a vector layer with the following style:
var vector_style = new OpenLayers.Style({
'fillColor': 'red',
'fillOpacity': .8,
'strokeColor': '#aaee77',
'strokeWidth': 3,
'pointRadius': 8,
'label': "${name}",
'labelAlign': "cc",
});
But the labels do not show.
I am just wondering if there is a conflict on this one "${name}". I tested it again with a simple page without Jquery. The labels do show. Please let me how to fix this. Thanks.
Update: I just figured out the conflict may come from Spring or JSTL. I use Firebug tool to check the javaScript source code of the style. It appears as this:
var vector_style = new OpenLayers.Style({
fillColor: 'red',
fillOpacity: .8,
strokeColor: '#aaee77',
strokeWidth: 3,
pointRadius: 8,
label: "",
labelAlign: "cc",
});
I returned an variable from the server side:
model.addAttribute("name", "test");
then all features show the label "test". It approved that ${name} is recognized as a spring variable.
map.layers[0].styleMap.styles.default.defaultStyle.labelreturns null andmap.layers[0].features[0].attributes.namereturns the value. – Alex Dec 21 '12 at 21:22