admin管理员组文章数量:1430704
I'm currently working on OL3 and trying to display a text on my map. No problem with that, I'm using the text property of ol.style to display it.
My problem is the following: this text has always the same size. ie: if I'm unzooming max or zooming max, it's still the same size on the screen. I want it to grow while zooming, and shrink while unzooming to keep the text's size relative to the ground.
I drew the expected result in the following image: Expected result
Is anyone having an idea? Maybe without using a ol.style text?
I'm currently working on OL3 and trying to display a text on my map. No problem with that, I'm using the text property of ol.style to display it.
My problem is the following: this text has always the same size. ie: if I'm unzooming max or zooming max, it's still the same size on the screen. I want it to grow while zooming, and shrink while unzooming to keep the text's size relative to the ground.
I drew the expected result in the following image: Expected result
Is anyone having an idea? Maybe without using a ol.style text?
Share Improve this question edited Aug 31, 2016 at 13:54 Jonatas Walker 14.2k6 gold badges57 silver badges82 bronze badges asked Aug 31, 2016 at 9:43 Yoann BYoann B 1232 silver badges12 bronze badges 1- Any feedback ...? – Jonatas Walker Commented Sep 8, 2016 at 7:55
1 Answer
Reset to default 5The way to go is a style function. See demo fiddle.
var style = function () {
var zoom = map.getView().getZoom();
var font_size = zoom * 10; // arbitrary value
return [
new ol.style.Style({
text: new ol.style.Text({
font: font_size + 'px Calibri,sans-serif',
fill: new ol.style.Fill({ color: '#000' }),
stroke: new ol.style.Stroke({
color: '#fff', width: 2
}),
text: 'Some text!'
})
})
];
};
本文标签: javascriptOpenLayers 3Display text on maptext size relative to zoomStack Overflow
版权声明:本文标题:javascript - OpenLayers 3 - Display text on map, text size relative to zoom - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745532135a2662109.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论