|
| 1 | +import { |
| 2 | + FluentProvider, |
| 3 | + webDarkTheme, |
| 4 | + Toolbar, |
| 5 | + ToolbarButton, |
| 6 | + ToolbarToggleButton, |
| 7 | + ToolbarDivider, |
| 8 | + Menu, |
| 9 | + MenuTrigger, |
| 10 | + MenuPopover, |
| 11 | + MenuList, |
| 12 | + MenuItem, |
| 13 | + Text, |
| 14 | + Input, |
| 15 | + Switch, |
| 16 | +} from "@fluentui/react-components"; |
| 17 | +import * as React from "react"; |
| 18 | +import { useEffect, useState } from "react"; |
| 19 | +import { |
| 20 | + Edit24Regular, |
| 21 | + Settings24Regular, |
| 22 | + Location24Regular, |
| 23 | +} from "@fluentui/react-icons"; |
| 24 | + |
| 25 | +import { watch } from "@arcgis/core/core/reactiveUtils.js"; |
| 26 | + |
| 27 | +import "./FluentCoordinateConversion.css"; |
| 28 | + |
| 29 | +async function reverseConvert({ vm, value, activeFormat }) { |
| 30 | + //coordinateEditable.editingEnabled = false; |
| 31 | + //const value = coordinateInput.value; |
| 32 | + try { |
| 33 | + const point = await vm.reverseConvert(value, activeFormat); |
| 34 | + vm.view.goTo(point); |
| 35 | + } catch (e) { |
| 36 | + //coordinateInput.status = "invalid"; |
| 37 | + } |
| 38 | +} |
| 39 | + |
| 40 | +export default function FluentCoordinateConversion({ vm }) { |
| 41 | + const [activeFormat, setActiveFormat] = useState(); |
| 42 | + |
| 43 | + useEffect(() => { |
| 44 | + const handle = watch( |
| 45 | + () => vm?.conversions?.getItemAt(0)?.format, |
| 46 | + (format) => setActiveFormat(format), |
| 47 | + { initial: true } |
| 48 | + ); |
| 49 | + |
| 50 | + return function cleanUp() { |
| 51 | + handle?.remove(); |
| 52 | + }; |
| 53 | + }, [vm]); |
| 54 | + |
| 55 | + const [activeDisplayCoordinate, setActiveDisplayCoordinate] = useState(); |
| 56 | + |
| 57 | + useEffect(() => { |
| 58 | + const handle = watch( |
| 59 | + () => vm?.conversions?.getItemAt(0)?.displayCoordinate, |
| 60 | + (displayCoordinate) => |
| 61 | + setActiveDisplayCoordinate(displayCoordinate ?? ""), |
| 62 | + { initial: true } |
| 63 | + ); |
| 64 | + |
| 65 | + return function cleanUp() { |
| 66 | + handle?.remove(); |
| 67 | + }; |
| 68 | + }, [vm]); |
| 69 | + |
| 70 | + console.log({ vm, reverseConvert, activeFormat }); |
| 71 | + |
| 72 | + const [checkedValues, setCheckedValues] = useState({ |
| 73 | + editing: [], |
| 74 | + }); |
| 75 | + |
| 76 | + const onChange = (e, { name, checkedItems }) => { |
| 77 | + setCheckedValues((s) => { |
| 78 | + return s ? { ...s, [name]: checkedItems } : { [name]: checkedItems }; |
| 79 | + }); |
| 80 | + }; |
| 81 | + |
| 82 | + const showEditing = checkedValues.editing.includes("edit"); |
| 83 | + |
| 84 | + return ( |
| 85 | + <div className="fluent-coordinate-conversion"> |
| 86 | + <FluentProvider theme={webDarkTheme}> |
| 87 | + <Toolbar |
| 88 | + checkedValues={checkedValues} |
| 89 | + aria-label="Default" |
| 90 | + onCheckedValueChange={onChange} |
| 91 | + > |
| 92 | + <Location24Regular /> |
| 93 | + {!showEditing ? ( |
| 94 | + <Text className="text"> |
| 95 | + {activeDisplayCoordinate || "No position"} |
| 96 | + </Text> |
| 97 | + ) : null} |
| 98 | + {showEditing ? ( |
| 99 | + <Input className="input" value={activeDisplayCoordinate} /> |
| 100 | + ) : null} |
| 101 | + <ToolbarDivider /> |
| 102 | + <ToolbarToggleButton |
| 103 | + aria-label="Edit Coordinate" |
| 104 | + name="editing" |
| 105 | + value="edit" |
| 106 | + icon={<Edit24Regular />} |
| 107 | + /> |
| 108 | + <ToolbarDivider /> |
| 109 | + <Switch |
| 110 | + label="Capture" |
| 111 | + onChange={(_event, data) => { |
| 112 | + vm.mode = data.checked ? "capture" : "live"; |
| 113 | + }} |
| 114 | + /> |
| 115 | + <ToolbarDivider /> |
| 116 | + <Menu> |
| 117 | + <MenuTrigger> |
| 118 | + <ToolbarButton |
| 119 | + aria-label="Formats" |
| 120 | + icon={<Settings24Regular />} |
| 121 | + /> |
| 122 | + </MenuTrigger> |
| 123 | + <MenuPopover> |
| 124 | + <MenuList> |
| 125 | + <MenuItem>New </MenuItem> |
| 126 | + <MenuItem>New Window</MenuItem> |
| 127 | + <MenuItem disabled>Open File</MenuItem> |
| 128 | + <MenuItem>Open Folder</MenuItem> |
| 129 | + </MenuList> |
| 130 | + </MenuPopover> |
| 131 | + </Menu> |
| 132 | + </Toolbar> |
| 133 | + </FluentProvider> |
| 134 | + </div> |
| 135 | + ); |
| 136 | +} |
0 commit comments