Avi*_*dam 5 javascript popup leaflet
我想删除标记弹出窗口中的关闭按钮。如何在 openPopup() 方法中设置选项。我的代码是:
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: '© <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();
});
Run Code Online (Sandbox Code Playgroud)
该.openPopup方法不需要任何选项。
您可以在该.bindPopup方法中为传单弹出窗口指定选项。
特别是,您应该对以下closeButton选项感兴趣:
控制弹出窗口中是否存在关闭按钮。
marker.bindPopup(loc_address, {
closeButton: false
});
Run Code Online (Sandbox Code Playgroud)
为了隐藏标记上的 x 图标,可以将display相关类的属性设置为none。尝试在您的 css 文件中使用以下代码:
.leaflet-popup-close-button {
display: none;
}
Run Code Online (Sandbox Code Playgroud)
.leaflet-popup-close-button {
display: none;
}
Run Code Online (Sandbox Code Playgroud)
var map = L.map('mapid').setView([51.505, -0.09], 13);
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
attribution: '© <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();Run Code Online (Sandbox Code Playgroud)
#mapid {
height: 100vh;
}
body {
margin: 0px;
}
.leaflet-popup-close-button {
display: none;
}Run Code Online (Sandbox Code Playgroud)