-
Notifications
You must be signed in to change notification settings - Fork 29
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adds onCancelPan optional prop and adds more calls to cancelPan #166
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,8 @@ import bearing from '@turf/bearing'; | |
import { | ||
generatePointsParallelToLinePoints, | ||
getPickedEditHandle, | ||
getPickedIntermediateEditHandle | ||
getPickedIntermediateEditHandle, | ||
shouldCancelPan | ||
} from './utils'; | ||
import {FeatureCollection} from '../utils/geojson-types'; | ||
import {ModeProps, StartDraggingEvent, StopDraggingEvent, DraggingEvent} from './types'; | ||
|
@@ -61,6 +62,10 @@ export class ExtrudeMode extends ModifyMode { | |
} | ||
|
||
handleStartDragging(event: StartDraggingEvent, props: ModeProps<FeatureCollection>) { | ||
if (shouldCancelPan(event)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does this need to be implemented by every mode? Could it be called by the framework before invoking Do we need a |
||
event.cancelPan(); | ||
} | ||
|
||
const selectedFeatureIndexes = props.selectedIndexes; | ||
|
||
const editHandle = getPickedIntermediateEditHandle(event.picks); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,10 +8,10 @@ | |
import bearing from '@turf/bearing'; | ||
import pointToLineDistance from '@turf/point-to-line-distance'; | ||
import {flattenEach} from '@turf/meta'; | ||
import {point, MultiLineString} from '@turf/helpers'; | ||
import {getCoords} from '@turf/invariant'; | ||
import WebMercatorViewport from 'viewport-mercator-project'; | ||
import {Viewport, Pick, EditHandleFeature, EditHandleType} from './types'; | ||
import {Viewport, Pick, EditHandleFeature, EditHandleType, StartDraggingEvent} from './types'; | ||
import { | ||
Geometry, | ||
Position, | ||
|
@@ -516,3 +516,7 @@ | |
}) | ||
.filter(Boolean); | ||
} | ||
|
||
export function shouldCancelPan(event: StartDraggingEvent) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Some TSDoc here would be helpful explaining when to call and why this criteria is used. |
||
return event.picks.length && event.picks.find((p) => p.featureType === 'points'); | ||
} |
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -20,6 +20,7 @@ const EVENT_TYPES = ['anyclick', 'pointermove', 'panstart', 'panmove', 'panend', | |||||||||
export type EditableLayerProps<DataType = any> = CompositeLayerProps & { | ||||||||||
pickingRadius?: number; | ||||||||||
pickingDepth?: number; | ||||||||||
onCancelPan?: () => void; | ||||||||||
}; | ||||||||||
|
||||||||||
export abstract class EditableLayer< | ||||||||||
|
@@ -154,7 +155,13 @@ export abstract class EditableLayer< | |||||||||
mapCoords, | ||||||||||
pointerDownScreenCoords: screenCoords, | ||||||||||
pointerDownMapCoords: mapCoords, | ||||||||||
cancelPan: event.stopImmediatePropagation, | ||||||||||
cancelPan: () => { | ||||||||||
if (this.props.onCancelPan) { | ||||||||||
this.props.onCancelPan(); | ||||||||||
} | ||||||||||
Comment on lines
+159
to
+161
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Or make the default prop an empty function? |
||||||||||
|
||||||||||
event.stopImmediatePropagation(); | ||||||||||
}, | ||||||||||
sourceEvent: event.srcEvent | ||||||||||
}); | ||||||||||
} | ||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe a comment that explains when this happens?