mirror of
https://github.com/muerwre/orchidmap-front.git
synced 2025-04-25 02:56:41 +07:00
fixed dragging polyline collision with router
This commit is contained in:
parent
2be073078f
commit
bdbe28b854
3 changed files with 31 additions and 19 deletions
|
@ -28,26 +28,33 @@ const RouteUnconnected: FC<Props> = memo(
|
||||||
({ map: { route }, editor: { editing, mode }, mapSetRoute, editorSetDistance }) => {
|
({ map: { route }, editor: { editing, mode }, mapSetRoute, editorSetDistance }) => {
|
||||||
const [layer, setLayer] = useState<InteractivePoly>(null);
|
const [layer, setLayer] = useState<InteractivePoly>(null);
|
||||||
|
|
||||||
const onDistanceChange = useCallback(
|
const onDistanceChange = useCallback(({ distance }) => editorSetDistance(distance), [
|
||||||
({ distance }) => editorSetDistance(distance),
|
editorSetDistance,
|
||||||
[editorSetDistance]
|
]);
|
||||||
);
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!MainMap) return;
|
if (!MainMap) return;
|
||||||
|
|
||||||
setLayer(
|
const interactive = new InteractivePoly([], {
|
||||||
new InteractivePoly([], {
|
color: 'url(#activePathGradient)',
|
||||||
color: 'url(#activePathGradient)',
|
weight: 6,
|
||||||
weight: 6,
|
maxMarkers: isMobile() ? 50 : 200,
|
||||||
maxMarkers: isMobile() ? 20 : 100,
|
smoothFactor: 3,
|
||||||
smoothFactor: 3,
|
})
|
||||||
})
|
.addTo(MainMap)
|
||||||
.addTo(MainMap)
|
.on('distancechange', onDistanceChange)
|
||||||
.on('distancechange', onDistanceChange)
|
.on('vertexdragstart', MainMap.disableClicks)
|
||||||
// .on("allvertexhide", console.log)
|
.on('vertexdragend', MainMap.enableClicks)
|
||||||
// .on("allvertexshow", console.log)
|
.on('vertexaddstart', MainMap.disableClicks)
|
||||||
);
|
.on('vertexaddend', MainMap.enableClicks);
|
||||||
|
// .on("allvertexhide", console.log)
|
||||||
|
// .on("allvertexshow", console.log)
|
||||||
|
|
||||||
|
setLayer(interactive);
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
interactive.removeFrom(MainMap);
|
||||||
|
};
|
||||||
}, [MainMap, onDistanceChange]);
|
}, [MainMap, onDistanceChange]);
|
||||||
|
|
||||||
const onRouteChanged = useCallback(
|
const onRouteChanged = useCallback(
|
||||||
|
|
|
@ -239,6 +239,8 @@ export class InteractivePoly extends Polyline {
|
||||||
this._map.on("mousemove", this.dragHintMove);
|
this._map.on("mousemove", this.dragHintMove);
|
||||||
this._map.on("mouseup", this.dragHintAddMarker);
|
this._map.on("mouseup", this.dragHintAddMarker);
|
||||||
this._map.on("mouseout", this.stopDragHintMove);
|
this._map.on("mouseout", this.stopDragHintMove);
|
||||||
|
|
||||||
|
this.fire('vertexaddstart');
|
||||||
};
|
};
|
||||||
|
|
||||||
stopDragHintMove = (): void => {
|
stopDragHintMove = (): void => {
|
||||||
|
@ -254,6 +256,7 @@ export class InteractivePoly extends Polyline {
|
||||||
|
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
this.is_dragging = false;
|
this.is_dragging = false;
|
||||||
|
this.fire('vertexaddend');
|
||||||
}, 0);
|
}, 0);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -598,6 +601,8 @@ InteractivePoly.addInitHook(function() {
|
||||||
vertexdragstart,
|
vertexdragstart,
|
||||||
vertexdragend,
|
vertexdragend,
|
||||||
vertexdrag,
|
vertexdrag,
|
||||||
|
vertexaddstart
|
||||||
|
vertexaddend
|
||||||
|
|
||||||
allvertexhide
|
allvertexhide
|
||||||
allvertexshow
|
allvertexshow
|
||||||
|
|
|
@ -7,8 +7,8 @@ import { MainMap } from '~/constants/map';
|
||||||
const createWaypointMarker = (): DomMarker => {
|
const createWaypointMarker = (): DomMarker => {
|
||||||
const element = document.createElement('div');
|
const element = document.createElement('div');
|
||||||
|
|
||||||
// element.addEventListener('mousedown', this.lockPropagations);
|
element.addEventListener('mousedown', event => event.stopPropagation());
|
||||||
// element.addEventListener('mouseup', this.unlockPropagations);
|
element.addEventListener('mouseup', event => event.stopPropagation());
|
||||||
|
|
||||||
return new DomMarker({
|
return new DomMarker({
|
||||||
element,
|
element,
|
||||||
|
@ -37,7 +37,7 @@ export const OsrmRouter = Routing.control({
|
||||||
},
|
},
|
||||||
show: false,
|
show: false,
|
||||||
plan: Routing.plan([], {
|
plan: Routing.plan([], {
|
||||||
createMarker: (i, wp) => {
|
createMarker: (_, wp) => {
|
||||||
const marker = new Marker(wp.latLng, {
|
const marker = new Marker(wp.latLng, {
|
||||||
draggable: true,
|
draggable: true,
|
||||||
icon: createWaypointMarker(),
|
icon: createWaypointMarker(),
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue