[OpenLayers-Users] Vector labels at different zoom levels

Cliang thephatness.nabble at mailnull.com
Sat Apr 17 11:36:35 EDT 2010


Arnd,

Thanks for that code. I wasn't aware you can apply context to a style. I was
able to hide labels if they do not fit within the geometry for the current
zoom. Is there a better way to get the average pixel width of a label
character for a fixed font size instead of hardcoding it like this?

context: {
  getLabel: function(ft) {
    var label = ft.attributes.label;
    var width = ft.geometry.getBounds().getSize().w /
ft.layer.map.getResolution();
    return width > (label.length * 7) ? label : '';
  }
}

-=Cliff
-- 
View this message in context: http://n2.nabble.com/Vector-labels-at-different-zoom-levels-tp4892404p4917936.html
Sent from the OpenLayers Users mailing list archive at Nabble.com.



More information about the Users mailing list