Art*_*Guy 21 javascript leaflet
我正在寻找自定义使用传单构建的地图,我想自定义Popup(L.popup).
我能想到的唯一方法是使用我的新对话框构建自定义弹出窗口,并在每次用户与标记交互时重新定位,这样当用户拖动地图时弹出窗口保持对齐.
有人知道有任何替代方法或现有方法吗?
谢谢
Rob*_*jic 35
您应该使用css自定义外观.以下选择器可能很有趣:
.leaflet-popup-content-wrapper {
}
.leaflet-popup-content-wrapper .leaflet-popup-content {
}
.leaflet-popup-tip-container {
}
Run Code Online (Sandbox Code Playgroud)
根据您的浏览器,你可以像使用工具的Firebug的Firefox或Chrome浏览器/ Safari浏览器开发者工具的版本(右键点击网页的任意位置上,然后点击审查元素,或使用快捷键),检查弹出式窗口,找到更多CSS选择器是你可能想修改.
要扩展它的功能,您应该首先查看弹出源代码.查看其他Leaflet组件的来源,直到您对正在发生的事情有所了解.以下列方式扩展Popup类,然后更改您想要的任何内容:
L.CustomPopup = L.Popup.extend({
// You changes here
});
Run Code Online (Sandbox Code Playgroud)
Adr*_* C. 12
自定义弹出窗口的另一种方法是为弹出窗口创建自定义css类,如:
<style>
/* css to customize Leaflet default styles */
.popupCustom .leaflet-popup-tip,
.popupCustom .leaflet-popup-content-wrapper {
background: #e0e0e0;
color: #234c5e;
}
</style>
Run Code Online (Sandbox Code Playgroud)
然后在你的地图中div
你可以用bindPopup
方法设置标记自定义弹出窗口并传递一个customOptions对象,你提到css class name
:
// create popup contents
var customPopup = "<b>My office</b><br/><img src='http://netdna.webdesignerdepot.com/uploads/2014/05/workspace_06_previo.jpg' alt='maptime logo gif' width='150px'/>";
// specify popup options
var customOptions =
{
'maxWidth': '400',
'width': '200',
'className' : 'popupCustom'
}
var marker = L.marker([lat, lng], {icon: myIcon}).addTo(map);
// bind the custom popup
marker.bindPopup(customPopup,customOptions);
Run Code Online (Sandbox Code Playgroud)
希望能帮助到你.
mapbox 上有一个使用leaflet.js 的例子。该示例显示了如何在传单中使用自定义工具提示。
<style>
/*
* These CSS rules affect the tooltips within maps with the custom-popup
* class. See the full CSS for all customizable options:
* https://github.com/mapbox/mapbox.js/blob/001754177f3985c0e6b4a26e3c869b0c66162c99/theme/style.css#L321-L366
*/
.custom-popup .leaflet-popup-content-wrapper {
background:#2c3e50;
color:#fff;
font-size:16px;
line-height:24px;
}
.custom-popup .leaflet-popup-content-wrapper a {
color:rgba(255,255,255,0.5);
}
.custom-popup .leaflet-popup-tip-container {
width:30px;
height:15px;
}
.custom-popup .leaflet-popup-tip {
border-left:15px solid transparent;
border-right:15px solid transparent;
border-top:15px solid #2c3e50;
}
</style>
<div class='custom-popup' id='map'></div>
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
34446 次 |
最近记录: |