I have a big problem with labels over OpenLayers.Feature.Vector. When I use Canvas renderer all labels are under the externalGraphic of feature. What you can see here:
http://jsfiddle.net/67aaJ/
Do not know how to force labels to be painted over markers. Is it easy to have labels over markers using let say SVG renderer, but in this case labels look messy when 开发者_JAVA百科there is more than one marker in place. It looks like first renderer paint all graphic and than all labels. Example:
http://jsfiddle.net/6kXYh/1/
I am looking for a solution (renderer does not matter) to display markers with labels over it but without "labels colisions", let say we have 5 markers in one position but with different labels I am expecting to see last added feature externalGraphic and its label, previous features (and labels) should be under last one.
Please help! Thank you.
OpenLayers don't have any label collision detection that I'm aware of. I suppose you will have to do it yourself or rely on some mapping software in the backend.
Apologies for answering a very old question, but for others coming upon this question, an alternative solution could be to use the Cluster Strategy and label the cluster. for clusters with more than 1 feature, you could comma separate or \n separate. Eg code here:
var style = new OpenLayers.Style({
label: "${type}",
fillColor: "#ffcc66",
fillOpacity: 0.8,
strokeColor: "#cc6633",
strokeWidth: 2,
strokeOpacity: 0.8
}, {
context: {
type: function(feature) {
// concatenate labels and return
return "the label";
}
}
});
adaped from: http://openlayers.org/dev/examples/strategy-cluster.html
精彩评论