@opengeoweb/warnings 9.12.0 → 9.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.esm.js
CHANGED
|
@@ -3,17 +3,17 @@ import React__default, { useState, useEffect } from 'react';
|
|
|
3
3
|
import { useDispatch, useSelector } from 'react-redux';
|
|
4
4
|
import { Polygons, Share, ExitDomain, Edit, Delete, DrawPolygon, Visibility, Add, Wind, Fog, Lightning, Snow, Rain, TemperatureHigh, FunnelCloud, TemperatureLow, CoastalEvent, breakpoints, Options, VisibilityOff, Success } from '@opengeoweb/theme';
|
|
5
5
|
import { uiTypes, uiActions, getSingularDrawtoolDrawLayerId, drawtoolSelectors, layerSelectors, uiSelectors, drawtoolActions, mapStoreActions, layerActions, useSetupDialog } from '@opengeoweb/store';
|
|
6
|
-
import { emptyGeoJSON, MapControlButton,
|
|
6
|
+
import { emptyGeoJSON, MapControlButton, getIcon, rewindGeometry, getGeoJSONPropertyValue, currentlySupportedDrawModes } from '@opengeoweb/webmap-react';
|
|
7
7
|
import { useConfirmationDialog, ToggleMenu, dateUtils, calculateStartSize, ToolContainerDraggable, AlertBanner, ConfirmationDialog, getAxiosErrorMessage, usePrevious, CustomIconButton, CustomTooltip, Avatar, getInitials, SwitchButton, LastUpdateTime, StatusTag, ErrorBoundary, isAxiosError, pollingIntervalTimeout } from '@opengeoweb/shared';
|
|
8
8
|
import { createEntityAdapter, createSlice, createSelector } from '@reduxjs/toolkit';
|
|
9
9
|
import { snackbarActions } from '@opengeoweb/snackbar';
|
|
10
10
|
import { styled, Box, Typography, ListItem, Grid, Paper, ListItemButton, Stack, LinearProgress, Button, FormHelperText, MenuItem, Tabs, Tab, FormControl, Card, CardContent, ListItemIcon, CircularProgress, List } from '@mui/material';
|
|
11
11
|
import { VariableSizeList } from 'react-window';
|
|
12
12
|
import AutoSizer from 'react-virtualized-auto-sizer';
|
|
13
|
-
import { DATE_FORMAT_FNS,
|
|
13
|
+
import { DATE_FORMAT_FNS, ReactHookFormHiddenInput, isValidGeoJsonCoordinates, ReactHookFormSelect, ReactHookFormTextField, ReactHookFormProvider, defaultFormOptions, useDraftFormHelpers, errorMessages, ReactHookFormDateTime, isValidDate, isXHoursBefore, isXHoursAfter, isEmpty } from '@opengeoweb/form-fields';
|
|
14
14
|
import { getApi, createApiInstance, createNonAuthApiInstance, createFakeApiInstance, ApiProvider } from '@opengeoweb/api';
|
|
15
15
|
import { useFormContext } from 'react-hook-form';
|
|
16
|
-
import { clamp } from 'lodash';
|
|
16
|
+
import { isEqual, cloneDeep, clamp } from 'lodash';
|
|
17
17
|
import { useAuthenticationContext } from '@opengeoweb/authentication';
|
|
18
18
|
import { takeLatest, put, call as call$b, select, delay } from 'redux-saga/effects';
|
|
19
19
|
import { isAxiosError as isAxiosError$1 } from 'axios';
|
|
@@ -232,7 +232,7 @@ const useCloseDrawDialog = ({
|
|
|
232
232
|
const dispatch = useDispatch();
|
|
233
233
|
const drawLayerId = getSingularDrawtoolDrawLayerId(mapId);
|
|
234
234
|
const drawDialogActiveDrawModeId = useSelector(store => drawtoolSelectors.getActiveDrawModeId(store, drawingDialogType));
|
|
235
|
-
const
|
|
235
|
+
const featureLayerContainsGeoJSON = useSelector(store => layerSelectors.getHasFeatureLayerGeoJSON(store, drawLayerId));
|
|
236
236
|
const dialogError = useSelector(store => uiSelectors.getDialogError(store, drawingDialogType));
|
|
237
237
|
const isFormDirty = useSelector(store => getWarningFormDirty(store, drawingDialogType));
|
|
238
238
|
const confirmDialog = useConfirmationDialog();
|
|
@@ -277,7 +277,7 @@ const useCloseDrawDialog = ({
|
|
|
277
277
|
}));
|
|
278
278
|
}
|
|
279
279
|
// clear existing geoJSON
|
|
280
|
-
if (
|
|
280
|
+
if (featureLayerContainsGeoJSON) {
|
|
281
281
|
dispatch(mapStoreActions.layerChangeGeojson({
|
|
282
282
|
layerId: drawLayerId,
|
|
283
283
|
geojson: emptyGeoJSON
|
|
@@ -5358,145 +5358,88 @@ const useFormDirty = ({
|
|
|
5358
5358
|
}, [isLoading, error, previousIsLoading, onSuccess]);
|
|
5359
5359
|
};
|
|
5360
5360
|
|
|
5361
|
+
/* *
|
|
5362
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5363
|
+
* you may not use this file except in compliance with the License.
|
|
5364
|
+
* You may obtain a copy of the License at
|
|
5365
|
+
*
|
|
5366
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
5367
|
+
*
|
|
5368
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
5369
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
5370
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
5371
|
+
* See the License for the specific language governing permissions and
|
|
5372
|
+
* limitations under the License.
|
|
5373
|
+
*
|
|
5374
|
+
* Copyright 2024 - Koninklijk Nederlands Meteorologisch Instituut (KNMI)
|
|
5375
|
+
* Copyright 2024 - Finnish Meteorological Institute (FMI)
|
|
5376
|
+
* */
|
|
5361
5377
|
const opacityOptions = [100, 90, 80, 70, 60, 50, 40, 30, 20, 10, 0];
|
|
5362
|
-
const getObjectName$1 = objectName => objectName || `${dateUtils.dateToString(new Date(), DATE_FORMAT_FNS, true)} UTC`;
|
|
5363
5378
|
const SAVE_OBJECT_BUTTON = 'Save new object';
|
|
5364
5379
|
const UPDATE_OBJECT_BUTTON = 'Update object';
|
|
5365
5380
|
const INPUT_OBJECT = 'Object name';
|
|
5366
5381
|
const INPUT_OPACITY = 'Opacity';
|
|
5367
5382
|
const DRAW_EXIT_MODE_MESSAGE = 'press ESC to exit draw mode';
|
|
5368
5383
|
const coordinatesEmptyMessage = 'An object drawing is required';
|
|
5369
|
-
const
|
|
5370
|
-
|
|
5371
|
-
|
|
5372
|
-
|
|
5373
|
-
|
|
5374
|
-
|
|
5375
|
-
|
|
5376
|
-
|
|
5377
|
-
|
|
5378
|
-
|
|
5379
|
-
|
|
5380
|
-
|
|
5381
|
-
|
|
5382
|
-
|
|
5383
|
-
|
|
5384
|
+
const DrawingToolFormContentsNoMemo = ({
|
|
5385
|
+
isLoading,
|
|
5386
|
+
dialogError,
|
|
5387
|
+
id,
|
|
5388
|
+
drawModes,
|
|
5389
|
+
onChangeDrawMode,
|
|
5390
|
+
activeDrawModeId,
|
|
5391
|
+
onKeyDown,
|
|
5392
|
+
isInEditMode,
|
|
5393
|
+
isDirty,
|
|
5394
|
+
errors,
|
|
5395
|
+
onChangeOpacity,
|
|
5396
|
+
onBlurName,
|
|
5397
|
+
opacity,
|
|
5398
|
+
onSubmit
|
|
5384
5399
|
}) => {
|
|
5385
|
-
const {
|
|
5386
|
-
handleSubmit,
|
|
5387
|
-
setValue,
|
|
5388
|
-
formState: {
|
|
5389
|
-
errors,
|
|
5390
|
-
isDirty
|
|
5391
|
-
},
|
|
5392
|
-
reset,
|
|
5393
|
-
getValues
|
|
5394
|
-
} = useFormContext();
|
|
5395
|
-
useFormDirty({
|
|
5396
|
-
isDirty,
|
|
5397
|
-
isLoading: _isLoading,
|
|
5398
|
-
error,
|
|
5399
|
-
onFormDirty: _onFormDirty,
|
|
5400
|
-
onSuccess: () => {
|
|
5401
|
-
// reset form dirty and update defaultvalues and formvalues after successfull saving
|
|
5402
|
-
reset(getValues());
|
|
5403
|
-
}
|
|
5404
|
-
});
|
|
5405
|
-
React.useEffect(() => {
|
|
5406
|
-
if (_activeDrawModeId) {
|
|
5407
|
-
setValue('geoJSON', geoJSON, {
|
|
5408
|
-
shouldDirty: true
|
|
5409
|
-
});
|
|
5410
|
-
}
|
|
5411
|
-
}, [_activeDrawModeId, geoJSON, setValue]);
|
|
5412
|
-
React.useEffect(() => {
|
|
5413
|
-
// Only set form value if not in edit mode
|
|
5414
|
-
if (!_isInEditMode && !_isLoading && geoJSON) {
|
|
5415
|
-
setValue('geoJSON', geoJSON, {
|
|
5416
|
-
shouldValidate: true
|
|
5417
|
-
});
|
|
5418
|
-
}
|
|
5419
|
-
}, [_isLoading, _isInEditMode, geoJSON, setValue]);
|
|
5420
|
-
const onSubmit = () => {
|
|
5421
|
-
_onDeactivateTool();
|
|
5422
|
-
handleSubmit(formValues => {
|
|
5423
|
-
// remove unneeded properties
|
|
5424
|
-
const {
|
|
5425
|
-
opacity,
|
|
5426
|
-
geoJSON
|
|
5427
|
-
} = formValues,
|
|
5428
|
-
allFormValues = __rest(formValues, ["opacity", "geoJSON"]);
|
|
5429
|
-
// rewind geometry
|
|
5430
|
-
const rewindedGeometry = rewindGeometry(geoJSON);
|
|
5431
|
-
onSubmitForm(Object.assign(Object.assign({}, allFormValues), {
|
|
5432
|
-
id: _id,
|
|
5433
|
-
geoJSON: rewindedGeometry
|
|
5434
|
-
}));
|
|
5435
|
-
})();
|
|
5436
|
-
};
|
|
5437
5400
|
const hasErrors = Object.keys(errors).length > 0;
|
|
5438
|
-
|
|
5439
|
-
const onChangeOpacity = event => {
|
|
5440
|
-
const {
|
|
5441
|
-
value
|
|
5442
|
-
} = event.target;
|
|
5443
|
-
const newOpacity = parseInt(value, 10) / 100;
|
|
5444
|
-
const additionalStrokeOpacity = 0.8;
|
|
5445
|
-
_onChangeProperties({
|
|
5446
|
-
'fill-opacity': newOpacity,
|
|
5447
|
-
'stroke-opacity': clamp(newOpacity + additionalStrokeOpacity, 0.01, 1)
|
|
5448
|
-
});
|
|
5449
|
-
};
|
|
5450
|
-
const onKeyDown = event => {
|
|
5451
|
-
if (event.key === 'Escape') {
|
|
5452
|
-
_onDeactivateTool();
|
|
5453
|
-
}
|
|
5454
|
-
};
|
|
5455
|
-
const onBlurName = event => {
|
|
5456
|
-
_onChangeName(event.target.value);
|
|
5457
|
-
};
|
|
5458
|
-
return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(Box, {
|
|
5401
|
+
return /*#__PURE__*/React__default.createElement(React__default.Fragment, null, /*#__PURE__*/React__default.createElement(Box, {
|
|
5459
5402
|
sx: {
|
|
5460
5403
|
height: 'calc( 100% - 72px )',
|
|
5461
5404
|
overflow: 'auto'
|
|
5462
5405
|
}
|
|
5463
|
-
},
|
|
5406
|
+
}, dialogError && ( /*#__PURE__*/React__default.createElement(Box, {
|
|
5464
5407
|
sx: {
|
|
5465
5408
|
width: '100%'
|
|
5466
5409
|
}
|
|
5467
|
-
}, /*#__PURE__*/
|
|
5468
|
-
title:
|
|
5410
|
+
}, /*#__PURE__*/React__default.createElement(AlertBanner, {
|
|
5411
|
+
title: dialogError,
|
|
5469
5412
|
shouldClose: true
|
|
5470
|
-
}))), /*#__PURE__*/
|
|
5413
|
+
}))), /*#__PURE__*/React__default.createElement(Grid, {
|
|
5471
5414
|
"data-testid": "drawingToolForm",
|
|
5472
5415
|
container: true,
|
|
5473
5416
|
direction: "column",
|
|
5474
5417
|
spacing: 1,
|
|
5475
5418
|
padding: 2
|
|
5476
|
-
}, /*#__PURE__*/
|
|
5419
|
+
}, /*#__PURE__*/React__default.createElement(Grid, {
|
|
5477
5420
|
item: true
|
|
5478
|
-
}, /*#__PURE__*/
|
|
5421
|
+
}, /*#__PURE__*/React__default.createElement(Typography, {
|
|
5479
5422
|
variant: "body2"
|
|
5480
|
-
}, "Tools")), /*#__PURE__*/
|
|
5423
|
+
}, "Tools")), /*#__PURE__*/React__default.createElement(Grid, {
|
|
5481
5424
|
item: true,
|
|
5482
5425
|
container: true
|
|
5483
|
-
}, /*#__PURE__*/
|
|
5426
|
+
}, /*#__PURE__*/React__default.createElement(Grid, {
|
|
5484
5427
|
item: true
|
|
5485
|
-
},
|
|
5428
|
+
}, drawModes.map(mode => ( /*#__PURE__*/React__default.createElement(CustomIconButton, {
|
|
5486
5429
|
key: mode.drawModeId,
|
|
5487
5430
|
variant: "tool",
|
|
5488
5431
|
tooltipTitle: mode.title,
|
|
5489
|
-
isSelected: mode.isSelectable &&
|
|
5490
|
-
onClick: () =>
|
|
5432
|
+
isSelected: mode.isSelectable && activeDrawModeId === mode.drawModeId,
|
|
5433
|
+
onClick: () => onChangeDrawMode(mode),
|
|
5491
5434
|
sx: {
|
|
5492
5435
|
marginRight: 1,
|
|
5493
5436
|
marginBottom: 1
|
|
5494
5437
|
},
|
|
5495
5438
|
"data-testid": mode.drawModeId,
|
|
5496
5439
|
onKeyDown: onKeyDown,
|
|
5497
|
-
disabled:
|
|
5440
|
+
disabled: isLoading,
|
|
5498
5441
|
size: "medium"
|
|
5499
|
-
}, getIcon(mode.selectionType)))),
|
|
5442
|
+
}, getIcon(mode.selectionType)))), isInEditMode && ( /*#__PURE__*/React__default.createElement(Typography, {
|
|
5500
5443
|
component: "span",
|
|
5501
5444
|
sx: {
|
|
5502
5445
|
display: 'inline-block',
|
|
@@ -5505,53 +5448,53 @@ const DrawingToolForm = ({
|
|
|
5505
5448
|
position: 'relative',
|
|
5506
5449
|
fontSize: 14
|
|
5507
5450
|
}
|
|
5508
|
-
}, DRAW_EXIT_MODE_MESSAGE)), !!errors.geoJSON && isDirty && ( /*#__PURE__*/
|
|
5451
|
+
}, DRAW_EXIT_MODE_MESSAGE)), !!errors.geoJSON && isDirty && ( /*#__PURE__*/React__default.createElement(FormHelperText, {
|
|
5509
5452
|
error: true,
|
|
5510
5453
|
variant: "filled",
|
|
5511
5454
|
sx: {
|
|
5512
5455
|
marginLeft: 0
|
|
5513
5456
|
}
|
|
5514
|
-
}, errors.geoJSON.message)), /*#__PURE__*/
|
|
5457
|
+
}, errors.geoJSON.message)), /*#__PURE__*/React__default.createElement(ReactHookFormHiddenInput, {
|
|
5515
5458
|
name: "geoJSON",
|
|
5516
5459
|
rules: {
|
|
5517
5460
|
validate: {
|
|
5518
5461
|
coordinatesNotEmpty: value => isValidGeoJsonCoordinates(value) || coordinatesEmptyMessage
|
|
5519
5462
|
}
|
|
5520
5463
|
}
|
|
5521
|
-
}))), /*#__PURE__*/
|
|
5464
|
+
}))), /*#__PURE__*/React__default.createElement(Grid, {
|
|
5522
5465
|
item: true,
|
|
5523
5466
|
container: true
|
|
5524
|
-
}, /*#__PURE__*/
|
|
5467
|
+
}, /*#__PURE__*/React__default.createElement(Grid, {
|
|
5525
5468
|
item: true,
|
|
5526
5469
|
xs: 12,
|
|
5527
5470
|
sm: 6
|
|
5528
|
-
}, /*#__PURE__*/
|
|
5471
|
+
}, /*#__PURE__*/React__default.createElement(ReactHookFormSelect, {
|
|
5529
5472
|
name: "opacity",
|
|
5530
5473
|
label: INPUT_OPACITY,
|
|
5531
5474
|
rules: {},
|
|
5532
|
-
disabled:
|
|
5475
|
+
disabled: isLoading,
|
|
5533
5476
|
isReadOnly: false,
|
|
5534
5477
|
"data-testid": "drawingToolForm-opacity",
|
|
5535
5478
|
onChange: onChangeOpacity,
|
|
5536
5479
|
autoFocus: true,
|
|
5537
5480
|
value: opacity * 100
|
|
5538
|
-
}, opacityOptions.map(opacity => ( /*#__PURE__*/
|
|
5481
|
+
}, opacityOptions.map(opacity => ( /*#__PURE__*/React__default.createElement(MenuItem, {
|
|
5539
5482
|
value: opacity,
|
|
5540
5483
|
key: opacity
|
|
5541
|
-
}, opacity, " %")))))), /*#__PURE__*/
|
|
5484
|
+
}, opacity, " %")))))), /*#__PURE__*/React__default.createElement(Grid, {
|
|
5542
5485
|
item: true
|
|
5543
|
-
}, /*#__PURE__*/
|
|
5486
|
+
}, /*#__PURE__*/React__default.createElement(ReactHookFormTextField, {
|
|
5544
5487
|
name: "objectName",
|
|
5545
5488
|
label: INPUT_OBJECT,
|
|
5546
5489
|
rules: {
|
|
5547
5490
|
required: true
|
|
5548
5491
|
},
|
|
5549
|
-
disabled:
|
|
5492
|
+
disabled: isLoading,
|
|
5550
5493
|
isReadOnly: false,
|
|
5551
5494
|
onBlur: onBlurName
|
|
5552
|
-
}), /*#__PURE__*/
|
|
5495
|
+
}), /*#__PURE__*/React__default.createElement(ReactHookFormHiddenInput, {
|
|
5553
5496
|
name: "id"
|
|
5554
|
-
})))), /*#__PURE__*/
|
|
5497
|
+
})))), /*#__PURE__*/React__default.createElement(Box, {
|
|
5555
5498
|
sx: {
|
|
5556
5499
|
padding: '24px 10px 14px 10px',
|
|
5557
5500
|
position: 'absolute',
|
|
@@ -5561,7 +5504,7 @@ const DrawingToolForm = ({
|
|
|
5561
5504
|
boxShadow: '0 2px 4px 0 rgba(0, 0, 0, 0.5)',
|
|
5562
5505
|
zIndex: 1
|
|
5563
5506
|
}
|
|
5564
|
-
}, /*#__PURE__*/
|
|
5507
|
+
}, /*#__PURE__*/React__default.createElement(Button, {
|
|
5565
5508
|
variant: "primary",
|
|
5566
5509
|
onClick: onSubmit,
|
|
5567
5510
|
sx: {
|
|
@@ -5570,8 +5513,118 @@ const DrawingToolForm = ({
|
|
|
5570
5513
|
fontSize: '12px'
|
|
5571
5514
|
},
|
|
5572
5515
|
"data-testid": "saveDrawingFormButton",
|
|
5573
|
-
disabled:
|
|
5574
|
-
},
|
|
5516
|
+
disabled: isLoading || hasErrors
|
|
5517
|
+
}, id !== '' ? UPDATE_OBJECT_BUTTON : SAVE_OBJECT_BUTTON)));
|
|
5518
|
+
};
|
|
5519
|
+
const DrawingToolFormContents = /*#__PURE__*/React__default.memo(DrawingToolFormContentsNoMemo, isEqual);
|
|
5520
|
+
|
|
5521
|
+
const getObjectName$1 = objectName => objectName || `${dateUtils.dateToString(new Date(), DATE_FORMAT_FNS, true)} UTC`;
|
|
5522
|
+
const DrawingToolForm = ({
|
|
5523
|
+
onSubmitForm,
|
|
5524
|
+
isLoading: _isLoading = false,
|
|
5525
|
+
dialogError,
|
|
5526
|
+
id: _id = '',
|
|
5527
|
+
drawModes: _drawModes = [],
|
|
5528
|
+
onChangeDrawMode: _onChangeDrawMode = () => {},
|
|
5529
|
+
activeDrawModeId: _activeDrawModeId = '',
|
|
5530
|
+
onDeactivateTool: _onDeactivateTool = () => {},
|
|
5531
|
+
isInEditMode: _isInEditMode = false,
|
|
5532
|
+
geoJSONProperties: _geoJSONProperties = {},
|
|
5533
|
+
onChangeProperties: _onChangeProperties = () => {},
|
|
5534
|
+
onChangeName: _onChangeName = () => {},
|
|
5535
|
+
onFormDirty: _onFormDirty = () => {},
|
|
5536
|
+
geoJSON
|
|
5537
|
+
}) => {
|
|
5538
|
+
const {
|
|
5539
|
+
handleSubmit,
|
|
5540
|
+
setValue,
|
|
5541
|
+
formState: {
|
|
5542
|
+
errors,
|
|
5543
|
+
isDirty
|
|
5544
|
+
},
|
|
5545
|
+
reset,
|
|
5546
|
+
getValues
|
|
5547
|
+
} = useFormContext();
|
|
5548
|
+
// copy errors because react-hook-form mutates the object which breaks memoization
|
|
5549
|
+
const currentErrors = cloneDeep(errors);
|
|
5550
|
+
useFormDirty({
|
|
5551
|
+
isDirty,
|
|
5552
|
+
isLoading: _isLoading,
|
|
5553
|
+
error: dialogError,
|
|
5554
|
+
onFormDirty: _onFormDirty,
|
|
5555
|
+
onSuccess: () => {
|
|
5556
|
+
// reset form dirty and update defaultvalues and formvalues after successfull saving
|
|
5557
|
+
reset(getValues());
|
|
5558
|
+
}
|
|
5559
|
+
});
|
|
5560
|
+
React.useEffect(() => {
|
|
5561
|
+
if (_activeDrawModeId) {
|
|
5562
|
+
setValue('geoJSON', geoJSON, {
|
|
5563
|
+
shouldDirty: true
|
|
5564
|
+
});
|
|
5565
|
+
}
|
|
5566
|
+
}, [_activeDrawModeId, geoJSON, setValue]);
|
|
5567
|
+
React.useEffect(() => {
|
|
5568
|
+
// Only set form value if not in edit mode
|
|
5569
|
+
if (!_isInEditMode && !_isLoading && geoJSON) {
|
|
5570
|
+
setValue('geoJSON', geoJSON, {
|
|
5571
|
+
shouldValidate: true
|
|
5572
|
+
});
|
|
5573
|
+
}
|
|
5574
|
+
}, [_isLoading, _isInEditMode, geoJSON, setValue]);
|
|
5575
|
+
const onSubmit = React.useCallback(() => {
|
|
5576
|
+
_onDeactivateTool();
|
|
5577
|
+
handleSubmit(formValues => {
|
|
5578
|
+
// remove unneeded properties
|
|
5579
|
+
const {
|
|
5580
|
+
opacity,
|
|
5581
|
+
geoJSON
|
|
5582
|
+
} = formValues,
|
|
5583
|
+
allFormValues = __rest(formValues, ["opacity", "geoJSON"]);
|
|
5584
|
+
// rewind geometry
|
|
5585
|
+
const rewindedGeometry = rewindGeometry(geoJSON);
|
|
5586
|
+
onSubmitForm(Object.assign(Object.assign({}, allFormValues), {
|
|
5587
|
+
id: _id,
|
|
5588
|
+
geoJSON: rewindedGeometry
|
|
5589
|
+
}));
|
|
5590
|
+
})();
|
|
5591
|
+
}, [handleSubmit, _id, _onDeactivateTool, onSubmitForm]);
|
|
5592
|
+
const opacity = React.useMemo(() => getGeoJSONPropertyValue('fill-opacity', _geoJSONProperties, _drawModes.find(mode => mode.value === 'POLYGON')), [_geoJSONProperties, _drawModes]);
|
|
5593
|
+
const onChangeOpacity = React.useCallback(event => {
|
|
5594
|
+
const {
|
|
5595
|
+
value
|
|
5596
|
+
} = event.target;
|
|
5597
|
+
const newOpacity = parseInt(value, 10) / 100;
|
|
5598
|
+
const additionalStrokeOpacity = 0.8;
|
|
5599
|
+
_onChangeProperties({
|
|
5600
|
+
'fill-opacity': newOpacity,
|
|
5601
|
+
'stroke-opacity': clamp(newOpacity + additionalStrokeOpacity, 0.01, 1)
|
|
5602
|
+
});
|
|
5603
|
+
}, [_onChangeProperties]);
|
|
5604
|
+
const onKeyDown = React.useCallback(event => {
|
|
5605
|
+
if (event.key === 'Escape') {
|
|
5606
|
+
_onDeactivateTool();
|
|
5607
|
+
}
|
|
5608
|
+
}, [_onDeactivateTool]);
|
|
5609
|
+
const onBlurName = React.useCallback(event => {
|
|
5610
|
+
_onChangeName(event.target.value);
|
|
5611
|
+
}, [_onChangeName]);
|
|
5612
|
+
return /*#__PURE__*/React.createElement(DrawingToolFormContents, {
|
|
5613
|
+
isLoading: _isLoading,
|
|
5614
|
+
dialogError: dialogError,
|
|
5615
|
+
id: _id,
|
|
5616
|
+
drawModes: _drawModes,
|
|
5617
|
+
activeDrawModeId: _activeDrawModeId,
|
|
5618
|
+
onChangeDrawMode: _onChangeDrawMode,
|
|
5619
|
+
onKeyDown: onKeyDown,
|
|
5620
|
+
isInEditMode: _isInEditMode,
|
|
5621
|
+
isDirty: isDirty,
|
|
5622
|
+
errors: currentErrors,
|
|
5623
|
+
onChangeOpacity: onChangeOpacity,
|
|
5624
|
+
onBlurName: onBlurName,
|
|
5625
|
+
opacity: opacity,
|
|
5626
|
+
onSubmit: onSubmit
|
|
5627
|
+
});
|
|
5575
5628
|
};
|
|
5576
5629
|
const Wrapper = props => {
|
|
5577
5630
|
const {
|
|
@@ -5617,28 +5670,28 @@ const DrawingToolFormConnect = () => {
|
|
|
5617
5670
|
const featureLayerGeoJSONProperties = useSelector(store => layerSelectors.getFeatureLayerGeoJSONProperties(store, drawTool === null || drawTool === void 0 ? void 0 : drawTool.geoJSONLayerId));
|
|
5618
5671
|
const isDialogLoading = useSelector(store => uiSelectors.getDialogIsLoading(store, drawToolId));
|
|
5619
5672
|
const dialogError = useSelector(store => uiSelectors.getDialogError(store, drawToolId));
|
|
5620
|
-
const onSubmitForm = formValues => {
|
|
5673
|
+
const onSubmitForm = React.useCallback(formValues => {
|
|
5621
5674
|
dispatch(drawActions.submitDrawValues({
|
|
5622
5675
|
geoJSON: formValues.geoJSON,
|
|
5623
5676
|
objectName: formValues.objectName,
|
|
5624
5677
|
scope: 'user',
|
|
5625
5678
|
id: drawing === null || drawing === void 0 ? void 0 : drawing.id
|
|
5626
5679
|
}));
|
|
5627
|
-
};
|
|
5628
|
-
const onChangeGeoJSONProperties = properties => {
|
|
5680
|
+
}, [dispatch, drawing === null || drawing === void 0 ? void 0 : drawing.id]);
|
|
5681
|
+
const onChangeGeoJSONProperties = React.useCallback(properties => {
|
|
5629
5682
|
dispatch(layerActions.updateFeatureProperties({
|
|
5630
5683
|
layerId: drawTool === null || drawTool === void 0 ? void 0 : drawTool.geoJSONLayerId,
|
|
5631
5684
|
properties,
|
|
5632
5685
|
origin: 'DrawingToolFormConnect'
|
|
5633
5686
|
}));
|
|
5634
|
-
};
|
|
5635
|
-
const onChangeDrawMode = tool => {
|
|
5687
|
+
}, [dispatch, drawTool === null || drawTool === void 0 ? void 0 : drawTool.geoJSONLayerId]);
|
|
5688
|
+
const onChangeDrawMode = React.useCallback(tool => {
|
|
5636
5689
|
dispatch(drawtoolActions.changeDrawToolMode({
|
|
5637
5690
|
drawToolId,
|
|
5638
5691
|
drawModeId: tool.drawModeId
|
|
5639
5692
|
}));
|
|
5640
|
-
};
|
|
5641
|
-
const onDeactivateTool = () => {
|
|
5693
|
+
}, [dispatch, drawToolId]);
|
|
5694
|
+
const onDeactivateTool = React.useCallback(() => {
|
|
5642
5695
|
dispatch(layerActions.toggleFeatureMode({
|
|
5643
5696
|
layerId: drawTool === null || drawTool === void 0 ? void 0 : drawTool.geoJSONLayerId,
|
|
5644
5697
|
isInEditMode: false,
|
|
@@ -5650,27 +5703,27 @@ const DrawingToolFormConnect = () => {
|
|
|
5650
5703
|
drawModeId: drawTool === null || drawTool === void 0 ? void 0 : drawTool.activeDrawModeId
|
|
5651
5704
|
}));
|
|
5652
5705
|
}
|
|
5653
|
-
};
|
|
5654
|
-
const onChangeName = newName => {
|
|
5706
|
+
}, [dispatch, drawTool === null || drawTool === void 0 ? void 0 : drawTool.activeDrawModeId, drawTool === null || drawTool === void 0 ? void 0 : drawTool.geoJSONLayerId, drawToolId]);
|
|
5707
|
+
const onChangeName = React.useCallback(newName => {
|
|
5655
5708
|
dispatch(drawActions.setDrawValues({
|
|
5656
5709
|
objectName: newName,
|
|
5657
5710
|
id: (drawing === null || drawing === void 0 ? void 0 : drawing.id) || '',
|
|
5658
5711
|
drawingInstanceId: drawingDialogType,
|
|
5659
5712
|
isFormDirty: drawing === null || drawing === void 0 ? void 0 : drawing.isFormDirty
|
|
5660
5713
|
}));
|
|
5661
|
-
};
|
|
5662
|
-
const onChangeFormDirty = isFormDirty => {
|
|
5714
|
+
}, [dispatch, drawing === null || drawing === void 0 ? void 0 : drawing.id, drawing === null || drawing === void 0 ? void 0 : drawing.isFormDirty]);
|
|
5715
|
+
const onChangeFormDirty = React.useCallback(isFormDirty => {
|
|
5663
5716
|
dispatch(drawActions.setFormDirty({
|
|
5664
5717
|
drawingInstanceId: drawingDialogType,
|
|
5665
5718
|
isFormDirty
|
|
5666
5719
|
}));
|
|
5667
|
-
};
|
|
5720
|
+
}, [dispatch]);
|
|
5668
5721
|
return /*#__PURE__*/React.createElement(Wrapper, {
|
|
5669
5722
|
id: drawing === null || drawing === void 0 ? void 0 : drawing.id,
|
|
5670
5723
|
onSubmitForm: onSubmitForm,
|
|
5671
5724
|
objectName: drawing === null || drawing === void 0 ? void 0 : drawing.objectName,
|
|
5672
5725
|
isLoading: isDialogLoading,
|
|
5673
|
-
|
|
5726
|
+
dialogError: dialogError,
|
|
5674
5727
|
// new
|
|
5675
5728
|
drawModes: drawTool === null || drawTool === void 0 ? void 0 : drawTool.drawModes,
|
|
5676
5729
|
onChangeDrawMode: onChangeDrawMode,
|
package/package.json
CHANGED
|
@@ -1,24 +1,14 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import { DrawMode } from '@opengeoweb/webmap-react';
|
|
3
3
|
import { FeatureCollection, GeoJsonProperties, Geometry } from 'geojson';
|
|
4
|
+
import { DrawingToolFormValues } from './DrawingToolFormContents';
|
|
4
5
|
export declare const opacityOptions: number[];
|
|
5
6
|
export declare const getObjectName: (objectName: string) => string;
|
|
6
|
-
export declare const SAVE_OBJECT_BUTTON = "Save new object";
|
|
7
|
-
export declare const UPDATE_OBJECT_BUTTON = "Update object";
|
|
8
|
-
export declare const INPUT_OBJECT = "Object name";
|
|
9
|
-
export declare const INPUT_OPACITY = "Opacity";
|
|
10
|
-
export declare const DRAW_EXIT_MODE_MESSAGE = "press ESC to exit draw mode";
|
|
11
|
-
export declare const coordinatesEmptyMessage = "An object drawing is required";
|
|
12
|
-
export interface DrawingToolFormValues {
|
|
13
|
-
objectName: string;
|
|
14
|
-
geoJSON: GeoJSON.FeatureCollection;
|
|
15
|
-
id: string;
|
|
16
|
-
}
|
|
17
7
|
export interface DrawingToolFormComponentProps {
|
|
18
8
|
onSubmitForm: (formValues: DrawingToolFormValues) => void;
|
|
19
9
|
objectName?: string;
|
|
20
10
|
isLoading?: boolean;
|
|
21
|
-
|
|
11
|
+
dialogError?: string;
|
|
22
12
|
id?: string;
|
|
23
13
|
drawModes: DrawMode[];
|
|
24
14
|
onChangeDrawMode: (newMode: DrawMode) => void;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { SelectChangeEvent } from '@mui/material';
|
|
3
|
+
import { DrawMode } from '@opengeoweb/webmap-react';
|
|
4
|
+
import { FieldErrors, FieldValues } from 'react-hook-form';
|
|
5
|
+
export declare const opacityOptions: number[];
|
|
6
|
+
export declare const SAVE_OBJECT_BUTTON = "Save new object";
|
|
7
|
+
export declare const UPDATE_OBJECT_BUTTON = "Update object";
|
|
8
|
+
export declare const INPUT_OBJECT = "Object name";
|
|
9
|
+
export declare const INPUT_OPACITY = "Opacity";
|
|
10
|
+
export declare const DRAW_EXIT_MODE_MESSAGE = "press ESC to exit draw mode";
|
|
11
|
+
export declare const coordinatesEmptyMessage = "An object drawing is required";
|
|
12
|
+
export interface DrawingToolFormValues {
|
|
13
|
+
objectName: string;
|
|
14
|
+
geoJSON: GeoJSON.FeatureCollection;
|
|
15
|
+
id: string;
|
|
16
|
+
}
|
|
17
|
+
export interface DrawingToolFormContentsProps {
|
|
18
|
+
isLoading?: boolean;
|
|
19
|
+
dialogError?: string;
|
|
20
|
+
id?: string;
|
|
21
|
+
drawModes: DrawMode[];
|
|
22
|
+
activeDrawModeId: string;
|
|
23
|
+
opacity: number;
|
|
24
|
+
isInEditMode: boolean;
|
|
25
|
+
isDirty: boolean;
|
|
26
|
+
errors: FieldErrors<FieldValues>;
|
|
27
|
+
onChangeDrawMode: (newMode: DrawMode) => void;
|
|
28
|
+
onKeyDown: (event: React.KeyboardEvent<HTMLElement>) => void;
|
|
29
|
+
onChangeOpacity: (event: SelectChangeEvent) => void;
|
|
30
|
+
onBlurName: (event: React.FocusEvent<HTMLInputElement>) => void;
|
|
31
|
+
onSubmit: () => void;
|
|
32
|
+
}
|
|
33
|
+
export declare const DrawingToolFormContentsNoMemo: React.FC<DrawingToolFormContentsProps>;
|
|
34
|
+
export declare const DrawingToolFormContents: React.NamedExoticComponent<DrawingToolFormContentsProps>;
|