-
Notifications
You must be signed in to change notification settings - Fork 383
/
annotations.js
719 lines (689 loc) · 29 KB
/
annotations.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
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
/*
* Copyright 2017, GeoSolutions Sas.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree.
*/
import assign from 'object-assign';
import { transformLineToArcs } from '../utils/CoordinatesUtils';
import circle from '@turf/circle';
import { PURGE_MAPINFO_RESULTS } from '../actions/mapInfo';
import { TOGGLE_CONTROL } from '../actions/controls';
import { FEATURES_SELECTED, DRAWING_FEATURE } from '../actions/draw';
import {
REMOVE_ANNOTATION,
CONFIRM_REMOVE_ANNOTATION,
CANCEL_REMOVE_ANNOTATION,
CLOSE_ANNOTATIONS,
CONFIRM_CLOSE_ANNOTATIONS,
CANCEL_CLOSE_ANNOTATIONS,
EDIT_ANNOTATION,
CANCEL_EDIT_ANNOTATION,
SAVE_ANNOTATION,
TOGGLE_ADD,
VALIDATION_ERROR,
REMOVE_ANNOTATION_GEOMETRY,
TOGGLE_STYLE,
SET_STYLE,
NEW_ANNOTATION,
SHOW_ANNOTATION,
CANCEL_SHOW_ANNOTATION,
FILTER_ANNOTATIONS,
UNSAVED_CHANGES,
TOGGLE_GEOMETRY_MODAL,
TOGGLE_CHANGES_MODAL,
CHANGED_PROPERTIES,
TOGGLE_STYLE_MODAL,
UNSAVED_STYLE,
ADD_TEXT,
CHANGED_SELECTED,
RESET_COORD_EDITOR,
CHANGE_RADIUS,
CHANGE_TEXT,
ADD_NEW_FEATURE,
SET_EDITING_FEATURE,
SET_INVALID_SELECTED,
TOGGLE_DELETE_FT_MODAL,
CONFIRM_DELETE_FEATURE,
HIGHLIGHT_POINT,
CHANGE_FORMAT,
UPDATE_SYMBOLS,
ERROR_SYMBOLS,
SET_DEFAULT_STYLE,
LOADING,
CHANGE_GEOMETRY_TITLE,
FILTER_MARKER,
HIDE_MEASURE_WARNING,
TOGGLE_SHOW_AGAIN,
INIT_PLUGIN
} from '../actions/annotations';
import {
validateCoordsArray,
getAvailableStyler,
convertGeoJSONToInternalModel,
addIds,
validateFeature,
getComponents,
updateAllStyles,
getBaseCoord
} from '../utils/AnnotationsUtils';
import { set } from '../utils/ImmutableUtils';
import { head, findIndex, isNil, slice, castArray, get } from 'lodash';
import uuid from 'uuid';
const fixCoordinates = (coords, type) => {
switch (type) {
case "Polygon": return [coords];
case "LineString": case "MultiPoint": return coords;
default: return coords[0];
}
};
function annotations(state = {validationErrors: {}}, action) {
switch (action.type) {
case INIT_PLUGIN: {
return {
...state,
showPopupWarning: localStorage && localStorage.getItem("showPopupWarning") !== null ? localStorage.getItem("showPopupWarning") === "true" : true
};
}
case CHANGED_SELECTED: {
let newState = set(`unsavedGeometry`, true, state);
let {coordinates, radius, text} = action;
let validCoordinates;
let ftChangedIndex = findIndex(state.editing.features, (f) => f.properties.id === state.selected.properties.id);
let ftChanged = ftChangedIndex === -1 ? {type: "Feature", geometry: {
type: state.selected.geometry.type
}, properties: {...state.selected.properties}} : assign({}, state.editing.features[ftChangedIndex]);
if (ftChanged.geometry && !ftChanged.geometry.type || !ftChanged.geometry) {
ftChanged = set("geometry.type", state.selected.geometry.type, ftChanged);
}
if (!isNil(coordinates)) {
validCoordinates = coordinates;// .filter(validateCoordsArray);
switch (ftChanged.geometry.type) {
case "Polygon": ftChanged = assign({}, ftChanged, {
geometry: assign({}, ftChanged.geometry, {
coordinates: fixCoordinates(validCoordinates, ftChanged.geometry.type)
})
}); break;
case "LineString": case "MultiPoint": ftChanged = assign({}, ftChanged, {
geometry: assign({}, ftChanged.geometry, {
coordinates: fixCoordinates(validCoordinates, ftChanged.geometry.type)
})
}); break;
default: ftChanged = assign({}, ftChanged, {
geometry: assign({}, ftChanged.geometry, {
coordinates: fixCoordinates(validCoordinates, ftChanged.geometry.type)
})
});
}
}
let selected = assign({}, ftChanged);
let features;
if (selected.properties.isCircle) {
let centerCoords = !isNil(coordinates) ? validCoordinates[0] : state.selected.properties.center;
selected = assign({}, {...selected, properties: {
...state.selected.properties, center: centerCoords, radius: !isNil(radius) ? radius : selected.properties.radius
}});
features = state.editing.features.map(f => {
return f.properties.id === state.selected.properties.id ? selected : f;
});
selected = { ...selected, geometry: { coordinates: centerCoords, type: "Circle"}};
let center;
let c = {
type: 'Polygon',
coordinates: [[[]]]
};
// polygonGeom setting
if (validateCoordsArray(selected.properties.center)) {
center = selected.properties.center;
// turf/circle by default use km unit hence we divide by 1000 the radius(in meters)
c = circle(
center,
action.crs === "EPSG:4326" ? action.radius : action.radius / 1000,
{ steps: 100, units: action.crs === "EPSG:4326" ? "degrees" : "kilometers" }
).geometry;
} else {
selected = set("properties.center", [], selected);
}
selected = set("properties.polygonGeom", c, selected);
} else if (selected.properties.isText) {
let c = !isNil(coordinates) ? validCoordinates[0] : state.selected.geometry.coordinates;
selected = assign({}, {...selected,
properties: {
...state.selected.properties,
valueText: !isNil(text) ? text : state.selected.properties.valueText
}});
features = state.editing.features.map(f => {
return f.properties.id === state.selected.properties.id ? selected : f;
});
selected = {...selected, geometry: {coordinates: c, type: "Point"}};
} else {
features = state.editing.features.map(f => {
return f.properties.id === state.selected.properties.id ? selected : f;
});
selected = {...selected, geometry: {...selected.geometry, coordinates: fixCoordinates(!isNil(coordinates) ? coordinates : selected.geometry.coordinates, selected.geometry.type)}};
}
selected = set("properties.isValidFeature", validateFeature({
properties: selected.properties,
components: getComponents(selected.geometry),
type: selected.geometry.type
}), selected);
return assign({}, newState, {
editing: {...newState.editing, features},
selected,
unsavedChanges: true
});
}
case FEATURES_SELECTED: {
let newState = state;
let selected = head(action.features) || null;
if (!selected) {
return state;
}
selected = set("properties.canEdit", true, selected);
if (selected && selected.properties && selected.properties.isCircle) {
selected = set("geometry.coordinates", selected.properties.center, selected);
selected = set("geometry.type", "Circle", selected);
}
if (selected && selected.properties && selected.properties.isText) {
selected = set("geometry.type", "Text", selected);
}
let ftChangedIndex = findIndex(state.editing.features, (f) => f.properties.id === selected.properties.id);
let selectedGeoJSON = selected;
if (selected && selected.properties && selected.properties.isCircle) {
selectedGeoJSON = set("geometry", selected.properties.polygonGeom, selectedGeoJSON);
} else if (selected && selected.properties && selected.properties.isText) {
selectedGeoJSON = set("geometry.type", "Point", selectedGeoJSON);
}
newState = set(`editing.features`, state.editing.features.map(f => {
return set("properties.canEdit", false, f);
}), state);
newState = set(`editing.tempFeatures`, newState.editing.features, newState);
newState = set(`editing`, updateAllStyles(newState.editing, {highlight: false}), newState);
if (ftChangedIndex === -1) {
newState = set("editing.features", newState.editing.features.concat([selectedGeoJSON]), newState);
} else {
selectedGeoJSON = set("style", castArray(newState.editing.features[ftChangedIndex].style).map(s => ({...s, highlight: true})), selectedGeoJSON);
newState = set(`editing.features[${ftChangedIndex}]`, selectedGeoJSON, newState);
selected = set("style", newState.editing.features[ftChangedIndex].style, selected);
}
return assign({}, newState, {
selected,
coordinateEditorEnabled: !!selected,
featureType: selected.geometry.type
});
}
case DRAWING_FEATURE: {
let selected = head(action.features) || null;
selected = set("style", state.selected.style, selected);
let newState = state;
if (selected && selected.properties && selected.properties.isCircle) {
selected = set("properties.polygonGeom", selected.geometry, selected);
selected = set("geometry", {coordinates: selected.properties.center, type: "Circle"}, selected);
} else if (selected && selected.properties && selected.properties.isText) {
selected = set("geometry.type", "Text", selected);
}
selected = set("properties.isValidFeature", validateFeature({
properties: selected.properties,
components: getComponents(selected.geometry),
type: selected.geometry.type
}), selected);
selected = set("properties.canEdit", true, selected);
newState = set(`editing.features`, state.editing.features.map(f => {
return set("properties.canEdit", false, f);
}), state);
let ftChangedIndex = findIndex(state.editing.features, (f) => f.properties.id === selected.properties.id);
let selectedGeoJSON = selected;
if (selected && selected.properties && selected.properties.isCircle) {
selectedGeoJSON = set("geometry", selected.properties.polygonGeom, selectedGeoJSON);
} else if (selected && selected.properties && selected.properties.isText) {
selectedGeoJSON = set("geometry.type", "Point", selectedGeoJSON);
}
newState = set(`unsavedGeometry`, true, newState);
if (ftChangedIndex === -1) {
newState = set("editing.features", newState.editing.features.concat([selectedGeoJSON]), newState);
} else {
newState = set(`editing.features[${ftChangedIndex}]`, selectedGeoJSON, newState);
}
return assign({}, newState, {
selected,
unsavedChanges: true,
stylerType: head(getAvailableStyler(convertGeoJSONToInternalModel(selected.geometry)))
});
}
case REMOVE_ANNOTATION:
return assign({}, state, {
removing: action.id
});
case CHANGE_RADIUS: {
let newState;
let selected = set("properties.radius", action.radius, state.selected);
if (action.components.length === 0 || action.radius === null) {
selected = set("properties.isValidFeature", false, selected);
return assign({}, state, {
selected,
unsavedChanges: true
});
}
selected = set("properties.isValidFeature", validateFeature({
properties: selected.properties,
components: getComponents({coordinates: action.components[0] || [], type: "Circle"}),
type: "Circle"
}), selected);
selected = set("properties.center", action.components[0], selected);
selected = set("geometry.coordinates", action.components[0], selected);
// need to change the polygon coords after radius changes
// but this implementation is ugly. is using openlayers to do that and maybe we need to refactor this
let feature = circle(
selected.properties.center,
action.crs === "EPSG:4326" ? action.radius : action.radius / 1000,
{ steps: 100, units: action.crs === "EPSG:4326" ? "degrees" : "kilometers" }
);
selected = set("properties.polygonGeom", feature.geometry, selected);
let ftChangedIndex = findIndex(state.editing.features, (f) => f.properties.id === state.selected.properties.id);
const selectedGeoJSON = set("geometry", selected.properties.polygonGeom, selected);
newState = set(`editing.features`, state.editing.features.map(f => {
return set("properties.canEdit", false, f);
}), state);
newState = set(`unsavedGeometry`, true, newState);
if (ftChangedIndex === -1) {
newState = set("editing.features", newState.editing.features.concat([selectedGeoJSON]), newState);
} else {
newState = set(`editing.features[${ftChangedIndex}]`, selectedGeoJSON, newState);
}
return assign({}, newState, {
selected,
unsavedChanges: true
});
}
case CHANGE_TEXT: {
let newState;
let selected = set("properties.valueText", action.text, state.selected);
selected = set("style[0].label", action.text, selected);
selected = set("properties.isValidFeature", validateFeature({
properties: selected.properties,
components: getComponents({coordinates: action.components[0] || [], type: "Text"}),
type: "Text"
}), selected);
selected = set("properties.isText", true, selected);
selected = set("geometry.coordinates", action.components[0] || [[]], selected);
let ftChangedIndex = findIndex(state.editing.features, (f) => f.properties.id === state.selected.properties.id);
const selectedGeoJSON = set("geometry.type", "Point", selected);
newState = set(`editing.features`, state.editing.features.map(f => {
return set("properties.canEdit", false, f);
}), state);
newState = set(`unsavedGeometry`, true, newState);
if (ftChangedIndex === -1) {
newState = set("editing.features", newState.editing.features.concat([selectedGeoJSON]), newState);
} else {
newState = set(`editing.features[${ftChangedIndex}]`, selectedGeoJSON, newState);
}
return assign({}, newState, {
selected,
unsavedChanges: true
});
}
case RESET_COORD_EDITOR: {
let newState = set(`editing.features`, state.editing.features.map(f => {
return set("properties.canEdit", false, f);
}), state);
const newfeatures = newState.editing.features;
// only for the circles the feature is not being added
let features = newState.editing.tempFeatures;
if (state.featureType !== "Circle" && state.drawing) {
features = slice(newfeatures, 0, newfeatures.length - 1);
}
return assign({}, newState, {
editing: {
...newState.editing,
features
},
drawing: false,
coordinateEditorEnabled: false,
unsavedGeometry: false,
selected: null,
showUnsavedGeometryModal: false
});
}
case ADD_NEW_FEATURE: {
let selected = state.selected;
let newState = state;
if (selected.properties && selected.properties.isCircle ) {
// verify this condition
selected = set("geometry", selected.properties.polygonGeom, selected);
}
if (selected.properties && selected.properties.isText) {
selected = set("geometry.type", "Point", selected);
}
if (selected.properties && selected.properties.useGeodesicLines) {
selected = set("properties.geometryGeodesic", {type: "LineString", coordinates: transformLineToArcs(selected.geometry.coordinates)}, selected);
}
selected = set("properties.canEdit", false, selected);
let ftChangedIndex = findIndex(state.editing.features, (f) => f.properties.id === state.selected.properties.id);
if (ftChangedIndex === -1) {
newState = set("editing.features", newState.editing.features.concat([selected]), newState);
} else {
selected = set("style", castArray(newState.editing.features[ftChangedIndex].style).map(s => ({...s, highlight: false})), selected);
newState = set(`editing.features[${ftChangedIndex}]`, selected, newState);
}
newState = set(`editing.tempFeatures`, newState.editing.features, newState);
newState = {...newState, editing: {...newState.editing, properties: {...newState.editing.properties, ...newState.editedFields}}};
return assign({}, newState, {
coordinateEditorEnabled: false,
drawing: false,
unsavedGeometry: false,
selected: null,
config: {...newState.config, filter: ''}
});
}
case SET_EDITING_FEATURE: {
if (!action.feature || action.feature.type !== 'FeatureCollection') {
return state;
}
const feature = set('features', action.feature.features.map(x => set('properties.canEdit', false, x)), action.feature);
const newFeature = set('newFeature', get(action.feature, "newFeature", true), set('properties.canEdit', false, set('tempFeatures', feature.features, feature)));
const newState = set('editing', newFeature, state);
return assign({}, newState, {
coordinateEditorEnabled: false,
drawing: false,
unsavedGeometry: false,
selected: null,
config: {...newState.config, filter: ''}
});
}
case TOGGLE_DELETE_FT_MODAL: {
return set("showDeleteFeatureModal", !state.showDeleteFeatureModal, state);
}
case CONFIRM_DELETE_FEATURE: {
let newState = set("editing.features", state.editing.features.filter(f => f.properties.id !== state.selected.properties.id), state);
newState = set("unsavedChanges", true, newState);
newState = set("drawing", false, newState);
newState = set("coordinateEditorEnabled", false, newState);
return newState;
}
case ADD_TEXT: {
return assign({}, state, {
drawingText: {
...state.drawingText,
drawing: true
}
});
}
case SET_INVALID_SELECTED: {
let selected = set("properties.isValidFeature", false, state.selected);
switch (action.errorFrom) {
case "text": selected = set("properties.valueText", undefined, selected); break;
case "radius": selected = set("properties.radius", undefined, selected); break;
case "coords": selected = set("geometry.coordinates", fixCoordinates(action.coordinates, selected.geometry.type), selected); break;
default: break;
}
return assign({}, state, {selected});
}
case REMOVE_ANNOTATION_GEOMETRY:
return assign({}, state, {
removing: action.id,
unsavedChanges: true
});
case EDIT_ANNOTATION: {
const features = addIds(action.feature.features);
const selected = head(action.feature.features);
let featureType = selected && selected.geometry && selected.geometry.type;
if (selected && selected.properties && selected.properties.isCircle) {
featureType = "Circle";
}
if (selected && selected.properties && selected.properties.isText) {
featureType = "Text";
}
return assign({}, state, {
editing: updateAllStyles(assign({}, action.feature, {features}), {highlight: false}),
stylerType: head(getAvailableStyler(convertGeoJSONToInternalModel(action.feature.geometry || action.feature))),
originalStyle: null,
featureType
});
}
case NEW_ANNOTATION:
const id = uuid.v1();
return assign({}, state, {
editing: {
type: "FeatureCollection",
id,
geometry: null,
features: [],
newFeature: true,
properties: {
id
}
},
selected: {},
originalStyle: null
});
case CONFIRM_REMOVE_ANNOTATION:
const features = state.editing?.features?.filter(feature=> feature.properties.id !== action.id) || [];
const delSelectedFeature = state?.selected?.properties?.id === action.id || false;
return assign({}, state, {
removing: null,
stylerType: "",
current: null,
...(delSelectedFeature && {selected: null}),
editing: state.editing ? assign({}, state.editing, {
features,
style: {
type: state.featureType
}
}) : null
});
case CHANGE_GEOMETRY_TITLE: {
let newState = state;
const ftIndex = findIndex(state.editing.features, (f) => f.properties.id === state.selected.properties.id);
const editingFt = set("properties.geometryTitle", action.title, state.editing.features[ftIndex]);
const selectedFt = set("properties.geometryTitle", action.title, state.selected);
newState = set(`editing.features[${ftIndex}]`, editingFt, newState);
return {...newState, selected: selectedFt};
}
case CANCEL_REMOVE_ANNOTATION:
return assign({}, state, {
removing: null
});
case CLOSE_ANNOTATIONS:
return assign({}, state, {
closing: true
});
case UNSAVED_CHANGES:
return assign({}, state, {
unsavedChanges: action.unsavedChanges
});
case UNSAVED_STYLE:
return assign({}, state, {
unsavedStyle: action.unsavedStyle
});
case CONFIRM_CLOSE_ANNOTATIONS: {
return assign({}, state, {
closing: false,
coordinateEditorEnabled: false
});
}
case CANCEL_CLOSE_ANNOTATIONS:
return assign({}, state, {
closing: false
});
case TOGGLE_CHANGES_MODAL:
return assign({}, state, {
showUnsavedChangesModal: !state.showUnsavedChangesModal
});
case TOGGLE_GEOMETRY_MODAL:
return assign({}, state, {
showUnsavedGeometryModal: !!state.unsavedGeometry && !state.showUnsavedGeometryModal
});
case TOGGLE_STYLE_MODAL:
return assign({}, state, {
showUnsavedStyleModal: !state.showUnsavedStyleModal
});
case CHANGED_PROPERTIES:
return assign({}, state, {
editedFields: assign({}, state.editedFields, {
[action.field]: action.value
})
});
case CANCEL_EDIT_ANNOTATION:
return assign({}, state, {
editing: null,
drawing: false,
styling: false,
originalStyle: null,
validationErrors: {},
editedFields: {},
unsavedChanges: false
});
case SAVE_ANNOTATION:
return assign({}, state, {
editing: null,
current: null,
drawing: false,
styling: false,
originalStyle: null,
validationErrors: {},
editedFields: {},
unsavedChanges: false
});
case PURGE_MAPINFO_RESULTS:
return assign({}, state, {
editing: null,
removing: null,
validationErrors: {},
styling: false,
drawing: false,
originalStyle: null,
selected: null,
filter: null,
unsavedChanges: false,
editedFields: {}
});
case TOGGLE_ADD: {
const type = action.featureType || state.featureType;
let properties = {
id: uuid.v1(),
isValidFeature: false,
canEdit: true
};
if (type === "Text") {
properties = set("isText", true, properties);
}
if (type === "Circle") {
properties = set("isCircle", true, properties);
properties = set("isDrawing", true, properties);
}
let selected = {type: "Feature", geometry: {type, coordinates: getBaseCoord(type)}, properties,
style: {...(state.config?.defaultPointType === 'symbol' ? state.defaultStyles?.POINT?.symbol : state.defaultStyles?.POINT.marker), id: uuid.v1()}};
let geojsonFt = set("geometry.type", type === "Text" ? "Point" : type === "Circle" ? "Polygon" : type, selected);
geojsonFt = set("geometry.coordinates", type === "Circle" ? [[]] : [], geojsonFt);
geojsonFt = set("geometry", type === "Point" || type === "Text" ? null : geojsonFt.geometry, geojsonFt);
let newState = set(`editing.tempFeatures`, state.editing.features, state);
return assign({}, state, {
drawing: !newState.drawing,
featureType: type,
drawingText: {
show: false,
drawing: false
},
validationErrors: {},
coordinateEditorEnabled: true,
editing: assign({}, newState.editing, {
features: newState.editing.features.map(f => {
return set("properties.canEdit", false, f);
}).concat([geojsonFt])
}),
stylerType: head(getAvailableStyler(convertGeoJSONToInternalModel(selected.geometry))),
selected
});
}
case TOGGLE_STYLE:
// removing highlight when the styler is opened
// const newStyling = !state.styling;
const newStyling = action.styling;
return {
...state,
styling: newStyling,
originalStyle: newStyling ? state.selected && state.selected.style : state.originalStyle,
selected: set("style", castArray(state.selected && state.selected.style).map(s => ({...s, highlight: !newStyling})), state.selected),
editing: set("features", (state.editing && state.editing.features || []).map(f => ({...f, style: castArray(f.style).map(s => ({...s, highlight: !newStyling ? f.properties.id === (state.selected && state.selected.properties.id) : false}))})), state.editing)
};
case VALIDATION_ERROR:
return assign({}, state, {
validationErrors: action.errors
});
case SET_STYLE: {
let selected = set("style", action.style, state.selected);
let originalFeatureIndex = findIndex(state.editing && state.editing.features, ftTemp => ftTemp.properties.id === state.selected.properties.id);
if (originalFeatureIndex !== -1) {
let editing = set(`features[${originalFeatureIndex}].style`, action.style, state.editing);
return assign({}, state, { selected, editing });
}
return assign({}, state, { selected });
}
case SHOW_ANNOTATION:
return assign({}, state, {
current: action.id
});
case CANCEL_SHOW_ANNOTATION:
return assign({}, state, {
current: null
});
case TOGGLE_CONTROL:
if (action.control === 'annotations') {
return assign({}, state, {
current: null,
editing: null,
removing: null,
validationErrors: {},
styling: false,
drawing: false,
coordinateEditorEnabled: false,
filter: null,
editedFields: {},
originalStyle: null,
selected: null
});
}
return state;
case HIGHLIGHT_POINT: {
return !action.point ?
{...state, clickPoint: null, showMarker: false} :
assign({}, state, {
clickPoint: {latlng: {lat: action.point.lat, lng: action.point.lon }},
showMarker: true
});
}
case CHANGE_FORMAT: {
return {...state, format: action.format};
}
case UPDATE_SYMBOLS: {
return {...state, symbolList: action.symbols || []};
}
case FILTER_ANNOTATIONS:
return assign({}, state, {
filter: action.filter
});
case ERROR_SYMBOLS:
return {...state, symbolErrors: action.symbolErrors};
case SET_DEFAULT_STYLE:
return set(`defaultStyles.${action.path}`, action.style, state);
case LOADING: {
// anyway sets loading to true
return set(action.name === "loading" ? "loading" : `loadFlags.${action.name}`, action.value, set(
"loading", action.value, state
));
}
case FILTER_MARKER: {
return {...state, config: {...state.config, filter: action.filter}};
}
case TOGGLE_SHOW_AGAIN: {
return {...state, showAgain: !state.showAgain};
}
case HIDE_MEASURE_WARNING: {
return {...state, showPopupWarning: false};
}
default:
return state;
}
}
export default annotations;