我正在使用leaflet.gesturehandling和react 来支持两个手指滚动和带有传单的ctrl+scroll-wheel。
使用演示测试此功能,我发现在桌面上一切正常。然而,在移动设备上,我发现这种行为非常古怪。尝试使用两个手指手势时页面将滚动。缩放与平移混合在一起,这简直是不可预测的。我已经包含了我认为遵循作者指导的实现。
我想知道,我在这里做错了吗?当两根手指与传单容器接触时,我是否需要禁用页面滚动?
有没有人遇到过这个?
import React from "react"
import PropTypes from "prop-types"
import { MapContainer, TileLayer, Marker, GeoJSON } from "react-leaflet"
import "./leafletMap.css"
import * as L from "leaflet";
import { GestureHandling } from "leaflet-gesture-handling";
import "leaflet/dist/leaflet.css";
import "leaflet-gesture-handling/dist/leaflet-gesture-handling.css";
const proj4 = typeof window !== `undefined` ? require("proj4leaflet") : null
class LeafletMap extends React.Component {
static propTypes = {
bounds: PropTypes.array,
startMarker: PropTypes.array,
endMarker: PropTypes.array,
route: PropTypes.object,
}
static defaultProps = {
position: [51, -1],
zoom: 13,
markerText: "",
}
render() {
/* Required by gatsby build, works fine witohut in develop since window is defined browser? */
if (typeof window !== "undefined") {
// Setup the EPSG:27700 (British National Grid) projection.
var crs = new proj4.CRS(
"EPSG:27700",
"+proj=tmerc +lat_0=49 +lon_0=-2 +k=0.9996012717 +x_0=400000 +y_0=-100000 +ellps=airy +towgs84=446.448,-125.157,542.06,0.15,0.247,0.842,-20.489 +units=m +no_defs",
{
resolutions: [
896.0,
448.0,
224.0,
112.0,
56.0,
28.0,
14.0,
7.0,
3.5,
1.75,
],
origin: [-238375.0, 1376256.0],
}
)
// Initialize the map.
var mapOptions = {
crs: crs,
minZoom: 0,
maxZoom: 9,
attributionControl: false,
//gestureHandling: true
}
L.Map.addInitHook("addHandler", "gestureHandling", GestureHandling);
return (
<MapContainer bounds={this.props.bounds} {...mapOptions}>
<TileLayer
attribution='© © <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'
url="https://api.os.uk/maps/raster/v1/zxy/Leisure_27700/{z}/{x}/{y}.png?key=4O65KRx7pDwdZq98W173UDKX1OSUNOAq"
/>
<GeoJSON data={this.props.route} />
<Marker position={this.props.startMarker} />
<Marker position={this.props.endMarker} />
</MapContainer>
)
}
return null
}
}
export default LeafletMap
