简体   繁体   English

在 Leaflet.js 地图上覆盖文本框

[英]Overlaying a text box on a leaflet.js map

This might seem a very simple question, but I've searched elsewhere for the answer with no luck!这似乎是一个非常简单的问题,但我在其他地方寻找答案却没有运气!

How do I overlay a simple text box on to a Leaflet map that loads when the map loads (not fixed to any point on a map) - for example, to give a title and more information within the actual map object.如何将一个简单的文本框叠加到在地图加载时加载的 Leaflet 地图上(不固定到地图上的任何点) - 例如,在实际地图对象中提供标题和更多信息。 Nothing fancy.没有什么花哨。

I know this is old, but here's some sample code, CSS as necessary:我知道这是旧的,但这里有一些示例代码,必要时使用 CSS:

 L.Control.textbox = L.Control.extend({ onAdd: function(map) { var text = L.DomUtil.create('div'); text.id = "info_text"; text.innerHTML = "<strong>text here</strong>" return text; }, onRemove: function(map) { // Nothing to do here } }); L.control.textbox = function(opts) { return new L.Control.textbox(opts);} L.control.textbox({ position: 'bottomleft' }).addTo(map);

您有两个简单的选项,扩展一个新的L.Control并将其放置在地图窗口的四个角之一中,其内容在onAdd方法内创建,或者将L.DivIcon放置在地图上的任何位置,与L.Marker一起L.Marker ,无论是地理坐标还是基于容器尺寸的坐标。将它作为“盒子”就像你想要的那样只包含一小部分CSS,比如一些paddingbackground-color等。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM