diff --git a/examples/basic/src/components/LoadingOverlay.tsx b/examples/basic/src/components/LoadingOverlay.tsx new file mode 100644 index 0000000..b438a3b --- /dev/null +++ b/examples/basic/src/components/LoadingOverlay.tsx @@ -0,0 +1,67 @@ +import { useEffect, useRef, useState } from 'react'; + +/** Shorter loads finish before the dialog appears, so small samples do not flash it. */ +const SHOW_DELAY_MS = 150; + +/** + * "Loading…" over the map while `visible`, put inside `` + * beside the collections it waits for. It does not block the map. + */ +export function LoadingOverlay({ visible }: { visible: boolean }) { + const [shown, setShown] = useState(false); + useEffect(() => { + if (!visible) { + setShown(false); + return; + } + const timer = setTimeout(() => setShown(true), SHOW_DELAY_MS); + return () => clearTimeout(timer); + }, [visible]); + if (!shown) return null; + return ( +
+
+
+
+ ); +} + +/** + * Whether any of a page's collections (``, ``, ``, + * ``) is still putting its states on the map. + * + * Spread `bind(key)` into each collection, one key per collection. A + * collection that stops being rendered while it loads gets no `onAddEnd`, so a + * key not bound in a render stops counting. + */ +export function useLoadingOverlay() { + const [active, setActive] = useState>(() => new Set()); + const bound = new Set(); + const boundRef = useRef(bound); + boundRef.current = bound; + + useEffect(() => { + setActive(current => { + const kept = [...current].filter(key => boundRef.current.has(key)); + return kept.length === current.size ? current : new Set(kept); + }); + }); + + const bind = (key: string) => { + bound.add(key); + return { + onAddStart: () => setActive(current => (current.has(key) ? current : new Set(current).add(key))), + onAddEnd: () => + setActive(current => { + if (!current.has(key)) return current; + const next = new Set(current); + next.delete(key); + return next; + }), + }; + }; + + return { active: active.size > 0, bind }; +} diff --git a/examples/basic/src/index.css b/examples/basic/src/index.css index fd4d79b..98440c6 100644 --- a/examples/basic/src/index.css +++ b/examples/basic/src/index.css @@ -1184,3 +1184,41 @@ body, .diagnostic.error { color: #b91c1c; } + +/* "Loading..." while a collection puts its states on the map (LoadingOverlay). */ +.loading-overlay { + position: absolute; + inset: 0; + display: flex; + align-items: center; + justify-content: center; + pointer-events: none; + z-index: 1500; +} + +.loading-overlay-dialog { + display: flex; + align-items: center; + gap: 10px; + padding: 12px 20px; + border-radius: 8px; + background: rgba(17, 24, 39, 0.85); + color: white; + font-size: 0.95rem; + box-shadow: 0 2px 12px rgba(0, 0, 0, 0.25); +} + +.loading-overlay-spinner { + width: 16px; + height: 16px; + border: 2px solid rgba(255, 255, 255, 0.35); + border-top-color: white; + border-radius: 50%; + animation: loading-overlay-spin 0.8s linear infinite; +} + +@keyframes loading-overlay-spin { + to { + transform: rotate(360deg); + } +} diff --git a/examples/basic/src/pages/MarkerPage.tsx b/examples/basic/src/pages/MarkerPage.tsx index fafce9f..f2d6ee2 100644 --- a/examples/basic/src/pages/MarkerPage.tsx +++ b/examples/basic/src/pages/MarkerPage.tsx @@ -3,6 +3,7 @@ import { createGeoPoint, createMarkerState, type MarkerState } from '@mapconduct import { Markers } from '@mapconductor/js-sdk-react'; import { Toast, useToast } from '../components/Toast'; import { MapViewContainer } from '../MapViewContainer'; +import { LoadingOverlay, useLoadingOverlay } from '../components/LoadingOverlay'; const INIT_CAMERA = { lat: 21.2910, lng: -157.8380, zoom: 12 }; @@ -13,6 +14,7 @@ const MARKER_DATA = [ ]; export function MarkerPage() { + const loading = useLoadingOverlay(); const { messages, showToast, dismissToast } = useToast(); const showToastRef = useRef(showToast); showToastRef.current = showToast; @@ -34,7 +36,8 @@ export function MarkerPage() { return ( - + + ); diff --git a/examples/basic/src/pages/PolygonPage.tsx b/examples/basic/src/pages/PolygonPage.tsx index 6dab823..2fa58f4 100644 --- a/examples/basic/src/pages/PolygonPage.tsx +++ b/examples/basic/src/pages/PolygonPage.tsx @@ -11,10 +11,12 @@ import { Toast, useToast } from '../components/Toast'; import { POLYGON_VERTICES } from '../data/storeData'; import { MapViewContainer } from '../MapViewContainer'; import { useSampleI18n } from '../samples/i18n'; +import { LoadingOverlay, useLoadingOverlay } from '../components/LoadingOverlay'; const INIT_CAMERA = { lat: 41.7969, lng: 140.7569, zoom: 16 }; export function PolygonPage() { + const loading = useLoadingOverlay(); const { t } = useSampleI18n(); const [vertices, setVertices] = useState(POLYGON_VERTICES); const [fillOpacity, setFillOpacity] = useState(0.3); @@ -68,7 +70,8 @@ export function PolygonPage() { return ( - + + (INITIAL_POINTS); const setPointsRef = useRef(setPoints); @@ -80,7 +82,8 @@ export function PolylinePage() { return ( - + +

{t( diff --git a/examples/basic/src/pages/circle/antennas/AntennaHorizonsPage.tsx b/examples/basic/src/pages/circle/antennas/AntennaHorizonsPage.tsx index f041b24..ae18394 100644 --- a/examples/basic/src/pages/circle/antennas/AntennaHorizonsPage.tsx +++ b/examples/basic/src/pages/circle/antennas/AntennaHorizonsPage.tsx @@ -3,6 +3,7 @@ import { createCircleState, createGeoPoint, type CircleEvent, type CircleState } import { Circles, InfoBubble } from '@mapconductor/js-sdk-react'; import { MapViewContainer } from '../../../MapViewContainer'; import { ControlPanel } from '../../../components/ControlPanel'; +import { LoadingOverlay, useLoadingOverlay } from '../../../components/LoadingOverlay'; import { decodeAntennas, type Antenna } from './antennaData'; const CARRIERS = ['AT&T', 'T-Mobile / Sprint', 'Verizon', 'Others']; @@ -24,6 +25,7 @@ export function AntennaHorizonsPage() { const [carriers, setCarriers] = useState([0, 1, 2, 3]); const [alaska, setAlaska] = useState(false); const [tap, setTap] = useState(null); + const loading = useLoadingOverlay(); useEffect(() => { const abort = new AbortController(); fetch('/antennas/us-antennas.bin', { signal: abort.signal }).then(r => { @@ -59,7 +61,8 @@ export function AntennaHorizonsPage() { const selection = useMemo(() => new CircleSelection(states), [states]); useEffect(() => { setTap(null); }, [states]); return setTap(null)}> - + + {tap &&

{CARRIERS[tap.carrier]}
Cell position · Display radius: 500 m
}
{error || (!data ? 'Loading OpenCellID data…' : `${states.length.toLocaleString()} / ${data.length.toLocaleString()} circles`)}
diff --git a/examples/basic/src/pages/circle/boston/StackCheck.tsx b/examples/basic/src/pages/circle/boston/StackCheck.tsx index d099875..a23df1e 100644 --- a/examples/basic/src/pages/circle/boston/StackCheck.tsx +++ b/examples/basic/src/pages/circle/boston/StackCheck.tsx @@ -1,6 +1,7 @@ import { useMemo } from 'react'; import { createGeoPoint, createMarkerState, createPolygonState, createPolylineState, type GeoPoint } from '@mapconductor/js-sdk-core'; import { Marker, Polygons, Polylines } from '@mapconductor/js-sdk-react'; +import { LoadingOverlay, useLoadingOverlay } from '../../../components/LoadingOverlay'; /** Opaque colours, so a pixel shows which one is on top. */ export const STACK_SQUARE_COLOR = '#7C3AED'; @@ -21,6 +22,7 @@ const MARKER_BELOW_ROAD = 0.0001; * in every cell; the road of the cell at the centre runs across the marker. */ export function StackCheck({ center }: { center: GeoPoint }) { + const loading = useLoadingOverlay(); const { squares, roads } = useMemo(() => { const squares = []; const roads = []; @@ -55,8 +57,9 @@ export function StackCheck({ center }: { center: GeoPoint }) { }), [center]); return ( <> - - + + + ); diff --git a/examples/basic/src/pages/groundimage/GroundImagePage.tsx b/examples/basic/src/pages/groundimage/GroundImagePage.tsx index 0696cb6..62d0a79 100644 --- a/examples/basic/src/pages/groundimage/GroundImagePage.tsx +++ b/examples/basic/src/pages/groundimage/GroundImagePage.tsx @@ -14,11 +14,13 @@ import { ControlPanel, SliderControl } from '../../components/ControlPanel'; import { Toast, useToast } from '../../components/Toast'; import { MapViewContainer } from '../../MapViewContainer'; import { useSampleI18n } from '../../samples/i18n'; +import { LoadingOverlay, useLoadingOverlay } from '../../components/LoadingOverlay'; const INIT_CAMERA = { lat: -26.479235, lng: 31.306239, zoom: 15 }; const GROUND_IMAGE_URL = `${import.meta.env.BASE_URL}university_of_eswatini.png`; export function GroundImagePage() { + const loading = useLoadingOverlay(); const { t } = useSampleI18n(); const { messages, showToast, dismissToast } = useToast(); const [southWest, setSouthWest] = useState(createGeoPoint({ latitude: -26.484901389754125, longitude: 31.2995982170105 })); @@ -110,7 +112,8 @@ export function GroundImagePage() { return ( - + + >( () => new Set(['marker_0', 'marker_1', 'marker_2']) ); @@ -48,7 +50,8 @@ export function MultipleBubblesPage() { return ( setSelectedMarkerIds(new Set())}> - + + {markers.map(marker => selectedMarkerIds.has(marker.id) ? ( diff --git a/examples/basic/src/pages/map/basic/StoreMapPage.tsx b/examples/basic/src/pages/map/basic/StoreMapPage.tsx index f395c51..613bbb3 100644 --- a/examples/basic/src/pages/map/basic/StoreMapPage.tsx +++ b/examples/basic/src/pages/map/basic/StoreMapPage.tsx @@ -11,6 +11,7 @@ import { InfoBubble, Markers } from '@mapconductor/js-sdk-react'; import { STORES, type StoreInfo } from '../../../data/storeData'; import { MapViewContainer } from '../../../MapViewContainer'; import { StoreInfoView } from './StoreInfoView'; +import { LoadingOverlay, useLoadingOverlay } from '../../../components/LoadingOverlay'; const INIT_CAMERA = { lat: 21.382314, lng: -157.933097, zoom: 10 }; @@ -22,6 +23,7 @@ const STORE_ICON_URLS: Record = { }; export function MapPage() { + const loading = useLoadingOverlay(); // Gets the mapViewState for controll map view. const [mapViewState, setMapViewState] = useState> | null>(null); // Holds the selected marker state. @@ -76,7 +78,8 @@ export function MapPage() { return ( setSelectedMarker(null)}> - + + {selectedMarker && ( diff --git a/examples/basic/src/pages/map/flyto/FlyToPage.tsx b/examples/basic/src/pages/map/flyto/FlyToPage.tsx index 1df6013..e32caf2 100644 --- a/examples/basic/src/pages/map/flyto/FlyToPage.tsx +++ b/examples/basic/src/pages/map/flyto/FlyToPage.tsx @@ -12,6 +12,7 @@ import { Markers, Polyline } from '@mapconductor/js-sdk-react'; import { ControlPanel } from '../../../components/ControlPanel'; import { MapViewContainer } from '../../../MapViewContainer'; import { useSampleI18n } from '../../../samples/i18n'; +import { LoadingOverlay, useLoadingOverlay } from '../../../components/LoadingOverlay'; const INIT_CAMERA = { lat: 35.0, lng: 0.0, zoom: 3 }; @@ -34,6 +35,7 @@ const CONNECTIONS = [ ] as const; function FlyToContent({ mapViewState }: { mapViewState: MapViewStateInterface> }) { + const loading = useLoadingOverlay(); const { t } = useSampleI18n(); const [icons, setIcons] = useState | null>(null); const [geodesic, setGeodesic] = useState(false); @@ -82,7 +84,8 @@ function FlyToContent({ mapViewState }: { mapViewState: MapViewStateInterface {polylines.map(polyline => )} - + + > | null>(null); return ( {ANCHOR_CIRCLES.map(circle => ( ))} - + + {mapViewState && } ); diff --git a/examples/basic/src/pages/marker/animation/MarkerAnimationPage.tsx b/examples/basic/src/pages/marker/animation/MarkerAnimationPage.tsx index fe6e5d2..3cf7135 100644 --- a/examples/basic/src/pages/marker/animation/MarkerAnimationPage.tsx +++ b/examples/basic/src/pages/marker/animation/MarkerAnimationPage.tsx @@ -3,6 +3,7 @@ import { Markers } from '@mapconductor/js-sdk-react'; import { ControlPanel } from '../../../components/ControlPanel'; import { MapViewContainer } from '../../../MapViewContainer'; import { useSampleI18n } from '../../../samples/i18n'; +import { LoadingOverlay, useLoadingOverlay } from '../../../components/LoadingOverlay'; // android の AnimationPageViewModel.kt / ios の AnimationPageViewModel.swift と同一仕様: // Drop / Bounce のラベルを持つ 2 マーカーを表示し、タップすると各マーカーに @@ -24,10 +25,12 @@ const MARKERS = SPOTS.map(spot => ); export function MarkerAnimationPage() { + const loading = useLoadingOverlay(); const { t } = useSampleI18n(); return ( - + + setSelected(null)}> - + + {typeof selected?.extra === 'string' && (
{selected.extra}
diff --git a/examples/basic/src/pages/marker/labelposition/MarkerLabelPositionPage.tsx b/examples/basic/src/pages/marker/labelposition/MarkerLabelPositionPage.tsx index f6c646a..ff83290 100644 --- a/examples/basic/src/pages/marker/labelposition/MarkerLabelPositionPage.tsx +++ b/examples/basic/src/pages/marker/labelposition/MarkerLabelPositionPage.tsx @@ -7,6 +7,7 @@ import { } from '@mapconductor/js-sdk-core'; import { InfoBubble, Markers } from '@mapconductor/js-sdk-react'; import { MapViewContainer } from '../../../MapViewContainer'; +import { LoadingOverlay, useLoadingOverlay } from '../../../components/LoadingOverlay'; // 信州大学(松本キャンパス)周辺に 3 × 3 で並べ、それぞれ違う labelPosition を付ける。 const CENTER = { latitude: 36.2526, longitude: 137.9828 }; @@ -20,6 +21,7 @@ const POSITIONS: MarkerLabelPosition[][] = [ ]; export function MarkerLabelPositionPage() { + const loading = useLoadingOverlay(); const [selectedId, setSelectedId] = useState(null); const markers = useMemo( () => @@ -47,7 +49,8 @@ export function MarkerLabelPositionPage() { return ( setSelectedId(null)}> - + + {selected ? ( labelPosition: "{selected.extra as string}" diff --git a/examples/basic/src/pages/marker/postoffice/PostOfficePage.tsx b/examples/basic/src/pages/marker/postoffice/PostOfficePage.tsx index 965b2e9..dc4700f 100644 --- a/examples/basic/src/pages/marker/postoffice/PostOfficePage.tsx +++ b/examples/basic/src/pages/marker/postoffice/PostOfficePage.tsx @@ -16,6 +16,7 @@ import { } from './PostOfficeMapProvider'; import { browserPostOfficeDataSource, type PostOfficeDataSource } from './postOfficeData'; import { usePostOfficeMarkers } from './usePostOfficeMarkers'; +import { LoadingOverlay, useLoadingOverlay } from '../../../components/LoadingOverlay'; const INITIAL_CAMERA = createMapCameraPosition({ position: createGeoPoint({ latitude: 35.68049, longitude: 139.76669 }), @@ -36,6 +37,7 @@ function PostOfficeContent({ renderMapView: PostOfficeMapContentProps['renderMapView']; dataSource: PostOfficeDataSource; }) { + const loading = useLoadingOverlay(); const { t } = useSampleI18n(); const [selected, setSelected] = useState(null); const selectMarker = useCallback((marker: MarkerState) => setSelected(marker), []); @@ -45,7 +47,8 @@ function PostOfficeContent({ return renderMapView( <> - + + {selected && } (null); const selectMarker = useCallback((marker: MarkerState) => setSelected(marker), []); @@ -89,7 +91,8 @@ export function StreetTreePage() { onCameraMoveEnd={relabel} onStateReady={applyTreeStyle} > - + + {selected && } buildStates(3, 0)); @@ -62,7 +64,8 @@ export function PolygonsPage() { return ( - + + (() => INITIAL_HOLES.map(hole => [...hole])); const setHolesRef = useRef(setHoles); @@ -101,7 +103,8 @@ export function PolygonHolePage() { return ( - + + { const out = []; const step = 0.0004, size = 0.0003; @@ -33,7 +35,8 @@ export function StackCheck({ center }: { center: GeoPoint }) { const marker = useMemo(() => createMarkerState({ id: 'stack-marker', position: center }), [center]); return ( <> - + + diff --git a/examples/basic/src/pages/polyline/click/PolylineClickPage.tsx b/examples/basic/src/pages/polyline/click/PolylineClickPage.tsx index 052eff9..53e8df6 100644 --- a/examples/basic/src/pages/polyline/click/PolylineClickPage.tsx +++ b/examples/basic/src/pages/polyline/click/PolylineClickPage.tsx @@ -12,10 +12,12 @@ import { Markers, Polyline } from '@mapconductor/js-sdk-react'; import { ControlPanel } from '../../../components/ControlPanel'; import { MapViewContainer } from '../../../MapViewContainer'; import { useSampleI18n } from '../../../samples/i18n'; +import { LoadingOverlay, useLoadingOverlay } from '../../../components/LoadingOverlay'; const INIT_CAMERA = { lat: 35.548852, lng: 139.784086, zoom: 4 }; export function PolylineClickPage() { + const loading = useLoadingOverlay(); const { t } = useSampleI18n(); const [clickMarkers, setClickMarkers] = useState([]); // The Android polyline-click sample draws no waypoint markers, so neither do @@ -52,7 +54,8 @@ export function PolylineClickPage() { - + +

{t( diff --git a/js-sdk-core b/js-sdk-core index fe3709b..47f6d0b 160000 --- a/js-sdk-core +++ b/js-sdk-core @@ -1 +1 @@ -Subproject commit fe3709b235f320455a8bf090a87dc47db1f8f1b4 +Subproject commit 47f6d0b59a634ebf916172a3cef32834f28530d5 diff --git a/js-sdk-react b/js-sdk-react index 076513c..d743b19 160000 --- a/js-sdk-react +++ b/js-sdk-react @@ -1 +1 @@ -Subproject commit 076513c3b97327ba5b2bb6097b227641d4ae0c38 +Subproject commit d743b19c639fde229bf1201665ce51d39f2a0167