From 37b2d3a5d66342d580cfc2362478f07d549ae24e Mon Sep 17 00:00:00 2001 From: Chad Burt Date: Tue, 8 Aug 2023 11:12:16 -0700 Subject: [PATCH] Add geostats info modal --- .../data/GLStyleEditor/GLStyleEditor.tsx | 136 +++++++++--------- .../data/GLStyleEditor/GeostatsModal.tsx | 107 ++++++++++++++ 2 files changed, 176 insertions(+), 67 deletions(-) create mode 100644 packages/client/src/admin/data/GLStyleEditor/GeostatsModal.tsx diff --git a/packages/client/src/admin/data/GLStyleEditor/GLStyleEditor.tsx b/packages/client/src/admin/data/GLStyleEditor/GLStyleEditor.tsx index f212c9ea6..240db00dc 100644 --- a/packages/client/src/admin/data/GLStyleEditor/GLStyleEditor.tsx +++ b/packages/client/src/admin/data/GLStyleEditor/GLStyleEditor.tsx @@ -43,7 +43,7 @@ import * as DropdownMenu from "@radix-ui/react-dropdown-menu"; import { CaretDownIcon, ChevronRightIcon } from "@radix-ui/react-icons"; import { undo, undoDepth, redo, redoDepth } from "@codemirror/commands"; import { MapContext } from "../../../dataLayers/MapContextManager"; -import { useOverlayState } from "../../../components/TreeView"; +import GeostatsModal, { Geostats } from "./GeostatsModal"; require("./RadixDropdown.css"); @@ -90,6 +90,8 @@ export default function GLStyleEditor(props: GLStyleEditorProps) { selectedSpriteId: number | null; }>(null); + const [geostatsModal, setGeostatsModal] = useState(null); + const extensions = useMemo(() => { return [ json(), @@ -192,41 +194,53 @@ export default function GLStyleEditor(props: GLStyleEditorProps) { className="p-2 border-b border-black border-opacity-30 z-10 shadow flex space-x-2 flex-0" style={{ backgroundColor: "#303841" }} > - - - - { - if (mapContext.manager && props.geostats) { - mapContext.manager.map?.fitBounds(props.bounds!); - } - }} - label="Show Layer Extent" - /> - {props.tocItemId && ( - { - if (mapContext.manager && props.geostats) { - mapContext.manager.setVisibleTocItems([props.tocItemId!]); - } - }} - /> - )} - {}} - /> - - - + {props.tocItemId && ( + <> + + + + { + if (mapContext.manager && props.geostats) { + mapContext.manager.map?.fitBounds(props.bounds!); + } + }} + label="Show layer extent" + /> + {props.tocItemId && ( + { + if (mapContext.manager && props.geostats) { + mapContext.manager.setVisibleTocItems([ + props.tocItemId!, + ]); + } + }} + /> + )} + {props.geostats && ( + { + setGeostatsModal({ + layers: [props.geostats!], + layerCount: 1, + }); + }} + /> + )} + + + + )} @@ -262,8 +276,13 @@ export default function GLStyleEditor(props: GLStyleEditorProps) { }} keyCode={`${mac ? "⌘" : "^"}+F`} /> - - + + {props.tocItemId && ( + <> + + + + )} {layerTypes.map((type) => ( - - zoom{" "} - - {Math.round(zoom) === zoom ? zoom + ".0" : zoom} + {props.tocItemId && ( + + zoom{" "} + + {Math.round(zoom) === zoom ? zoom + ".0" : zoom} + - + )} @@ -379,30 +400,11 @@ export default function GLStyleEditor(props: GLStyleEditorProps) { } }} /> - {insertLayerOptions && ( - setInsertLayerOptions(null)} - options={insertLayerOptions} - onSelect={(option) => { - setInsertLayerOptions(null); - if (editorRef.current?.view) { - const editorView = editorRef.current?.view; - editorView.dispatch({ - changes: { - from: editorView.state.doc.length - 2, - to: editorView.state.doc.length - 2, - insert: - editorView.state.doc.length > 10 - ? "," + JSON.stringify(option.layer) - : JSON.stringify(option.layer), - }, - scrollIntoView: true, - selection: { - anchor: editorView.state.doc.length - 1, - }, - }); - formatJSONCommand(editorView); - } + {geostatsModal && ( + { + setGeostatsModal(null); }} /> )} diff --git a/packages/client/src/admin/data/GLStyleEditor/GeostatsModal.tsx b/packages/client/src/admin/data/GLStyleEditor/GeostatsModal.tsx new file mode 100644 index 000000000..d3a4c6f1c --- /dev/null +++ b/packages/client/src/admin/data/GLStyleEditor/GeostatsModal.tsx @@ -0,0 +1,107 @@ +/* eslint-disable i18next/no-literal-string */ +import Badge from "../../../components/Badge"; +import Modal from "../../../components/Modal"; +import { GeostatsLayer } from "./extensions/glStyleAutocomplete"; + +export interface Geostats { + layers: GeostatsLayer[]; + layerCount: number; +} + +interface GeostatsModalProps { + geostats: Geostats; + onRequestClose: () => void; +} + +/** + * Displays information about the layers included in the geostats prop. + * @param props + * @returns + */ +export default function GeostatsModal(props: GeostatsModalProps) { + return ( + +
+

Layers

+
+
+
    + {props.geostats.layers.map((layer) => ( +
  • +
    +
    +

    + {layer.layer} +

    +
    +

    + {layer.geometry} +

    +
    +
    +
    +
    +

    + {layer.count} features +

    +
    +
    + {layer.attributeCount} properties +
    +
    +
    +
    +
    +
    +
    +
    +
      + {layer.attributes.map((attribute) => ( + <> +
      +
      + + {attribute.attribute} + +
      +
      + + {attribute.type} + +
      +
      +
      + {attribute.type === "number" && + attribute.values.length > 10 + ? attribute.min !== undefined && + attribute.max !== undefined + ? `${attribute.min} - ${attribute.max}` + : `${attribute.values.length} values` + : attribute.values + .map((v) => + /,/.test(v?.toString() || "") + ? (v = `"${v}"`) + : v + ) + .join(", ")} +
      + + ))} +
    +
    +
    +
    +
    +
    +
  • + ))} +
+
+
+
+
+ ); +}