diff --git a/src/routerModule/util.spec.ts b/src/routerModule/util.spec.ts index ac15ff5981b022ed662be9c7796e07fff9e941a0..b2ed55ea82db7f09f581114c2157a40ad2731bb6 100644 --- a/src/routerModule/util.spec.ts +++ b/src/routerModule/util.spec.ts @@ -6,6 +6,8 @@ import { cvtFullRouteToState, cvtStateToHashedRoutes, DummyCmp, routes } from '. import { encodeNumber } from './cipher' import { Router } from '@angular/router' import { RouterTestingModule } from '@angular/router/testing' +import * as parsedRoute from './parseRouteToTmplParcReg' +import { spaceMiscInfoMap } from 'src/util/pureConstant.service' describe('> util.ts', () => { describe('> cvtFullRouteToState', () => { @@ -61,6 +63,53 @@ describe('> util.ts', () => { }) }) + describe('> navigation', () => { + let parseSpy: jasmine.Spy + let mapGetSpy: jasmine.Spy + beforeEach(() => { + parseSpy = spyOnProperty(parsedRoute, 'parseSearchParamForTemplateParcellationRegion') + mapGetSpy = spyOn(spaceMiscInfoMap, 'get') + }) + it('> if not present, should show something palatable', () => { + parseSpy.and.returnValue(() => ({ + parcellationSelected: { + id: 'dummpy-id-parc' + }, + regionsSelected: [], + templateSelected: { + id: 'dummpy-id-tmpl-sel' + }, + })) + + const scale = 0.25 + + mapGetSpy.and.returnValue({ scale }) + + const router = TestBed.inject(Router) + const route = `/a:juelich:iav:atlas:v1.0.0:1/t:minds:core:referencespace:v1.0.0:dafcffc5-4826-4bf1-8ff6-46b8a31ff8e2/p:minds:core:parcellationatlas:v1.0.0:94c1125b-b87e-45e4-901c-00daee7f2579-290` + const parsedUrl = router.parseUrl(route) + const { viewerState = {} } = cvtFullRouteToState(parsedUrl, {}) || {} + const { navigation } = viewerState + const { + orientation, + perspectiveOrientation, + position, + zoom, + perspectiveZoom, + } = navigation + + expect(orientation).toEqual([0,0,0,1]) + expect(perspectiveOrientation).toEqual([ + 0.3140767216682434, + -0.7418519854545593, + 0.4988985061645508, + -0.3195493221282959 + ]) + expect(position).toEqual([0,0,0]) + expect(zoom).toEqual(350000 * scale) + expect(perspectiveZoom).toEqual(1922235.5293810747 * scale) + }) + }) }) describe('> cvtStateToHashedRoutes', () => { diff --git a/src/routerModule/util.ts b/src/routerModule/util.ts index 21ccdc6e7bbbb9bab69a399a96ac388d5fbc7439..e0115ee6268f033cf55a17e1ddac3c39e1b8839f 100644 --- a/src/routerModule/util.ts +++ b/src/routerModule/util.ts @@ -18,6 +18,7 @@ import { parseSearchParamForTemplateParcellationRegion, encodeId, } from './parseRouteToTmplParcReg' +import { spaceMiscInfoMap } from "src/util/pureConstant.service" const endcodePath = (key: string, val: string|string[]) => key[0] === '?' @@ -34,6 +35,17 @@ const decodePath = (path: string) => { } } +export const DEFAULT_NAV = { + orientation: [0, 0, 0, 1], + perspectiveOrientation: [ + 0.3140767216682434, + -0.7418519854545593, + 0.4988985061645508, + -0.3195493221282959 + ], + position: [0, 0, 0], +} + export const cvtFullRouteToState = (fullPath: UrlTree, state: any, _warnCb?: (arg: string) => void) => { const warnCb = _warnCb || ((...e: any[]) => console.warn(...e)) @@ -78,7 +90,7 @@ export const cvtFullRouteToState = (fullPath: UrlTree, state: any, _warnCb?: (ar // nav obj is almost always defined, regardless if standaloneVolume or not const cViewerState = returnObj['@'] && returnObj['@'][0] - let parsedNavObj = {} + let parsedNavObj: any if (cViewerState) { try { const [ cO, cPO, cPZ, cP, cZ ] = cViewerState.split(`${separator}${separator}`) @@ -171,7 +183,12 @@ export const cvtFullRouteToState = (fullPath: UrlTree, state: any, _warnCb?: (ar returnState['viewerState']['regionsSelected'] = regionsSelected returnState['viewerState']['templateSelected'] = templateSelected - returnState['viewerState']['navigation'] = parsedNavObj + const { scale } = spaceMiscInfoMap.get(templateSelected.id) || { scale: 1 } + returnState['viewerState']['navigation'] = parsedNavObj || ({ + ...DEFAULT_NAV, + zoom: 350000 * scale, + perspectiveZoom: 1922235.5293810747 * scale + }) } catch (e) { // if error, show error on UI? warnCb(`parse template, parc, region error`, e) diff --git a/src/util/pureConstant.service.ts b/src/util/pureConstant.service.ts index 74a1280e039ff583e2d75cd94334916bb5a94ad9..c6145b3d2a7617850815eb6bf9212c81481b5efd 100644 --- a/src/util/pureConstant.service.ts +++ b/src/util/pureConstant.service.ts @@ -52,7 +52,7 @@ type TIAVAtlas = { } & THasId)[] } & THasId -const spaceMiscInfoMap = new Map([ +export const spaceMiscInfoMap = new Map([ ['minds/core/referencespace/v1.0.0/a1655b99-82f1-420f-a3c2-fe80fd4c8588', { name: 'bigbrain', scale: 1,