編輯2017年5月18日:原始CSS和Javascript通過傳單框架(推薦)
我一直在尋找通過源代碼the BoxZoom plugin,發現使用Leaflet's built-in DOM mutators他們的做法,並希望在這裏推廣。 ..這當然是最好的做法。
Example jsfiddle
某處在你的CSS包括像這樣一類..
.leaflet-container.crosshair-cursor-enabled {
cursor:crosshair;
}
如果要啓用十字線,在你的JS做..
// Assumes your Leaflet map variable is 'map'..
L.DomUtil.addClass(map._container,'crosshair-cursor-enabled');
然後,當你想禁用十字線,在你的JS做這個..
L.DomUtil.removeClass(map._container,'crosshair-cursor-enabled');
原來的答案:地圖級別的十字線
@ scud42讓我在正確的道路上。您可以使用jQuery來改變單張地圖光標這樣的:後來
$('.leaflet-container').css('cursor','crosshair');
然後,當你想重置地圖光標,你可以這樣做:
$('.leaflet-container').css('cursor','');
編輯1.21 。2016年每功能準星
您也可以爲個別功能支持className
選項,如多邊形或功能頂點等
這裏十字線是一個可拖動的頂點,將切換指針的例子十字線(jsfiddle):
var svg_html_default = '<div style="margin:0px;padding:0px;height:8px;width:8px;border-style:solid;border-color:#FFFFFF;border-width:1px;background-color:#424242"</div>';
var default_icon = L.divIcon({
html: svg_html_default,
className: 'leaflet-mouse-marker',
iconAnchor: [5,5],
iconSize: [8,8]
});
var m = new L.marker([33.9731003, -80.9968865], {
icon: default_icon,
draggable: true,
opacity: 0.7
}).addTo(map);
m.on("mouseover",function(){$('.leaflet-mouse-marker').css('cursor','crosshair');});
m.on("mouseout",function(){$('.leaflet-mouse-marker').css('cursor','');});
當控制按鈕被禁用時,任何類已被添加到按鈕? –