Leaflet Webサイトの例を使用して、L.Controlオブジェクトがとしてインスタンス化される場所に注意してくださいinfo。これは、<div>マップのホバーインタラクションに関連付けられた右上のボックスです。以下はindex.html、リーフレットの例で定義されている場所です。
// control that shows state info on hover
var info = L.control();
info.onAdd = function (map) {
this._div = L.DomUtil.create('div', 'info');
this.update();
return this._div;
};
info.update = function (props) {
this._div.innerHTML = '<h4>US Population Density</h4>' + (props ?
'<b>' + props.name + '</b><br />' + props.density + ' people / mi<sup>2</sup>'
: 'Hover over a state');
};
info.addTo(map);
ユーザーのカーソルがこの<div>ボックス内にあるときにドラッグを無効にするには、オブジェクトを含むHTMLElement(<div>要素)にイベントリスナーを追加しL.Controlます。
// Disable dragging when user's cursor enters the element
info.getContainer().addEventListener('mouseover', function () {
map.dragging.disable();
});
// Re-enable dragging when user's cursor leaves the element
info.getContainer().addEventListener('mouseout', function () {
map.dragging.enable();
});
以前にインスタンスmapとして定義されたことを思い出してくださいL.Map。