@itwin/map-layers 5.0.0 → 5.1.1

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.
Files changed (80) hide show
  1. package/CHANGELOG.md +20 -1
  2. package/README.md +1 -1
  3. package/lib/cjs/public/locales/en/mapLayers.json +7 -2
  4. package/lib/cjs/ui/widget/AttachLayerPopupButton.d.ts.map +1 -1
  5. package/lib/cjs/ui/widget/AttachLayerPopupButton.js +144 -64
  6. package/lib/cjs/ui/widget/AttachLayerPopupButton.js.map +1 -1
  7. package/lib/cjs/ui/widget/BasemapPanel.d.ts.map +1 -1
  8. package/lib/cjs/ui/widget/BasemapPanel.js +47 -18
  9. package/lib/cjs/ui/widget/BasemapPanel.js.map +1 -1
  10. package/lib/cjs/ui/widget/MapLayerDroppable.d.ts.map +1 -1
  11. package/lib/cjs/ui/widget/MapLayerDroppable.js +26 -3
  12. package/lib/cjs/ui/widget/MapLayerDroppable.js.map +1 -1
  13. package/lib/cjs/ui/widget/MapLayerManager.d.ts.map +1 -1
  14. package/lib/cjs/ui/widget/MapLayerManager.js +35 -57
  15. package/lib/cjs/ui/widget/MapLayerManager.js.map +1 -1
  16. package/lib/cjs/ui/widget/MapLayerManager.scss +7 -9
  17. package/lib/cjs/ui/widget/MapLayerSettingsMenu.d.ts.map +1 -1
  18. package/lib/cjs/ui/widget/MapLayerSettingsMenu.js +12 -20
  19. package/lib/cjs/ui/widget/MapLayerSettingsMenu.js.map +1 -1
  20. package/lib/cjs/ui/widget/MapSelectFeaturesDialog.d.ts +11 -0
  21. package/lib/cjs/ui/widget/MapSelectFeaturesDialog.d.ts.map +1 -0
  22. package/lib/cjs/ui/widget/MapSelectFeaturesDialog.js +58 -0
  23. package/lib/cjs/ui/widget/MapSelectFeaturesDialog.js.map +1 -0
  24. package/lib/cjs/ui/widget/MapSelectFeaturesDialog.scss +17 -0
  25. package/lib/cjs/ui/widget/MapUrlDialog.d.ts +7 -2
  26. package/lib/cjs/ui/widget/MapUrlDialog.d.ts.map +1 -1
  27. package/lib/cjs/ui/widget/MapUrlDialog.js +38 -134
  28. package/lib/cjs/ui/widget/MapUrlDialog.js.map +1 -1
  29. package/lib/cjs/ui/widget/MapUrlDialog.scss +10 -10
  30. package/lib/cjs/ui/widget/SubLayersDataProvider.d.ts +3 -1
  31. package/lib/cjs/ui/widget/SubLayersDataProvider.d.ts.map +1 -1
  32. package/lib/cjs/ui/widget/SubLayersDataProvider.js +3 -3
  33. package/lib/cjs/ui/widget/SubLayersDataProvider.js.map +1 -1
  34. package/lib/cjs/ui/widget/SubLayersPopupButton.js +1 -1
  35. package/lib/cjs/ui/widget/SubLayersPopupButton.js.map +1 -1
  36. package/lib/cjs/ui/widget/SubLayersTree.d.ts +5 -0
  37. package/lib/cjs/ui/widget/SubLayersTree.d.ts.map +1 -1
  38. package/lib/cjs/ui/widget/SubLayersTree.js +12 -36
  39. package/lib/cjs/ui/widget/SubLayersTree.js.map +1 -1
  40. package/lib/cjs/ui/widget/SubLayersTree.scss +12 -3
  41. package/lib/esm/public/locales/en/mapLayers.json +7 -2
  42. package/lib/esm/ui/widget/AttachLayerPopupButton.d.ts.map +1 -1
  43. package/lib/esm/ui/widget/AttachLayerPopupButton.js +145 -65
  44. package/lib/esm/ui/widget/AttachLayerPopupButton.js.map +1 -1
  45. package/lib/esm/ui/widget/BasemapPanel.d.ts.map +1 -1
  46. package/lib/esm/ui/widget/BasemapPanel.js +47 -18
  47. package/lib/esm/ui/widget/BasemapPanel.js.map +1 -1
  48. package/lib/esm/ui/widget/MapLayerDroppable.d.ts.map +1 -1
  49. package/lib/esm/ui/widget/MapLayerDroppable.js +27 -4
  50. package/lib/esm/ui/widget/MapLayerDroppable.js.map +1 -1
  51. package/lib/esm/ui/widget/MapLayerManager.d.ts.map +1 -1
  52. package/lib/esm/ui/widget/MapLayerManager.js +36 -58
  53. package/lib/esm/ui/widget/MapLayerManager.js.map +1 -1
  54. package/lib/esm/ui/widget/MapLayerManager.scss +7 -9
  55. package/lib/esm/ui/widget/MapLayerSettingsMenu.d.ts.map +1 -1
  56. package/lib/esm/ui/widget/MapLayerSettingsMenu.js +13 -21
  57. package/lib/esm/ui/widget/MapLayerSettingsMenu.js.map +1 -1
  58. package/lib/esm/ui/widget/MapSelectFeaturesDialog.d.ts +11 -0
  59. package/lib/esm/ui/widget/MapSelectFeaturesDialog.d.ts.map +1 -0
  60. package/lib/esm/ui/widget/MapSelectFeaturesDialog.js +54 -0
  61. package/lib/esm/ui/widget/MapSelectFeaturesDialog.js.map +1 -0
  62. package/lib/esm/ui/widget/MapSelectFeaturesDialog.scss +17 -0
  63. package/lib/esm/ui/widget/MapUrlDialog.d.ts +7 -2
  64. package/lib/esm/ui/widget/MapUrlDialog.d.ts.map +1 -1
  65. package/lib/esm/ui/widget/MapUrlDialog.js +38 -134
  66. package/lib/esm/ui/widget/MapUrlDialog.js.map +1 -1
  67. package/lib/esm/ui/widget/MapUrlDialog.scss +10 -10
  68. package/lib/esm/ui/widget/SubLayersDataProvider.d.ts +3 -1
  69. package/lib/esm/ui/widget/SubLayersDataProvider.d.ts.map +1 -1
  70. package/lib/esm/ui/widget/SubLayersDataProvider.js +3 -3
  71. package/lib/esm/ui/widget/SubLayersDataProvider.js.map +1 -1
  72. package/lib/esm/ui/widget/SubLayersPopupButton.js +1 -1
  73. package/lib/esm/ui/widget/SubLayersPopupButton.js.map +1 -1
  74. package/lib/esm/ui/widget/SubLayersTree.d.ts +5 -0
  75. package/lib/esm/ui/widget/SubLayersTree.d.ts.map +1 -1
  76. package/lib/esm/ui/widget/SubLayersTree.js +13 -37
  77. package/lib/esm/ui/widget/SubLayersTree.js.map +1 -1
  78. package/lib/esm/ui/widget/SubLayersTree.scss +12 -3
  79. package/lib/public/locales/en/mapLayers.json +7 -2
  80. package/package.json +17 -16
@@ -14,14 +14,14 @@ const imodel_components_react_1 = require("@itwin/imodel-components-react");
14
14
  const itwinui_react_1 = require("@itwin/itwinui-react");
15
15
  const React = require("react");
16
16
  const mapLayers_1 = require("../../mapLayers");
17
- require("./BasemapPanel.scss");
18
17
  const MapLayerManager_1 = require("./MapLayerManager");
19
18
  const TransparencyPopupButton_1 = require("./TransparencyPopupButton");
20
- function getBaseMapFromStyle(displayStyle) {
21
- if (!displayStyle)
19
+ require("./BasemapPanel.scss");
20
+ function getBaseMapFromStyle(backgroundBase) {
21
+ if (!backgroundBase)
22
22
  return undefined;
23
- if (displayStyle.settings.mapImagery.backgroundBase instanceof core_common_1.ImageMapLayerSettings || displayStyle.settings.mapImagery.backgroundBase instanceof core_common_1.ColorDef)
24
- return displayStyle.settings.mapImagery.backgroundBase.toJSON();
23
+ if (backgroundBase instanceof core_common_1.ImageMapLayerSettings || backgroundBase instanceof core_common_1.ColorDef)
24
+ return backgroundBase.toJSON();
25
25
  return undefined;
26
26
  }
27
27
  /** @internal */
@@ -29,11 +29,23 @@ function getBaseMapFromStyle(displayStyle) {
29
29
  function BasemapPanel(props) {
30
30
  const [useColorLabel] = React.useState(mapLayers_1.MapLayersUI.localization.getLocalizedString("mapLayers:Basemap.ColorFill"));
31
31
  const { activeViewport, bases } = (0, MapLayerManager_1.useSourceMapContext)();
32
- const [selectedBaseMap, setSelectedBaseMap] = React.useState(getBaseMapFromStyle(activeViewport?.displayStyle));
32
+ const [selectedBaseMap, setSelectedBaseMap] = React.useState(getBaseMapFromStyle(activeViewport?.displayStyle.settings.mapImagery.backgroundBase));
33
33
  const [baseMapTransparencyValue, setBaseMapTransparencyValue] = React.useState(() => {
34
- if (activeViewport)
35
- return activeViewport.displayStyle.baseMapTransparency;
36
- return 0;
34
+ if (activeViewport) {
35
+ const mapImagery = activeViewport.displayStyle.settings.mapImagery;
36
+ if (mapImagery.backgroundBase instanceof core_common_1.ImageMapLayerSettings) {
37
+ return mapImagery.backgroundBase.transparency;
38
+ }
39
+ else if (mapImagery.backgroundBase instanceof core_common_1.ColorDef) {
40
+ return mapImagery.backgroundBase.getAlpha() / 255;
41
+ }
42
+ else {
43
+ return 0;
44
+ }
45
+ }
46
+ else {
47
+ return 0;
48
+ }
37
49
  });
38
50
  const [baseMapVisible, setBaseMapVisible] = React.useState(() => {
39
51
  if (activeViewport && activeViewport.displayStyle.backgroundMapBase instanceof core_common_1.ImageMapLayerSettings) {
@@ -41,17 +53,34 @@ function BasemapPanel(props) {
41
53
  }
42
54
  return false;
43
55
  });
56
+ const handleMapImageryChanged = React.useCallback((args) => {
57
+ // selectedBaseMap
58
+ const baseMap = getBaseMapFromStyle(args.backgroundBase);
59
+ if (JSON.stringify(baseMap) !== JSON.stringify(selectedBaseMap))
60
+ setSelectedBaseMap(baseMap);
61
+ // baseMapTransparencyValue
62
+ if (args.backgroundBase instanceof core_common_1.ImageMapLayerSettings && args.backgroundBase.transparency !== baseMapTransparencyValue) {
63
+ setBaseMapTransparencyValue(args.backgroundBase.transparency);
64
+ }
65
+ else if (args.backgroundBase instanceof core_common_1.ColorDef && args.backgroundBase.getAlpha() !== baseMapTransparencyValue) {
66
+ setBaseMapTransparencyValue(args.backgroundBase.getAlpha() / 255);
67
+ }
68
+ // baseMapVisible
69
+ if (args.backgroundBase instanceof core_common_1.ImageMapLayerSettings && args.backgroundBase.visible !== baseMapVisible) {
70
+ setBaseMapVisible(args.backgroundBase.visible);
71
+ }
72
+ }, [baseMapTransparencyValue, baseMapVisible, selectedBaseMap, setBaseMapTransparencyValue, setBaseMapVisible, setSelectedBaseMap]);
73
+ // Monitor display style's onMapImageryChanged event
74
+ React.useEffect(() => {
75
+ return activeViewport?.displayStyle.settings.onMapImageryChanged.addListener(handleMapImageryChanged);
76
+ }, [activeViewport, handleMapImageryChanged]);
44
77
  // Monitor viewport updates, and refresh the widget accordingly.
45
78
  // Note: This is needed for multiple viewport applications.
46
79
  React.useEffect(() => {
47
80
  if (activeViewport) {
48
- setBaseMapTransparencyValue(activeViewport.displayStyle.baseMapTransparency);
49
- setSelectedBaseMap(getBaseMapFromStyle(activeViewport.displayStyle));
50
- if (activeViewport.displayStyle.backgroundMapBase instanceof core_common_1.ImageMapLayerSettings) {
51
- setBaseMapVisible(activeViewport.displayStyle.backgroundMapBase.visible);
52
- }
81
+ handleMapImageryChanged(activeViewport.displayStyle.settings.mapImagery);
53
82
  }
54
- }, [activeViewport]);
83
+ }, [activeViewport, handleMapImageryChanged]);
55
84
  const handleBasemapTransparencyChange = React.useCallback((transparency) => {
56
85
  if (activeViewport) {
57
86
  activeViewport.displayStyle.changeBaseMapTransparency(transparency);
@@ -110,10 +139,10 @@ function BasemapPanel(props) {
110
139
  if (baseMap) {
111
140
  const baseProps = baseMap.toJSON();
112
141
  if (activeViewport.displayStyle.backgroundMapBase instanceof core_common_1.BaseMapLayerSettings) {
113
- activeViewport.displayStyle.backgroundMapBase = activeViewport.displayStyle.backgroundMapBase.clone(baseProps);
142
+ activeViewport.displayStyle.backgroundMapBase = activeViewport.displayStyle.backgroundMapBase.clone({ ...baseProps, visible: baseMapVisible });
114
143
  }
115
144
  else {
116
- activeViewport.displayStyle.backgroundMapBase = core_common_1.BaseMapLayerSettings.fromJSON(baseProps);
145
+ activeViewport.displayStyle.backgroundMapBase = core_common_1.BaseMapLayerSettings.fromJSON({ ...baseProps, visible: baseMapVisible });
117
146
  }
118
147
  setSelectedBaseMap(baseProps);
119
148
  }
@@ -124,7 +153,7 @@ function BasemapPanel(props) {
124
153
  setSelectedBaseMap(bgColorDef.toJSON());
125
154
  }
126
155
  }
127
- }, [bases, activeViewport, bgColor]);
156
+ }, [baseMapVisible, bases, activeViewport, bgColor]);
128
157
  const handleVisibilityChange = React.useCallback(() => {
129
158
  if (activeViewport) {
130
159
  const newState = !baseMapVisible;
@@ -1 +1 @@
1
- {"version":3,"file":"BasemapPanel.js","sourceRoot":"","sources":["../../../../src/ui/widget/BasemapPanel.tsx"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F,4CAA4C;AAC5C,2CAA2C;;;AAE3C,oDAAiD;AACjD,oDAAuH;AAEvH,kDAAgD;AAChD,4EAAgF;AAChF,wDAAoE;AACpE,+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E,QAAQ,EAAE,KAAK,CAAC,QAAQ,IAAI,CAAC,cAAc,IAAI,CAAC,CAAC,cAAc,CAAC,YAAY,CAAC,iBAAiB,YAAY,mCAAqB,CAAC;gBACpO,oBAAC,wBAAW,IAAC,QAAQ,EAAE,cAAc,CAAC,CAAC,CAAC,iBAAiB,CAAC,CAAC,CAAC,wBAAwB,GAAI,CACjF;YACT,8BAAM,SAAS,EAAC,wBAAwB,IAAE,cAAc,CAAQ;YAChE,oBAAC,sBAAM,IAAC,SAAS,EAAC,8BAA8B,EAC9C,OAAO,EAAE,cAAc,EACvB,WAAW,EAAE,kBAAkB,EAC/B,KAAK,EAAE,oBAAoB,CAAC,KAAK,EACjC,QAAQ,EAAE,sBAAsB,EAAE,IAAI,EAAC,OAAO,EAC9C,QAAQ,EAAE,KAAK,CAAC,QAAQ,GACxB;YAEA,WAAW;gBACX,oBAAC,qCAAW,IAAC,SAAS,EAAC,6BAA6B,EAAC,QAAQ,EAAE,sBAAQ,CAAC,QAAQ,CAAC,OAAO,CAAC,EAAE,KAAK,EAAE,KAAK,EAAE,WAAW,EAAE,kBAAkB,GAAI;YAE9I,oBAAC,iDAAuB,IAAC,QAAQ,EAAE,KAAK,CAAC,QAAQ,EAAE,YAAY,EAAE,wBAAwB,EAAE,oBAAoB,EAAE,+BAA+B,GAAI,CAChJ,CACL,CACJ,CAAC;AACJ,CAAC;AAnJD,oCAmJC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n* See LICENSE.md in the project root for license terms and full copyright notice.\n*--------------------------------------------------------------------------------------------*/\n/* eslint-disable deprecation/deprecation */\n// cSpell:ignore droppable Sublayer Basemap\n\nimport { UiFramework } from \"@itwin/appui-react\";\nimport { BaseMapLayerSettings, ColorByName, ColorDef, ImageMapLayerSettings, MapLayerProps } from \"@itwin/core-common\";\nimport { DisplayStyleState } from \"@itwin/core-frontend\";\nimport { WebFontIcon } from \"@itwin/core-react\";\nimport { ColorPickerDialog, ColorSwatch } from \"@itwin/imodel-components-react\";\nimport { Button, Select, SelectOption } from \"@itwin/itwinui-react\";\nimport * as React from \"react\";\nimport { MapLayersUI } from \"../../mapLayers\";\nimport \"./BasemapPanel.scss\";\nimport { useSourceMapContext } from \"./MapLayerManager\";\nimport { TransparencyPopupButton } from \"./TransparencyPopupButton\";\n\nfunction getBaseMapFromStyle(displayStyle: DisplayStyleState | undefined) {\n if (!displayStyle)\n return undefined;\n\n if (displayStyle.settings.mapImagery.backgroundBase instanceof ImageMapLayerSettings || displayStyle.settings.mapImagery.backgroundBase instanceof ColorDef)\n return displayStyle.settings.mapImagery.backgroundBase.toJSON();\n\n return undefined;\n}\n\ninterface BasemapPanelProps {\n disabled?: boolean;\n}\n\n/** @internal */\n// eslint-disable-next-line @typescript-eslint/naming-convention\nexport function BasemapPanel(props: BasemapPanelProps) {\n const [useColorLabel] = React.useState(MapLayersUI.localization.getLocalizedString(\"mapLayers:Basemap.ColorFill\"));\n const { activeViewport, bases } = useSourceMapContext();\n const [selectedBaseMap, setSelectedBaseMap] = React.useState<MapLayerProps | number | undefined>(getBaseMapFromStyle(activeViewport?.displayStyle));\n const [baseMapTransparencyValue, setBaseMapTransparencyValue] = React.useState(() => {\n if (activeViewport)\n return activeViewport.displayStyle.baseMapTransparency;\n return 0;\n });\n const [baseMapVisible, setBaseMapVisible] = React.useState(() => {\n if (activeViewport && activeViewport.displayStyle.backgroundMapBase instanceof ImageMapLayerSettings) {\n return activeViewport.displayStyle.backgroundMapBase.visible;\n }\n return false;\n });\n\n // Monitor viewport updates, and refresh the widget accordingly.\n // Note: This is needed for multiple viewport applications.\n React.useEffect(() => {\n if (activeViewport) {\n setBaseMapTransparencyValue(activeViewport.displayStyle.baseMapTransparency);\n setSelectedBaseMap(getBaseMapFromStyle(activeViewport.displayStyle));\n if (activeViewport.displayStyle.backgroundMapBase instanceof ImageMapLayerSettings) {\n setBaseMapVisible(activeViewport.displayStyle.backgroundMapBase.visible);\n }\n }\n }, [activeViewport]);\n\n const handleBasemapTransparencyChange = React.useCallback((transparency: number) => {\n if (activeViewport) {\n activeViewport.displayStyle.changeBaseMapTransparency(transparency);\n setBaseMapTransparencyValue(transparency);\n }\n }, [activeViewport]);\n\n const baseMapOptions = React.useMemo<SelectOption<string>[]>(() => {\n const baseOptions: SelectOption<string>[] = [];\n\n baseOptions.push({ value: useColorLabel, label: useColorLabel });\n\n if (bases)\n baseOptions.push(...bases.map((value) => ({ value: value.name, label: value.name })));\n return baseOptions;\n }, [bases, useColorLabel]);\n\n const [presetColors] = React.useState([\n ColorDef.create(ColorByName.grey),\n ColorDef.create(ColorByName.lightGrey),\n ColorDef.create(ColorByName.darkGrey),\n ColorDef.create(ColorByName.lightBlue),\n ColorDef.create(ColorByName.lightGreen),\n ColorDef.create(ColorByName.darkGreen),\n ColorDef.create(ColorByName.tan),\n ColorDef.create(ColorByName.darkBrown),\n ]);\n\n const baseIsColor = React.useMemo(() => typeof selectedBaseMap === \"number\", [selectedBaseMap]);\n const baseIsMap = React.useMemo(() => !baseIsColor && (selectedBaseMap !== undefined), [baseIsColor, selectedBaseMap]);\n const bgColor = React.useMemo(() => baseIsColor ? selectedBaseMap as number : presetColors[0].toJSON(), [baseIsColor, selectedBaseMap, presetColors]);\n const [colorDialogTitle] = React.useState(MapLayersUI.localization.getLocalizedString(\"mapLayers:ColorDialog.Title\"));\n const selectedBaseMapValue = React.useMemo(() => {\n if (baseIsMap) {\n const mapName = (selectedBaseMap! as MapLayerProps).name;\n const foundItem = baseMapOptions.find((value) => value.label === mapName);\n if (foundItem)\n return foundItem;\n }\n return baseMapOptions[0];\n }, [selectedBaseMap, baseMapOptions, baseIsMap]);\n\n const handleBackgroundColorDialogOk = React.useCallback((bgColorDef: ColorDef) => {\n UiFramework.dialogs.modal.close();\n if (activeViewport) {\n // change color and make sure previously set transparency is not lost.\n const curTransparency = activeViewport.displayStyle.backgroundMapBase instanceof ColorDef ? activeViewport.displayStyle.backgroundMapBase.getTransparency() : 0;\n activeViewport.displayStyle.backgroundMapBase = bgColorDef.withTransparency(curTransparency);\n setSelectedBaseMap(bgColorDef.toJSON());\n }\n }, [activeViewport]);\n\n const handleBackgroundColorDialogCancel = React.useCallback(() => {\n UiFramework.dialogs.modal.close();\n }, []);\n\n const handleBgColorClick = React.useCallback((newColor: ColorDef, e: React.MouseEvent<Element, MouseEvent>) => {\n e.preventDefault();\n UiFramework.dialogs.modal.open(<ColorPickerDialog dialogTitle={colorDialogTitle} color={newColor} colorPresets={presetColors} colorInputType={\"rgb\"}\n onOkResult={handleBackgroundColorDialogOk} onCancelResult={handleBackgroundColorDialogCancel} />);\n }, [presetColors, handleBackgroundColorDialogOk]); // eslint-disable-line react-hooks/exhaustive-deps\n\n const handleBaseMapSelection = React.useCallback((value: string) => {\n if (bases && activeViewport && value) {\n const baseMap = bases.find((map) => map.name === value);\n if (baseMap) {\n const baseProps: MapLayerProps = baseMap.toJSON();\n if (activeViewport.displayStyle.backgroundMapBase instanceof BaseMapLayerSettings) {\n activeViewport.displayStyle.backgroundMapBase = activeViewport.displayStyle.backgroundMapBase.clone(baseProps);\n } else {\n activeViewport.displayStyle.backgroundMapBase = BaseMapLayerSettings.fromJSON(baseProps);\n }\n setSelectedBaseMap(baseProps);\n } else {\n const bgColorDef = ColorDef.fromJSON(bgColor);\n const curTransparency = activeViewport.displayStyle.backgroundMapBase instanceof ColorDef ? activeViewport.displayStyle.backgroundMapBase.getTransparency() : 0;\n activeViewport.displayStyle.backgroundMapBase = bgColorDef.withTransparency(curTransparency);\n setSelectedBaseMap(bgColorDef.toJSON());\n }\n }\n }, [bases, activeViewport, bgColor]);\n\n const handleVisibilityChange = React.useCallback(() => {\n if (activeViewport) {\n const newState = !baseMapVisible;\n // BaseMap visibility is only support when backgroundBase is an instance of BaseMapLayerSettings (i.e not a color)...\n if (activeViewport.displayStyle.backgroundMapBase instanceof BaseMapLayerSettings) {\n activeViewport.displayStyle.backgroundMapBase = activeViewport.displayStyle.backgroundMapBase.clone({ visible: newState });\n }\n setBaseMapVisible(newState);\n }\n }, [baseMapVisible, activeViewport]);\n\n const [baseLayerLabel] = React.useState(MapLayersUI.localization.getLocalizedString(\"mapLayers:Basemap.BaseLayer\"));\n const [selectBaseMapLabel] = React.useState(MapLayersUI.localization.getLocalizedString(\"mapLayers:Basemap.SelectBaseMap\"));\n const [toggleVisibility] = React.useState(MapLayersUI.localization.getLocalizedString(\"mapLayers:Widget.ToggleVisibility\"));\n\n return (\n <>\n <div className=\"map-manager-base-item\" >\n <Button size=\"small\" styleType=\"borderless\" title={toggleVisibility} onClick={handleVisibilityChange} disabled={props.disabled || !activeViewport || !(activeViewport.displayStyle.backgroundMapBase instanceof ImageMapLayerSettings)}>\n <WebFontIcon iconName={baseMapVisible ? \"icon-visibility\" : \"icon-visibility-hide-2\"} />\n </Button>\n <span className=\"map-manager-base-label\">{baseLayerLabel}</span>\n <Select className=\"map-manager-base-item-select\"\n options={baseMapOptions}\n placeholder={selectBaseMapLabel}\n value={selectedBaseMapValue.value}\n onChange={handleBaseMapSelection} size=\"small\"\n disabled={props.disabled}\n />\n {\n baseIsColor &&\n <ColorSwatch className=\"map-manager-base-item-color\" colorDef={ColorDef.fromJSON(bgColor)} round={false} onColorPick={handleBgColorClick} />\n }\n <TransparencyPopupButton disabled={props.disabled} transparency={baseMapTransparencyValue} onTransparencyChange={handleBasemapTransparencyChange} />\n </div>\n </>\n );\n}\n"]}
1
+ {"version":3,"file":"BasemapPanel.js","sourceRoot":"","sources":["../../../../src/ui/widget/BasemapPanel.tsx"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F,4CAA4C;AAC5C,2CAA2C;;;AAE3C,oDAAiD;AACjD,oDAA8K;AAC9K,kDAAgD;AAChD,4EAAgF;AAChF,wDAAoE;AACpE,+BAA+B;AAC/B,+CAA8C;AAC9C,uDAAwD;AACxD,uEAAoE;AACpE,+BAA6B;AAE7B,SAAS,mBAAmB,CAAC,cAA6C;IACxE,IAAI,CAAC,cAAc;QAC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QAAQ,IAAI,CAAC,cAAc,IAAI,CAAC,CAAC,cAAc,CAAC,YAAY,CAAC,iBAAiB,YAAY,mCAAqB,CAAC;gBACpO,oBAAC,wBAAW,IAAC,QAAQ,EAAE,cAAc,CAAC,CAAC,CAAC,iBAAiB,CAAC,CAAC,CAAC,wBAAwB,GAAI,CACjF;YACT,8BAAM,SAAS,EAAC,wBAAwB,IAAE,cAAc,CAAQ;YAChE,oBAAC,sBAAM,IAAC,SAAS,EAAC,8BAA8B,EAC9C,OAAO,EAAE,cAAc,EACvB,WAAW,EAAE,kBAAkB,EAC/B,KAAK,EAAE,oBAAoB,CAAC,KAAK,EACjC,QAAQ,EAAE,sBAAsB,EAAE,IAAI,EAAC,OAAO,EAC9C,QAAQ,EAAE,KAAK,CAAC,QAAQ,GACxB;YAEA,WAAW;gBACX,oBAAC,qCAAW,IAAC,SAAS,EAAC,6BAA6B,EAAC,QAAQ,EAAE,sBAAQ,CAAC,QAAQ,CAAC,OAAO,CAAC,EAAE,KAAK,EAAE,KAAK,EAAE,WAAW,EAAE,kBAAkB,GAAI;YAE9I,oBAAC,iDAAuB,IAAC,QAAQ,EAAE,KAAK,CAAC,QAAQ,EAAE,YAAY,EAAE,wBAAwB,EAAE,oBAAoB,EAAE,+BAA+B,GAAI,CAChJ,CACL,CACJ,CAAC;AACJ,CAAC;AAjLD,oCAiLC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n* See LICENSE.md in the project root for license terms and full copyright notice.\n*--------------------------------------------------------------------------------------------*/\n/* eslint-disable deprecation/deprecation */\n// cSpell:ignore droppable Sublayer Basemap\n\nimport { UiFramework } from \"@itwin/appui-react\";\nimport { BaseLayerProps, BaseLayerSettings, BaseMapLayerSettings, ColorByName, ColorDef, ImageMapLayerSettings, MapImagerySettings, MapLayerProps } from \"@itwin/core-common\";\nimport { WebFontIcon } from \"@itwin/core-react\";\nimport { ColorPickerDialog, ColorSwatch } from \"@itwin/imodel-components-react\";\nimport { Button, Select, SelectOption } from \"@itwin/itwinui-react\";\nimport * as React from \"react\";\nimport { MapLayersUI } from \"../../mapLayers\";\nimport { useSourceMapContext } from \"./MapLayerManager\";\nimport { TransparencyPopupButton } from \"./TransparencyPopupButton\";\nimport \"./BasemapPanel.scss\";\n\nfunction getBaseMapFromStyle(backgroundBase: BaseLayerSettings | undefined) {\n if (!backgroundBase)\n return undefined;\n\n if (backgroundBase instanceof ImageMapLayerSettings || backgroundBase instanceof ColorDef)\n return backgroundBase.toJSON();\n\n return undefined;\n}\n\ninterface BasemapPanelProps {\n disabled?: boolean;\n}\n\n/** @internal */\n// eslint-disable-next-line @typescript-eslint/naming-convention\nexport function BasemapPanel(props: BasemapPanelProps) {\n const [useColorLabel] = React.useState(MapLayersUI.localization.getLocalizedString(\"mapLayers:Basemap.ColorFill\"));\n const { activeViewport, bases } = useSourceMapContext();\n const [selectedBaseMap, setSelectedBaseMap] = React.useState<BaseLayerProps | undefined>(getBaseMapFromStyle(activeViewport?.displayStyle.settings.mapImagery.backgroundBase));\n const [baseMapTransparencyValue, setBaseMapTransparencyValue] = React.useState(() => {\n if (activeViewport) {\n const mapImagery = activeViewport.displayStyle.settings.mapImagery;\n if (mapImagery.backgroundBase instanceof ImageMapLayerSettings) {\n return mapImagery.backgroundBase.transparency;\n } else if (mapImagery.backgroundBase instanceof ColorDef ) {\n return mapImagery.backgroundBase.getAlpha()/255;\n } else {\n return 0;\n }\n } else {\n return 0;\n }\n });\n\n const [baseMapVisible, setBaseMapVisible] = React.useState(() => {\n if (activeViewport && activeViewport.displayStyle.backgroundMapBase instanceof ImageMapLayerSettings) {\n return activeViewport.displayStyle.backgroundMapBase.visible;\n }\n return false;\n });\n\n const handleMapImageryChanged = React.useCallback((args: Readonly<MapImagerySettings>) => {\n // selectedBaseMap\n const baseMap = getBaseMapFromStyle(args.backgroundBase);\n if (JSON.stringify(baseMap) !== JSON.stringify(selectedBaseMap))\n setSelectedBaseMap(baseMap);\n\n // baseMapTransparencyValue\n if (args.backgroundBase instanceof ImageMapLayerSettings && args.backgroundBase.transparency !== baseMapTransparencyValue) {\n setBaseMapTransparencyValue(args.backgroundBase.transparency);\n } else if (args.backgroundBase instanceof ColorDef && args.backgroundBase.getAlpha() !== baseMapTransparencyValue ) {\n setBaseMapTransparencyValue(args.backgroundBase.getAlpha()/255);\n }\n\n // baseMapVisible\n if (args.backgroundBase instanceof ImageMapLayerSettings && args.backgroundBase.visible !== baseMapVisible) {\n setBaseMapVisible(args.backgroundBase.visible);\n }\n }, [baseMapTransparencyValue, baseMapVisible, selectedBaseMap, setBaseMapTransparencyValue, setBaseMapVisible, setSelectedBaseMap]);\n\n // Monitor display style's onMapImageryChanged event\n React.useEffect(() => {\n return activeViewport?.displayStyle.settings.onMapImageryChanged.addListener(handleMapImageryChanged);\n }, [activeViewport, handleMapImageryChanged]);\n\n // Monitor viewport updates, and refresh the widget accordingly.\n // Note: This is needed for multiple viewport applications.\n React.useEffect(() => {\n if (activeViewport) {\n handleMapImageryChanged(activeViewport.displayStyle.settings.mapImagery);\n }\n }, [activeViewport, handleMapImageryChanged]);\n\n const handleBasemapTransparencyChange = React.useCallback((transparency: number) => {\n if (activeViewport) {\n activeViewport.displayStyle.changeBaseMapTransparency(transparency);\n setBaseMapTransparencyValue(transparency);\n }\n }, [activeViewport]);\n\n const baseMapOptions = React.useMemo<SelectOption<string>[]>(() => {\n const baseOptions: SelectOption<string>[] = [];\n\n baseOptions.push({ value: useColorLabel, label: useColorLabel });\n\n if (bases)\n baseOptions.push(...bases.map((value) => ({ value: value.name, label: value.name })));\n return baseOptions;\n }, [bases, useColorLabel]);\n\n const [presetColors] = React.useState([\n ColorDef.create(ColorByName.grey),\n ColorDef.create(ColorByName.lightGrey),\n ColorDef.create(ColorByName.darkGrey),\n ColorDef.create(ColorByName.lightBlue),\n ColorDef.create(ColorByName.lightGreen),\n ColorDef.create(ColorByName.darkGreen),\n ColorDef.create(ColorByName.tan),\n ColorDef.create(ColorByName.darkBrown),\n ]);\n\n const baseIsColor = React.useMemo(() => typeof selectedBaseMap === \"number\", [selectedBaseMap]);\n const baseIsMap = React.useMemo(() => !baseIsColor && (selectedBaseMap !== undefined), [baseIsColor, selectedBaseMap]);\n const bgColor = React.useMemo(() => baseIsColor ? selectedBaseMap as number : presetColors[0].toJSON(), [baseIsColor, selectedBaseMap, presetColors]);\n const [colorDialogTitle] = React.useState(MapLayersUI.localization.getLocalizedString(\"mapLayers:ColorDialog.Title\"));\n const selectedBaseMapValue = React.useMemo(() => {\n if (baseIsMap) {\n const mapName = (selectedBaseMap! as MapLayerProps).name;\n const foundItem = baseMapOptions.find((value) => value.label === mapName);\n if (foundItem)\n return foundItem;\n }\n return baseMapOptions[0];\n }, [selectedBaseMap, baseMapOptions, baseIsMap]);\n\n const handleBackgroundColorDialogOk = React.useCallback((bgColorDef: ColorDef) => {\n UiFramework.dialogs.modal.close();\n if (activeViewport) {\n // change color and make sure previously set transparency is not lost.\n const curTransparency = activeViewport.displayStyle.backgroundMapBase instanceof ColorDef ? activeViewport.displayStyle.backgroundMapBase.getTransparency() : 0;\n activeViewport.displayStyle.backgroundMapBase = bgColorDef.withTransparency(curTransparency);\n setSelectedBaseMap(bgColorDef.toJSON());\n }\n }, [activeViewport]);\n\n const handleBackgroundColorDialogCancel = React.useCallback(() => {\n UiFramework.dialogs.modal.close();\n }, []);\n\n const handleBgColorClick = React.useCallback((newColor: ColorDef, e: React.MouseEvent<Element, MouseEvent>) => {\n e.preventDefault();\n UiFramework.dialogs.modal.open(<ColorPickerDialog dialogTitle={colorDialogTitle} color={newColor} colorPresets={presetColors} colorInputType={\"rgb\"}\n onOkResult={handleBackgroundColorDialogOk} onCancelResult={handleBackgroundColorDialogCancel} />);\n }, [presetColors, handleBackgroundColorDialogOk]); // eslint-disable-line react-hooks/exhaustive-deps\n\n const handleBaseMapSelection = React.useCallback((value: string) => {\n if (bases && activeViewport && value) {\n const baseMap = bases.find((map) => map.name === value);\n if (baseMap) {\n const baseProps: MapLayerProps = baseMap.toJSON();\n if (activeViewport.displayStyle.backgroundMapBase instanceof BaseMapLayerSettings) {\n activeViewport.displayStyle.backgroundMapBase = activeViewport.displayStyle.backgroundMapBase.clone({...baseProps, visible: baseMapVisible});\n } else {\n activeViewport.displayStyle.backgroundMapBase = BaseMapLayerSettings.fromJSON({...baseProps, visible: baseMapVisible});\n }\n setSelectedBaseMap(baseProps);\n } else {\n const bgColorDef = ColorDef.fromJSON(bgColor);\n const curTransparency = activeViewport.displayStyle.backgroundMapBase instanceof ColorDef ? activeViewport.displayStyle.backgroundMapBase.getTransparency() : 0;\n activeViewport.displayStyle.backgroundMapBase = bgColorDef.withTransparency(curTransparency);\n setSelectedBaseMap(bgColorDef.toJSON());\n }\n }\n }, [baseMapVisible, bases, activeViewport, bgColor]);\n\n const handleVisibilityChange = React.useCallback(() => {\n if (activeViewport) {\n const newState = !baseMapVisible;\n // BaseMap visibility is only support when backgroundBase is an instance of BaseMapLayerSettings (i.e not a color)...\n if (activeViewport.displayStyle.backgroundMapBase instanceof BaseMapLayerSettings) {\n activeViewport.displayStyle.backgroundMapBase = activeViewport.displayStyle.backgroundMapBase.clone({ visible: newState });\n }\n setBaseMapVisible(newState);\n }\n }, [baseMapVisible, activeViewport]);\n\n const [baseLayerLabel] = React.useState(MapLayersUI.localization.getLocalizedString(\"mapLayers:Basemap.BaseLayer\"));\n const [selectBaseMapLabel] = React.useState(MapLayersUI.localization.getLocalizedString(\"mapLayers:Basemap.SelectBaseMap\"));\n const [toggleVisibility] = React.useState(MapLayersUI.localization.getLocalizedString(\"mapLayers:Widget.ToggleVisibility\"));\n\n return (\n <>\n <div className=\"map-manager-base-item\" >\n <Button size=\"small\" styleType=\"borderless\" title={toggleVisibility} onClick={handleVisibilityChange} disabled={props.disabled || !activeViewport || !(activeViewport.displayStyle.backgroundMapBase instanceof ImageMapLayerSettings)}>\n <WebFontIcon iconName={baseMapVisible ? \"icon-visibility\" : \"icon-visibility-hide-2\"} />\n </Button>\n <span className=\"map-manager-base-label\">{baseLayerLabel}</span>\n <Select className=\"map-manager-base-item-select\"\n options={baseMapOptions}\n placeholder={selectBaseMapLabel}\n value={selectedBaseMapValue.value}\n onChange={handleBaseMapSelection} size=\"small\"\n disabled={props.disabled}\n />\n {\n baseIsColor &&\n <ColorSwatch className=\"map-manager-base-item-color\" colorDef={ColorDef.fromJSON(bgColor)} round={false} onColorPick={handleBgColorClick} />\n }\n <TransparencyPopupButton disabled={props.disabled} transparency={baseMapTransparencyValue} onTransparencyChange={handleBasemapTransparencyChange} />\n </div>\n </>\n );\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"MapLayerDroppable.d.ts","sourceRoot":"","sources":["../../../../src/ui/widget/MapLayerDroppable.tsx"],"names":[],"mappings":"AAWA,OAAO,EAAkE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAOtH,OAAO,EAAE,eAAe,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAC;AAGvE,OAAO,wBAAwB,CAAC;AAIhC,gBAAgB;AAChB,UAAU,sBAAsB;IAC9B,SAAS,EAAE,OAAO,CAAC;IACnB,UAAU,CAAC,EAAE,qBAAqB,EAAE,CAAC;IACrC,eAAe,CAAC,EAAE,eAAe,CAAC;IAClC,oBAAoB,EAAE,MAAM,WAAW,CAAC;IACxC,cAAc,EAAE,cAAc,CAAC;IAC/B,kBAAkB,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,gBAAgB,EAAE,qBAAqB,KAAK,IAAI,CAAC;IACtF,6BAA6B,EAAE,CAAC,gBAAgB,EAAE,qBAAqB,KAAK,IAAI,CAAC;IACjF,YAAY,EAAE,MAAM,IAAI,CAAC;IACzB,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAED,gBAAgB;AAEhB,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,sBAAsB,eA4H9D"}
1
+ {"version":3,"file":"MapLayerDroppable.d.ts","sourceRoot":"","sources":["../../../../src/ui/widget/MapLayerDroppable.tsx"],"names":[],"mappings":"AAWA,OAAO,EAAyI,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAO7L,OAAO,EAAE,eAAe,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAC;AAGvE,OAAO,wBAAwB,CAAC;AAIhC,gBAAgB;AAChB,UAAU,sBAAsB;IAC9B,SAAS,EAAE,OAAO,CAAC;IACnB,UAAU,CAAC,EAAE,qBAAqB,EAAE,CAAC;IACrC,eAAe,CAAC,EAAE,eAAe,CAAC;IAClC,oBAAoB,EAAE,MAAM,WAAW,CAAC;IACxC,cAAc,EAAE,cAAc,CAAC;IAC/B,kBAAkB,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,gBAAgB,EAAE,qBAAqB,KAAK,IAAI,CAAC;IACtF,6BAA6B,EAAE,CAAC,gBAAgB,EAAE,qBAAqB,KAAK,IAAI,CAAC;IACjF,YAAY,EAAE,MAAM,IAAI,CAAC;IACzB,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAED,gBAAgB;AAEhB,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,sBAAsB,eA4J9D"}
@@ -38,6 +38,28 @@ function MapLayerDroppable(props) {
38
38
  if (mapLayerStyleIdx !== -1 && activeLayer.subLayers)
39
39
  props.activeViewport.displayStyle.changeMapSubLayerProps({ visible: isSelected }, subLayerId, { index: mapLayerStyleIdx, isOverlay: activeLayer.isOverlay });
40
40
  };
41
+ const handleOk = React.useCallback((index, sourceState) => {
42
+ appui_react_1.UiFramework.dialogs.modal.close();
43
+ const source = sourceState?.source;
44
+ const vp = props?.activeViewport;
45
+ if (vp === undefined || sourceState === undefined || source === undefined) {
46
+ const error = mapLayers_1.MapLayersUI.localization.getLocalizedString("mapLayers:Messages.MapLayerAttachMissingViewOrSource");
47
+ const msg = mapLayers_1.MapLayersUI.localization.getLocalizedString("mapLayers:Messages.MapLayerAttachError", { error, sourceName: source?.name ?? "" });
48
+ core_frontend_1.IModelApp.notifications.outputMessage(new core_frontend_1.NotifyMessageDetails(core_frontend_1.OutputMessagePriority.Error, msg));
49
+ return;
50
+ }
51
+ const validation = sourceState.validation;
52
+ // Layer is already attached,
53
+ // This calls invalidateRenderPlan()
54
+ vp.displayStyle.changeMapLayerProps({ subLayers: validation.subLayers }, index);
55
+ vp.displayStyle.changeMapLayerCredentials(index, source.userName, source.password);
56
+ // Either initial attach/initialize failed or the layer failed to load at least one tile
57
+ // because of an invalid token; in both cases tile tree needs to be fully reset
58
+ const provider = vp.getMapLayerImageryProvider(index);
59
+ provider?.resetStatus();
60
+ vp.resetMapLayer(index);
61
+ props.onItemEdited();
62
+ }, [props]);
41
63
  const renderItem = (dragProvided, _, rubric) => {
42
64
  (0, core_bentley_1.assert)(props.layersList !== undefined);
43
65
  const activeLayer = props.layersList[rubric.source.index];
@@ -47,14 +69,15 @@ function MapLayerDroppable(props) {
47
69
  React.createElement(core_react_1.Icon, { iconSpec: activeLayer.visible ? "icon-visibility" : "icon-visibility-hide-2" })),
48
70
  React.createElement("span", { className: props.disabled || outOfRange ? "map-manager-item-label-disabled" : "map-manager-item-label", title: outOfRange ? outOfRangeTitle : undefined, ...dragProvided.dragHandleProps }, activeLayer.name),
49
71
  React.createElement("div", { className: "map-manager-item-sub-layer-container" }, activeLayer.subLayers && activeLayer.subLayers.length > 1 &&
50
- React.createElement(SubLayersPopupButton_1.SubLayersPopupButton, { subLayers: props.activeViewport ? activeLayer.subLayers : undefined, singleVisibleSubLayer: activeLayer.provider?.mutualExclusiveSubLayer, onSubLayerStateChange: (subLayerId, isSelected) => { onSubLayerStateChange(activeLayer, subLayerId, isSelected); } })),
72
+ React.createElement(SubLayersPopupButton_1.SubLayersPopupButton, { checkboxStyle: "eye", expandMode: "rootGroupOnly", subLayers: props.activeViewport ? activeLayer.subLayers : undefined, singleVisibleSubLayer: activeLayer.provider?.mutualExclusiveSubLayer, onSubLayerStateChange: (subLayerId, isSelected) => { onSubLayerStateChange(activeLayer, subLayerId, isSelected); } })),
51
73
  activeLayer.provider?.status === core_frontend_1.MapLayerImageryProviderStatus.RequireAuth &&
52
74
  React.createElement(itwinui_react_1.Button, { disabled: props.disabled, size: "small", styleType: "borderless", onClick: () => {
53
75
  const indexInDisplayStyle = props.activeViewport?.displayStyle.findMapLayerIndexByNameAndSource(activeLayer.name, activeLayer.source, activeLayer.isOverlay);
54
76
  if (indexInDisplayStyle !== undefined && indexInDisplayStyle >= 0) {
55
- const layerSettings = props.activeViewport.displayStyle.mapLayerAtIndex({ index: indexInDisplayStyle, isOverlay: activeLayer.isOverlay });
77
+ const index = { index: indexInDisplayStyle, isOverlay: activeLayer.isOverlay };
78
+ const layerSettings = props.activeViewport.displayStyle.mapLayerAtIndex(index);
56
79
  if (layerSettings instanceof core_common_1.ImageMapLayerSettings) {
57
- appui_react_1.UiFramework.dialogs.modal.open(React.createElement(MapUrlDialog_1.MapUrlDialog, { activeViewport: props.activeViewport, isOverlay: props.isOverlay, layerRequiringCredentials: layerSettings?.toJSON(), onOkResult: props.onItemEdited, mapTypesOptions: props.mapTypesOptions }));
80
+ appui_react_1.UiFramework.dialogs.modal.open(React.createElement(MapUrlDialog_1.MapUrlDialog, { activeViewport: props.activeViewport, isOverlay: props.isOverlay, layerRequiringCredentials: layerSettings?.toJSON(), onOkResult: (sourceState) => handleOk(index, sourceState), onCancelResult: () => { appui_react_1.UiFramework.dialogs.modal.close(); }, mapTypesOptions: props.mapTypesOptions }));
58
81
  }
59
82
  }
60
83
  }, title: requireAuthTooltip },
@@ -1 +1 @@
1
- {"version":3,"file":"MapLayerDroppable.js","sourceRoot":"","sources":["../../../../src/ui/widget/MapLayerDroppable.tsx"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F,2CAA2C;;;AAE3C,oEAAoE;AACpE,sDAAsD;AAEtD,+BAA+B;AAC/B,6DAA2H;AAC3H,wDAAsH;AACtH,kDAAyC;AACzC,sDAA6C;AAC7C,oDAAiD;AACjD,wDAA8C;AAC9C,iEAA8D;AAC9D,qEAAyF;AAEzF,iEAA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KAAK,EAAE,KAAK,EAAE,SAAS,EAAC,iCAAiC,IAC3D,QAAQ,CAAC,cAAc,CAAC,CAAC;oBACxB,8BAAM,SAAS,EAAC,6BAA6B,IAAE,cAAc,CAAQ;oBACrE,CAAC;wBACD;4BACE,8BAAM,SAAS,EAAC,6BAA6B,IAAE,KAAK,CAAQ;4BAC5D,oBAAC,+CAAsB,IAAC,QAAQ,EAAE,KAAK,CAAC,QAAQ,EAAE,UAAU,EAAE,8CAAqB,CAAC,IAAI,EAAE,SAAS,EAAE,KAAK,CAAC,SAAS,GAAI,CACvH,CAED,CAAC;SACV;QACD,OAAO,IAAI,CAAC;IACd,CAAC;IAED,SAAS,eAAe,CAAC,YAA+B,EAAE,YAAoC;QAC5F,OAAO,CACL,6BAAK,SAAS,EAAE,0BAA0B,YAAY,CAAC,cAAc,IAAI,aAAa,CAAC,CAAC,CAAC,uBAAuB,CAAC,CAAC,CAAC,EAAE,EAAE,EAAE,GAAG,EAAE,YAAY,CAAC,QAAQ,KAAM,YAAY,CAAC,cAAc;YAEjL,sBAAsB,CAAC,YAAY,CAAC;YAOrC,6BAAK,KAAK,EAAE,aAAa,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,MAAM,EAAE,IAAG,YAAY,CAAC,WAAW,CAAO,CACzF,CAAC,CAAC;IACZ,CAAC;IAED,OAAO,CACL,oBAAC,+BAAS,IACR,WAAW,EAAE,WAAW,EACxB,WAAW,EAAE,UAAU,EACvB,oBAAoB,EAAE,KAAK,CAAC,oBAA2B,IAEtD,eAAe,CACN,CACb,CAAC;AACJ,CAAC;AA5HD,8CA4HC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n* See LICENSE.md in the project root for license terms and full copyright notice.\n*--------------------------------------------------------------------------------------------*/\n// cSpell:ignore droppable Sublayer Basemap\n\n// the following quiet warning caused by react-beautiful-dnd package\n/* eslint-disable @typescript-eslint/unbound-method */\n\nimport * as React from \"react\";\nimport { Draggable, DraggableChildrenFn, Droppable, DroppableProvided, DroppableStateSnapshot } from \"react-beautiful-dnd\";\nimport { MapLayerImageryProviderStatus, MapTileTreeScaleRangeVisibility, ScreenViewport } from \"@itwin/core-frontend\";\nimport { Icon } from \"@itwin/core-react\";\nimport { assert } from \"@itwin/core-bentley\";\nimport { UiFramework } from \"@itwin/appui-react\";\nimport { Button } from \"@itwin/itwinui-react\";\nimport { SubLayersPopupButton } from \"./SubLayersPopupButton\";\nimport { AttachLayerButtonType, AttachLayerPopupButton } from \"./AttachLayerPopupButton\";\nimport { MapTypesOptions, StyleMapLayerSettings } from \"../Interfaces\";\nimport { MapLayerSettingsMenu } from \"./MapLayerSettingsMenu\";\nimport { MapUrlDialog } from \"./MapUrlDialog\";\nimport \"./MapLayerManager.scss\";\nimport { MapLayersUI } from \"../../mapLayers\";\nimport { ImageMapLayerSettings, SubLayerId } from \"@itwin/core-common\";\n\n/** @internal */\ninterface MapLayerDroppableProps {\n isOverlay: boolean;\n layersList?: StyleMapLayerSettings[];\n mapTypesOptions?: MapTypesOptions;\n getContainerForClone: () => HTMLElement;\n activeViewport: ScreenViewport;\n onMenuItemSelected: (action: string, mapLayerSettings: StyleMapLayerSettings) => void;\n onItemVisibilityToggleClicked: (mapLayerSettings: StyleMapLayerSettings) => void;\n onItemEdited: () => void;\n disabled?: boolean;\n}\n\n/** @internal */\n// eslint-disable-next-line @typescript-eslint/naming-convention\nexport function MapLayerDroppable(props: MapLayerDroppableProps) {\n const containsLayer = props.layersList && props.layersList.length > 0;\n const droppableId = props.isOverlay ? \"overlayMapLayers\" : \"backgroundMapLayers\";\n const [toggleVisibility] = React.useState(MapLayersUI.localization.getLocalizedString(\"mapLayers:Widget.ToggleVisibility\"));\n const [requireAuthTooltip] = React.useState(MapLayersUI.localization.getLocalizedString(\"mapLayers:Widget.RequireAuthTooltip\"));\n const [noBackgroundMapsSpecifiedLabel] = React.useState(MapLayersUI.localization.getLocalizedString(\"mapLayers:Widget.NoBackgroundLayers\"));\n const [noUnderlaysSpecifiedLabel] = React.useState(MapLayersUI.localization.getLocalizedString(\"mapLayers:Widget.NoOverlayLayers\"));\n const [dropLayerLabel] = React.useState(MapLayersUI.localization.getLocalizedString(\"mapLayers:Widget.DropLayerLabel\"));\n const [outOfRangeTitle] = React.useState(MapLayersUI.localization.getLocalizedString(\"mapLayers:Widget.layerOutOfRange\"));\n\n const onSubLayerStateChange = (activeLayer: StyleMapLayerSettings, subLayerId: SubLayerId, isSelected: boolean) => {\n const mapLayerStyleIdx = props.activeViewport.displayStyle.findMapLayerIndexByNameAndSource(activeLayer.name, activeLayer.source, activeLayer.isOverlay);\n if (mapLayerStyleIdx !== -1 && activeLayer.subLayers)\n props.activeViewport.displayStyle.changeMapSubLayerProps({ visible: isSelected }, subLayerId, { index: mapLayerStyleIdx, isOverlay: activeLayer.isOverlay });\n };\n\n const renderItem: DraggableChildrenFn = (dragProvided, _, rubric) => {\n assert(props.layersList !== undefined);\n const activeLayer = props.layersList[rubric.source.index];\n const outOfRange = activeLayer.treeVisibility === MapTileTreeScaleRangeVisibility.Hidden;\n\n return (\n <div className=\"map-manager-source-item\" data-id={rubric.source.index} key={activeLayer.name}\n {...dragProvided.draggableProps}\n ref={dragProvided.innerRef} >\n {/* Visibility icon */}\n <Button disabled={props.disabled} size=\"small\" styleType=\"borderless\" className=\"map-manager-item-visibility\" title={toggleVisibility} onClick={() => { props.onItemVisibilityToggleClicked(activeLayer); }}>\n <Icon iconSpec={activeLayer.visible ? \"icon-visibility\" : \"icon-visibility-hide-2\"} />\n </Button>\n {/* Label */}\n <span className={props.disabled || outOfRange ? \"map-manager-item-label-disabled\" : \"map-manager-item-label\"}\n title={outOfRange ? outOfRangeTitle : undefined}\n {...dragProvided.dragHandleProps}\n\n >\n {activeLayer.name}\n </span>\n <div className=\"map-manager-item-sub-layer-container\">\n {activeLayer.subLayers && activeLayer.subLayers.length > 1 &&\n <SubLayersPopupButton\n subLayers={props.activeViewport ? activeLayer.subLayers : undefined}\n singleVisibleSubLayer={activeLayer.provider?.mutualExclusiveSubLayer}\n onSubLayerStateChange={(subLayerId: SubLayerId, isSelected: boolean) => { onSubLayerStateChange(activeLayer, subLayerId, isSelected); }} />\n }\n </div>\n {activeLayer.provider?.status === MapLayerImageryProviderStatus.RequireAuth &&\n <Button\n disabled={props.disabled}\n size=\"small\"\n styleType=\"borderless\"\n onClick={() => {\n const indexInDisplayStyle = props.activeViewport?.displayStyle.findMapLayerIndexByNameAndSource(activeLayer.name, activeLayer.source, activeLayer.isOverlay);\n if (indexInDisplayStyle !== undefined && indexInDisplayStyle >= 0) {\n const layerSettings = props.activeViewport.displayStyle.mapLayerAtIndex({ index: indexInDisplayStyle, isOverlay: activeLayer.isOverlay });\n if (layerSettings instanceof ImageMapLayerSettings) {\n UiFramework.dialogs.modal.open(<MapUrlDialog activeViewport={props.activeViewport}\n isOverlay={props.isOverlay}\n layerRequiringCredentials={layerSettings?.toJSON()}\n onOkResult={props.onItemEdited}\n mapTypesOptions={props.mapTypesOptions}></MapUrlDialog>);\n }\n }\n\n }}\n title={requireAuthTooltip}\n >\n <Icon className=\"map-layer-source-item-warnMessage-icon\" iconSpec=\"icon-status-warning\" />\n </Button>\n }\n <MapLayerSettingsMenu activeViewport={props.activeViewport} mapLayerSettings={activeLayer} onMenuItemSelection={props.onMenuItemSelected} disabled={props.disabled} />\n </div>\n );\n };\n\n function renderDraggableContent(snapshot: DroppableStateSnapshot): React.ReactNode {\n let node: React.ReactNode;\n if (containsLayer) {\n // Render a <Draggable>\n node = (props.layersList?.map((mapLayerSettings, i) =>\n <Draggable isDragDisabled={props.disabled} key={mapLayerSettings.name} draggableId={mapLayerSettings.name} index={i}>\n {renderItem}\n </Draggable>));\n } else {\n // Render a label that provide a 'Drop here' hint\n const label = props.isOverlay ? noUnderlaysSpecifiedLabel : noBackgroundMapsSpecifiedLabel;\n node =\n <div title={label} className=\"map-manager-no-layers-container\">\n {snapshot.isDraggingOver ?\n <span className=\"map-manager-no-layers-label\">{dropLayerLabel}</span>\n :\n <>\n <span className=\"map-manager-no-layers-label\">{label}</span>\n <AttachLayerPopupButton disabled={props.disabled} buttonType={AttachLayerButtonType.Blue} isOverlay={props.isOverlay} />\n </>\n }\n </div>;\n }\n return node;\n }\n\n function renderDraggable(dropProvided: DroppableProvided, dropSnapshot: DroppableStateSnapshot): React.ReactElement<HTMLElement> {\n return (\n <div className={`map-manager-attachments${dropSnapshot.isDraggingOver && containsLayer ? \" is-dragging-map-over\" : \"\"}`} ref={dropProvided.innerRef} {...dropProvided.droppableProps} >\n\n {renderDraggableContent(dropSnapshot)}\n\n {\n /* We don't want a placeholder when displaying the 'Drop here' message\n Unfortunately, if don't add it, 'react-beautiful-dnd' show an error message in the console.\n So I simply make it hidden. See https://github.com/atlassian/react-beautiful-dnd/issues/518 */\n }\n <div style={containsLayer ? undefined : { display: \"none\" }}>{dropProvided.placeholder}</div>\n </div>);\n }\n\n return (\n <Droppable\n droppableId={droppableId}\n renderClone={renderItem}\n getContainerForClone={props.getContainerForClone as any}\n >\n {renderDraggable}\n </Droppable>\n );\n}\n"]}
1
+ {"version":3,"file":"MapLayerDroppable.js","sourceRoot":"","sources":["../../../../src/ui/widget/MapLayerDroppable.tsx"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F,2CAA2C;;;AAE3C,oEAAoE;AACpE,sDAAsD;AAEtD,+BAA+B;AAC/B,6DAA2H;AAC3H,wDAA6L;AAC7L,kDAAyC;AACzC,sDAA6C;AAC7C,oDAAiD;AACjD,wDAA8C;AAC9C,iEAA8D;AAC9D,qEAAyF;AAEzF,iEAA8D;AAC9D,iDAA2D;AAC3D,kCAAgC;AAChC,+CAA8C;AAC9C,oDAAuE;AAevE,gBAAgB;AAChB,gEAAgE;AAChE,SAAgB,iBAAiB,CAAC,KAA6B;IAC7D,MAAM,aAAa,GAAG,KAAK,CAAC,UAAU,IAAI,KAAK,CAAC,UAAU,CAAC,MAAM,GAAG,CAAC,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yBAAyB,CAAC,CAAC,CAAC,8BAA8B,CAAC;YAC3F,IAAI;gBACF,6BAAK,KAAK,EAAE,KAAK,EAAE,SAAS,EAAC,iCAAiC,IAC3D,QAAQ,CAAC,cAAc,CAAC,CAAC;oBACxB,8BAAM,SAAS,EAAC,6BAA6B,IAAE,cAAc,CAAQ;oBACrE,CAAC;wBACD;4BACE,8BAAM,SAAS,EAAC,6BAA6B,IAAE,KAAK,CAAQ;4BAC5D,oBAAC,+CAAsB,IAAC,QAAQ,EAAE,KAAK,CAAC,QAAQ,EAAE,UAAU,EAAE,8CAAqB,CAAC,IAAI,EAAE,SAAS,EAAE,KAAK,CAAC,SAAS,GAAI,CACvH,CAED,CAAC;SACV;QACD,OAAO,IAAI,CAAC;IACd,CAAC;IAED,SAAS,eAAe,CAAC,YAA+B,EAAE,YAAoC;QAC5F,OAAO,CACL,6BAAK,SAAS,EAAE,0BAA0B,YAAY,CAAC,cAAc,IAAI,aAAa,CAAC,CAAC,CAAC,uBAAuB,CAAC,CAAC,CAAC,EAAE,EAAE,EAAE,GAAG,EAAE,YAAY,CAAC,QAAQ,KAAM,YAAY,CAAC,cAAc;YAEjL,sBAAsB,CAAC,YAAY,CAAC;YAOrC,6BAAK,KAAK,EAAE,aAAa,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,MAAM,EAAE,IAAG,YAAY,CAAC,WAAW,CAAO,CACzF,CAAC,CAAC;IACZ,CAAC;IAED,OAAO,CACL,oBAAC,+BAAS,IACR,WAAW,EAAE,WAAW,EACxB,WAAW,EAAE,UAAU,EACvB,oBAAoB,EAAE,KAAK,CAAC,oBAA2B,IAEtD,eAAe,CACN,CACb,CAAC;AACJ,CAAC;AA5JD,8CA4JC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n* See LICENSE.md in the project root for license terms and full copyright notice.\n*--------------------------------------------------------------------------------------------*/\n// cSpell:ignore droppable Sublayer Basemap\n\n// the following quiet warning caused by react-beautiful-dnd package\n/* eslint-disable @typescript-eslint/unbound-method */\n\nimport * as React from \"react\";\nimport { Draggable, DraggableChildrenFn, Droppable, DroppableProvided, DroppableStateSnapshot } from \"react-beautiful-dnd\";\nimport { IModelApp, MapLayerImageryProviderStatus, MapLayerIndex, MapTileTreeScaleRangeVisibility, NotifyMessageDetails, OutputMessagePriority, ScreenViewport } from \"@itwin/core-frontend\";\nimport { Icon } from \"@itwin/core-react\";\nimport { assert } from \"@itwin/core-bentley\";\nimport { UiFramework } from \"@itwin/appui-react\";\nimport { Button } from \"@itwin/itwinui-react\";\nimport { SubLayersPopupButton } from \"./SubLayersPopupButton\";\nimport { AttachLayerButtonType, AttachLayerPopupButton } from \"./AttachLayerPopupButton\";\nimport { MapTypesOptions, StyleMapLayerSettings } from \"../Interfaces\";\nimport { MapLayerSettingsMenu } from \"./MapLayerSettingsMenu\";\nimport { MapUrlDialog, SourceState } from \"./MapUrlDialog\";\nimport \"./MapLayerManager.scss\";\nimport { MapLayersUI } from \"../../mapLayers\";\nimport { ImageMapLayerSettings, SubLayerId } from \"@itwin/core-common\";\n\n/** @internal */\ninterface MapLayerDroppableProps {\n isOverlay: boolean;\n layersList?: StyleMapLayerSettings[];\n mapTypesOptions?: MapTypesOptions;\n getContainerForClone: () => HTMLElement;\n activeViewport: ScreenViewport;\n onMenuItemSelected: (action: string, mapLayerSettings: StyleMapLayerSettings) => void;\n onItemVisibilityToggleClicked: (mapLayerSettings: StyleMapLayerSettings) => void;\n onItemEdited: () => void;\n disabled?: boolean;\n}\n\n/** @internal */\n// eslint-disable-next-line @typescript-eslint/naming-convention\nexport function MapLayerDroppable(props: MapLayerDroppableProps) {\n const containsLayer = props.layersList && props.layersList.length > 0;\n const droppableId = props.isOverlay ? \"overlayMapLayers\" : \"backgroundMapLayers\";\n const [toggleVisibility] = React.useState(MapLayersUI.localization.getLocalizedString(\"mapLayers:Widget.ToggleVisibility\"));\n const [requireAuthTooltip] = React.useState(MapLayersUI.localization.getLocalizedString(\"mapLayers:Widget.RequireAuthTooltip\"));\n const [noBackgroundMapsSpecifiedLabel] = React.useState(MapLayersUI.localization.getLocalizedString(\"mapLayers:Widget.NoBackgroundLayers\"));\n const [noUnderlaysSpecifiedLabel] = React.useState(MapLayersUI.localization.getLocalizedString(\"mapLayers:Widget.NoOverlayLayers\"));\n const [dropLayerLabel] = React.useState(MapLayersUI.localization.getLocalizedString(\"mapLayers:Widget.DropLayerLabel\"));\n const [outOfRangeTitle] = React.useState(MapLayersUI.localization.getLocalizedString(\"mapLayers:Widget.layerOutOfRange\"));\n\n const onSubLayerStateChange = (activeLayer: StyleMapLayerSettings, subLayerId: SubLayerId, isSelected: boolean) => {\n const mapLayerStyleIdx = props.activeViewport.displayStyle.findMapLayerIndexByNameAndSource(activeLayer.name, activeLayer.source, activeLayer.isOverlay);\n if (mapLayerStyleIdx !== -1 && activeLayer.subLayers)\n props.activeViewport.displayStyle.changeMapSubLayerProps({ visible: isSelected }, subLayerId, { index: mapLayerStyleIdx, isOverlay: activeLayer.isOverlay });\n };\n\n const handleOk = React.useCallback((index: MapLayerIndex, sourceState?: SourceState) => {\n UiFramework.dialogs.modal.close();\n\n const source = sourceState?.source;\n const vp = props?.activeViewport;\n if (vp === undefined || sourceState === undefined || source === undefined) {\n const error = MapLayersUI.localization.getLocalizedString(\"mapLayers:Messages.MapLayerAttachMissingViewOrSource\");\n const msg = MapLayersUI.localization.getLocalizedString(\"mapLayers:Messages.MapLayerAttachError\", { error, sourceName: source?.name ?? \"\" });\n IModelApp.notifications.outputMessage(new NotifyMessageDetails(OutputMessagePriority.Error, msg));\n return;\n }\n\n const validation = sourceState.validation;\n\n // Layer is already attached,\n // This calls invalidateRenderPlan()\n vp.displayStyle.changeMapLayerProps({subLayers: validation.subLayers}, index);\n vp.displayStyle.changeMapLayerCredentials(index, source.userName, source.password);\n\n // Either initial attach/initialize failed or the layer failed to load at least one tile\n // because of an invalid token; in both cases tile tree needs to be fully reset\n const provider = vp.getMapLayerImageryProvider(index);\n provider?.resetStatus();\n vp.resetMapLayer(index);\n\n props.onItemEdited();\n }, [props]);\n\n const renderItem: DraggableChildrenFn = (dragProvided, _, rubric) => {\n assert(props.layersList !== undefined);\n const activeLayer = props.layersList[rubric.source.index];\n const outOfRange = activeLayer.treeVisibility === MapTileTreeScaleRangeVisibility.Hidden;\n\n return (\n <div className=\"map-manager-source-item\" data-id={rubric.source.index} key={activeLayer.name}\n {...dragProvided.draggableProps}\n ref={dragProvided.innerRef} >\n {/* Visibility icon */}\n <Button disabled={props.disabled} size=\"small\" styleType=\"borderless\" className=\"map-manager-item-visibility\" title={toggleVisibility} onClick={() => { props.onItemVisibilityToggleClicked(activeLayer); }}>\n <Icon iconSpec={activeLayer.visible ? \"icon-visibility\" : \"icon-visibility-hide-2\"} />\n </Button>\n {/* Label */}\n <span className={props.disabled || outOfRange ? \"map-manager-item-label-disabled\" : \"map-manager-item-label\"}\n title={outOfRange ? outOfRangeTitle : undefined}\n {...dragProvided.dragHandleProps}\n\n >\n {activeLayer.name}\n </span>\n <div className=\"map-manager-item-sub-layer-container\">\n {activeLayer.subLayers && activeLayer.subLayers.length > 1 &&\n <SubLayersPopupButton\n checkboxStyle=\"eye\"\n expandMode=\"rootGroupOnly\"\n subLayers={props.activeViewport ? activeLayer.subLayers : undefined}\n singleVisibleSubLayer={activeLayer.provider?.mutualExclusiveSubLayer}\n onSubLayerStateChange={(subLayerId: SubLayerId, isSelected: boolean) => { onSubLayerStateChange(activeLayer, subLayerId, isSelected); }} />\n }\n </div>\n {activeLayer.provider?.status === MapLayerImageryProviderStatus.RequireAuth &&\n <Button\n disabled={props.disabled}\n size=\"small\"\n styleType=\"borderless\"\n onClick={() => {\n const indexInDisplayStyle = props.activeViewport?.displayStyle.findMapLayerIndexByNameAndSource(activeLayer.name, activeLayer.source, activeLayer.isOverlay);\n if (indexInDisplayStyle !== undefined && indexInDisplayStyle >= 0) {\n const index = { index: indexInDisplayStyle, isOverlay: activeLayer.isOverlay };\n const layerSettings = props.activeViewport.displayStyle.mapLayerAtIndex(index);\n if (layerSettings instanceof ImageMapLayerSettings) {\n UiFramework.dialogs.modal.open(<MapUrlDialog activeViewport={props.activeViewport}\n isOverlay={props.isOverlay}\n layerRequiringCredentials={layerSettings?.toJSON()}\n onOkResult={(sourceState?: SourceState) => handleOk(index, sourceState)}\n onCancelResult={() => {UiFramework.dialogs.modal.close();}}\n mapTypesOptions={props.mapTypesOptions}></MapUrlDialog>);\n }\n }\n\n }}\n title={requireAuthTooltip}\n >\n <Icon className=\"map-layer-source-item-warnMessage-icon\" iconSpec=\"icon-status-warning\" />\n </Button>\n }\n <MapLayerSettingsMenu activeViewport={props.activeViewport} mapLayerSettings={activeLayer} onMenuItemSelection={props.onMenuItemSelected} disabled={props.disabled} />\n </div>\n );\n };\n\n function renderDraggableContent(snapshot: DroppableStateSnapshot): React.ReactNode {\n let node: React.ReactNode;\n if (containsLayer) {\n // Render a <Draggable>\n node = (props.layersList?.map((mapLayerSettings, i) =>\n <Draggable isDragDisabled={props.disabled} key={mapLayerSettings.name} draggableId={mapLayerSettings.name} index={i}>\n {renderItem}\n </Draggable>));\n } else {\n // Render a label that provide a 'Drop here' hint\n const label = props.isOverlay ? noUnderlaysSpecifiedLabel : noBackgroundMapsSpecifiedLabel;\n node =\n <div title={label} className=\"map-manager-no-layers-container\">\n {snapshot.isDraggingOver ?\n <span className=\"map-manager-no-layers-label\">{dropLayerLabel}</span>\n :\n <>\n <span className=\"map-manager-no-layers-label\">{label}</span>\n <AttachLayerPopupButton disabled={props.disabled} buttonType={AttachLayerButtonType.Blue} isOverlay={props.isOverlay} />\n </>\n }\n </div>;\n }\n return node;\n }\n\n function renderDraggable(dropProvided: DroppableProvided, dropSnapshot: DroppableStateSnapshot): React.ReactElement<HTMLElement> {\n return (\n <div className={`map-manager-attachments${dropSnapshot.isDraggingOver && containsLayer ? \" is-dragging-map-over\" : \"\"}`} ref={dropProvided.innerRef} {...dropProvided.droppableProps} >\n\n {renderDraggableContent(dropSnapshot)}\n\n {\n /* We don't want a placeholder when displaying the 'Drop here' message\n Unfortunately, if don't add it, 'react-beautiful-dnd' show an error message in the console.\n So I simply make it hidden. See https://github.com/atlassian/react-beautiful-dnd/issues/518 */\n }\n <div style={containsLayer ? undefined : { display: \"none\" }}>{dropProvided.placeholder}</div>\n </div>);\n }\n\n return (\n <Droppable\n droppableId={droppableId}\n renderClone={renderItem}\n getContainerForClone={props.getContainerForClone as any}\n >\n {renderDraggable}\n </Droppable>\n );\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"MapLayerManager.d.ts","sourceRoot":"","sources":["../../../../src/ui/widget/MapLayerManager.tsx"],"names":[],"mappings":"AAWA,OAAO,EACiF,cAAc,EACpG,cAAc,EACf,MAAM,sBAAsB,CAAC;AAE9B,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAG/B,OAAO,EAAE,eAAe,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAC;AAIvE,OAAO,wBAAwB,CAAC;AAIhC,gBAAgB;AAChB,MAAM,WAAW,qBAAqB;IACpC,QAAQ,CAAC,OAAO,EAAE,cAAc,EAAE,CAAC;IACnC,QAAQ,CAAC,cAAc,EAAE,OAAO,CAAC;IACjC,QAAQ,CAAC,KAAK,EAAE,cAAc,EAAE,CAAC;IACjC,QAAQ,CAAC,gBAAgB,EAAE,MAAM,IAAI,CAAC;IACtC,QAAQ,CAAC,cAAc,CAAC,EAAE,cAAc,CAAC;IACzC,QAAQ,CAAC,gBAAgB,CAAC,EAAE,qBAAqB,EAAE,CAAC;IACpD,QAAQ,CAAC,aAAa,CAAC,EAAE,qBAAqB,EAAE,CAAC;IACjD,QAAQ,CAAC,eAAe,CAAC,EAAE,eAAe,CAAC;CAC5C;AAED,gBAAgB;AAChB,eAAO,MAAM,gBAAgB,sCAK3B,CAAC;AAEH,gBAAgB;AAChB,wBAAgB,mBAAmB,IAAI,qBAAqB,CAE3D;AAuCD,UAAU,oB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@ -111,10 +111,7 @@ function MapLayerManager(props) {
111
111
  loadMapLayerSettingsFromViewport(activeViewport);
112
112
  }
113
113
  };
114
- core_frontend_1.IModelApp.tileAdmin.onTileTreeLoad.addListener(handleTileTreeLoad);
115
- return () => {
116
- core_frontend_1.IModelApp.tileAdmin.onTileTreeLoad.removeListener(handleTileTreeLoad);
117
- };
114
+ return core_frontend_1.IModelApp.tileAdmin.onTileTreeLoad.addListener(handleTileTreeLoad);
118
115
  }, [activeViewport, loadMapLayerSettingsFromViewport]);
119
116
  React.useEffect(() => {
120
117
  const handleScaleRangeVisibilityChanged = (layerIndexes) => {
@@ -132,10 +129,7 @@ function MapLayerManager(props) {
132
129
  setBackgroundMapLayers(updateLayers(backgroundMapLayers));
133
130
  setOverlayMapLayers(updateLayers(overlayMapLayers));
134
131
  };
135
- activeViewport.onMapLayerScaleRangeVisibilityChanged.addListener(handleScaleRangeVisibilityChanged);
136
- return () => {
137
- activeViewport.onMapLayerScaleRangeVisibilityChanged.removeListener(handleScaleRangeVisibilityChanged);
138
- };
132
+ return activeViewport.onMapLayerScaleRangeVisibilityChanged.addListener(handleScaleRangeVisibilityChanged);
139
133
  }, [activeViewport, backgroundMapLayers, loadMapLayerSettingsFromViewport, overlayMapLayers]);
140
134
  // Setup onMapImageryChanged events listening.
141
135
  React.useEffect(() => {
@@ -145,10 +139,7 @@ function MapLayerManager(props) {
145
139
  loadMapLayerSettingsFromViewport(activeViewport);
146
140
  }
147
141
  };
148
- activeViewport?.displayStyle.settings.onMapImageryChanged.addListener(handleMapImageryChanged);
149
- return () => {
150
- activeViewport?.displayStyle.settings.onMapImageryChanged.removeListener(handleMapImageryChanged);
151
- };
142
+ return activeViewport?.displayStyle.settings.onMapImageryChanged.addListener(handleMapImageryChanged);
152
143
  }, [activeViewport, backgroundMapLayers, loadMapLayerSettingsFromViewport, overlayMapLayers]);
153
144
  const handleProviderStatusChanged = React.useCallback((_args) => {
154
145
  loadMapLayerSettingsFromViewport(activeViewport);
@@ -171,17 +162,14 @@ function MapLayerManager(props) {
171
162
  loadMapLayerSettingsFromViewport(activeViewport);
172
163
  }, [activeViewport, loadMapLayerSettingsFromViewport]);
173
164
  React.useEffect(() => {
174
- async function fetchWmsMapData() {
175
- const sources = [];
176
- const bases = [];
165
+ async function fetchSources() {
166
+ let preferenceSources = [];
177
167
  const sourceLayers = await core_frontend_1.MapLayerSources.create(undefined, (fetchPublicMapLayerSources && !hideExternalMapLayersSection));
178
- const iModel = core_frontend_1.IModelApp.viewManager.selectedView ? core_frontend_1.IModelApp.viewManager.selectedView.iModel : undefined;
168
+ const iModel = activeViewport.iModel;
179
169
  try {
180
- const preferenceSources = (iModel?.iTwinId === undefined
181
- ? []
182
- : await MapLayerPreferences_1.MapLayerPreferences.getSources(iModel?.iTwinId, iModel?.iModelId));
183
- for (const source of preferenceSources)
184
- await core_frontend_1.MapLayerSources.addSourceToMapLayerSources(source);
170
+ if (iModel?.iTwinId !== undefined) {
171
+ preferenceSources = await MapLayerPreferences_1.MapLayerPreferences.getSources(iModel.iTwinId, iModel.iModelId);
172
+ }
185
173
  }
186
174
  catch (err) {
187
175
  core_frontend_1.IModelApp.notifications.outputMessage(new core_frontend_1.NotifyMessageDetails(core_frontend_1.OutputMessagePriority.Error, core_frontend_1.IModelApp.localization.getLocalizedString("mapLayers:CustomAttach.ErrorLoadingLayers"), core_bentley_1.BentleyError.getErrorMessage(err)));
@@ -189,16 +177,22 @@ function MapLayerManager(props) {
189
177
  if (!isMounted.current) {
190
178
  return;
191
179
  }
192
- // This is where the list of layers first gets populated... I need to update it
193
- // MapUrlDialog gets around knowing MapLayerManager exists and vice versa by affecting the viewports displayStyle which MapLayerManager is listening for
194
- // We know when displayStyle changes we've added a layer, this layer may not be a custom layer
195
- sourceLayers?.layers.forEach((source) => { sources.push(source); });
180
+ // This is where the list of layers first gets populated...
181
+ const sources = [];
182
+ const bases = [];
183
+ const addSource = (source) => source.baseMap ? bases.push(source) : sources.push(source);
184
+ sourceLayers?.allSource.forEach(addSource);
185
+ preferenceSources.forEach((source) => {
186
+ // Do not add duplicate
187
+ if (!sources.find((curSource) => source.name === curSource.name))
188
+ addSource(source);
189
+ });
190
+ sources.sort((a, b) => (0, core_bentley_1.compareStrings)(a.name.toLowerCase(), b.name.toLowerCase()));
196
191
  setMapSources(sources);
197
- sourceLayers?.bases.forEach((source) => { bases.push(source); });
198
192
  setBaseSources(bases);
199
193
  }
200
194
  setLoadingSources(true);
201
- fetchWmsMapData().then(() => {
195
+ fetchSources().then(() => {
202
196
  if (isMounted.current) {
203
197
  setLoadingSources(false);
204
198
  }
@@ -207,55 +201,39 @@ function MapLayerManager(props) {
207
201
  setLoadingSources(false);
208
202
  }
209
203
  });
210
- }, [setMapSources, fetchPublicMapLayerSources, hideExternalMapLayersSection]);
211
- const updateMapSources = React.useCallback(() => {
212
- const newSources = [];
213
- core_frontend_1.MapLayerSources.getInstance()?.layers?.forEach((sourceLayer) => { newSources.push(sourceLayer); });
214
- setMapSources(newSources);
215
- }, [setMapSources]);
204
+ }, [setMapSources, fetchPublicMapLayerSources, hideExternalMapLayersSection, activeViewport.iModel]);
216
205
  /**
217
206
  * Handle change events in the MapLayerPreferences
218
207
  */
219
208
  React.useEffect(() => {
220
209
  const handleLayerSourceChange = async (changeType, oldSource, newSource) => {
221
- const removeSourceOnly = (changeType === MapLayerPreferences_1.MapLayerSourceChangeType.Removed);
222
210
  const removeSource = (changeType === MapLayerPreferences_1.MapLayerSourceChangeType.Replaced || changeType === MapLayerPreferences_1.MapLayerSourceChangeType.Removed);
223
211
  const addSource = (changeType === MapLayerPreferences_1.MapLayerSourceChangeType.Replaced || changeType === MapLayerPreferences_1.MapLayerSourceChangeType.Added);
212
+ let tmpSources = (mapSources ? [...mapSources] : undefined);
224
213
  if (removeSource) {
225
- if (oldSource) {
226
- const succeeded = core_frontend_1.MapLayerSources.removeLayerByName(oldSource.name);
227
- (0, core_bentley_1.assert)(succeeded);
228
- if (!succeeded) {
229
- return;
230
- }
231
- if (removeSourceOnly) {
232
- updateMapSources();
233
- return;
234
- }
214
+ if (oldSource && tmpSources) {
215
+ tmpSources = tmpSources.filter((source) => source.name !== oldSource.name);
216
+ // We don't update state in case of replacement... it will be done when the source is re-added right after.
217
+ if (changeType !== MapLayerPreferences_1.MapLayerSourceChangeType.Replaced)
218
+ setMapSources(tmpSources);
235
219
  }
236
220
  }
237
221
  if (addSource) {
238
- const sources = await core_frontend_1.MapLayerSources.addSourceToMapLayerSources(newSource);
239
- (0, core_bentley_1.assert)(sources !== undefined);
240
- if (sources) {
241
- updateMapSources();
222
+ if (tmpSources && newSource && !tmpSources.find((curSource) => newSource.name === curSource.name)) {
223
+ tmpSources.push(newSource);
224
+ tmpSources.sort((a, b) => (0, core_bentley_1.compareStrings)(a.name.toLowerCase(), b.name.toLowerCase()));
225
+ setMapSources(tmpSources);
242
226
  }
243
227
  }
244
228
  };
245
- MapLayerPreferences_1.MapLayerPreferences.onLayerSourceChanged.addListener(handleLayerSourceChange);
246
- return (() => {
247
- MapLayerPreferences_1.MapLayerPreferences.onLayerSourceChanged.removeListener(handleLayerSourceChange);
248
- });
249
- }, [updateMapSources]);
229
+ return MapLayerPreferences_1.MapLayerPreferences.onLayerSourceChanged.addListener(handleLayerSourceChange);
230
+ }, [setMapSources, mapSources]);
250
231
  // update when a different display style is loaded.
251
232
  React.useEffect(() => {
252
233
  const handleDisplayStyleChange = (vp) => {
253
234
  loadMapLayerSettingsFromViewport(vp);
254
235
  };
255
- activeViewport?.onDisplayStyleChanged.addListener(handleDisplayStyleChange);
256
- return () => {
257
- activeViewport?.onDisplayStyleChanged.removeListener(handleDisplayStyleChange);
258
- };
236
+ return activeViewport?.onDisplayStyleChanged.addListener(handleDisplayStyleChange);
259
237
  }, [activeViewport, loadMapLayerSettingsFromViewport]);
260
238
  const handleOnMenuItemSelection = React.useCallback((action, mapLayerSettings) => {
261
239
  if (!activeViewport || !activeViewport.displayStyle)