mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-16 16:22:20 +00:00
feat(installations): add Navara renderer
This commit is contained in:
1 parent
965a82144c
commit
1a694baf5a
27 files changed
+1426
-47
No files matched your search
@@ -34,8 +34,13 @@ export const OPENMAPTILES_CREDIT = {
|
||||
key: 'openfreemap',
|
||||
html: 'Vector tiles: <a href="https://openfreemap.org" target="_blank" rel="noopener">OpenFreeMap</a> © <a href="https://openmaptiles.org" target="_blank" rel="noopener">OpenMapTiles</a>',
|
||||
};
|
||||
export const GOOGLE_PLACES_CREDIT = {
|
||||
key: 'google-maps-places',
|
||||
html: 'Google Maps Places: <a href="https://developers.google.com/maps/documentation/places/web-service/policies" target="_blank" rel="noopener">Google Maps</a>',
|
||||
};
|
||||
|
||||
const osmDisplays = new WeakMap();
|
||||
const googlePlacesDisplays = new WeakMap();
|
||||
const viewerCredits = new WeakMap();
|
||||
|
||||
/**
|
||||
@@ -114,6 +119,36 @@ export function hideOsmCredit(target, owner) {
|
||||
return true;
|
||||
}
|
||||
|
||||
/** Keep Places attribution visible only while a layer displays Places results. */
|
||||
export function showGooglePlacesCredit(target, owner) {
|
||||
const credits = creditsOf(target);
|
||||
if (!credits || !owner) return false;
|
||||
let state = googlePlacesDisplays.get(target);
|
||||
if (!state) {
|
||||
state = { owners: new Set(), remove: null };
|
||||
googlePlacesDisplays.set(target, state);
|
||||
}
|
||||
if (state.owners.has(owner)) return false;
|
||||
state.owners.add(owner);
|
||||
state.remove ||= credits.addStatic(GOOGLE_PLACES_CREDIT.html, {
|
||||
onScreen: true,
|
||||
});
|
||||
credits.request();
|
||||
return true;
|
||||
}
|
||||
|
||||
/** Release this layer's Places attribution when it stops displaying results. */
|
||||
export function hideGooglePlacesCredit(target, owner) {
|
||||
const state = googlePlacesDisplays.get(target);
|
||||
if (!state?.owners.delete(owner)) return false;
|
||||
if (!state.owners.size) {
|
||||
state.remove?.();
|
||||
state.remove = null;
|
||||
}
|
||||
creditsOf(target)?.request();
|
||||
return true;
|
||||
}
|
||||
|
||||
export const DATA_CREDITS = [
|
||||
// ── Live sources ────────────────────────────────────────────────
|
||||
{
|
||||
|
||||
@@ -160,16 +160,49 @@ test('data credits go through the globe engine credits', async () => {
|
||||
);
|
||||
});
|
||||
|
||||
test('Google Places attribution is visible only while a layer displays Places data', async () => {
|
||||
const { showGooglePlacesCredit, hideGooglePlacesCredit } =
|
||||
await import('./dataCredits.js');
|
||||
const { createFakeEngine } = await import('../globe/testing/fakeEngine.js');
|
||||
const engine = createFakeEngine();
|
||||
assert.equal(showGooglePlacesCredit(engine, 'installations'), true);
|
||||
assert.equal(showGooglePlacesCredit(engine, 'installations'), false);
|
||||
assert.equal(showGooglePlacesCredit(engine, 'other-layer'), true);
|
||||
const visible = engine.fake.credits.filter(({ onScreen }) => onScreen);
|
||||
assert.equal(visible.length, 1);
|
||||
assert.match(visible[0].html, /Google Maps Places/);
|
||||
assert.match(
|
||||
visible[0].html,
|
||||
/developers\.google\.com\/maps\/documentation\/places/,
|
||||
);
|
||||
assert.ok(engine.fake.callsOf('render.request').length > 0);
|
||||
assert.equal(hideGooglePlacesCredit(engine, 'installations'), true);
|
||||
assert.equal(
|
||||
engine.fake.credits.filter(({ onScreen }) => onScreen).length,
|
||||
1,
|
||||
);
|
||||
assert.equal(hideGooglePlacesCredit(engine, 'other-layer'), true);
|
||||
assert.equal(hideGooglePlacesCredit(engine, 'installations'), false);
|
||||
assert.equal(
|
||||
engine.fake.credits.filter(({ onScreen }) => onScreen).length,
|
||||
0,
|
||||
);
|
||||
});
|
||||
|
||||
test('without a viewer or engine the OSM and dynamic credits skip cleanly', async () => {
|
||||
const {
|
||||
registerDataCredits,
|
||||
registerDynamicCredit,
|
||||
showOsmCredit,
|
||||
hideOsmCredit,
|
||||
showGooglePlacesCredit,
|
||||
hideGooglePlacesCredit,
|
||||
} = await import('./dataCredits.js');
|
||||
// The Navara mode has no viewer; a layer-side call with it must not throw.
|
||||
assert.doesNotThrow(() => registerDataCredits(null, [{ html: 'A' }]));
|
||||
assert.equal(showOsmCredit(null, 'owner'), false);
|
||||
assert.equal(hideOsmCredit(null, 'owner'), false);
|
||||
assert.equal(showGooglePlacesCredit(null, 'owner'), false);
|
||||
assert.equal(hideGooglePlacesCredit(null, 'owner'), false);
|
||||
assert.equal(registerDynamicCredit(null, { key: 'k', html: 'K' }), false);
|
||||
});
|
||||
@@ -121,7 +121,7 @@ test('every scene click handler consults ownership before it picks', () => {
|
||||
['src/layers/bikeshare/selection.js', 'viewer.scene.pick(click.position)'],
|
||||
['src/layers/firms/selection.js', 'scene.pick(click.position)'],
|
||||
[
|
||||
'src/layers/installations/selection.js',
|
||||
'src/layers/installations/render/cesium/selection.js',
|
||||
'viewer.scene.pick(click.position)',
|
||||
],
|
||||
['src/layers/launches/render/cesium.js', 'drillPick(movement.position'],
|
||||
|
||||
@@ -276,13 +276,18 @@ test('tracking layers write gevLabelModel and expose only their cached display p
|
||||
'flights.js',
|
||||
'militaryFlights.js',
|
||||
'satellites.js',
|
||||
'militaryInstallations.js',
|
||||
].map(async (name) => [name, readLayerSource(new URL(`./${name}`, import.meta.url))]));
|
||||
const sources = Object.fromEntries(files);
|
||||
for (const [name, source] of files) {
|
||||
assert.ok(source.includes('.gevLabelModel ='), `${name} writes the explicit model directly`);
|
||||
assert.ok(source.includes('.gevDisplayPosition ='), `${name} exposes a display-position cache`);
|
||||
}
|
||||
const installations = await readFile(
|
||||
new URL('../layers/installations/render/cesium/rendering.js', import.meta.url),
|
||||
'utf8',
|
||||
);
|
||||
assert.ok(installations.includes('entity.gevLabelModel ='));
|
||||
assert.ok(installations.includes('entity.gevDisplayPosition = () => displayPosition'));
|
||||
assert.match(sources['flights.js'], /gevDisplayPosition\s*=\s*parts\.motion\._trackedDisplayCached/);
|
||||
assert.match(sources['militaryFlights.js'], /gevDisplayPosition\s*=\s*parts\.motion\._trackedDisplayCached/);
|
||||
assert.ok(sources['satellites.js'].includes('gevDisplayPosition = _trackedDisplayCached'));
|
||||
|
||||
Reference in new issue
Block a user