Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions examples/basic/public/antennas/carrier-att.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions examples/basic/public/antennas/carrier-others.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions examples/basic/public/antennas/carrier-tmobile.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions examples/basic/public/antennas/carrier-verizon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
25 changes: 25 additions & 0 deletions examples/basic/src/components/BelowMapCard.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { createContext, useContext, type ReactNode } from 'react';
import { createPortal } from 'react-dom';

/** The element under the map stage where SamplePageLayout puts a page's below-map card. */
export const BelowMapSlot = createContext<HTMLElement | null>(null);

/**
* A sample's options as a card under the map instead of a ControlPanel over it, for pages
* whose controls would hide too much of the map.
*
* The page renders inside the map stage, so the card is portalled out to the layout's slot.
* The slot is only known after mount, which also keeps the server-rendered page (where
* portals do not render) and the first client paint the same.
*/
export function BelowMapCard({ title, children }: { title: string; children: ReactNode }) {
const slot = useContext(BelowMapSlot);
if (!slot) return null;
return createPortal(
<section className="below-map-card">
<h3 className="below-map-card-title">{title}</h3>
{children}
</section>,
slot,
);
}
83 changes: 44 additions & 39 deletions examples/basic/src/components/SamplePageLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import type { SupportedLanguage } from '../samples/sampleRegistry';
import { SamplePageSeo } from '../samples/SamplePageSeo';
import { SampleDocumentation } from './SampleDocumentation';
import { SampleIntroOverlay } from './SampleIntroOverlay';
import { BelowMapSlot } from './BelowMapCard';
import { translate } from '../samples/i18n';

export function SamplePageLayout({
Expand All @@ -17,6 +18,7 @@ export function SamplePageLayout({
children?: ReactNode;
}) {
const { stageRef, fullscreen, toggleFullscreen } = useMapFullscreen();
const [belowMap, setBelowMap] = useState<HTMLElement | null>(null);
const labels = {
enter: translate(language, { en: 'Full screen', ja: '全画面表示', 'es-419': 'Pantalla completa', de: 'Vollbild', th: 'เต็มหน้าจอ', hi: 'फ़ुल स्क्रीन' }),
exit: translate(language, { en: 'Exit full screen', ja: '全画面表示を終了', 'es-419': 'Salir de pantalla completa', de: 'Vollbild beenden', th: 'ออกจากโหมดเต็มหน้าจอ', hi: 'फ़ुल स्क्रीन से बाहर निकलें' }),
Expand All @@ -33,47 +35,50 @@ export function SamplePageLayout({
}

return (
<div className="sample-page-layout">
<SamplePageSeo page={page} provider={provider} language={language} />
<div className="sample-map-padding">
<div ref={stageRef} className={`sample-map-stage${fullscreen ? ' is-fullscreen' : ''}`}>
{/* Camera Sync has its own full screen, for both of its maps. */}
{page !== 'camera-sync' && <button
type="button"
className="map-fullscreen-button"
aria-pressed={fullscreen}
aria-label={fullscreen ? labels.exit : labels.enter}
title={fullscreen ? labels.exit : labels.enter}
onClick={toggleFullscreen}
>
<svg viewBox="0 0 24 24" width="20" height="20" aria-hidden="true">
{fullscreen ? (
<path d="M9 4v5H4M15 4v5h5M9 20v-5H4M15 20v-5h5" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" />
) : (
<path d="M4 9V4h5M20 9V4h-5M4 15v5h5M20 15v5h-5" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" />
)}
</svg>
</button>}
{children ?? (
<div className="sample-map-placeholder" aria-hidden="true">
{translate(
language,
{
en: 'Loading map…',
ja: '地図を読み込んでいます…',
'es-419': 'Cargando el mapa…',
de: 'Karte wird geladen…',
th: 'กำลังโหลดแผนที่…',
hi: 'मैप लोड हो रहा है…',
},
)}
</div>
)}
<SampleIntroOverlay page={page} language={language} />
<BelowMapSlot.Provider value={belowMap}>
<div className="sample-page-layout">
<SamplePageSeo page={page} provider={provider} language={language} />
<div className="sample-map-padding">
<div ref={stageRef} className={`sample-map-stage${fullscreen ? ' is-fullscreen' : ''}`}>
{/* Camera Sync has its own full screen, for both of its maps. */}
{page !== 'camera-sync' && <button
type="button"
className="map-fullscreen-button"
aria-pressed={fullscreen}
aria-label={fullscreen ? labels.exit : labels.enter}
title={fullscreen ? labels.exit : labels.enter}
onClick={toggleFullscreen}
>
<svg viewBox="0 0 24 24" width="20" height="20" aria-hidden="true">
{fullscreen ? (
<path d="M9 4v5H4M15 4v5h5M9 20v-5H4M15 20v-5h5" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" />
) : (
<path d="M4 9V4h5M20 9V4h-5M4 15v5h5M20 15v5h-5" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" />
)}
</svg>
</button>}
{children ?? (
<div className="sample-map-placeholder" aria-hidden="true">
{translate(
language,
{
en: 'Loading map…',
ja: '地図を読み込んでいます…',
'es-419': 'Cargando el mapa…',
de: 'Karte wird geladen…',
th: 'กำลังโหลดแผนที่…',
hi: 'मैप लोड हो रहा है…',
},
)}
</div>
)}
<SampleIntroOverlay page={page} language={language} />
</div>
</div>
<div ref={setBelowMap} className="below-map-slot" />
<SampleDocumentation page={page} provider={provider} language={language} />
</div>
<SampleDocumentation page={page} provider={provider} language={language} />
</div>
</BelowMapSlot.Provider>
);
}

Expand Down
15 changes: 15 additions & 0 deletions examples/basic/src/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -561,6 +561,21 @@ body,
outline-offset: 2px;
}

.below-map-card {
margin: 0 min(15px, 10vmin) min(15px, 10vmin);
padding: 16px;
border: 1px solid #d9dde7;
border-radius: 8px;
background: #ffffff;
color: #1f2937;
box-shadow: 0 2px 10px rgba(15, 23, 42, 0.08);
}

.below-map-card-title {
margin: 0 0 8px;
font-size: 16px;
}

.sample-documentation {
margin: 0 min(15px, 10vmin) min(15px, 10vmin);
padding: clamp(16px, 3vw, 28px);
Expand Down
43 changes: 29 additions & 14 deletions examples/basic/src/pages/circle/antennas/AntennaHorizonsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,17 @@
import { createCircleState, createGeoPoint, type CircleEvent, type CircleState } from '@mapconductor/js-sdk-core';
import { Circles, InfoBubble } from '@mapconductor/js-sdk-react';
import { MapViewContainer } from '../../../MapViewContainer';
import { ControlPanel } from '../../../components/ControlPanel';
import { BelowMapCard } from '../../../components/BelowMapCard';
import { LoadingOverlay, useLoadingOverlay } from '../../../components/LoadingOverlay';

import { decodeAntennas, type Antenna } from './antennaData';
const CARRIERS = ['AT&T', 'T-Mobile / Sprint', 'Verizon', 'Others'];
const COLORS = ['37,99,235', '219,39,119', '217,119,6', '100,116,139'];
const STROKE_COLORS = COLORS.map(color => `rgba(${color},0.35)`);
const FILL_COLORS = COLORS.map(color => `rgba(${color},0.65)`);
// Drawn for this sample in the carrier's circle colour (not the carriers' logos); the
// Android and iOS samples ship the same drawing.
const CARRIER_ICONS = ['att', 'tmobile', 'verizon', 'others'].map(name => `/antennas/carrier-${name}.svg`);

// Keep the population out of React's development performance-entry payload.
class CircleSelection implements Iterable<CircleState> {
Expand Down Expand Up @@ -67,28 +70,40 @@
return () => { cancelled = true; };
}, [data]);
const preparing = data != null && allStates.length !== data.length;
const counts = useMemo(() => {
const result = [0, 0, 0, 0];
for (const row of data ?? []) result[row.carrier]++;
return result;
}, [data]);
const states = useMemo(() => {
if (carriers.length === CARRIERS.length) return allStates;
if (!data || carriers.length === 0 || preparing) return [];

Check warning on line 75 in examples/basic/src/pages/circle/antennas/AntennaHorizonsPage.tsx

View workflow job for this annotation

GitHub Actions / Unit tests

react-hooks(exhaustive-deps)

examples/basic/src/pages/circle/antennas/AntennaHorizonsPage.tsx:75:43: React Hook useMemo has a missing dependency: 'preparing'
return allStates.filter((_, index) => carriers.includes(data[index].carrier));
}, [allStates, data, carriers]);
const selection = useMemo(() => new CircleSelection(states), [states]);
useEffect(() => { setTap(null); }, [states]);
return <MapViewContainer key={String(alaska)} initialCamera={alaska ? { lat: 64, lng: -150, zoom: 5 } : { lat: 39, lng: -98, zoom: 4 }} onMapClick={() => setTap(null)}>
<Circles states={selection} {...loading.bind('circles')} />
<LoadingOverlay visible={loading.active || preparing} />
{tap && <InfoBubble position={createGeoPoint(tap)}><div>{CARRIERS[tap.carrier]}<br />Cell position · Display radius: 500 m</div></InfoBubble>}
<ControlPanel title="US cell positions (MCC 310–314)">
return <>
<MapViewContainer key={String(alaska)} initialCamera={alaska ? { lat: 64, lng: -150, zoom: 5 } : { lat: 39, lng: -98, zoom: 4 }} onMapClick={() => setTap(null)}>
<Circles states={selection} {...loading.bind('circles')} />
<LoadingOverlay visible={loading.active || preparing} />
{tap && <InfoBubble position={createGeoPoint(tap)}><div>{CARRIERS[tap.carrier]}<br />Cell position · Display radius: 500 m</div></InfoBubble>}
</MapViewContainer>
<BelowMapCard title="US cell positions (MCC 310–314)">
<div>{error || (!data ? 'Loading OpenCellID data…' : `${states.length.toLocaleString()} / ${data.length.toLocaleString()} circles`)}</div>
<button onClick={() => setAlaska(!alaska)}>{alaska ? 'US overview' : 'Alaska'}</button>
{CARRIERS.map((name, index) => <label key={name} style={{ display: 'block' }}><input type="checkbox" checked={carriers.includes(index)} onChange={e => setCarriers(current => e.target.checked ? [...current, index] : current.filter(c => c !== index))} />{name} ({counts[index].toLocaleString()})</label>)}
<div style={{ display: 'flex', gap: 6, margin: '8px 0' }}>
{CARRIERS.map((name, index) => {
const on = carriers.includes(index);
return <button key={name} type="button" aria-pressed={on} title={name}
onClick={() => setCarriers(current => on ? current.filter(c => c !== index) : [...current, index])}
style={{
flex: '1 1 0', display: 'flex', flexDirection: 'column', alignItems: 'center', gap: 4,
padding: '6px 2px', borderRadius: 8, cursor: 'pointer', background: 'transparent',
border: `2px solid ${on ? `rgb(${COLORS[index]})` : 'transparent'}`,
color: 'inherit', font: 'inherit', fontSize: 12, lineHeight: 1.2, opacity: on ? 1 : 0.45,
}}>
<img src={CARRIER_ICONS[index]} alt="" width={32} height={32} style={{ filter: on ? undefined : 'grayscale(1)' }} />
{name}
</button>;
})}
</div>
<p>Cell positions shown as 500 m radius circles; not signal coverage. Showing all cells for the selected carriers. MCC 310–314; not a complete tower inventory.</p>
<div>Cell tower data from <a href="https://opencellid.org">OpenCellID</a> · <a href="https://creativecommons.org/licenses/by-sa/4.0/">CC BY-SA 4.0</a></div>
</ControlPanel>
</MapViewContainer>;
</BelowMapCard>
</>;
}
Loading