fix: ios 12 点击事件问题 & regl 版本锁定

This commit is contained in:
thinkinggis 2020-03-15 12:55:23 +08:00
parent ab3b639ecd
commit cf77dbc0df
3 changed files with 25 additions and 7 deletions

View File

@ -61,6 +61,7 @@ export default class InteractionService extends EventEmitter
// hammertime.on('panmove', this.onPanmove); // hammertime.on('panmove', this.onPanmove);
// hammertime.on('panend', this.onPanend); // hammertime.on('panend', this.onPanend);
// hammertime.on('pinch', this.onPinch); // hammertime.on('pinch', this.onPinch);
$containter.addEventListener('touchstart', this.onTouch);
$containter.addEventListener('mousemove', this.onHover); $containter.addEventListener('mousemove', this.onHover);
$containter.addEventListener('click', this.onHover); $containter.addEventListener('click', this.onHover);
$containter.addEventListener('mousedown', this.onHover); $containter.addEventListener('mousedown', this.onHover);
@ -85,6 +86,15 @@ export default class InteractionService extends EventEmitter
$containter.removeEventListener('contextmenu', this.onHover); $containter.removeEventListener('contextmenu', this.onHover);
} }
} }
private onTouch = (target: TouchEvent) => {
const touch = target.touches[0];
// @ts-ignore
this.onHover({
x: touch.pageX,
y: touch.pageY,
type: 'touch',
});
};
private onHover = ({ x, y, type }: MouseEvent) => { private onHover = ({ x, y, type }: MouseEvent) => {
const $containter = this.mapService.getMapContainer(); const $containter = this.mapService.getMapContainer();
@ -120,7 +130,9 @@ export default class InteractionService extends EventEmitter
} }
return; return;
} }
if (type === 'touch') {
type = 'click';
}
this.emit(InteractionEvent.Hover, { x, y, lngLat, type }); this.emit(InteractionEvent.Hover, { x, y, lngLat, type });
}; };
} }

View File

@ -11,9 +11,10 @@
} }
#map { #map {
position: absolute; position: absolute;
top: 0; top: 0,
bottom: 0; left: 0,
width: 100%; right: 0,
bottom: 0,
} }
</style> </style>
<link <link
@ -88,12 +89,16 @@
const scene = new L7.Scene({ const scene = new L7.Scene({
id: "map", id: "map",
map: new L7.Mapbox({ map: new L7.Mapbox({
style: "dark", // 样式URL style: "blank", // 样式URL
center: [ -96, 37.8 ], center: [ -96, 37.8 ],
zoom: 3, zoom: 3,
pitch: 0, pitch: 0,
}) })
}); })
scene.on('loaded',()=>{
alert('加载完成');
const color = [ 'rgb(255,255,217)', 'rgb(237,248,177)', 'rgb(199,233,180)', 'rgb(127,205,187)', 'rgb(65,182,196)', 'rgb(29,145,192)', 'rgb(34,94,168)', 'rgb(12,44,132)' ]; const color = [ 'rgb(255,255,217)', 'rgb(237,248,177)', 'rgb(199,233,180)', 'rgb(127,205,187)', 'rgb(65,182,196)', 'rgb(29,145,192)', 'rgb(34,94,168)', 'rgb(12,44,132)' ];
const layer = new L7.PolygonLayer({}) const layer = new L7.PolygonLayer({})
.source(data) .source(data)
@ -115,6 +120,7 @@
opacity: 1.0 opacity: 1.0
}); });
scene.addLayer(layer); scene.addLayer(layer);
});
</script> </script>
</body> </body>
</html> </html>

View File

@ -30,7 +30,7 @@
"inversify": "^5.0.1", "inversify": "^5.0.1",
"lodash": "^4.17.15", "lodash": "^4.17.15",
"reflect-metadata": "^0.1.13", "reflect-metadata": "^0.1.13",
"regl": "^1.3.11" "regl": "1.3.11"
}, },
"gitHead": "a5d354b66873f700730248d015c5e539c54b34b7", "gitHead": "a5d354b66873f700730248d015c5e539c54b34b7",
"publishConfig": { "publishConfig": {