Skip to content

Commit

Permalink
Hide map layer info tool when map layers is off or no arcgis feature …
Browse files Browse the repository at this point in the history
…info layers exist (#1016)

* Hide map layer info tool when map layers is off or no arcgis feature layers exist

* Switch from using SyncUiEventId.ViewStateChanged to custom event MapFeatureInfoTool.toolSyncUiEventId to trigger isHidden for MapFeatureInfoTool

* Switch to using exported SyncUiEventId MapLayersSyncUiEventId.MapImageryChanged

* Add change file

* Switch to checking supportsMapFeatureInfo instead of hardcoded string ArcGISFeature

* Draft PR rework (#1035)

* Draft PR rework

* Add isOverlay parameter to supportsMapFeatureInfo()

* Add check if map layer is visible to enable tool

* Removed event handling for SyncUiEventId.ActiveViewportChanged and SyncUiEventId.ViewStateChanged to rely only on MapLayersSyncUiEventId.MapImageryChanged

* Ignore lint error for alpha supportsMapFeatureInfo use
  • Loading branch information
wilmaier authored Sep 11, 2024
1 parent 82f03a8 commit 9ac4d0f
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "minor",
"comment": "Hide map layer info tool when map layers is off or no arcgis feature layers exist",
"packageName": "@itwin/map-layers",
"email": "[email protected]",
"dependentChangeType": "patch"
}
6 changes: 6 additions & 0 deletions packages/itwin/map-layers/src/MapLayersActionIds.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// Copyright (c) Bentley Systems, Incorporated. All rights reserved.

export enum MapLayersSyncUiEventId {
/** The display style settings map imagery has changed. */
MapImageryChanged = "mapimagerychanged",
}
1 change: 1 addition & 0 deletions packages/itwin/map-layers/src/map-layers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* See LICENSE.md in the project root for license terms and full copyright notice.
*--------------------------------------------------------------------------------------------*/
export * from "./mapLayers";
export * from "./MapLayersActionIds";
export * from "./MapLayersPrefBrowserStorage";
export * from "./ui/Interfaces";
export * from "./ui/MapLayersUiItemsProvider";
Expand Down
46 changes: 41 additions & 5 deletions packages/itwin/map-layers/src/ui/FeatureInfoUiItemsProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* See LICENSE.md in the project root for license terms and full copyright notice.
*--------------------------------------------------------------------------------------------*/

import { BadgeType, ConditionalBooleanValue } from "@itwin/appui-abstract";
import type { ToolbarItem, UiItemsProvider } from "@itwin/appui-react";
import {
StagePanelLocation,
Expand All @@ -14,13 +15,44 @@ import {
ToolItemDef,
WidgetState,
} from "@itwin/appui-react";
import { MapFeatureInfoWidget } from "./widget/FeatureInfoWidget";
import type { MapFeatureInfoOptions } from "./Interfaces";
import { MapLayersUI } from "../mapLayers";
import { IModelApp } from "@itwin/core-frontend";
import { MapFeatureInfoTool } from "@itwin/map-layers-formats";
import type { ScreenViewport } from "@itwin/core-frontend";
import type { MapLayerProps } from "@itwin/core-common";
import { SvgMapInfo } from "@itwin/itwinui-icons-react";
import { BadgeType } from "@itwin/appui-abstract";
import { MapFeatureInfoTool } from "@itwin/map-layers-formats";

import { MapLayersUI } from "../mapLayers";
import { MapFeatureInfoWidget } from "./widget/FeatureInfoWidget";
import type { MapFeatureInfoOptions } from "./Interfaces";
import { MapLayersSyncUiEventId } from "../MapLayersActionIds";

const supportsMapFeatureInfo = (vp: ScreenViewport, isOverlay: boolean, mapLayerProps: MapLayerProps[]): boolean => {
for (let mapLayerIndex = 0; mapLayerIndex < mapLayerProps.length; mapLayerIndex++) {
if (mapLayerProps[mapLayerIndex].visible && mapLayerProps[mapLayerIndex].transparency !== 1.0) {
const layerProvider = vp.getMapLayerImageryProvider({ index: mapLayerIndex, isOverlay });
// eslint-disable-next-line @itwin/no-internal
if (layerProvider?.supportsMapFeatureInfo) {
return true;
}
}
}
return false;
};

const isMapFeatureInfoSupported = (): boolean => {
const vp = IModelApp.viewManager.selectedView;
if (vp?.viewFlags.backgroundMap) {
const backgroundLayers = vp.displayStyle.settings.mapImagery.backgroundLayers.map((value) => value.toJSON());
if (supportsMapFeatureInfo(vp, false, backgroundLayers)) {
return true;
}
const overlayLayers = vp.displayStyle.settings.mapImagery.overlayLayers.map((value) => value.toJSON());
if (supportsMapFeatureInfo(vp, true, overlayLayers)) {
return true;
}
}
return false;
};

export const getMapFeatureInfoToolItemDef = (): ToolItemDef =>
new ToolItemDef({
Expand All @@ -32,6 +64,10 @@ export const getMapFeatureInfoToolItemDef = (): ToolItemDef =>
await IModelApp.tools.run(MapFeatureInfoTool.toolId);
},
badgeType: BadgeType.TechnicalPreview,
isHidden: new ConditionalBooleanValue(() => {
// Hide the MapFeatureInfoTool if the Map Layers toggle is off or no ArcGISFeature layers are active
return !isMapFeatureInfoSupported();
}, [MapLayersSyncUiEventId.MapImageryChanged]),
});

export class FeatureInfoUiItemsProvider implements UiItemsProvider {
Expand Down
3 changes: 3 additions & 0 deletions packages/itwin/map-layers/src/ui/widget/MapLayerManager.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import { MapLayerActionButtons } from "./MapLayerActionButtons";
import { MapLayerDroppable } from "./MapLayerDroppable";
import { MapLayerSettingsPopupButton } from "./MapLayerSettingsPopupButton";
import { MapManagerLayersHeader } from "./MapManagerMapLayersHeader";
import { MapLayersSyncUiEventId } from "../../MapLayersActionIds";

/** @internal */
export interface SourceMapContextProps {
Expand Down Expand Up @@ -202,6 +203,7 @@ export function MapLayerManager(props: MapLayerManagerProps) {
) {
loadMapLayerSettingsFromViewport(activeViewport);
}
IModelApp.toolAdmin.dispatchUiSyncEvent(MapLayersSyncUiEventId.MapImageryChanged);
};
return activeViewport?.displayStyle.settings.onMapImageryChanged.addListener(handleMapImageryChanged);
}, [activeViewport, backgroundMapLayers, loadMapLayerSettingsFromViewport, overlayMapLayers]);
Expand Down Expand Up @@ -402,6 +404,7 @@ export function MapLayerManager(props: MapLayerManagerProps) {
const newState = !backgroundMapVisible;
activeViewport.viewFlags = activeViewport.viewFlags.with("backgroundMap", newState);
setBackgroundMapVisible(newState);
IModelApp.toolAdmin.dispatchUiSyncEvent(MapLayersSyncUiEventId.MapImageryChanged);
}
}, [backgroundMapVisible, setBackgroundMapVisible, activeViewport]);

Expand Down

0 comments on commit 9ac4d0f

Please sign in to comment.