简体   繁体   English

如何在 Leaflet openPopup 中设置各种选项?

[英]How to set various option in Leaflet openPopup?

I want to remove close button in popup of marker.我想删除标记弹出窗口中的关闭按钮。 How to set option in openPopup() method.如何在 openPopup() 方法中设置选项。 My code is:我的代码是:

var mymap = L.map('map1').setView([lat, lng], 13);

var OpenStreetMap_Mapnik = L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
    maxZoom: 19,
    attribution: '&copy; <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a>'
}).addTo(mymap);

var marker = L.marker([lat, lng]).addTo(mymap);
marker.bindPopup(loc_address);

marker.on('mouseover', function (e) {       
     this.openPopup();
});

marker.on('mouseout', function (e) {
     this.closePopup();
});

The .openPopup method does not expect any option. .openPopup方法不需要任何选项。

It is within the .bindPopup method that you can specify options for your Leaflet Popup.您可以在.bindPopup方法中为 Leaflet Popup 指定选项。

In particular, you should be interested in the closeButton option:特别是,您应该对closeButton选项感兴趣:

Controls the presence of a close button in the popup.控制弹出窗口中关闭按钮的存在。

marker.bindPopup(loc_address, {
  closeButton: false
});

In order to hide the x icon on the marker, you can set the display property of the relevant class to none .为了隐藏标记上的 x 图标,您可以将相关类的display属性设置为none Try using the following code in your css file:尝试在您的 css 文件中使用以下代码:

.leaflet-popup-close-button {
   display: none; 
}

 var map = L.map('mapid').setView([51.505, -0.09], 13); L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', { attribution: '&copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors' }).addTo(map); L.marker([51.5, -0.09]).addTo(map) .bindPopup('A pretty CSS3 popup.<br> Easily customizable.') .openPopup();
 #mapid { height: 100vh; } body { margin: 0px; } .leaflet-popup-close-button { display: none; }
 <link rel="stylesheet" href="https://unpkg.com/leaflet@1.4.0/dist/leaflet.css" integrity="sha512-puBpdR0798OZvTTbP4A8Ix/l+A4dHDD0DGqYW6RQ+9jxkRFclaxxQb/SJAWZfWAkuyeQUytO7+7N4QKrDh+drA==" crossorigin="" /> <script src="https://unpkg.com/leaflet@1.4.0/dist/leaflet.js" integrity="sha512-QVftwZFqvtRNi0ZyCtsznlKSWOStnDORoefr1enyq5mVL4tmKB3S/EnC3rRJcxCPavG10IcrVGSmPh6Qw5lwrg==" crossorigin=""></script> <div id="mapid"></div>

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

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