@osm-editor-kit/street-imagery-react 0.1.0-alpha.0 → 0.1.0-alpha.10

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 (52) hide show
  1. package/README.md +186 -4
  2. package/dist/MapillaryPanel-FAXVZH37.js +2 -0
  3. package/dist/PanoramaxPanel-TWKTSOXM.js +2 -0
  4. package/dist/StreetLevelImagerySelectionOverlay.d.ts +22 -3
  5. package/dist/StreetLevelImagerySourcesAndLayers.d.ts +24 -1
  6. package/dist/StreetLevelImageryViewCone.d.ts +13 -1
  7. package/dist/StreetLevelImageryViewer.d.ts +23 -1
  8. package/dist/chunk-6EMFFIL2.js +147 -0
  9. package/dist/chunk-SGIB7AVC.js +309 -0
  10. package/dist/chunk-XQXYV6SR.js +466 -0
  11. package/dist/filters/PhotoDateRangeFilter.d.ts +46 -0
  12. package/dist/hooks/useAllProviderMapFeatures.d.ts +0 -4
  13. package/dist/hooks/useProviderData.d.ts +8 -3
  14. package/dist/i18n/PhotoCount.d.ts +12 -0
  15. package/dist/i18n/PhotoDate.d.ts +16 -0
  16. package/dist/i18n/StreetImageryLocaleProvider.d.ts +21 -0
  17. package/dist/i18n/messages.d.ts +45 -0
  18. package/dist/index.d.ts +19 -4
  19. package/dist/index.js +1542 -141
  20. package/dist/mapillary/MapillaryFeatureBar.d.ts +16 -0
  21. package/dist/mapillary/SelectedMapFeatureLayer.d.ts +19 -0
  22. package/dist/mapillary/featureBarLabels.d.ts +16 -0
  23. package/dist/mapillary/useMapillaryFeatures.d.ts +54 -0
  24. package/dist/openers/LocationPickOnMap.d.ts +10 -0
  25. package/dist/openers/useLocationPickStore.d.ts +9 -0
  26. package/dist/panels/MapillaryPanel.d.ts +19 -1
  27. package/dist/panels/PanoramaxPanel.d.ts +14 -4
  28. package/dist/panels/PanoramaxWebViewerPanel.d.ts +20 -0
  29. package/dist/panels/mapillaryLookAt.d.ts +41 -0
  30. package/dist/panels/panoramaxDataProvider.d.ts +44 -0
  31. package/dist/panels/panoramaxItem.d.ts +96 -0
  32. package/dist/panels/panoramaxLimitPanning.d.ts +54 -0
  33. package/dist/panels/panoramaxPhotoFromMetadata.d.ts +8 -0
  34. package/dist/panoramax-web-viewer/index.d.ts +1 -0
  35. package/dist/panoramax-web-viewer.js +314 -0
  36. package/dist/photo-details/PhotoDetailsDialog.d.ts +21 -0
  37. package/dist/photo-details/index.d.ts +6 -0
  38. package/dist/photo-details/labels.d.ts +33 -0
  39. package/dist/photo-details.js +235 -0
  40. package/dist/streetImageryClick.d.ts +4 -0
  41. package/dist/viewer-panels/index.d.ts +5 -0
  42. package/dist/viewer-panels.js +3 -0
  43. package/dist/viewpoints/FloatingPhotoViewer.d.ts +73 -0
  44. package/dist/viewpoints/ViewpointLayer.d.ts +17 -0
  45. package/dist/viewpoints/useViewSuggestions.d.ts +23 -0
  46. package/dist/viewpoints/useViewpointSessionStore.d.ts +35 -0
  47. package/dist/viewpoints/viewDirectionLabels.d.ts +4 -0
  48. package/package.json +37 -6
  49. package/dist/MapillaryPanel-QX6NESX7.js +0 -2
  50. package/dist/PanoramaxPanel-J6ANR6LB.js +0 -2
  51. package/dist/chunk-BS6LPDMY.js +0 -143
  52. package/dist/chunk-ZH3TPW4D.js +0 -165
@@ -0,0 +1,309 @@
1
+ import { useViewerActions } from './chunk-25UGGXIE.js';
2
+ import { viewFromOutline, SIGN_TARGET, viewFromFlatCamera, cameraPitch, panoX, bearingDeg, viewFromLocation, getStreetImageryConfig, fetchImageDetections } from '@osm-editor-kit/street-imagery';
3
+ import 'mapillary-js/dist/mapillary.css';
4
+ import { OutlineTag, PolygonGeometry, Viewer } from 'mapillary-js';
5
+ import { useRef, useEffectEvent, useEffect } from 'react';
6
+ import { jsx } from 'react/jsx-runtime';
7
+
8
+ var isSpherical = (image) => image.cameraType === "spherical" || image.cameraType === "equirectangular";
9
+ var mapillaryViewFor = async (viewer, image, { lngLat, shape = SIGN_TARGET, outline }) => {
10
+ const spherical = isSpherical(image);
11
+ if (outline?.length) {
12
+ return viewFromOutline(outline, spherical, shape.maxZoom);
13
+ }
14
+ const position = image.lngLat ?? image.originalLngLat;
15
+ const imageLngLat = [position.lng, position.lat];
16
+ const compass = image.computedCompassAngle ?? image.compassAngle;
17
+ if (!spherical) {
18
+ const focal = image.cameraParameters?.[0];
19
+ return focal ? viewFromFlatCamera(
20
+ {
21
+ focal,
22
+ width: image.width,
23
+ height: image.height,
24
+ compassAngle: compass,
25
+ pitch: cameraPitch(image.rotation)
26
+ },
27
+ imageLngLat,
28
+ lngLat,
29
+ shape
30
+ ) : void 0;
31
+ }
32
+ let x = panoX(bearingDeg(imageLngLat, lngLat), compass);
33
+ try {
34
+ viewer.setCenter([x, 0.5]);
35
+ const pixel = await viewer.project({ lng: lngLat[0], lat: lngLat[1] });
36
+ const basic = pixel ? await viewer.unprojectToBasic(pixel) : null;
37
+ const projected = basic?.[0];
38
+ if (projected != null && projected >= 0 && projected <= 1) {
39
+ x = projected;
40
+ }
41
+ } catch {
42
+ }
43
+ return viewFromLocation(x, { lngLat: imageLngLat, isPano: true }, lngLat, shape);
44
+ };
45
+ var xDistance = (a, b, spherical) => {
46
+ const distance = Math.abs(a - b);
47
+ return spherical ? Math.min(distance, 1 - distance) : distance;
48
+ };
49
+ var findOwnDetection = async (image, value, estimate) => {
50
+ const spherical = isSpherical(image);
51
+ const candidates = await fetchImageDetections(image.id, { filter: (v) => v === value }).catch(
52
+ () => []
53
+ );
54
+ const centerX = (detection) => viewFromOutline(detection.outline, spherical)?.center[0] ?? 0.5;
55
+ return candidates.sort(
56
+ (a, b) => estimate ? xDistance(centerX(a), estimate.center[0], spherical) - xDistance(centerX(b), estimate.center[0], spherical) : 0
57
+ )[0];
58
+ };
59
+ var turnMapillaryViewerTo = async (viewer, image, lookAt) => {
60
+ let outline = lookAt.outline?.length ? lookAt.outline : void 0;
61
+ let outlineId = `look-at-${image.id}`;
62
+ let view;
63
+ if (!outline) {
64
+ view = await mapillaryViewFor(viewer, image, lookAt);
65
+ const own = lookAt.value ? await findOwnDetection(image, lookAt.value, view) : void 0;
66
+ if (own) {
67
+ outline = own.outline;
68
+ outlineId = own.id;
69
+ }
70
+ }
71
+ if (outline) {
72
+ view = viewFromOutline(outline, isSpherical(image), (lookAt.shape ?? SIGN_TARGET).maxZoom);
73
+ }
74
+ if (!view) {
75
+ return false;
76
+ }
77
+ viewer.setCenter(view.center);
78
+ viewer.setZoom(view.zoom);
79
+ return outline ? { id: outlineId, outline, label: lookAt.label } : null;
80
+ };
81
+ var setMapillaryViewerOutlines = (viewer, outlines) => {
82
+ const tags = viewer.getComponent("tag");
83
+ tags.removeAll();
84
+ tags.add(
85
+ outlines.filter(({ outline }) => outline.length >= 3).map(({ id, outline, label, color = 16776960 }) => {
86
+ const first = outline[0];
87
+ const last = outline[outline.length - 1];
88
+ const closed = first[0] === last[0] && first[1] === last[1] ? outline : [...outline, first];
89
+ return new OutlineTag(id, new PolygonGeometry(closed), {
90
+ text: label,
91
+ textColor: color,
92
+ lineColor: color,
93
+ lineWidth: 2,
94
+ fillColor: color,
95
+ fillOpacity: 0.3
96
+ });
97
+ })
98
+ );
99
+ };
100
+ var panoCenterX = (bearing, compassAngle) => ((0.5 + (bearing - compassAngle) / 360) % 1 + 1) % 1;
101
+ var MapillaryPanel = ({
102
+ photo,
103
+ onPhotoSelected,
104
+ onEaseMapToPoint,
105
+ onViewerPhoto,
106
+ lookAtBearing,
107
+ lookAt,
108
+ outlines,
109
+ hideAttribution = false
110
+ }) => {
111
+ const containerRef = useRef(null);
112
+ const viewerRef = useRef(null);
113
+ const navigableRef = useRef(false);
114
+ const pendingImageIdRef = useRef(null);
115
+ const lastViewerPhotoIdRef = useRef(null);
116
+ const bearingRafRef = useRef(null);
117
+ const pendingBearingRef = useRef(null);
118
+ const actions = useViewerActions();
119
+ const initialPhotoIdRef = useRef(photo.photoId);
120
+ const initialHideAttributionRef = useRef(hideAttribution);
121
+ const emitPhotoSelected = useEffectEvent(onPhotoSelected);
122
+ const emitEaseMapToPoint = useEffectEvent(onEaseMapToPoint);
123
+ const turnToWantedBearing = useEffectEvent((viewer, image) => {
124
+ if (image.id !== photo.photoId) {
125
+ return;
126
+ }
127
+ if (lookAt) {
128
+ void turnMapillaryViewerTo(viewer, image, lookAt).then((aimedAt) => {
129
+ if (aimedAt && !outlines && lastViewerPhotoIdRef.current === image.id) {
130
+ setMapillaryViewerOutlines(viewer, [aimedAt]);
131
+ }
132
+ }).catch(() => {
133
+ });
134
+ return;
135
+ }
136
+ const spherical = image.cameraType === "spherical" || image.cameraType === "equirectangular";
137
+ const compass = image.computedCompassAngle ?? image.compassAngle;
138
+ if (lookAtBearing != null && spherical && compass != null) {
139
+ viewer.setCenter([panoCenterX(lookAtBearing, compass), 0.5]);
140
+ }
141
+ });
142
+ const drawOutlines = useEffectEvent((viewer) => {
143
+ setMapillaryViewerOutlines(viewer, outlines ?? []);
144
+ });
145
+ const emitViewerPhoto = useEffectEvent(
146
+ (viewerPhoto) => onViewerPhoto?.(viewerPhoto)
147
+ );
148
+ useEffect(
149
+ function resetViewerStoreOnProviderChange() {
150
+ return () => {
151
+ actions.reset();
152
+ };
153
+ },
154
+ [actions, photo.providerId]
155
+ );
156
+ useEffect(
157
+ function mountMapillaryViewer() {
158
+ const container = containerRef.current;
159
+ if (!container) {
160
+ return;
161
+ }
162
+ const viewer = new Viewer({
163
+ accessToken: getStreetImageryConfig().mapillaryToken,
164
+ container,
165
+ imageId: initialPhotoIdRef.current,
166
+ component: {
167
+ attribution: !initialHideAttributionRef.current,
168
+ cover: false,
169
+ sequence: { visible: true },
170
+ tag: true
171
+ }
172
+ });
173
+ viewerRef.current = viewer;
174
+ lastViewerPhotoIdRef.current = initialPhotoIdRef.current;
175
+ const flushPendingMove = () => {
176
+ const pendingId = pendingImageIdRef.current;
177
+ if (!pendingId) {
178
+ return;
179
+ }
180
+ pendingImageIdRef.current = null;
181
+ void viewer.moveTo(pendingId).catch(() => {
182
+ });
183
+ };
184
+ const onNavigable = (event) => {
185
+ navigableRef.current = event.navigable;
186
+ if (event.navigable) {
187
+ flushPendingMove();
188
+ }
189
+ };
190
+ const onImage = (event) => {
191
+ const { image } = event;
192
+ lastViewerPhotoIdRef.current = image.id;
193
+ turnToWantedBearing(viewer, image);
194
+ drawOutlines(viewer);
195
+ emitPhotoSelected({
196
+ provider: "mapillary",
197
+ sequenceId: image.sequenceId,
198
+ photoId: image.id
199
+ });
200
+ const position = image.lngLat ?? image.originalLngLat;
201
+ if (!position) {
202
+ return;
203
+ }
204
+ emitViewerPhoto({
205
+ providerId: "mapillary",
206
+ photoId: image.id,
207
+ sequenceId: image.sequenceId,
208
+ capturedAt: image.capturedAt,
209
+ isPano: image.cameraType === "spherical" || image.cameraType === "equirectangular",
210
+ heading: image.computedCompassAngle ?? image.compassAngle,
211
+ lngLat: [position.lng, position.lat],
212
+ ...image.creatorUsername ? { creatorName: image.creatorUsername } : {}
213
+ });
214
+ const isFlat = image.cameraType !== "spherical" && image.cameraType !== "equirectangular";
215
+ const compass = image.computedCompassAngle ?? image.compassAngle;
216
+ actions.setPov({
217
+ lngLat: [position.lng, position.lat],
218
+ ...isFlat && compass != null ? { bearing: compass } : {}
219
+ });
220
+ emitEaseMapToPoint(position.lng, position.lat);
221
+ };
222
+ const flushBearing = () => {
223
+ bearingRafRef.current = null;
224
+ if (pendingBearingRef.current != null) {
225
+ actions.setPov({ bearing: pendingBearingRef.current });
226
+ pendingBearingRef.current = null;
227
+ }
228
+ void viewer.getFieldOfView().then((fov) => {
229
+ actions.setPov({ hfov: fov });
230
+ }).catch(() => {
231
+ });
232
+ };
233
+ const onBearing = (event) => {
234
+ pendingBearingRef.current = event.bearing;
235
+ if (bearingRafRef.current == null) {
236
+ bearingRafRef.current = requestAnimationFrame(flushBearing);
237
+ }
238
+ };
239
+ viewer.on("navigable", onNavigable);
240
+ viewer.on("image", onImage);
241
+ viewer.on("bearing", onBearing);
242
+ const resizeObserver = new ResizeObserver(() => {
243
+ viewer.resize();
244
+ });
245
+ resizeObserver.observe(container);
246
+ return () => {
247
+ if (bearingRafRef.current != null) {
248
+ cancelAnimationFrame(bearingRafRef.current);
249
+ bearingRafRef.current = null;
250
+ }
251
+ resizeObserver.disconnect();
252
+ viewer.off("navigable", onNavigable);
253
+ viewer.off("image", onImage);
254
+ viewer.off("bearing", onBearing);
255
+ viewer.remove();
256
+ viewerRef.current = null;
257
+ };
258
+ },
259
+ [actions]
260
+ );
261
+ useEffect(
262
+ function syncExternalPhotoSelection() {
263
+ const viewer = viewerRef.current;
264
+ if (!viewer || photo.photoId === lastViewerPhotoIdRef.current) {
265
+ return;
266
+ }
267
+ actions.reset();
268
+ lastViewerPhotoIdRef.current = photo.photoId;
269
+ if (navigableRef.current) {
270
+ void viewer.moveTo(photo.photoId).catch(() => {
271
+ });
272
+ } else {
273
+ pendingImageIdRef.current = photo.photoId;
274
+ }
275
+ },
276
+ [actions, photo.photoId]
277
+ );
278
+ const lookAtKey = lookAt ? `${lookAt.lngLat.join(",")}|${lookAt.outline?.length ?? 0}|${lookAt.value ?? ""}` : String(lookAtBearing);
279
+ useEffect(
280
+ function turnToTargetOnChange() {
281
+ const viewer = viewerRef.current;
282
+ if (!viewer || lastViewerPhotoIdRef.current !== photo.photoId) {
283
+ return;
284
+ }
285
+ void viewer.getImage().then((image) => turnToWantedBearing(viewer, image)).catch(() => {
286
+ });
287
+ },
288
+ [lookAtKey, photo.photoId]
289
+ );
290
+ useEffect(
291
+ function redrawOutlinesOnChange() {
292
+ const viewer = viewerRef.current;
293
+ if (viewer && navigableRef.current) {
294
+ drawOutlines(viewer);
295
+ }
296
+ },
297
+ [outlines]
298
+ );
299
+ return /* @__PURE__ */ jsx(
300
+ "div",
301
+ {
302
+ ref: containerRef,
303
+ className: "min-h-48 overflow-hidden rounded-lg border border-slate-200 bg-slate-900",
304
+ style: { aspectRatio: "4 / 3" }
305
+ }
306
+ );
307
+ };
308
+
309
+ export { MapillaryPanel, mapillaryViewFor, setMapillaryViewerOutlines, turnMapillaryViewerTo };