【发布时间】:2021-10-14 05:50:22
【问题描述】:
我有一个带有自定义光标的传单地图的 React 实现。光标的功能取决于:
L.CursorHandler = L.Handler.extend({
addHooks: function () {
this._popup = new L.Popup();
this._map.on('mouseover', this._open, this);
this._map.on('mousemove', this._update, this);
// this._map.on('mouseout', this._close, this);
},
removeHooks: function () {
this._map.off('mouseover', this._open, this);
this._map.off('mousemove', this._update, this);
this._map.off('mouseout', this._close, this);
},
_open: function (e) {
this._update(e);
this._popup.openOn(this._map);
},
_close: function () {
this._map.closePopup(this._popup);
},
_update: function (e) {
var latitude = e.latlng.toString().split(",")[0];
latitude = latitude.replace('LatLng','').replace('(','')
var longitude = e.latlng.toString().split(",")[1];
longitude = longitude.replace('LatLng','').replace(')','')
this._popup.setLatLng(e.latlng)
// .setContent(roundToTwo(parseFloat(latitude)).toString() + String(",") + roundToTwo(parseFloat(longitude)).toString());
.setContent("lat: " + roundToTwo(parseFloat(latitude)).toString() + String(", lon: ") + roundToTwo(parseFloat(longitude)).toString()
+ " | Relative %: " + roundToTwo( parseFloat( getColor(parseFloat(latitude), parseFloat(longitude)) ) ).toString());
}
});
L.Map.addInitHook('addHandler', 'cursor', L.CursorHandler);
但是,当我将光标移近地图边缘时,地图会自动平移(例如:当光标悬停在地图左侧附近时,它开始向左平移)。我不想要这个功能,只希望能够通过点击和拖动来移动地图,而不是在移动光标时自动平移(无需点击)。
【问题讨论】:
标签: reactjs react-hooks leaflet react-leaflet