@mapcomponents/react-maplibre 0.1.71 → 0.1.73

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/CHANGELOG.md CHANGED
@@ -1,7 +1,21 @@
1
1
  # Change Log
2
2
 
3
3
 
4
- ## [v0.1.71] - 2023-03-05
4
+ ## [v0.1.73] - 2023-03-11
5
+
6
+ ### Fixed
7
+ - 547db2c: Fix/layerlist visibility settings
8
+
9
+ ## [v0.1.72] - 2023-03-08
10
+
11
+ ### Fixed
12
+ - Fix/maplibremap registration react 18 (#89) …
13
+ - remove mui-color dependency
14
+ ### Added
15
+ - add new ColorPicker ui component
16
+ - add MlWmsLayer support to LayerList component
17
+
18
+ ## [v0.1.71] - 2023-03-04
5
19
 
6
20
  ### Fixed
7
21
  - e3178b5: fix Topbar sidebar defaults
@@ -39,6 +39,7 @@ interface MapLibreGlWrapper extends MapType {
39
39
  }) | (CustomLayerInterface & {
40
40
  source?: string | SourceSpecification | undefined;
41
41
  }), beforeId?: string | undefined, componentId?: string | undefined) => this;
42
+ cancelled: boolean;
42
43
  }
43
44
  declare class MapLibreGlWrapper {
44
45
  registeredElements: {
@@ -1,5 +1,5 @@
1
1
  /// <reference types="react" />
2
- import { paintPropsType } from './LayerPropertyForm';
2
+ import { paintPropsType } from '../../../ui_components/LayerList/util/LayerPropertyForm';
3
3
  type Props = {
4
4
  key: string;
5
5
  value: string;
package/dist/index.esm.js CHANGED
@@ -41,7 +41,7 @@ var ListItemText = require('@mui/material/ListItemText');
41
41
  var IconButton = require('@mui/material/IconButton');
42
42
  var d3 = require('d3');
43
43
  var TuneIcon = require('@mui/icons-material/Tune');
44
- var muiColor = require('mui-color');
44
+ var reactColor = require('react-color');
45
45
  var iconsMaterial = require('@mui/icons-material');
46
46
  var system = require('@mui/system');
47
47
  var AppBar = require('@mui/material/AppBar');
@@ -392,6 +392,7 @@ var MapLibreGlWrapper = /** @class */ (function () {
392
392
  self.wrapper.viewportState = self.wrapper.getViewport();
393
393
  },
394
394
  };
395
+ this.cancelled = false;
395
396
  /**
396
397
  * Initializes an empty registered elements object for the given componentId
397
398
  *
@@ -702,7 +703,6 @@ var MapLibreGlWrapper = /** @class */ (function () {
702
703
  _a.label = 2;
703
704
  case 2:
704
705
  self.map = new maplibreGl.Map(props.mapOptions);
705
- window['_map'] = self.map;
706
706
  self.addNativeMaplibreFunctionsAndProps();
707
707
  self.wrapper.refreshViewport();
708
708
  self.wrapper.fire('viewportchange');
@@ -868,12 +868,11 @@ var MapComponentsProvider = function (_a) {
868
868
  mapIds_raw.current.splice(mapIdIndex, 1);
869
869
  }
870
870
  setMapIds(__spreadArray([], mapIds_raw.current, true));
871
- if (mapIds.length === 1 && map) {
871
+ if (mapIds_raw.current.length === 0 && map) {
872
872
  setMap(undefined);
873
873
  }
874
874
  }
875
875
  else {
876
- setMap(undefined);
877
876
  removeMap('anonymous_map');
878
877
  }
879
878
  };
@@ -895,7 +894,7 @@ var MapComponentsProvider = function (_a) {
895
894
  maps.current[mapId] = mapInstance;
896
895
  mapIds_raw.current.push(mapId);
897
896
  setMapIds(__spreadArray([], mapIds_raw.current, true));
898
- if (!map) {
897
+ if (!map || (map === null || map === void 0 ? void 0 : map.cancelled) === true) {
899
898
  setMap(mapInstance);
900
899
  }
901
900
  }
@@ -962,7 +961,7 @@ var defaultProps$1 = {
962
961
  */
963
962
  var MapLibreMap = function (props) {
964
963
  var _a, _b;
965
- var map = React.useRef();
964
+ var mapRef = React.useRef();
966
965
  var mapContainer = React.useRef();
967
966
  var mapContext = React.useContext(MapContext);
968
967
  var mapIdRef = React.useRef(props.mapId);
@@ -971,11 +970,14 @@ var MapLibreMap = function (props) {
971
970
  React.useEffect(function () {
972
971
  var mapId = mapIdRef.current;
973
972
  return function () {
974
- var _a, _b, _c;
973
+ var _a, _b;
975
974
  initializedRef.current = false;
976
975
  mapContext.removeMap(mapId);
977
- (_c = (_b = (_a = map.current) === null || _a === void 0 ? void 0 : _a.map) === null || _b === void 0 ? void 0 : _b.remove) === null || _c === void 0 ? void 0 : _c.call(_b);
978
- map.current = undefined;
976
+ if (mapRef.current) {
977
+ (_b = (_a = mapRef.current.map) === null || _a === void 0 ? void 0 : _a.remove) === null || _b === void 0 ? void 0 : _b.call(_a);
978
+ mapRef.current.cancelled = true;
979
+ mapRef.current = undefined;
980
+ }
979
981
  };
980
982
  }, []);
981
983
  React.useEffect(function () {
@@ -984,15 +986,22 @@ var MapLibreMap = function (props) {
984
986
  return;
985
987
  if (mapContainer.current) {
986
988
  initializedRef.current = true;
987
- map.current = new MapLibreGlWrapper({
989
+ mapRef.current = new MapLibreGlWrapper({
988
990
  mapOptions: __assign(__assign(__assign({ style: '' }, props.options), (((_a = props === null || props === void 0 ? void 0 : props.options) === null || _a === void 0 ? void 0 : _a.style) ? {} : { style: (_b = defaultProps$1 === null || defaultProps$1 === void 0 ? void 0 : defaultProps$1.options) === null || _b === void 0 ? void 0 : _b.style })), { container: mapContainer.current }),
989
991
  onReady: function (map, wrapper) {
990
992
  map.once('load', function () {
991
- if (props.mapId) {
992
- mapContext.registerMap(props.mapId, wrapper);
993
+ if (!(wrapper === null || wrapper === void 0 ? void 0 : wrapper.cancelled)) {
994
+ // add maplibre instance to window for debugging purposes
995
+ window['_map'] = map;
996
+ if (props.mapId) {
997
+ mapContext.registerMap(props.mapId, wrapper);
998
+ }
999
+ else {
1000
+ mapContext.setMap(wrapper);
1001
+ }
993
1002
  }
994
1003
  else {
995
- mapContext.setMap(wrapper);
1004
+ map.remove();
996
1005
  }
997
1006
  });
998
1007
  },
@@ -1001,10 +1010,11 @@ var MapLibreMap = function (props) {
1001
1010
  }, [props.options, props.mapId]);
1002
1011
  React.useEffect(function () {
1003
1012
  var _a, _b;
1004
- if (((_a = map.current) === null || _a === void 0 ? void 0 : _a.map) && ((_b = props === null || props === void 0 ? void 0 : props.options) === null || _b === void 0 ? void 0 : _b.style) && currentStyle.current !== props.options.style) {
1005
- console.log('set style');
1013
+ if (((_a = mapRef.current) === null || _a === void 0 ? void 0 : _a.map) &&
1014
+ ((_b = props === null || props === void 0 ? void 0 : props.options) === null || _b === void 0 ? void 0 : _b.style) &&
1015
+ currentStyle.current !== props.options.style) {
1006
1016
  currentStyle.current = props.options.style;
1007
- map.current.map.setStyle(props.options.style);
1017
+ mapRef.current.map.setStyle(props.options.style);
1008
1018
  }
1009
1019
  }, [(_b = props === null || props === void 0 ? void 0 : props.options) === null || _b === void 0 ? void 0 : _b.style]);
1010
1020
  return (React__default["default"].createElement("div", { ref: mapContainer, className: "mapContainer", style: props.style }));
@@ -1142,7 +1152,6 @@ useMapState.propTypes = {
1142
1152
  };
1143
1153
 
1144
1154
  function useMap(props) {
1145
- // Use a useRef hook to reference the layer object to be able to access it later inside useEffect hooks
1146
1155
  var mapContext = React.useContext(MapContext);
1147
1156
  var _a = React.useState(), map = _a[0], setMap = _a[1];
1148
1157
  var mapState = useMapState({
@@ -1156,7 +1165,6 @@ function useMap(props) {
1156
1165
  includeBaseLayers: true,
1157
1166
  },
1158
1167
  });
1159
- var initializedRef = React.useRef(false);
1160
1168
  var mapRef = React.useRef();
1161
1169
  var componentId = React.useRef(uuid.v4());
1162
1170
  var _b = React.useState(false), mapIsReady = _b[0], setMapIsReady = _b[1];
@@ -1164,7 +1172,6 @@ function useMap(props) {
1164
1172
  if (mapRef.current) {
1165
1173
  mapRef.current.cleanup(componentId.current);
1166
1174
  }
1167
- initializedRef.current = false;
1168
1175
  };
1169
1176
  React.useEffect(function () {
1170
1177
  return function () {
@@ -1175,7 +1182,12 @@ function useMap(props) {
1175
1182
  }, []);
1176
1183
  React.useEffect(function () {
1177
1184
  var _a;
1178
- if (!mapContext.mapExists(props === null || props === void 0 ? void 0 : props.mapId) || initializedRef.current)
1185
+ if (mapRef.current && mapRef.current.cancelled === true) {
1186
+ mapRef.current = undefined;
1187
+ setMap(undefined);
1188
+ setMapIsReady(false);
1189
+ }
1190
+ if (mapRef.current || !mapContext.mapExists(props === null || props === void 0 ? void 0 : props.mapId))
1179
1191
  return;
1180
1192
  // check if waitForLayer (string, layer id of the layer this hook is supposed to wait for)
1181
1193
  // exists as layer in the MapLibre instance
@@ -1190,9 +1202,6 @@ function useMap(props) {
1190
1202
  return;
1191
1203
  }
1192
1204
  }
1193
- // the MapLibre-gl instance (mapContext.getMap(props.mapId)) is accessible here
1194
- // initialize the layer and add it to the MapLibre-gl instance or do something else with it
1195
- initializedRef.current = true;
1196
1205
  mapRef.current = mapContext.getMap(props === null || props === void 0 ? void 0 : props.mapId);
1197
1206
  setMap(mapRef.current);
1198
1207
  setMapIsReady(true);
@@ -3332,7 +3341,7 @@ function useLayer(props) {
3332
3341
  var layerId = React.useRef(props.layerId || (props.idPrefix ? props.idPrefix : 'Layer-') + mapHook.componentId);
3333
3342
  var createLayer = React.useCallback(function () {
3334
3343
  var _a, _b;
3335
- if (!mapHook.map)
3344
+ if (!mapHook.map || (mapHook === null || mapHook === void 0 ? void 0 : mapHook.map.cancelled))
3336
3345
  return;
3337
3346
  if (mapHook.map.map.getLayer(layerId.current)) {
3338
3347
  mapHook.cleanup();
@@ -3388,9 +3397,12 @@ function useLayer(props) {
3388
3397
  layerTypeRef.current = props.options.type;
3389
3398
  }, [props, mapHook.map]);
3390
3399
  React.useEffect(function () {
3400
+ var _a, _b, _c, _d;
3391
3401
  if (!mapHook.map)
3392
3402
  return;
3393
- if (initializedRef.current &&
3403
+ if (((_a = mapHook.map) === null || _a === void 0 ? void 0 : _a.cancelled) === false &&
3404
+ initializedRef.current &&
3405
+ ((_d = (_c = (_b = mapHook === null || mapHook === void 0 ? void 0 : mapHook.map) === null || _b === void 0 ? void 0 : _b.map) === null || _c === void 0 ? void 0 : _c.getLayer) === null || _d === void 0 ? void 0 : _d.call(_c, layerId.current)) &&
3394
3406
  (legalLayerTypes.indexOf(props.options.type) === -1 ||
3395
3407
  (legalLayerTypes.indexOf(props.options.type) !== -1 &&
3396
3408
  props.options.type === layerTypeRef.current))) {
@@ -3399,17 +3411,20 @@ function useLayer(props) {
3399
3411
  createLayer();
3400
3412
  }, [mapHook.map, props.options, createLayer]);
3401
3413
  React.useEffect(function () {
3402
- var _a, _b, _c, _d;
3403
- if (!initializedRef.current || !((_b = (_a = mapHook.map) === null || _a === void 0 ? void 0 : _a.map) === null || _b === void 0 ? void 0 : _b.getSource(layerId.current)))
3414
+ var _a, _b, _c, _d, _e, _f;
3415
+ if (((_a = mapHook.map) === null || _a === void 0 ? void 0 : _a.cancelled) === true ||
3416
+ !initializedRef.current ||
3417
+ !((_d = (_c = (_b = mapHook.map) === null || _b === void 0 ? void 0 : _b.map) === null || _c === void 0 ? void 0 : _c.getSource) === null || _d === void 0 ? void 0 : _d.call(_c, layerId.current)))
3404
3418
  return;
3405
3419
  // eslint-disable-next-line @typescript-eslint/ban-ts-comment
3406
3420
  //@ts-ignore setData only exists on GeoJsonSource
3407
- (_d = (_c = mapHook.map.map.getSource(layerId.current)) === null || _c === void 0 ? void 0 : _c.setData) === null || _d === void 0 ? void 0 : _d.call(_c, props.geojson);
3421
+ (_f = (_e = mapHook.map.map.getSource(layerId.current)) === null || _e === void 0 ? void 0 : _e.setData) === null || _f === void 0 ? void 0 : _f.call(_e, props.geojson);
3408
3422
  }, [props.geojson, mapHook.map, props.options.type]);
3409
3423
  React.useEffect(function () {
3410
- var _a, _b, _c, _d, _e;
3411
- if (!mapHook.map ||
3412
- !((_c = (_b = (_a = mapHook.map) === null || _a === void 0 ? void 0 : _a.map) === null || _b === void 0 ? void 0 : _b.getLayer) === null || _c === void 0 ? void 0 : _c.call(_b, layerId.current)) ||
3424
+ var _a, _b, _c, _d, _e, _f;
3425
+ if (((_a = mapHook.map) === null || _a === void 0 ? void 0 : _a.cancelled) === true ||
3426
+ !mapHook.map ||
3427
+ !((_d = (_c = (_b = mapHook.map) === null || _b === void 0 ? void 0 : _b.map) === null || _c === void 0 ? void 0 : _c.getLayer) === null || _d === void 0 ? void 0 : _d.call(_c, layerId.current)) ||
3413
3428
  !initializedRef.current ||
3414
3429
  props.options.type !== layerTypeRef.current)
3415
3430
  return;
@@ -3418,7 +3433,7 @@ function useLayer(props) {
3418
3433
  if (props.options.layout && layoutString !== layerLayoutConfRef.current) {
3419
3434
  var oldLayout = JSON.parse(layerLayoutConfRef.current);
3420
3435
  for (key in props.options.layout) {
3421
- if (((_d = props.options.layout) === null || _d === void 0 ? void 0 : _d[key]) && props.options.layout[key] !== oldLayout[key]) {
3436
+ if (((_e = props.options.layout) === null || _e === void 0 ? void 0 : _e[key]) && props.options.layout[key] !== oldLayout[key]) {
3422
3437
  mapHook.map.map.setLayoutProperty(layerId.current, key, props.options.layout[key]);
3423
3438
  }
3424
3439
  }
@@ -3428,7 +3443,7 @@ function useLayer(props) {
3428
3443
  if (paintString !== layerPaintConfRef.current) {
3429
3444
  var oldPaint = JSON.parse(layerPaintConfRef.current);
3430
3445
  for (key in props.options.paint) {
3431
- if (((_e = props.options.paint) === null || _e === void 0 ? void 0 : _e[key]) && props.options.paint[key] !== oldPaint[key]) {
3446
+ if (((_f = props.options.paint) === null || _f === void 0 ? void 0 : _f[key]) && props.options.paint[key] !== oldPaint[key]) {
3432
3447
  mapHook.map.map.setPaintProperty(layerId.current, key, props.options.paint[key]);
3433
3448
  }
3434
3449
  }
@@ -3495,6 +3510,7 @@ var getDefaultPaintPropsByType = function (type, defaultPaintOverrides) {
3495
3510
  }
3496
3511
  return {
3497
3512
  'fill-color': 'rgba(10,240,256,0.6)',
3513
+ 'fill-outline-color': 'rgba(20,230,256,0.8)',
3498
3514
  };
3499
3515
  case 'line':
3500
3516
  if (defaultPaintOverrides === null || defaultPaintOverrides === void 0 ? void 0 : defaultPaintOverrides.line) {
@@ -3514,6 +3530,7 @@ var getDefaultPaintPropsByType = function (type, defaultPaintOverrides) {
3514
3530
  'circle-color': 'rgba(10,240,256,0.8)',
3515
3531
  'circle-stroke-color': '#fff',
3516
3532
  'circle-stroke-width': 2,
3533
+ 'circle-radius': 4,
3517
3534
  };
3518
3535
  }
3519
3536
  };
@@ -3919,21 +3936,21 @@ var MlNavigationTools = function (props) {
3919
3936
  }, mapHook.componentId);
3920
3937
  setPitch(mapHook.map.map.getPitch());
3921
3938
  }, [mapHook.map, props.mapId]);
3922
- var zoomIn = function () {
3939
+ var zoomIn = React.useCallback(function () {
3923
3940
  if (!mapHook.map)
3924
3941
  return;
3925
3942
  if (mapHook.map.map.transform._zoom + 0.5 <= mapHook.map.map.transform._maxZoom) {
3926
3943
  mapHook.map.map.easeTo({ zoom: mapHook.map.map.transform._zoom + 0.5 });
3927
3944
  }
3928
- };
3929
- var zoomOut = function () {
3945
+ }, [mapHook.map]);
3946
+ var zoomOut = React.useCallback(function () {
3930
3947
  if (!mapHook.map)
3931
3948
  return;
3932
3949
  if (mapHook.map.map.transform._zoom - 0.5 >= mapHook.map.map.transform._minZoom) {
3933
3950
  mapHook.map.map.easeTo({ zoom: mapHook.map.map.transform._zoom - 0.5 });
3934
3951
  }
3935
- };
3936
- var adjustPitch = function () {
3952
+ }, [mapHook.map]);
3953
+ var adjustPitch = React.useCallback(function () {
3937
3954
  if (!mapHook.map)
3938
3955
  return;
3939
3956
  var targetPitch = 60;
@@ -3941,7 +3958,7 @@ var MlNavigationTools = function (props) {
3941
3958
  targetPitch = 0;
3942
3959
  }
3943
3960
  mapHook.map.map.easeTo({ pitch: targetPitch });
3944
- };
3961
+ }, [mapHook.map]);
3945
3962
  return (React__default["default"].createElement(Box__default["default"], { sx: __assign(__assign({ zIndex: 501, position: 'absolute', display: 'flex', flexDirection: 'column' }, (mediaIsMobile ? { margin: '20px 10px 20px 10px' } : {})), props.sx) },
3946
3963
  React__default["default"].createElement(MlNavigationCompass, { style: {
3947
3964
  width: '31px',
@@ -6322,17 +6339,17 @@ var MlWmsLoader = function (props) {
6322
6339
  };
6323
6340
  }, [getFeatureInfo]);
6324
6341
  React.useEffect(function () {
6325
- var _a, _b, _c, _d, _e, _f, _g, _h;
6342
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
6326
6343
  if (!(capabilities === null || capabilities === void 0 ? void 0 : capabilities.Service))
6327
6344
  return;
6328
- if (((_d = (_c = (_b = (_a = capabilities === null || capabilities === void 0 ? void 0 : capabilities.Capability) === null || _a === void 0 ? void 0 : _a.Layer) === null || _b === void 0 ? void 0 : _b.CRS) === null || _c === void 0 ? void 0 : _c.indexOf) === null || _d === void 0 ? void 0 : _d.call(_c, 'EPSG:3857')) === -1) {
6345
+ if (((_d = (_c = (_b = (_a = capabilities === null || capabilities === void 0 ? void 0 : capabilities.Capability) === null || _a === void 0 ? void 0 : _a.Layer) === null || _b === void 0 ? void 0 : _b.CRS) === null || _c === void 0 ? void 0 : _c.indexOf) === null || _d === void 0 ? void 0 : _d.call(_c, 'EPSG:3857')) === -1 && ((_h = (_g = (_f = (_e = capabilities === null || capabilities === void 0 ? void 0 : capabilities.Capability) === null || _e === void 0 ? void 0 : _e.Layer) === null || _f === void 0 ? void 0 : _f.CRS) === null || _g === void 0 ? void 0 : _g.indexOf) === null || _h === void 0 ? void 0 : _h.call(_g, 'CRS:84')) === -1) {
6329
6346
  console.log('MlWmsLoader (' + capabilities.Service.Title + '): No WGS 84/Pseudo-Mercator support');
6330
6347
  }
6331
6348
  else {
6332
6349
  console.log('MlWmsLoader (' + capabilities.Service.Title + '): WGS 84/Pseudo-Mercator supported');
6333
6350
  var _LatLonBoundingBox_1 = [];
6334
6351
  // collect aueriable Layer2 layers
6335
- var _layers_1 = (_f = (_e = capabilities === null || capabilities === void 0 ? void 0 : capabilities.Capability) === null || _e === void 0 ? void 0 : _e.Layer) === null || _f === void 0 ? void 0 : _f.Layer.filter(function (el) { var _a; return !((_a = el.Layer) === null || _a === void 0 ? void 0 : _a.length); }).map(function (layer, idx) {
6352
+ var _layers_1 = (_k = (_j = capabilities === null || capabilities === void 0 ? void 0 : capabilities.Capability) === null || _j === void 0 ? void 0 : _j.Layer) === null || _k === void 0 ? void 0 : _k.Layer.filter(function (el) { var _a; return !((_a = el.Layer) === null || _a === void 0 ? void 0 : _a.length); }).map(function (layer, idx) {
6336
6353
  var _a, _b, _c;
6337
6354
  if (idx === 0) {
6338
6355
  _LatLonBoundingBox_1 = layer.EX_GeographicBoundingBox;
@@ -6340,7 +6357,7 @@ var MlWmsLoader = function (props) {
6340
6357
  return __assign({ visible: ((_c = (_b = (_a = capabilities === null || capabilities === void 0 ? void 0 : capabilities.Capability) === null || _a === void 0 ? void 0 : _a.Layer) === null || _b === void 0 ? void 0 : _b.Layer) === null || _c === void 0 ? void 0 : _c.length) > 2 ? idx > 1 : true, Attribution: { Title: '' } }, layer);
6341
6358
  });
6342
6359
  // collect aueriable Layer3 layers
6343
- (_h = (_g = capabilities === null || capabilities === void 0 ? void 0 : capabilities.Capability) === null || _g === void 0 ? void 0 : _g.Layer) === null || _h === void 0 ? void 0 : _h.Layer.forEach(function (el) {
6360
+ (_m = (_l = capabilities === null || capabilities === void 0 ? void 0 : capabilities.Capability) === null || _l === void 0 ? void 0 : _l.Layer) === null || _m === void 0 ? void 0 : _m.Layer.forEach(function (el) {
6344
6361
  var _a;
6345
6362
  var tmpLayers = (_a = el === null || el === void 0 ? void 0 : el.Layer) === null || _a === void 0 ? void 0 : _a.filter(function (el) { return el.CRS.length; }).map(function (layer, idx) {
6346
6363
  if (idx === 0) {
@@ -6710,37 +6727,81 @@ function LayerList(_a) {
6710
6727
  return React__default["default"].createElement(material.List, { sx: { marginTop: '15px' } }, children);
6711
6728
  }
6712
6729
 
6730
+ var converters = {
6731
+ rgba: function (c) { return "rgba(".concat(c.rgb.r, ", ").concat(c.rgb.g, ", ").concat(c.rgb.b, ", ").concat(c.rgb.a, ")"); },
6732
+ rgb: function (c) { return "rgb(".concat(c.rgb.r, ", ").concat(c.rgb.g, ", ").concat(c.rgb.b, ")"); },
6733
+ hex: function (c) { return c.hex; },
6734
+ rgba_rgb: function (c) { return c.rgb.a === 1 ? converters.rgb(c) : converters.rgba(c); },
6735
+ rgba_hex: function (c) { return c.rgb.a === 1 ? converters.hex(c) : converters.rgba(c); }
6736
+ };
6737
+
6738
+ var ColorPicker = function (_a) {
6739
+ var convert = _a.convert, props = __rest(_a, ["convert"]);
6740
+ var _b = React.useState(false), showPicker = _b[0], setShowPicker = _b[1];
6741
+ var _c = React.useState((props === null || props === void 0 ? void 0 : props.value) || ''), value = _c[0], setValue = _c[1];
6742
+ return (React__default["default"].createElement(React__default["default"].Fragment, null,
6743
+ React__default["default"].createElement(material.Grid, { container: true, sx: { flexWrap: 'nowrap' } },
6744
+ React__default["default"].createElement(material.Grid, { xs: 2, item: true },
6745
+ React__default["default"].createElement(material.Button, { variant: "outlined", onClick: function () { return setShowPicker(true); }, sx: {
6746
+ minWidth: 'initial',
6747
+ padding: '5px',
6748
+ borderColor: function (theme) { return theme.palette.text.primary; },
6749
+ } },
6750
+ React__default["default"].createElement("div", { style: { width: '25px', height: '25px', backgroundColor: value } }))),
6751
+ React__default["default"].createElement(material.Grid, { xs: 10, item: true },
6752
+ React__default["default"].createElement(material.TextField, { onClick: function () { return setShowPicker(true); }, value: value, variant: "outlined", disabled: true }))),
6753
+ showPicker && (React__default["default"].createElement("div", { style: { position: 'relative', marginTop: 0 } },
6754
+ React__default["default"].createElement("div", { style: { position: 'absolute', zIndex: 1000 } },
6755
+ React__default["default"].createElement("div", { style: { position: 'fixed', top: '0px', right: '0px', bottom: '0px', left: '0px' }, onClick: function () {
6756
+ setShowPicker(false);
6757
+ } }),
6758
+ React__default["default"].createElement(reactColor.ChromePicker, { color: value, onChange: function (c) {
6759
+ var _a;
6760
+ var newValue = converters[convert](c);
6761
+ setValue(newValue);
6762
+ (_a = props === null || props === void 0 ? void 0 : props.onChange) === null || _a === void 0 ? void 0 : _a.call(props, newValue);
6763
+ } }))))));
6764
+ };
6765
+ ColorPicker.defaultProps = {
6766
+ convert: 'rgba_hex',
6767
+ label: 'Color',
6768
+ name: 'color',
6769
+ };
6770
+
6713
6771
  function PaintPropsColorPicker(_a) {
6714
6772
  var propKey = _a.propKey, value = _a.value, setPaintProps = _a.setPaintProps;
6715
- return (React__default["default"].createElement(muiColor.ColorPicker, { value: value, onChange: function (value) {
6773
+ return (React__default["default"].createElement(ColorPicker, { value: value, label: "Color", onChange: function (value) {
6716
6774
  setPaintProps(function (current) {
6717
6775
  var _a;
6718
- var _b;
6719
- if (!((_b = value === null || value === void 0 ? void 0 : value.rgb) === null || _b === void 0 ? void 0 : _b[0])) {
6720
- return current;
6721
- }
6722
- var newProps = __assign(__assign({}, current), (_a = {}, _a[propKey] = 'rgba(' +
6723
- value.rgb[0] +
6724
- ',' +
6725
- value.rgb[1] +
6726
- ',' +
6727
- value.rgb[2] +
6728
- ',' +
6729
- value.alpha +
6730
- ')', _a));
6776
+ var newProps = __assign(__assign({}, current), (_a = {}, _a[propKey] = value, _a));
6731
6777
  return newProps;
6732
6778
  });
6733
6779
  } }));
6734
6780
  }
6735
6781
 
6736
6782
  var mapPropKeyToFormInputType = {
6783
+ 'circle-color': 'colorpicker',
6784
+ 'circle-radius': 'slider',
6785
+ 'circle-stroke-color': 'colorpicker',
6786
+ 'circle-stroke-width': 'slider',
6737
6787
  'fill-color': 'colorpicker',
6788
+ 'fill-outline-color': 'colorpicker',
6738
6789
  'line-color': 'colorpicker',
6739
6790
  'line-width': 'slider',
6740
6791
  'line-blur': 'slider',
6741
6792
  };
6742
6793
  var mapPropKeyToFormInputTypeKeys = Object.keys(mapPropKeyToFormInputType);
6743
6794
  var inputPropsByPropKey = {
6795
+ 'circle-stroke-width': {
6796
+ step: 1,
6797
+ min: 1,
6798
+ max: 20,
6799
+ },
6800
+ 'circle-radius': {
6801
+ step: 1,
6802
+ min: 1,
6803
+ max: 100,
6804
+ },
6744
6805
  'line-blur': {
6745
6806
  step: 1,
6746
6807
  min: 1,
@@ -6763,7 +6824,7 @@ function LayerPropertyForm(_a) {
6763
6824
  case 'slider':
6764
6825
  return (React__default["default"].createElement(React__default["default"].Fragment, null,
6765
6826
  label,
6766
- React__default["default"].createElement(material.Slider, __assign({}, inputPropsByPropKey[key], { inputProps: { inputMode: 'decimal', pattern: '[0-9]*' }, value: paintProps[key], onChange: function (_ev, value) {
6827
+ React__default["default"].createElement(material.Slider, __assign({}, inputPropsByPropKey[key], { inputProps: { inputMode: 'decimal', pattern: '[0-9]*' }, value: paintProps[key], valueLabelDisplay: "auto", onChange: function (_ev, value) {
6767
6828
  if (value) {
6768
6829
  setPaintProps(function (current) {
6769
6830
  var _a;
@@ -6798,6 +6859,7 @@ function LayerPropertyForm(_a) {
6798
6859
  padding: '15px',
6799
6860
  boxShadow: 'inset 0px 0px 10px rgb(50 50 50 / 10%)',
6800
6861
  borderRadius: '5px',
6862
+ width: '100%',
6801
6863
  } }, Object.keys(paintProps).map(function (el) { return getFormInputByType(el); })))));
6802
6864
  }
6803
6865
 
@@ -6848,7 +6910,7 @@ function LayerListFolder(_a) {
6848
6910
  }
6849
6911
 
6850
6912
  function LayerListItemVectorLayer(_a) {
6851
- var configurable = _a.configurable, vtProps = _a.vtProps, setVtProps = _a.setVtProps, id = _a.id;
6913
+ var configurable = _a.configurable, vtProps = _a.vtProps, setVtProps = _a.setVtProps, id = _a.id, props = __rest(_a, ["configurable", "vtProps", "setVtProps", "id"]);
6852
6914
  var _b = React.useState(false), paintPropsFormVisible = _b[0], setPaintPropsFormVisible = _b[1];
6853
6915
  var _c = React.useState(true), visible = _c[0], setVisible = _c[1];
6854
6916
  var _d = React.useState(vtProps.layers[id].paint), paintProps = _d[0], setPaintProps = _d[1];
@@ -6864,6 +6926,9 @@ function LayerListItemVectorLayer(_a) {
6864
6926
  }
6865
6927
  setVtProps(__assign(__assign({}, vtProps), { layers: _layers }));
6866
6928
  }, [visible, id, setVtProps, vtProps]);
6929
+ React.useEffect(function () {
6930
+ setVisible(!!props.visibleMaster);
6931
+ }, [props.visibleMaster]);
6867
6932
  React.useEffect(function () {
6868
6933
  if (!setVtProps)
6869
6934
  return;
@@ -6911,20 +6976,22 @@ function LayerListItem(_a) {
6911
6976
  return localVisible;
6912
6977
  }, [visible, localVisible]);
6913
6978
  React.useEffect(function () {
6914
- var _a, _b;
6979
+ var _a, _b, _c;
6915
6980
  if (!setLayerState || !((_a = layerComponent === null || layerComponent === void 0 ? void 0 : layerComponent.props) === null || _a === void 0 ? void 0 : _a.layers) || _visible === visibleRef.current)
6916
6981
  return;
6917
6982
  visibleRef.current = _visible;
6918
6983
  var state = __assign({}, layerComponent === null || layerComponent === void 0 ? void 0 : layerComponent.props);
6919
- state.layers = (_b = layerComponent === null || layerComponent === void 0 ? void 0 : layerComponent.props) === null || _b === void 0 ? void 0 : _b.layers.map(function (el) {
6920
- if (el.layout) {
6921
- el.layout['visibility'] = _visible ? 'visible' : 'none';
6922
- }
6923
- else {
6924
- el.layout = { visibility: _visible ? 'visible' : 'none' };
6925
- }
6926
- return el;
6927
- });
6984
+ if ((_b = layerComponent === null || layerComponent === void 0 ? void 0 : layerComponent.props) === null || _b === void 0 ? void 0 : _b.layers) {
6985
+ state.layers = (_c = layerComponent === null || layerComponent === void 0 ? void 0 : layerComponent.props) === null || _c === void 0 ? void 0 : _c.layers.map(function (el) {
6986
+ if (el.layout) {
6987
+ el.layout['visibility'] = _visible ? 'visible' : 'none';
6988
+ }
6989
+ else {
6990
+ el.layout = { visibility: _visible ? 'visible' : 'none' };
6991
+ }
6992
+ return el;
6993
+ });
6994
+ }
6928
6995
  setLayerState(state);
6929
6996
  }, [_visible, setLayerState, (_d = layerComponent === null || layerComponent === void 0 ? void 0 : layerComponent.props) === null || _d === void 0 ? void 0 : _d.layers]);
6930
6997
  React.useEffect(function () {
@@ -6933,15 +7000,18 @@ function LayerListItem(_a) {
6933
7000
  setLayerState(__assign(__assign({}, layerComponent.props), { paint: paintProps }));
6934
7001
  }, [paintProps, setLayerState]);
6935
7002
  var _layerComponent = React.useMemo(function () {
6936
- var _a, _b;
7003
+ var _a;
6937
7004
  if (layerComponent && type === 'layer') {
6938
- if ((_a = layerComponent === null || layerComponent === void 0 ? void 0 : layerComponent.props) === null || _a === void 0 ? void 0 : _a.layers) {
6939
- return React__default["default"].cloneElement(layerComponent, __assign(__assign({}, layerComponent === null || layerComponent === void 0 ? void 0 : layerComponent.props), { layers: (_b = layerComponent === null || layerComponent === void 0 ? void 0 : layerComponent.props) === null || _b === void 0 ? void 0 : _b.layers }));
6940
- }
6941
- else {
6942
- return React__default["default"].cloneElement(layerComponent, __assign({ layout: {
6943
- visibility: _visible ? 'visible' : 'none',
6944
- } }, (setLayerState ? {} : { paint: paintProps })));
7005
+ switch (layerComponent.type.name) {
7006
+ case 'MlWmsLayer':
7007
+ return React__default["default"].cloneElement(layerComponent, __assign(__assign({}, layerComponent === null || layerComponent === void 0 ? void 0 : layerComponent.props), { visible: _visible }));
7008
+ case 'MlVectorTileLayer':
7009
+ return React__default["default"].cloneElement(layerComponent, __assign(__assign({}, layerComponent === null || layerComponent === void 0 ? void 0 : layerComponent.props), { layers: (_a = layerComponent === null || layerComponent === void 0 ? void 0 : layerComponent.props) === null || _a === void 0 ? void 0 : _a.layers }));
7010
+ default:
7011
+ case 'MlGeoJsonLayer':
7012
+ return React__default["default"].cloneElement(layerComponent, __assign({ layout: {
7013
+ visibility: _visible ? 'visible' : 'none',
7014
+ } }, (setLayerState ? {} : { paint: paintProps })));
6945
7015
  }
6946
7016
  }
6947
7017
  return React__default["default"].createElement(React__default["default"].Fragment, null);
@@ -6976,7 +7046,7 @@ function LayerListItem(_a) {
6976
7046
  React__default["default"].createElement(material.ListItemText, { primary: name, primaryTypographyProps: { sx: { fontSize: '0.9rem' } }, secondary: description, secondaryTypographyProps: { sx: { fontSize: '0.7rem' } } }))),
6977
7047
  _layerComponent,
6978
7048
  !((_g = layerComponent === null || layerComponent === void 0 ? void 0 : layerComponent.props) === null || _g === void 0 ? void 0 : _g.layers) && configurable && paintPropsFormVisible && (React__default["default"].createElement(LayerPropertyForm, { paintProps: paintProps, setPaintProps: setPaintProps, layerType: layerType })),
6979
- ((_h = layerComponent === null || layerComponent === void 0 ? void 0 : layerComponent.props) === null || _h === void 0 ? void 0 : _h.layers) && (React__default["default"].createElement(LayerListFolder, { visible: localVisible, setVisible: setLocalVisible, name: name }, (_l = (_k = (_j = layerComponent === null || layerComponent === void 0 ? void 0 : layerComponent.props) === null || _j === void 0 ? void 0 : _j.layers) === null || _k === void 0 ? void 0 : _k.map) === null || _l === void 0 ? void 0 : _l.call(_k, function (_el, idx) { return (React__default["default"].createElement(LayerListItemVectorLayer, { vtProps: layerComponent === null || layerComponent === void 0 ? void 0 : layerComponent.props, setVtProps: setLayerState, id: '' + idx, key: '' + idx })); })))));
7049
+ ((_h = layerComponent === null || layerComponent === void 0 ? void 0 : layerComponent.props) === null || _h === void 0 ? void 0 : _h.layers) && (React__default["default"].createElement(LayerListFolder, { visible: localVisible, setVisible: setLocalVisible, name: name }, (_l = (_k = (_j = layerComponent === null || layerComponent === void 0 ? void 0 : layerComponent.props) === null || _j === void 0 ? void 0 : _j.layers) === null || _k === void 0 ? void 0 : _k.map) === null || _l === void 0 ? void 0 : _l.call(_k, function (_el, idx) { return (React__default["default"].createElement(LayerListItemVectorLayer, { vtProps: layerComponent === null || layerComponent === void 0 ? void 0 : layerComponent.props, setVtProps: setLayerState, id: '' + idx, key: '' + idx, visibleMaster: _visible })); })))));
6980
7050
  }
6981
7051
  LayerListItem.defaultProps = {
6982
7052
  type: 'layer',
@@ -7062,7 +7132,7 @@ function Sidebar(_a) {
7062
7132
  var _b = React.useState(false), drawerOpen = _b[0], setDrawerOpen = _b[1];
7063
7133
  return (React__default["default"].createElement(React__default["default"].Fragment, null,
7064
7134
  !mediaIsMobile ? (React__default["default"].createElement(Box__default["default"], { sx: { display: { xs: 'none', sm: 'flex' }, mr: 1 } },
7065
- React__default["default"].createElement(material.Drawer, __assign({ transitionDuration: 0, variant: "persistent", anchor: "left", open: typeof props.open === 'undefined' ? drawerOpen : props.open, PaperProps: __assign(__assign({}, drawerPaperProps), { sx: __assign({ maxWidth: { lg: '30%', md: '40%', sm: '50%', xs: '78%' }, padding: { lg: '20px', md: '20px', sm: '20px', xs: '10px' }, top: '64px', width: {
7135
+ React__default["default"].createElement(material.Drawer, __assign({ transitionDuration: 0, variant: "persistent", anchor: "left", open: typeof props.open === 'undefined' ? drawerOpen : props.open, PaperProps: __assign(__assign({}, drawerPaperProps), { sx: __assign({ maxWidth: { lg: '30%', md: '40%', sm: '50%', xs: '78%' }, padding: { sm: '84px 20px 20px 20px', xs: '74px 10px 10px 10px' }, width: {
7066
7136
  xs: '80%',
7067
7137
  sm: '60%',
7068
7138
  md: '350px',