admin管理员组文章数量:1303404
I want to add a text to the map that not scaled when zoom change and remain with it's original sizes.
I use this code (javascript):
var text = new L.marker(rect.getBounds().getSouthWest(), {opacity: 0.0001});
text.bindLabel("TEXT", styleProperties);
text.addTo(myLayer);
and obtain this unwanted result:
I want that the text remain with the sizes of the first image at left when zoom are applied. Is it possible?
edit: the text must be like a name of the city, that moves with map but not change it's size when zoom (yes, I know that name of cities are images, for that not is easy solve my problem). Thanks however for answers, for now I maintain the labes, not is an elegant solution but works.
I want to add a text to the map that not scaled when zoom change and remain with it's original sizes.
I use this code (javascript):
var text = new L.marker(rect.getBounds().getSouthWest(), {opacity: 0.0001});
text.bindLabel("TEXT", styleProperties);
text.addTo(myLayer);
and obtain this unwanted result:
I want that the text remain with the sizes of the first image at left when zoom are applied. Is it possible?
edit: the text must be like a name of the city, that moves with map but not change it's size when zoom (yes, I know that name of cities are images, for that not is easy solve my problem). Thanks however for answers, for now I maintain the labes, not is an elegant solution but works.
Share Improve this question edited Sep 8, 2016 at 11:17 user.kt asked Sep 7, 2016 at 10:11 user.ktuser.kt 1971 gold badge3 silver badges12 bronze badges4 Answers
Reset to default 2It looks to me your text is not really related to your map. What about adding the text in another div over the container of the map ?
<div>
<div id="map" style="width: 600px; height: 400px"></div>
<div style="pointer-events: none; position: absolute; top: 100px; left: 100px">foo bar</div>
</div>
See full example here
You could use Leaflet.label plugin (starting with Leaflet 1.0, L.Label is added to Leaflet core as L.Tooltip). You can style it with your own css. See the example.
As far as I understand, you want dynamic font size according to the zoom level. Just the opposite you mentioned.
You can change the font size according to the zoom level. For Leaflet.Label plugin you can add an event handler for zoomend and play with the font-size of the label and other styles of the label.
I have another example without Leaflet.Label, which adds a text element next to the path object. So the text is embedded in the svg and I change the font size according to the zoom level. Though I couldn't find a better function.
https://embed.plnkr.co/hU6ip8T58tvE7CHJwniR/
Use a marker with a L.DivIcon
.
本文标签: javascriptcan I have fixed text in leafletStack Overflow
版权声明:本文标题:javascript - can I have fixed text in leaflet? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741747441a2395620.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论