Skip to content

Commit 5a64660

Browse files
committed
feat: implement loadWebdggrid utility for dynamic loading of Webdggrid class and update components to use it
1 parent 4767dd8 commit 5a64660

File tree

7 files changed

+35
-5
lines changed

7 files changed

+35
-5
lines changed

docs/.vitepress/theme/components/DggsAddressTypesDemo.vue

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<script setup>
22
import { computed, nextTick, onMounted, reactive, ref } from 'vue'
3+
import { loadWebdggrid } from '../utils/loadWebdggrid.js'
34
45
const svgRef = ref(null)
56
const info = ref('')
@@ -41,7 +42,7 @@ let d3 = null
4142
4243
onMounted(async () => {
4344
await loadScript('https://cdn.jsdelivr.net/npm/d3@7/dist/d3.min.js')
44-
const { Webdggrid } = await import('webdggrid')
45+
const Webdggrid = await loadWebdggrid()
4546
dggs = await Webdggrid.load()
4647
d3 = window.d3
4748
applySettings()

docs/.vitepress/theme/components/DggsD3Globe.vue

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<script setup>
22
import { ref, onMounted, onUnmounted } from 'vue'
33
import { VPButton } from 'vitepress/theme'
4+
import { loadWebdggrid } from '../utils/loadWebdggrid.js'
45
56
const props = defineProps({
67
resolution: { type: Number, default: 3 },
@@ -245,7 +246,7 @@ onMounted(async () => {
245246
246247
try {
247248
await loadScript('https://cdn.jsdelivr.net/npm/d3@7/dist/d3.min.js')
248-
const { Webdggrid } = await new Function('return import("https://cdn.jsdelivr.net/npm/webdggrid/dist/index.js")')()
249+
const Webdggrid = await loadWebdggrid()
249250
webdggrid = await Webdggrid.load()
250251
251252
const rect = wrapRef.value.getBoundingClientRect()

docs/.vitepress/theme/components/DggsD3HierarchyDemo.vue

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<script setup>
22
import { computed, nextTick, onMounted, reactive, ref } from 'vue'
3+
import { loadWebdggrid } from '../utils/loadWebdggrid.js'
34
45
const svgRef = ref(null)
56
const info = ref('')
@@ -38,7 +39,7 @@ let d3 = null
3839
3940
onMounted(async () => {
4041
await loadScript('https://cdn.jsdelivr.net/npm/d3@7/dist/d3.min.js')
41-
const { Webdggrid } = await import('webdggrid')
42+
const Webdggrid = await loadWebdggrid()
4243
dggs = await Webdggrid.load()
4344
d3 = window.d3
4445
applySettings()

docs/.vitepress/theme/components/DggsGlobe.vue

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<script setup>
22
import { ref, reactive, computed, onMounted, onUnmounted, watch } from 'vue'
33
import { ylOrBrRgba, processFcForGlobe } from '../utils/globeUtils.js'
4+
import { loadWebdggrid } from '../utils/loadWebdggrid.js'
45
56
const props = defineProps({
67
/** Show OSM raster basemap */
@@ -547,7 +548,7 @@ onMounted(async () => {
547548
loadScript('https://unpkg.com/deck.gl@9/dist.min.js'),
548549
])
549550
550-
const { Webdggrid } = await import('webdggrid')
551+
const Webdggrid = await loadWebdggrid()
551552
552553
const isDark = document.documentElement.classList.contains('dark')
553554
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/**
2+
* Load the Webdggrid class, trying the local build first (available in dev via
3+
* Vite alias) and falling back to the jsDelivr CDN for production builds.
4+
*/
5+
export async function loadWebdggrid() {
6+
try {
7+
const mod = await import('webdggrid')
8+
if (mod.Webdggrid) return mod.Webdggrid
9+
} catch { /* local build not available */ }
10+
11+
// Fallback: CDN (works in production where the Vite alias doesn't exist)
12+
const mod = await new Function(
13+
'return import("https://cdn.jsdelivr.net/npm/webdggrid/dist/webdggrid.js")'
14+
)()
15+
return mod.Webdggrid
16+
}

docs/getting-started.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,10 @@ const distkm = dggs.cellDistKM(3); // average cell spacing in km
8383

8484
## Live Demo
8585

86-
See the [interactive globe demo](/demo) for a live example with topology switching, multi-aperture grids, hierarchical cell selection, and drag-to-rotate.
86+
- [Globe Demo](/demo) — interactive MapLibre globe with topology switching, multi-aperture grids, and hierarchical cell selection
87+
- [Hierarchical Operations Demo](/hierarchical-operations#interactive-demo) — explore parent, children, and neighbor relationships
88+
- [Address Types Demo](/hierarchical-addresses#interactive-demo) — compare index types and see bitwise digit breakdowns
89+
- [Index Arithmetic Demo](/index-arithmetic#interactive-demo) — live demonstration of digit manipulation on Z3, Z7, and ZORDER indices
8790

8891
## API Overview
8992

readme.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,13 @@ const seqNum = dggs.geoToSequenceNum([[0, 0]]);
5959
```
6060
6161
62+
## Live Demos
63+
64+
- [Globe Demo](https://am2222.github.io/webDggrid/demo) — interactive MapLibre globe with topology switching, multi-aperture grids, and hierarchical cell selection
65+
- [Hierarchical Operations Demo](https://am2222.github.io/webDggrid/hierarchical-operations#interactive-demo) — explore parent, children, and neighbor relationships
66+
- [Address Types Demo](https://am2222.github.io/webDggrid/hierarchical-addresses#interactive-demo) — compare index types and see bitwise digit breakdowns
67+
- [Index Arithmetic Demo](https://am2222.github.io/webDggrid/index-arithmetic#interactive-demo) — live demonstration of digit manipulation on Z3, Z7, and ZORDER indices
68+
6269
## API
6370
6471
### Lifecycle

0 commit comments

Comments
 (0)