-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
show geoadmin iframe in map-container component
- Loading branch information
Showing
6 changed files
with
62 additions
and
463 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 4 additions & 16 deletions
20
libs/ui/map/src/lib/components/map-container/map-container.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,4 @@ | ||
<div class="h-full w-full" #map></div> | ||
<div | ||
class="absolute inset-0 p-2 rounded z-40 transition-all flex flex-col justify-center items-center text-primary font-sans pointer-events-none" | ||
[ngClass]=" | ||
(displayMessage$ | async) ? 'visible opacity-100' : 'invisible opacity-0' | ||
" | ||
> | ||
<div | ||
class="absolute z-[-1] inset-0 bg-gradient-to-b from-white to-primary-lightest opacity-60" | ||
></div> | ||
<ng-icon | ||
class="!w-16 !h-16 text-[64px] mb-4" | ||
name="matSwipeOutline" | ||
></ng-icon> | ||
<p translate>map.navigation.message</p> | ||
</div> | ||
<ng-container *ngFor="let url of [geoadminUrl]"> | ||
<!-- this will recreate the iframe on src change --> | ||
<iframe *ngIf="url" class="h-full w-full" [src]="url"></iframe> | ||
</ng-container> |
229 changes: 1 addition & 228 deletions
229
libs/ui/map/src/lib/components/map-container/map-container.component.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,228 +1 @@ | ||
import { | ||
ComponentFixture, | ||
discardPeriodicTasks, | ||
fakeAsync, | ||
TestBed, | ||
tick, | ||
} from '@angular/core/testing' | ||
import { MockBuilder } from 'ng-mocks' | ||
import { | ||
mapCtxFixture, | ||
mapCtxLayerWmsFixture, | ||
mapCtxLayerXyzFixture, | ||
} from '@geonetwork-ui/common/fixtures' | ||
import { applyContextDiffToMap } from '@geospatial-sdk/openlayers' | ||
import { MapContainerComponent } from './map-container.component' | ||
import { computeMapContextDiff } from '@geospatial-sdk/core' | ||
|
||
jest.mock('@geospatial-sdk/core', () => ({ | ||
computeMapContextDiff: jest.fn(() => ({ | ||
'this is': 'a diff', | ||
})), | ||
})) | ||
|
||
jest.mock('@geospatial-sdk/openlayers', () => ({ | ||
applyContextDiffToMap: jest.fn(), | ||
createMapFromContext: jest.fn(() => Promise.resolve(new OpenLayersMapMock())), | ||
listen: jest.fn(), | ||
})) | ||
|
||
let mapmutedCallback | ||
let movestartCallback | ||
let singleclickCallback | ||
class OpenLayersMapMock { | ||
_size = undefined | ||
setTarget = jest.fn() | ||
updateSize() { | ||
this._size = [100, 100] | ||
} | ||
getSize() { | ||
return this._size | ||
} | ||
on(type, callback) { | ||
if (type === 'mapmuted') { | ||
mapmutedCallback = callback | ||
} | ||
if (type === 'movestart') { | ||
movestartCallback = callback | ||
} | ||
if (type === 'singleclick') { | ||
singleclickCallback = callback | ||
} | ||
} | ||
off() { | ||
// do nothing! | ||
} | ||
} | ||
|
||
const defaultBaseMap = { | ||
attributions: | ||
'<span>© <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors, © <a href="https://carto.com/">Carto</a></span>', | ||
type: 'xyz', | ||
url: 'https://{a-c}.basemaps.cartocdn.com/rastertiles/voyager/{z}/{x}/{y}.png', | ||
} | ||
|
||
describe('MapContainerComponent', () => { | ||
let component: MapContainerComponent | ||
let fixture: ComponentFixture<MapContainerComponent> | ||
|
||
beforeEach(() => { | ||
jest.clearAllMocks() | ||
}) | ||
|
||
beforeEach(() => { | ||
return MockBuilder(MapContainerComponent) | ||
}) | ||
|
||
beforeEach(async () => { | ||
await TestBed.configureTestingModule({}).compileComponents() | ||
}) | ||
|
||
beforeEach(() => { | ||
fixture = TestBed.createComponent(MapContainerComponent) | ||
component = fixture.componentInstance | ||
fixture.detectChanges() | ||
}) | ||
|
||
it('creates', () => { | ||
expect(component).toBeTruthy() | ||
}) | ||
|
||
describe('#processContext', () => { | ||
it('returns a default context if null provided', () => { | ||
expect(component.processContext(null)).toEqual({ | ||
layers: [defaultBaseMap], | ||
view: { | ||
center: [0, 15], | ||
zoom: 2, | ||
}, | ||
}) | ||
}) | ||
it('adds base layers to context', () => { | ||
const context = { | ||
layers: [mapCtxLayerWmsFixture()], | ||
view: null, | ||
} | ||
expect(component.processContext(context)).toEqual({ | ||
layers: [defaultBaseMap, mapCtxLayerWmsFixture()], | ||
view: { | ||
center: [0, 15], | ||
zoom: 2, | ||
}, | ||
}) | ||
}) | ||
it('uses provided basemaps if any', () => { | ||
component['basemapLayers'] = [mapCtxLayerXyzFixture()] | ||
const context = { layers: [], view: null } | ||
expect(component.processContext(context)).toEqual({ | ||
layers: [defaultBaseMap, mapCtxLayerXyzFixture()], | ||
view: { | ||
center: [0, 15], | ||
zoom: 2, | ||
}, | ||
}) | ||
}) | ||
it('does not use the default base layer if specified', () => { | ||
component['doNotUseDefaultBasemap'] = true | ||
const context = { layers: [mapCtxLayerXyzFixture()], view: null } | ||
expect(component.processContext(context)).toEqual({ | ||
layers: [mapCtxLayerXyzFixture()], | ||
view: { | ||
center: [0, 15], | ||
zoom: 2, | ||
}, | ||
}) | ||
}) | ||
it('applies map constraints if any', () => { | ||
component['mapViewConstraints'] = { | ||
maxZoom: 18, | ||
maxExtent: [10, 20, 30, 40], | ||
} | ||
const context = { layers: [mapCtxLayerXyzFixture()], view: null } | ||
expect(component.processContext(context)).toEqual({ | ||
layers: [defaultBaseMap, mapCtxLayerXyzFixture()], | ||
view: { | ||
center: [0, 15], | ||
zoom: 2, | ||
maxExtent: [10, 20, 30, 40], | ||
maxZoom: 18, | ||
}, | ||
}) | ||
}) | ||
}) | ||
|
||
describe('#afterViewInit', () => { | ||
beforeEach(async () => { | ||
await component.ngAfterViewInit() | ||
}) | ||
it('creates a map', () => { | ||
expect(component.olMap).toBeInstanceOf(OpenLayersMapMock) | ||
}) | ||
describe('display message that map navigation has been muted', () => { | ||
let messageDisplayed | ||
beforeEach(() => { | ||
messageDisplayed = null | ||
component.displayMessage$.subscribe( | ||
(value) => (messageDisplayed = value) | ||
) | ||
}) | ||
it('mapmuted event displays message after 300ms (delay for eventually hiding message)', fakeAsync(() => { | ||
mapmutedCallback() | ||
tick(400) | ||
expect(messageDisplayed).toEqual(true) | ||
discardPeriodicTasks() | ||
})) | ||
it('message goes away after 2s', fakeAsync(() => { | ||
mapmutedCallback() | ||
tick(2500) | ||
expect(messageDisplayed).toEqual(false) | ||
discardPeriodicTasks() | ||
})) | ||
it('message does not display if map fires movestart event', fakeAsync(() => { | ||
movestartCallback() | ||
tick(300) | ||
expect(messageDisplayed).toEqual(false) | ||
discardPeriodicTasks() | ||
})) | ||
it('message does not display if map fires singleclick event', fakeAsync(() => { | ||
singleclickCallback() | ||
tick(300) | ||
expect(messageDisplayed).toEqual(false) | ||
discardPeriodicTasks() | ||
})) | ||
}) | ||
}) | ||
|
||
describe('#ngOnChanges', () => { | ||
beforeEach(async () => { | ||
await component.ngAfterViewInit() | ||
}) | ||
it('updates the map with the new context', async () => { | ||
const newContext = { | ||
...mapCtxFixture(), | ||
layers: [mapCtxLayerWmsFixture()], | ||
} | ||
await component.ngOnChanges({ | ||
context: { | ||
currentValue: mapCtxFixture(), | ||
previousValue: newContext, | ||
firstChange: false, | ||
isFirstChange: () => false, | ||
}, | ||
}) | ||
expect(computeMapContextDiff).toHaveBeenCalledWith( | ||
{ | ||
layers: [defaultBaseMap, ...mapCtxFixture().layers], | ||
view: mapCtxFixture().view, | ||
}, | ||
{ | ||
layers: [defaultBaseMap, mapCtxLayerWmsFixture()], | ||
view: mapCtxFixture().view, | ||
} | ||
) | ||
expect(applyContextDiffToMap).toHaveBeenCalledWith(component.olMap, { | ||
'this is': 'a diff', | ||
}) | ||
}) | ||
}) | ||
}) | ||
describe.skip('MapContainerComponent', () => {}) | ||
Oops, something went wrong.