-
Notifications
You must be signed in to change notification settings - Fork 6
/
DrawHandler.js
31 lines (29 loc) · 982 Bytes
/
DrawHandler.js
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
export default class DrawHandler {
constructor(onFinish) {
this.isDrawing = false;
this.onFinish = onFinish;
}
init(channel) {
channel.handleEvent('DrawingEvent', (data) => {
if (!data.isFinished) {
return;
}
if (!data.geojson.features.length || typeof data.geojson.features[0].properties.area !== 'number') {
this.onFinish(null);
return;
}
this.onFinish(data.geojson.features[0]);
});
}
synchronize(channel, state) {
if (this.isDrawing === state.isDrawing) {
return;
}
if (state.isDrawing) {
channel.postRequest('DrawTools.StartDrawingRequest', ['draw-handler', 'Polygon', {allowMultipleDrawing: false}]);
} else {
channel.postRequest('DrawTools.StopDrawingRequest', ['draw-handler', true]);
}
this.isDrawing = state.isDrawing;
}
}