@geogirafe/lib-geoportal 1.3.0-dev.2925672052 → 1.3.0-dev.2926313891

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. package/api/apigeogirafeapp.js +3 -1
  2. package/assets/i18n/de.json +4 -0
  3. package/assets/i18n/en.json +4 -0
  4. package/assets/i18n/fr.json +4 -0
  5. package/assets/i18n/it.json +4 -0
  6. package/assets/icons/layout-1+2.svg +1 -0
  7. package/assets/icons/layout-2+1.svg +1 -0
  8. package/assets/icons/streetview-marker.svg +1 -0
  9. package/components/layout/component.d.ts +8 -3
  10. package/components/layout/component.js +15 -9
  11. package/components/main.d.ts +1 -0
  12. package/components/main.js +1 -0
  13. package/components/map-grid/component.d.ts +19 -5
  14. package/components/map-grid/component.js +58 -29
  15. package/components/map-grid/style.css +10 -8
  16. package/components/streetview/component.d.ts +59 -0
  17. package/components/streetview/component.js +193 -0
  18. package/components/streetview/google.d.ts +7 -0
  19. package/components/streetview/google.js +16 -0
  20. package/components/streetview/style.css +41 -0
  21. package/components/streetview/tools/googleprovider.d.ts +26 -0
  22. package/components/streetview/tools/googleprovider.js +102 -0
  23. package/components/streetview/tools/provider.d.ts +27 -0
  24. package/components/streetview/tools/provider.js +1 -0
  25. package/package.json +2 -1
  26. package/templates/iframe.html +1 -0
  27. package/templates/index.html +1 -0
  28. package/templates/mobile.html +1 -0
  29. package/templates/public/about.json +1 -1
  30. package/tools/app/geogirafeapp-mobile.js +2 -0
  31. package/tools/app/geogirafeapp.js +2 -0
  32. package/tools/configuration/girafeconfig.d.ts +2 -0
  33. package/tools/configuration/girafeconfig.js +10 -0
  34. package/tools/configuration/streetviewconfig.d.ts +13 -0
  35. package/tools/configuration/streetviewconfig.js +18 -0
  36. package/tools/main.d.ts +7 -2
  37. package/tools/main.js +4 -1
  38. package/tools/share/serializers/layoutserializer.js +3 -2
  39. package/tools/share/serializers/streetviewserializer.d.ts +18 -0
  40. package/tools/share/serializers/streetviewserializer.js +29 -0
  41. package/tools/share/stateserializer.js +3 -0
  42. package/tools/state/layout.d.ts +37 -7
  43. package/tools/state/layout.js +55 -12
  44. package/tools/state/state.d.ts +2 -0
  45. package/tools/state/state.js +6 -0
  46. package/tools/state/streetview.d.ts +22 -0
  47. package/tools/state/streetview.js +24 -0
@@ -0,0 +1,193 @@
1
+ import { html as uHtml } from 'uhtml';
2
+ import Feature from 'ol/Feature.js';
3
+ import Point from 'ol/geom/Point.js';
4
+ import VectorLayer from 'ol/layer/Vector.js';
5
+ import { fromLonLat, toLonLat } from 'ol/proj.js';
6
+ import VectorSource from 'ol/source/Vector.js';
7
+ import { Icon, Style } from 'ol/style.js';
8
+ import GirafeHTMLElement from '../../base/GirafeHTMLElement.js';
9
+ import { DEFAULT_STREETVIEW_SEARCH_RADIUS } from '../../tools/configuration/streetviewconfig.js';
10
+ /**
11
+ * A StreetView, displaying the footage of a provider (Google Street View, ...) side by side with the 2D Map.
12
+ *
13
+ * The Component stays lightweight: the provider and its external library are only loaded when the
14
+ * StreetView is displayed for the first time. A click on the map displays the closest footage, and a
15
+ * marker on the map shows the position and the direction of sight of the displayed footage.
16
+ * The map is accessed through the MapManager: there is no dependency to the map-2d Component.
17
+ */
18
+ export default class StreetViewComponent extends GirafeHTMLElement {
19
+ templateUrl = null;
20
+ styleUrls = null;
21
+ template = () => {
22
+ return uHtml `<style>
23
+ .hidden{display:none!important}.gg-rotate90{transform:rotate(90deg)}.gg-rotate180{transform:rotate(180deg)}.gg-rotate270{transform:rotate(270deg)}img{filter:var(--svg-filter)}img.legend-image{filter:var(--svg-map-filter);background:var(--svg-legend-bkg)}div{scrollbar-width:thin}a,a:visited{color:var(--link-color)}@keyframes spin{0%{transform:rotate(0)}to{transform:rotate(360deg)}}@keyframes spin-wait{0%{transform:rotate(0)}7%{transform:rotate(360deg)}to{transform:rotate(360deg)}}.gg-spin{animation-name:spin;animation-duration:2s;animation-timing-function:linear;animation-iteration-count:infinite}.gg-spin-wait{animation-name:spin-wait;animation-duration:10s;animation-timing-function:linear;animation-iteration-count:infinite}::-webkit-scrollbar{width:5px}::-webkit-scrollbar-thumb{background:#999}button,input,select,textarea{font:inherit}.gg-button,.gg-select,.gg-input,.gg-textarea{background-color:var(--bkg-color);color:var(--text-color);border:var(--app-standard-border);box-sizing:border-box;cursor:pointer;border-radius:3px;outline:0;margin:0;padding:0 0 0 .5rem;display:inline-block}.gg-label{background-color:var(--bkg-color);color:var(--text-color);border:none;align-items:center;margin:0;padding:0;display:flex}.gg-button,.gg-select,.gg-input,.gg-label{min-height:calc(var(--app-standard-height) / 1.5)}.gg-textarea{max-height:initial;resize:vertical;height:6rem;padding:.5rem;line-height:1.3rem}.gg-input{cursor:text}.gg-checkbox{accent-color:var(--text-color);cursor:pointer;width:1.2rem}.gg-range{accent-color:var(--text-color)}.gg-button{padding:0 .5rem}.gg-button.active{border:solid 1px var(--text-color-grad1);background-color:var(--bkg-color-grad2)}.gg-button:disabled{background-color:var(--bkg-color-grad1);color:var(--text-color-grad2);cursor:not-allowed;border:none}.gg-button:disabled img{filter:opacity(.6)}.gg-input:disabled,.gg-select:disabled,.gg-textarea:disabled{background-color:var(--bkg-color-grad1);color:var(--text-color-grad2);cursor:not-allowed}.gg-button>img{vertical-align:middle}.gg-icon-button{color:var(--text-color);cursor:pointer;background-color:#0000;border:none;flex-direction:column;justify-content:center;align-items:center;padding:0;display:flex}.gg-icon{justify-content:center;align-items:center;display:flex}.gg-big,.gg-big-withtext{min-width:var(--app-standard-height);min-height:var(--app-standard-height);max-height:var(--app-standard-height)}.gg-big img,.gg-big-withtext img{width:calc(var(--app-standard-height) - 1.5rem);margin:0}.gg-big-withtext span{font-variant:small-caps;padding:0 1rem;font-size:.9rem}.gg-medium,.gg-medium-withtext{min-width:calc(var(--app-standard-height) / 1.2);min-height:calc(var(--app-standard-height) / 1.2);max-height:calc(var(--app-standard-height) / 1.2);flex-direction:row}.gg-medium img{width:calc(var(--app-standard-height) / 2.4);margin:0}.gg-medium-withtext img{width:calc(var(--app-standard-height) / 2.4);margin-left:.5rem}.gg-medium-withtext span{padding:0 1rem 0 .5rem;font-size:.9rem}.gg-small,.gg-small-withtext{min-width:calc(var(--app-standard-height) / 2);min-height:calc(var(--app-standard-height) / 2);max-height:calc(var(--app-standard-height) / 2);flex-direction:row}.gg-small img{width:calc(var(--app-standard-height) / 3);margin:0}.gg-small-withtext img{width:calc(var(--app-standard-height) / 3);margin-left:.5rem}.gg-small-withtext span{padding:0 .5rem 0 .3rem;font-size:.9rem}.gg-button:hover:not(:disabled),.gg-select:hover:not(:disabled),.gg-input:hover:not(:disabled),.gg-textarea:hover:not(:disabled),.gg-icon-button:hover:not(:disabled){background-color:var(--bkg-color-grad1)}.gg-opacity{opacity:.5}.gg-opacity:hover{opacity:1;background-color:#0000}.gg-tabs{cursor:pointer;grid-auto-flow:column;padding-bottom:1rem;font-size:1rem;display:grid}.gg-tab{border:none;border-bottom:var(--app-standard-border);cursor:pointer;color:var(--text-color);background:0 0;padding:.5rem}.gg-tab.active{border-bottom:solid 1px var(--text-color)}.girafe-button-big,.girafe-button-large,.girafe-button-small,.girafe-button-tiny{color:var(--text-color);background-color:#0000;border:none;flex-direction:column;display:flex}.girafe-button-big:hover,.girafe-button-large:hover,.girafe-button-small:hover,.girafe-button-tiny:hover{background-color:var(--bkg-color-grad1);cursor:pointer}.girafe-button-big.dark,.girafe-button-large.dark,.girafe-button-small.dark,.girafe-button-tiny.dark{background-color:var(--bkg-color);filter:invert()}.girafe-button-big{width:var(--app-standard-height);height:var(--app-standard-height);align-items:center;padding:1rem}.girafe-button-big img{overflow:hidden}.girafe-button-large{flex-direction:row}.girafe-button-large img{height:2rem;margin:.3rem}.girafe-button-large span{height:2rem;margin:.3rem;line-height:2rem}.girafe-button-small{min-width:calc(var(--app-standard-height) / 2);height:calc(var(--app-standard-height) / 2);align-items:center;padding:.5rem}.girafe-button-small img{overflow:hidden}.girafe-button-small span{text-align:left;text-overflow:ellipsis;width:100%;overflow:hidden}.girafe-button-tiny{align-items:center;width:1rem;height:1rem;padding:0}.girafe-button-tiny img{overflow:hidden}.girafe-onboarding-theme{background-color:var(--bkg-color)!important;color:var(--text-color)!important}.girafe-onboarding-theme button{background-color:var(--bkg-color)!important;color:var(--text-color)!important;text-shadow:none!important}.girafe-onboarding-theme button.driver-popover-close-btn{z-index:10000}.tippy-box{background-color:var(--bkg-color)!important;border:var(--app-standard-border)!important}.tippy-content{color:var(--text-color)!important}.tippy-arrow{color:var(--bkg-color)!important}.tippy-box[data-theme~=error]{background-color:var(--error-color);white-space:pre-line}div.tippy-box[data-theme=image-popup]{border:var(--app-standard-border)!important;& div.tippy-content{background-color:var(--bkg-color)!important;& img{max-width:20rem;max-height:20rem}}& div.tippy-arrow{color:var(--bkg-color)!important}}
24
+ </style><style>
25
+ #streetview{background-color:var(--bkg-color);width:100%;height:100%;position:relative;overflow:hidden}#viewer{position:absolute;inset:0}.overlay{text-align:center;color:var(--text-color);pointer-events:none;z-index:1;flex-direction:column;justify-content:center;align-items:center;gap:1rem;padding:1rem;font-weight:600;display:flex;position:absolute;inset:0}.no-data{color:#999;font-variant:small-caps;gap:.3rem;font-size:1rem;font-weight:400}.hidden{display:none}
26
+ </style>
27
+ <style>${this.customStyle}</style>
28
+ <div id="streetview"><div id="viewer"></div><div class="${this.loading ? 'overlay' : 'overlay hidden'}"><img alt="loading-icon" src="icons/loading.svg" class="gg-spin"> <span i18n="Loading StreetView...">Loading StreetView...</span></div><div class="${!this.loading && !this.hasFootage ? 'overlay no-data' : 'overlay no-data hidden'}"><span i18n="Click on the map to display the StreetView at this location">Click on the map to display the StreetView at this location</span></div></div>
29
+ ${this.htmlUnsafe(this.feedbackTemplateHtml ?? '')}`;
30
+ };
31
+ loading = false;
32
+ hasFootage = false;
33
+ provider;
34
+ adapter = null;
35
+ /** Promise of the currently running adapter creation, to prevent creating it twice. */
36
+ adapterCreation = null;
37
+ /** The view of the footage displayed by the adapter, to tell the views coming from a shared state apart. */
38
+ displayedView = null;
39
+ markerIcon = new Icon({
40
+ src: 'icons/streetview-marker.svg',
41
+ anchor: [0.5, 0.5],
42
+ rotateWithView: true
43
+ });
44
+ markerGeometry = new Point([0, 0]);
45
+ marker = new Feature(this.markerGeometry);
46
+ markerSource = new VectorSource();
47
+ markerLayer = new VectorLayer({ source: this.markerSource, zIndex: 2000 });
48
+ constructor(provider) {
49
+ super(`streetview-${provider}`);
50
+ this.provider = provider;
51
+ this.marker.setStyle(new Style({ image: this.markerIcon }));
52
+ this.onMapClick = this.onMapClick.bind(this);
53
+ }
54
+ get olMap() {
55
+ return this.context.mapManager.getMap();
56
+ }
57
+ get cellId() {
58
+ return `streetview-${this.provider}`;
59
+ }
60
+ get isDisplayed() {
61
+ return this.state.layout.cells.includes(this.cellId);
62
+ }
63
+ get searchRadius() {
64
+ return this.context.configManager.Config.streetview?.searchRadius ?? DEFAULT_STREETVIEW_SEARCH_RADIUS;
65
+ }
66
+ /** The StreetView is displayed in a Cell of the Grid, like the Maps. */
67
+ get isFullscreenComponent() {
68
+ return true;
69
+ }
70
+ connectedCallback() {
71
+ super.connectedCallback();
72
+ this.render();
73
+ this.registerEvents();
74
+ void this.onDisplayToggled();
75
+ }
76
+ disconnectedCallback() {
77
+ super.disconnectedCallback();
78
+ this.olMap.un('singleclick', this.onMapClick);
79
+ this.olMap.removeLayer(this.markerLayer);
80
+ }
81
+ render() {
82
+ super.render();
83
+ this.girafeTranslate();
84
+ }
85
+ registerEvents() {
86
+ this.subscribe('layout.cells', () => void this.onDisplayToggled());
87
+ this.subscribe(`streetview.views.${this.provider}`, (_oldView, newView) => this.onViewChanged(newView));
88
+ this.olMap.on('singleclick', this.onMapClick);
89
+ }
90
+ /**
91
+ * Loads the provider and shows its viewer when the StreetView is displayed in a Cell of the Grid,
92
+ * and hides it when it is not displayed anymore. The clicks on the map are only followed while displayed.
93
+ */
94
+ async onDisplayToggled() {
95
+ if (!this.isDisplayed) {
96
+ this.unregisterInteractionListeners('map.mouseclick');
97
+ this.olMap.removeLayer(this.markerLayer);
98
+ this.adapter?.setVisible(false);
99
+ return;
100
+ }
101
+ this.registerInteractionListener('map.mouseclick', false);
102
+ if (!this.olMap.getLayers().getArray().includes(this.markerLayer)) {
103
+ this.olMap.addLayer(this.markerLayer);
104
+ }
105
+ await this.createAdapterOnce();
106
+ this.adapter?.setVisible(true);
107
+ this.showStateView();
108
+ }
109
+ async createAdapterOnce() {
110
+ if (this.adapter) {
111
+ return;
112
+ }
113
+ this.adapterCreation ??= (async () => {
114
+ this.loading = true;
115
+ this.refreshRender();
116
+ try {
117
+ const adapter = await this.createAdapter();
118
+ await adapter.initialize(this.getById('viewer'), (footage) => this.onFootageChanged(footage));
119
+ this.adapter = adapter;
120
+ }
121
+ catch (error) {
122
+ console.error(error);
123
+ // Allows to try again the next time the StreetView is displayed
124
+ this.adapterCreation = null;
125
+ }
126
+ finally {
127
+ this.loading = false;
128
+ this.refreshRender();
129
+ }
130
+ })();
131
+ return this.adapterCreation;
132
+ }
133
+ onMapClick(event) {
134
+ if (!this.adapter || !this.isDisplayed || !this.canExecute('map.mouseclick')) {
135
+ return;
136
+ }
137
+ this.showClosestFootage(this.adapter, event.coordinate).catch((error) => console.error(error));
138
+ }
139
+ async showClosestFootage(adapter, coordinate) {
140
+ const lonLat = toLonLat(coordinate, this.olMap.getView().getProjection());
141
+ const found = await adapter.showClosestFootage(lonLat, this.searchRadius);
142
+ if (!found) {
143
+ void window.gAlert('No StreetView footage was found near this location', 'StreetView');
144
+ }
145
+ }
146
+ onFootageChanged(footage) {
147
+ const view = {
148
+ position: fromLonLat(footage.lonLat, this.olMap.getView().getProjection()),
149
+ heading: footage.heading,
150
+ pitch: footage.pitch
151
+ };
152
+ this.displayedView = view;
153
+ this.state.streetview.views[this.provider] = view;
154
+ }
155
+ onViewChanged(view) {
156
+ this.updateMarker(view);
157
+ this.showStateView();
158
+ }
159
+ /**
160
+ * Displays the footage of the view in the state when it was not displayed by this Component itself,
161
+ * which is the case when a shared state is restored.
162
+ */
163
+ showStateView() {
164
+ const view = this.state.streetview.views[this.provider];
165
+ if (!this.adapter || !this.isDisplayed || !view || this.isDisplayedView(view)) {
166
+ return;
167
+ }
168
+ const lonLat = toLonLat(view.position, this.olMap.getView().getProjection());
169
+ this.adapter
170
+ .showClosestFootage(lonLat, this.searchRadius, { heading: view.heading, pitch: view.pitch })
171
+ .catch((error) => console.error(error));
172
+ }
173
+ isDisplayedView(view) {
174
+ const displayed = this.displayedView;
175
+ return (displayed !== null &&
176
+ displayed.position[0] === view.position[0] &&
177
+ displayed.position[1] === view.position[1] &&
178
+ displayed.heading === view.heading &&
179
+ displayed.pitch === view.pitch);
180
+ }
181
+ updateMarker(view) {
182
+ this.markerGeometry.setCoordinates(view.position);
183
+ this.markerIcon.setRotation((view.heading * Math.PI) / 180);
184
+ this.marker.changed();
185
+ if (!this.markerSource.hasFeature(this.marker)) {
186
+ this.markerSource.addFeature(this.marker);
187
+ }
188
+ if (!this.hasFootage) {
189
+ this.hasFootage = true;
190
+ this.refreshRender();
191
+ }
192
+ }
193
+ }
@@ -0,0 +1,7 @@
1
+ import StreetViewComponent from './component.js';
2
+ import type { StreetViewProviderAdapter } from './tools/provider.js';
3
+ /** The StreetView displaying the footage of Google Street View. */
4
+ export default class GoogleStreetViewComponent extends StreetViewComponent {
5
+ constructor();
6
+ protected createAdapter(): Promise<StreetViewProviderAdapter>;
7
+ }
@@ -0,0 +1,16 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ import StreetViewComponent from './component.js';
3
+ /** The StreetView displaying the footage of Google Street View. */
4
+ export default class GoogleStreetViewComponent extends StreetViewComponent {
5
+ constructor() {
6
+ super('google');
7
+ }
8
+ async createAdapter() {
9
+ const apiKey = this.context.configManager.Config.streetview?.google?.apiKey;
10
+ if (!apiKey) {
11
+ throw new Error('The Google StreetView cannot be displayed: streetview.google.apiKey is not configured');
12
+ }
13
+ const { default: GoogleStreetViewProvider } = await import('./tools/googleprovider');
14
+ return new GoogleStreetViewProvider(apiKey);
15
+ }
16
+ }
@@ -0,0 +1,41 @@
1
+ /* SPDX-License-Identifier: Apache-2.0 */
2
+ #streetview {
3
+ position: relative;
4
+ width: 100%;
5
+ height: 100%;
6
+ overflow: hidden;
7
+ background-color: var(--bkg-color);
8
+ }
9
+
10
+ #viewer {
11
+ position: absolute;
12
+ inset: 0;
13
+ }
14
+
15
+ .overlay {
16
+ position: absolute;
17
+ inset: 0;
18
+ display: flex;
19
+ flex-direction: column;
20
+ align-items: center;
21
+ justify-content: center;
22
+ gap: 1rem;
23
+ padding: 1rem;
24
+ text-align: center;
25
+ color: var(--text-color);
26
+ font-weight: 600;
27
+ pointer-events: none;
28
+ z-index: 1;
29
+ }
30
+
31
+ .no-data {
32
+ color: #999;
33
+ font-variant: small-caps;
34
+ font-size: 1rem;
35
+ font-weight: normal;
36
+ gap: 0.3rem;
37
+ }
38
+
39
+ .hidden {
40
+ display: none;
41
+ }
@@ -0,0 +1,26 @@
1
+ import type { Coordinate } from 'ol/coordinate.js';
2
+ import type { Footage, PointOfView, StreetViewProviderAdapter } from './provider.js';
3
+ declare const MAPS_API_LOADED_CALLBACK = "girafeGoogleMapsApiLoaded";
4
+ declare global {
5
+ interface Window {
6
+ [MAPS_API_LOADED_CALLBACK]?: () => void;
7
+ }
8
+ }
9
+ /**
10
+ * The Google Street View footage, displayed by a StreetViewPanorama.
11
+ * This module is the only place where the Google Maps API is used. It is loaded on demand
12
+ * by the StreetView Component, so that the API stays out of the application as long as
13
+ * no Google StreetView is displayed.
14
+ */
15
+ export default class GoogleStreetViewProvider implements StreetViewProviderAdapter {
16
+ private readonly apiKey;
17
+ private service;
18
+ private panorama;
19
+ private nearest;
20
+ constructor(apiKey: string);
21
+ initialize(target: HTMLElement, onFootageChanged: (footage: Footage) => void): Promise<void>;
22
+ private getFootage;
23
+ showClosestFootage(lonLat: Coordinate, radius: number, pov?: PointOfView): Promise<boolean>;
24
+ setVisible(visible: boolean): void;
25
+ }
26
+ export {};
@@ -0,0 +1,102 @@
1
+ const MAPS_API_LOADED_CALLBACK = 'girafeGoogleMapsApiLoaded';
2
+ let mapsApiLoading = null;
3
+ /**
4
+ * Loads the Google Maps JavaScript API once, when the first Google StreetView is displayed.
5
+ * The API is only usable once it calls back the application: the load event of the script fires
6
+ * before the API has finished loading.
7
+ * The API key is part of the script URL, and therefore visible to the user: it must be restricted
8
+ * to the domain of the application in the Google Cloud Console.
9
+ */
10
+ function loadMapsApi(apiKey) {
11
+ mapsApiLoading ??= new Promise((resolve, reject) => {
12
+ window[MAPS_API_LOADED_CALLBACK] = () => {
13
+ delete window[MAPS_API_LOADED_CALLBACK];
14
+ resolve();
15
+ };
16
+ const script = document.createElement('script');
17
+ const params = new URLSearchParams({
18
+ key: apiKey,
19
+ v: 'weekly',
20
+ loading: 'async',
21
+ callback: MAPS_API_LOADED_CALLBACK
22
+ });
23
+ script.src = `https://maps.googleapis.com/maps/api/js?${params}`;
24
+ script.async = true;
25
+ script.addEventListener('error', () => reject(new Error('The Google Maps JavaScript API could not be loaded')));
26
+ document.head.appendChild(script);
27
+ });
28
+ return mapsApiLoading;
29
+ }
30
+ function isZeroResults(error) {
31
+ return error?.code === 'ZERO_RESULTS';
32
+ }
33
+ /**
34
+ * The Google Street View footage, displayed by a StreetViewPanorama.
35
+ * This module is the only place where the Google Maps API is used. It is loaded on demand
36
+ * by the StreetView Component, so that the API stays out of the application as long as
37
+ * no Google StreetView is displayed.
38
+ */
39
+ export default class GoogleStreetViewProvider {
40
+ apiKey;
41
+ service;
42
+ panorama;
43
+ nearest;
44
+ constructor(apiKey) {
45
+ this.apiKey = apiKey;
46
+ }
47
+ async initialize(target, onFootageChanged) {
48
+ await loadMapsApi(this.apiKey);
49
+ const library = (await google.maps.importLibrary('streetView'));
50
+ this.nearest = library.StreetViewPreference.NEAREST;
51
+ this.service = new library.StreetViewService();
52
+ this.panorama = new library.StreetViewPanorama(target, {
53
+ visible: false,
54
+ pov: { heading: 0, pitch: 0 }
55
+ });
56
+ const notifyFootageChanged = () => {
57
+ const footage = this.getFootage();
58
+ if (footage) {
59
+ onFootageChanged(footage);
60
+ }
61
+ };
62
+ this.panorama.addListener('position_changed', notifyFootageChanged);
63
+ this.panorama.addListener('pov_changed', notifyFootageChanged);
64
+ }
65
+ getFootage() {
66
+ const position = this.panorama.getPosition();
67
+ if (!position) {
68
+ return null;
69
+ }
70
+ const pov = this.panorama.getPov();
71
+ return { lonLat: [position.lng(), position.lat()], heading: pov.heading, pitch: pov.pitch };
72
+ }
73
+ async showClosestFootage(lonLat, radius, pov) {
74
+ try {
75
+ const response = await this.service.getPanorama({
76
+ location: { lng: lonLat[0], lat: lonLat[1] },
77
+ radius: radius,
78
+ preference: this.nearest
79
+ });
80
+ // The API does not respond when it is in error (invalid key, ...)
81
+ const pano = response?.data?.location?.pano;
82
+ if (!pano) {
83
+ return false;
84
+ }
85
+ this.panorama.setPano(pano);
86
+ if (pov) {
87
+ this.panorama.setPov(pov);
88
+ }
89
+ this.panorama.setVisible(true);
90
+ return true;
91
+ }
92
+ catch (error) {
93
+ if (isZeroResults(error)) {
94
+ return false;
95
+ }
96
+ throw error;
97
+ }
98
+ }
99
+ setVisible(visible) {
100
+ this.panorama?.setVisible(visible && this.panorama.getPosition() !== null);
101
+ }
102
+ }
@@ -0,0 +1,27 @@
1
+ import type { Coordinate } from 'ol/coordinate.js';
2
+ /** The footage displayed by a provider, with the position it was taken from in WGS84 (longitude, latitude). */
3
+ export type Footage = {
4
+ lonLat: Coordinate;
5
+ heading: number;
6
+ pitch: number;
7
+ };
8
+ /** The direction of sight to apply to a displayed footage. */
9
+ export type PointOfView = Pick<Footage, 'heading' | 'pitch'>;
10
+ /**
11
+ * A service providing the footage displayed by a StreetView Component.
12
+ * All the coordinates are in WGS84 (longitude, latitude): the Component takes care of the map projection.
13
+ */
14
+ export interface StreetViewProviderAdapter {
15
+ /**
16
+ * Loads the external library, if needed, and creates the viewer in the target element.
17
+ * The callback is called each time the displayed footage or the direction of sight changes.
18
+ */
19
+ initialize(target: HTMLElement, onFootageChanged: (footage: Footage) => void): Promise<void>;
20
+ /**
21
+ * Displays the closest footage around the coordinate, within the radius (in meters),
22
+ * looking in the given direction or, by default, in the direction the footage was taken.
23
+ * Resolves to false when there is no footage within the radius.
24
+ */
25
+ showClosestFootage(lonLat: Coordinate, radius: number, pov?: PointOfView): Promise<boolean>;
26
+ setVisible(visible: boolean): void;
27
+ }
@@ -0,0 +1 @@
1
+ export {};
package/package.json CHANGED
@@ -5,7 +5,7 @@
5
5
  "name": "GeoGirafe PSC",
6
6
  "url": "https://doc.geogirafe.org"
7
7
  },
8
- "version": "1.3.0-dev.2925672052",
8
+ "version": "1.3.0-dev.2926313891",
9
9
  "type": "module",
10
10
  "engines": {
11
11
  "node": ">=20.19.0"
@@ -71,6 +71,7 @@
71
71
  "@types/d3": "7.4.3",
72
72
  "@types/file-saver": "2.0.7",
73
73
  "@types/geojson": "7946.0.16",
74
+ "@types/google.maps": "3.66.3",
74
75
  "@types/jsts": "0.17.24",
75
76
  "@types/lodash-es": "4.17.12",
76
77
  "@types/node": "25.5.2",
@@ -81,6 +81,7 @@
81
81
  <girafe-map-grid>
82
82
  <girafe-map-2d></girafe-map-2d>
83
83
  <girafe-map-3d></girafe-map-3d>
84
+ <girafe-streetview-google></girafe-streetview-google>
84
85
  </girafe-map-grid>
85
86
  <girafe-basemap></girafe-basemap>
86
87
  <girafe-search id="search"></girafe-search>
@@ -109,6 +109,7 @@
109
109
  <girafe-map-grid>
110
110
  <girafe-map-2d></girafe-map-2d>
111
111
  <girafe-map-3d></girafe-map-3d>
112
+ <girafe-streetview-google></girafe-streetview-google>
112
113
  </girafe-map-grid>
113
114
  <div class="info-area">
114
115
  <girafe-basemap data-tour="basemap-selection"></girafe-basemap>
@@ -96,6 +96,7 @@
96
96
  <girafe-map-grid>
97
97
  <girafe-map-2d></girafe-map-2d>
98
98
  <girafe-map-3d></girafe-map-3d>
99
+ <girafe-streetview-google></girafe-streetview-google>
99
100
  </girafe-map-grid>
100
101
  <girafe-infobox></girafe-infobox>
101
102
  </div>
@@ -1 +1 @@
1
- {"version":"1.3.0-dev.2925672052", "build":"2925672052", "date":"08/10/2026"}
1
+ {"version":"1.3.0-dev.2926313891", "build":"2926313891", "date":"08/10/2026"}
@@ -11,6 +11,7 @@ import InfoboxComponent from '../../components/infobox/component.js';
11
11
  import Map2dComponent from '../../components/map-2d/component.js';
12
12
  import DeprecatedMapComponent from '../../components/map-2d/deprecatedmapcomponent.js';
13
13
  import Map3dComponent from '../../components/map-3d/component.js';
14
+ import GoogleStreetViewComponent from '../../components/streetview/google.js';
14
15
  import MapGridComponent from '../../components/map-grid/component.js';
15
16
  import MenuMobile3dButton from '../../components/menu-buttons-mobile/MenuMobile3dButton.js';
16
17
  import MenuMobileDrawingButton from '../../components/menu-buttons-mobile/MenuMobileDrawingButton.js';
@@ -50,6 +51,7 @@ export default class GeoGirafeAppMobile extends GeoGirafeApp {
50
51
  customElements.define('girafe-infobox', InfoboxComponent);
51
52
  customElements.define('girafe-map-2d', Map2dComponent);
52
53
  customElements.define('girafe-map-3d', Map3dComponent);
54
+ customElements.define('girafe-streetview-google', GoogleStreetViewComponent);
53
55
  customElements.define('girafe-map-grid', MapGridComponent);
54
56
  // Deprecated alias of <girafe-map-2d>, kept for the applications that were not migrated yet.
55
57
  customElements.define('girafe-map', DeprecatedMapComponent);
@@ -20,6 +20,7 @@ import LRPanelComponent from '../../components/lr-panel/component.js';
20
20
  import Map2dComponent from '../../components/map-2d/component.js';
21
21
  import DeprecatedMapComponent from '../../components/map-2d/deprecatedmapcomponent.js';
22
22
  import Map3dComponent from '../../components/map-3d/component.js';
23
+ import GoogleStreetViewComponent from '../../components/streetview/google.js';
23
24
  import MapGridComponent from '../../components/map-grid/component.js';
24
25
  import MenuButtonComponent from '../../components/menubutton/component.js';
25
26
  import ModalsComponent from '../../components/modals/component.js';
@@ -124,6 +125,7 @@ export default class GeoGirafeApp {
124
125
  customElements.define('girafe-lr-panel', LRPanelComponent);
125
126
  customElements.define('girafe-map-2d', Map2dComponent);
126
127
  customElements.define('girafe-map-3d', Map3dComponent);
128
+ customElements.define('girafe-streetview-google', GoogleStreetViewComponent);
127
129
  customElements.define('girafe-map-grid', MapGridComponent);
128
130
  // Deprecated alias of <girafe-map-2d>, kept for the applications that were not migrated yet.
129
131
  customElements.define('girafe-map', DeprecatedMapComponent);
@@ -9,6 +9,7 @@ export type UserDataConfig = {
9
9
  };
10
10
  import { Config as SanitizeConfig } from 'dompurify';
11
11
  import { LayoutType } from '../state/layout.js';
12
+ import { StreetViewConfig } from './streetviewconfig.js';
12
13
  declare class GirafeConfig {
13
14
  general: {
14
15
  locale: string;
@@ -144,6 +145,7 @@ declare class GirafeConfig {
144
145
  tilesetsUrls: string[];
145
146
  maximumZoomDistance: number;
146
147
  };
148
+ streetview?: StreetViewConfig;
147
149
  lidar?: {
148
150
  url: string;
149
151
  };
@@ -6,6 +6,7 @@ export var HighlightMode;
6
6
  })(HighlightMode || (HighlightMode = {}));
7
7
  import { defaultNewsSanitizeConfig, defaultPermalinkSanitizeConfig, defaultQuerySanitizeConfig } from './sanitizeconfig-defaults.js';
8
8
  import { isLayoutType, LAYOUT_TYPES } from '../state/layout.js';
9
+ import { initConfigStreetView } from './streetviewconfig.js';
9
10
  class GirafeConfig {
10
11
  general;
11
12
  languages;
@@ -21,6 +22,7 @@ class GirafeConfig {
21
22
  projections;
22
23
  map;
23
24
  map3d;
25
+ streetview;
24
26
  lidar;
25
27
  news;
26
28
  externalLayers;
@@ -115,6 +117,14 @@ class GirafeConfig {
115
117
  // We just display a warning in the console
116
118
  console.warn(e);
117
119
  }
120
+ try {
121
+ this.streetview = initConfigStreetView(config);
122
+ }
123
+ catch (e) {
124
+ // The application can be started even if the StreetView is not correctly configured
125
+ // We just display a warning in the console
126
+ console.warn(e);
127
+ }
118
128
  try {
119
129
  this.news = this.initConfigNews(config);
120
130
  }
@@ -0,0 +1,13 @@
1
+ import type { StreetViewProvider } from '../state/streetview.js';
2
+ /** Maximal distance, in meters, between a click on the map and the footage displayed for it. */
3
+ export declare const DEFAULT_STREETVIEW_SEARCH_RADIUS = 100;
4
+ export type StreetViewConfig = {
5
+ searchRadius: number;
6
+ google?: {
7
+ apiKey: string;
8
+ };
9
+ };
10
+ export declare function initConfigStreetView(config: {
11
+ streetview?: Partial<StreetViewConfig>;
12
+ }): StreetViewConfig | undefined;
13
+ export declare function isStreetViewProviderConfigured(config: StreetViewConfig | undefined, provider: StreetViewProvider): boolean;
@@ -0,0 +1,18 @@
1
+ /** Maximal distance, in meters, between a click on the map and the footage displayed for it. */
2
+ export const DEFAULT_STREETVIEW_SEARCH_RADIUS = 100;
3
+ export function initConfigStreetView(config) {
4
+ const streetview = config.streetview;
5
+ if (!streetview) {
6
+ return undefined;
7
+ }
8
+ if (streetview.google && !streetview.google.apiKey) {
9
+ throw new Error(`Configuration for streetview.google requires an apiKey. See https://doc.geogirafe.org/docs/configuration`);
10
+ }
11
+ return {
12
+ searchRadius: streetview.searchRadius ?? DEFAULT_STREETVIEW_SEARCH_RADIUS,
13
+ google: streetview.google
14
+ };
15
+ }
16
+ export function isStreetViewProviderConfigured(config, provider) {
17
+ return config?.[provider] !== undefined;
18
+ }
package/tools/main.d.ts CHANGED
@@ -12,6 +12,8 @@ export { default as ConfigManager } from './configuration/configmanager.js';
12
12
  export type { HighlightMode, UserDataConfig } from './configuration/girafeconfig.js';
13
13
  export { default as GirafeConfig } from './configuration/girafeconfig.js';
14
14
  export { defaultNewsSanitizeConfig, defaultPermalinkSanitizeConfig, defaultQuerySanitizeConfig } from './configuration/sanitizeconfig-defaults.js';
15
+ export type { StreetViewConfig } from './configuration/streetviewconfig.js';
16
+ export { DEFAULT_STREETVIEW_SEARCH_RADIUS, initConfigStreetView, isStreetViewProviderConfigured } from './configuration/streetviewconfig.js';
15
17
  export { default as GirafeContext } from './context/context.js';
16
18
  export { default as ContextInitializationHelper } from './context/contexthelper.js';
17
19
  export type { default as IGirafeContext } from './context/icontext.js';
@@ -81,6 +83,7 @@ export { default as MapPositionSerializer } from './share/serializers/mappositio
81
83
  export type { SharedInitialSelection } from './share/serializers/selectionserializer.js';
82
84
  export { default as SelectionSerializer } from './share/serializers/selectionserializer.js';
83
85
  export type { SharedFilterCondition, SharedFilter, SharedLayer, SharedInternalTheme, SharedInternalGroup, SharedInternalLayer, SharedExternalTheme, SharedExternalLayer, SharedBasemap } from './share/serializers/sharedtypes.js';
86
+ export { default as StreetViewSerializer } from './share/serializers/streetviewserializer.js';
84
87
  export { serializeWfsFilter, deserializeWfsFilter } from './share/serializers/wfsfilterserializer.js';
85
88
  export { default as SessionManager } from './share/sessionmanager.js';
86
89
  export { default as ShareManager } from './share/sharemanager.js';
@@ -101,8 +104,8 @@ export { default as GraphicalInterface } from './state/graphicalInterface.js';
101
104
  export type { default as IGirafePanel } from './state/igirafepanel.js';
102
105
  export { isGirafePanel } from './state/igirafepanel.js';
103
106
  export { default as LayersConfig } from './state/layersConfig.js';
104
- export type { LayoutType, CellComponent, CellContent } from './state/layout.js';
105
- export { default as LayoutState, LAYOUT_TYPES, MIN_CELL_SIZE, MAX_CELL_SIZE, AVAILABLE_CELL_COMPONENTS, isLayoutType, isCellComponent, getGridSize, getDefaultSizes, distributeCells } from './state/layout.js';
107
+ export type { LayoutType, LayoutCell, CellComponent, CellContent } from './state/layout.js';
108
+ export { default as LayoutState, LAYOUT_TYPES, MIN_CELL_SIZE, MAX_CELL_SIZE, AVAILABLE_CELL_COMPONENTS, isLayoutType, isCellComponent, isCellComponentAvailable, getGridSize, getLayoutCells, getDefaultSizes, distributeCells } from './state/layout.js';
106
109
  export { default as MapManager } from './state/mapManager.js';
107
110
  export type { MapMarkerTooltip, MapMarker } from './state/mapposition.js';
108
111
  export { default as MapPosition } from './state/mapposition.js';
@@ -113,6 +116,8 @@ export { default as State } from './state/state.js';
113
116
  export { default as StateToggleManager } from './state/stateToggleManager.js';
114
117
  export type { Callback } from './state/statemanager.js';
115
118
  export { default as StateManager } from './state/statemanager.js';
119
+ export type { StreetViewProvider, StreetViewView } from './state/streetview.js';
120
+ export { default as StreetViewState, STREETVIEW_PROVIDERS, isStreetViewProvider, isStreetViewView } from './state/streetview.js';
116
121
  export type { SwipeupPanelMode } from './state/swipeuppanelmode.js';
117
122
  export type { GgUserInteractionListener } from './state/userInteractionManager.js';
118
123
  export { default as UserInteractionManager } from './state/userInteractionManager.js';