-
Notifications
You must be signed in to change notification settings - Fork 166
/
base-mode.ts
100 lines (82 loc) · 2.75 KB
/
base-mode.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
import {
EditMode,
GuideFeatureCollection,
Feature,
ClickEvent,
PointerMoveEvent,
StartDraggingEvent,
StopDraggingEvent,
FeatureCollection,
Tooltip,
DraggingEvent,
} from '@nebula.gl/edit-modes';
import { ModeProps } from '../types';
import { GEOJSON_TYPE, GUIDE_TYPE } from '../constants';
import { getFeatureCoordinates, isNumeric } from './utils';
export default class BaseMode implements EditMode<FeatureCollection, GuideFeatureCollection> {
_tentativeFeature: Feature | null | undefined;
_editHandles: Feature[] | null | undefined;
constructor() {
this._tentativeFeature = null;
this._editHandles = null;
}
handlePan(event: ClickEvent, props: ModeProps<FeatureCollection>) {}
handleClick(event: ClickEvent, props: ModeProps<FeatureCollection>) {}
handleDblClick(event: ClickEvent, props: ModeProps<FeatureCollection>) {}
handlePointerMove(event: PointerMoveEvent, props: ModeProps<FeatureCollection>) {}
handleStartDragging(event: StartDraggingEvent, props: ModeProps<FeatureCollection>) {}
handleStopDragging(event: StopDraggingEvent, props: ModeProps<FeatureCollection>) {}
handleKeyUp(event: KeyboardEvent, props: ModeProps<FeatureCollection>): void {}
getGuides(props: ModeProps<FeatureCollection>): GuideFeatureCollection | null | undefined {
return null;
}
getTooltips(props: ModeProps<FeatureCollection>): Tooltip[] {
return [];
}
handleDragging(event: DraggingEvent, props: ModeProps<FeatureCollection>): void {}
getTentativeFeature = () => {
return this._tentativeFeature;
};
getEditHandles = () => {
return this._editHandles;
};
setTentativeFeature = (feature: Feature) => {
this._tentativeFeature = feature;
};
getEditHandlesFromFeature(feature: Feature, featureIndex: number | null | undefined) {
const coordinates = getFeatureCoordinates(feature);
if (!coordinates) {
return null;
}
// @ts-ignore
return coordinates.map((coord, i) => {
return {
type: 'Feature',
properties: {
// TODO deprecate renderType
renderType: feature.properties.renderType,
guideType: GUIDE_TYPE.EDIT_HANDLE,
editHandleType: 'existing',
featureIndex,
positionIndexes: [i],
},
geometry: {
type: GEOJSON_TYPE.POINT,
coordinates: coord,
},
};
});
}
getSelectedFeature = (
props: ModeProps<FeatureCollection>,
featureIndex: number | null | undefined
) => {
const { data, selectedIndexes } = props;
// @ts-ignore
const features = data && data.features;
const selectedIndex = isNumeric(featureIndex)
? Number(featureIndex)
: selectedIndexes && selectedIndexes[0];
return features && features[selectedIndex];
};
}