forked from MapComplete/MapComplete
Feature: 360-view, experimenting with photo-sphere-viewer
This commit is contained in:
parent
fb4fbe2be3
commit
4a45c650be
7 changed files with 265 additions and 29 deletions
54
src/UI/Image/photoAdapter.ts
Normal file
54
src/UI/Image/photoAdapter.ts
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
import {
|
||||
EquirectangularTilesAdapter,
|
||||
EquirectangularTilesAdapterConfig
|
||||
} from "@photo-sphere-viewer/equirectangular-tiles-adapter"
|
||||
|
||||
export class PhotoAdapter extends EquirectangularTilesAdapter {
|
||||
// This code was shamelessly stolen from https://gitlab.com/panoramax/clients/web-viewer/-/blob/develop/src/utils/PhotoAdapter.js
|
||||
// MIT-license; thank you adrien!
|
||||
|
||||
private readonly _shouldGoFast: () => boolean
|
||||
|
||||
constructor(viewer, config?: EquirectangularTilesAdapterConfig & { shouldGoFast?: () => boolean }) {
|
||||
super(viewer, config)
|
||||
this._shouldGoFast = config?.shouldGoFast ?? (() => true)
|
||||
}
|
||||
|
||||
/**
|
||||
* Override to skip loading SD images according to shouldGoFast option.
|
||||
*/
|
||||
public async loadTexture(panorama, loader) {
|
||||
if (!panorama.origBaseUrl) {
|
||||
panorama.origBaseUrl = panorama.baseUrl
|
||||
} else {
|
||||
panorama.baseUrl = panorama.origBaseUrl
|
||||
}
|
||||
|
||||
// Fast mode + thumbnail available + no HD image loaded yet + flat picture
|
||||
if (
|
||||
this._shouldGoFast()
|
||||
&& panorama.thumbUrl
|
||||
&& !panorama.hdLoaded
|
||||
&& panorama.rows == 1
|
||||
) {
|
||||
panorama.baseUrl = panorama.thumbUrl
|
||||
}
|
||||
|
||||
let data = await super.loadTexture(panorama, loader)
|
||||
if (panorama.baseUrl === panorama.origBaseUrl) {
|
||||
panorama.hdLoaded = true
|
||||
}
|
||||
return data
|
||||
}
|
||||
|
||||
/**
|
||||
* Override to skip loading tiles according to shouldGoFast option.
|
||||
* @private
|
||||
*/
|
||||
/*
|
||||
private __loadTiles(tiles) {
|
||||
if (!this._shouldGoFast()) {
|
||||
super.__loadTiles(tiles)
|
||||
}
|
||||
}*/
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue