Skip to content

Commit

Permalink
refactor: use components
Browse files Browse the repository at this point in the history
  • Loading branch information
sagewall committed Oct 17, 2024
1 parent 0a520fa commit 24df728
Show file tree
Hide file tree
Showing 8 changed files with 809 additions and 780 deletions.
1,356 changes: 720 additions & 636 deletions package-lock.json

Large diffs are not rendered by default.

27 changes: 14 additions & 13 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,29 +11,30 @@
"preview": "vite preview"
},
"dependencies": {
"@arcgis/core": "^4.30.0",
"@esri/calcite-components-react": "2.8.5",
"@arcgis/map-components-react": "^4.31.0-next.129",
"@esri/calcite-components-react": "^2.13.1",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"react-router-dom": "^6.23.1"
"react-router-dom": "^6.27.0"
},
"devDependencies": {
"@eslint/js": "^9.5.0",
"@types/react": "^18.3.3",
"@types/react-dom": "^18.3.0",
"@eslint/js": "^9.12.0",
"@types/node": "^22.7.6",
"@types/react": "^18.3.11",
"@types/react-dom": "^18.3.1",
"@typescript-eslint/eslint-plugin": "^7.13.1",
"@typescript-eslint/parser": "^7.13.1",
"@vitejs/plugin-react": "^4.3.1",
"@vitejs/plugin-react": "^4.3.2",
"eslint": "^8.57.0",
"eslint-plugin-react": "^7.34.3",
"eslint-plugin-react": "^7.37.1",
"eslint-plugin-react-hooks": "^4.6.2",
"eslint-plugin-react-refresh": "^0.4.7",
"globals": "^15.6.0",
"prettier": "^3.3.2",
"rollup-plugin-bundle-stats": "^4.13.3",
"globals": "^15.11.0",
"prettier": "^3.3.3",
"rollup-plugin-bundle-stats": "^4.16.0",
"rollup-plugin-visualizer": "^5.12.0",
"typescript": "^5.4.0",
"typescript": "^5.6.3",
"typescript-eslint": "^7.13.1",
"vite": "^5.3.1"
"vite": "^5.4.9"
}
}
64 changes: 35 additions & 29 deletions src/components/MapView.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import type Graphic from "@arcgis/core/Graphic";
import type Collection from "@arcgis/core/core/Collection";
import type ArcMapView from "@arcgis/core/views/MapView";
import Point from "@arcgis/core/geometry/Point";
import type { ArcgisMapCustomEvent } from "@arcgis/map-components";
import { ArcgisMap, ArcgisPlacement } from "@arcgis/map-components-react";
import { CalciteAction } from "@esri/calcite-components-react";
import React, { useEffect, useRef, useState } from "react";

const viewStyles = {
Expand All @@ -13,42 +16,45 @@ interface MapViewProps {
}

const MapView = ({ graphics }: MapViewProps) => {
const viewDivRef = useRef<HTMLDivElement>(null);

const [mounted, setMounted] = useState(true);
const [view, setView] = useState<ArcMapView | null>(null);

useEffect(() => {
if (viewDivRef.current) {
const loadMapView = async () => {
const { createMapView } = await import("./lib/mapview");
setView(await createMapView(viewDivRef.current as HTMLDivElement, graphics));
};
loadMapView();

return () => {
view && view.destroy();
};
}
}, []);
const arcgisMap = useRef<HTMLArcgisMapElement>(null);

useEffect(() => {
setMounted(true);
}, [view]);
}, []);

useEffect(() => {
if (view) {
const loadGraphics = async () => {
if (graphics) {
view.graphics = graphics;
}
};
loadGraphics();
}
}, [view, graphics]);
const handleArcgisViewReadyChange = (event: ArcgisMapCustomEvent<void>) => {
event.target.center = new Point({ longitude: -117.1957098, latitude: 34.0564505 });
event.target.zoom = 18;
};

return (
<React.Fragment>{mounted && <div style={viewStyles} ref={viewDivRef}></div>}</React.Fragment>
<React.Fragment>
{mounted && (
<ArcgisMap
basemap="gray-vector"
graphics={graphics}
onArcgisViewReadyChange={(event) => {
handleArcgisViewReadyChange(event);
}}
ref={arcgisMap}
style={viewStyles}
>
<ArcgisPlacement position="top-right">
<CalciteAction
icon="zoom-to-object"
scale="s"
text="Zoom to Graphics"
textEnabled
onClick={() => {
arcgisMap.current?.goTo(arcgisMap.current.graphics);
}}
></CalciteAction>
</ArcgisPlacement>
</ArcgisMap>
)}
</React.Fragment>
);
};

Expand Down
64 changes: 35 additions & 29 deletions src/components/SceneView.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import type Graphic from "@arcgis/core/Graphic";
import type Collection from "@arcgis/core/core/Collection";
import type ArcSceneView from "@arcgis/core/views/SceneView";
import Point from "@arcgis/core/geometry/Point";
import type { ArcgisSceneCustomEvent } from "@arcgis/map-components";
import { ArcgisPlacement, ArcgisScene } from "@arcgis/map-components-react";
import { CalciteAction } from "@esri/calcite-components-react";
import React, { useEffect, useRef, useState } from "react";

const viewStyles = {
Expand All @@ -13,42 +16,45 @@ interface SceneViewProps {
}

const SceneView = ({ graphics }: SceneViewProps) => {
const viewDivRef = useRef<HTMLDivElement>(null);

const [mounted, setMounted] = useState(true);
const [view, setView] = useState<ArcSceneView | null>(null);

useEffect(() => {
if (viewDivRef.current) {
const loadSceneView = async () => {
const { createSceneView } = await import("./lib/sceneview");
setView(await createSceneView(viewDivRef.current as HTMLDivElement, graphics));
};
loadSceneView();

return () => {
view && view.destroy();
};
}
}, []);
const arcgisScene = useRef<HTMLArcgisSceneElement>(null);

useEffect(() => {
setMounted(true);
}, [view]);
}, []);

useEffect(() => {
if (view) {
const loadGraphics = async () => {
if (graphics) {
view.graphics = graphics;
}
};
loadGraphics();
}
}, [view, graphics]);
const handleArcgisViewReadyChange = (event: ArcgisSceneCustomEvent<void>) => {
event.target.center = new Point({ longitude: -117.1957098, latitude: 34.0564505 });
event.target.view.zoom = 17;
};

return (
<React.Fragment>{mounted && <div style={viewStyles} ref={viewDivRef}></div>}</React.Fragment>
<React.Fragment>
{mounted && (
<ArcgisScene
basemap="gray-vector"
graphics={graphics}
onArcgisViewReadyChange={(event) => {
handleArcgisViewReadyChange(event);
}}
ref={arcgisScene}
style={viewStyles}
>
<ArcgisPlacement position="top-right">
<CalciteAction
icon="zoom-to-object"
scale="s"
text="Zoom to Graphics"
textEnabled
onClick={() => {
arcgisScene.current?.goTo(arcgisScene.current.graphics);
}}
></CalciteAction>
</ArcgisPlacement>
</ArcgisScene>
)}
</React.Fragment>
);
};

Expand Down
35 changes: 0 additions & 35 deletions src/components/lib/mapview.ts

This file was deleted.

36 changes: 0 additions & 36 deletions src/components/lib/sceneview.ts

This file was deleted.

5 changes: 4 additions & 1 deletion src/main.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import "@arcgis/core/assets/esri/themes/light/main.css";
import "@arcgis/map-components/dist/components/arcgis-map";
import "@arcgis/map-components/dist/components/arcgis-placement";
import "@arcgis/map-components/dist/components/arcgis-scene";
import "@esri/calcite-components/dist/calcite/calcite.css";
import { setAssetPath } from "@esri/calcite-components/dist/components";
import "@esri/calcite-components/dist/components/calcite-action";
Expand Down Expand Up @@ -48,7 +51,7 @@ import SimpleMarkerSymbolPage from "./pages/simple-marker-symbol";
import TextSymbolPage from "./pages/text-symbol";
import WebStyleSymbolPage from "./pages/web-style-symbol";

setAssetPath("https://js.arcgis.com/calcite-components/2.8.5/assets");
setAssetPath("https://js.arcgis.com/calcite-components/2.13.1/assets");

const router = createBrowserRouter(
[
Expand Down
2 changes: 1 addition & 1 deletion vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export default defineConfig(({ mode }) => {
return {
base: env.VITE_BASE_NAME,
build: {
chunkSizeWarningLimit: 2500
chunkSizeWarningLimit: 2600
},
plugins: [
bundleStats({
Expand Down

0 comments on commit 24df728

Please sign in to comment.