forked from MapComplete/MapComplete
Feature(offline): rework to use a protocol handler instead of a service worker to intercept as service workers don't always work, simplify code, add option to auto-download
This commit is contained in:
parent
ca819cf8a6
commit
44748051dd
11 changed files with 193 additions and 293 deletions
|
|
@ -142,6 +142,8 @@ export default class Constants {
|
|||
public static readonly mapillary_client_token_v4 = Constants.config.api_keys.mapillary_v4
|
||||
public static defaultOverpassUrls = Constants.config.default_overpass_urls
|
||||
public static countryCoderEndpoint: string = Constants.config.country_coder_host
|
||||
public static readonly pmtiles_host = Constants.config.protomaps_archive_server
|
||||
|
||||
public static countryCoderInfo: ServerSourceInfo = {
|
||||
url: this.countryCoderEndpoint,
|
||||
trigger: ["always"],
|
||||
|
|
|
|||
|
|
@ -22,6 +22,10 @@ import { GeolocationControlState } from "../../UI/BigComponents/GeolocationContr
|
|||
import ShowOverlayRasterLayer from "../../UI/Map/ShowOverlayRasterLayer"
|
||||
import { BBox } from "../../Logic/BBox"
|
||||
import ShowDataLayer from "../../UI/Map/ShowDataLayer"
|
||||
import { OfflineBasemapManager } from "../../Logic/OfflineBasemapManager"
|
||||
import { IsOnline } from "../../Logic/Web/IsOnline"
|
||||
import { Tiles } from "../TileRange"
|
||||
import { LocalStorageSource } from "../../Logic/Web/LocalStorageSource"
|
||||
|
||||
/**
|
||||
* The first core of the state management; everything related to:
|
||||
|
|
@ -51,6 +55,8 @@ export class UserMapFeatureswitchState extends WithUserRelatedState {
|
|||
readonly currentView: FeatureSource<Feature<Polygon>>
|
||||
readonly fullNodeDatabase?: FullNodeDatabaseSource
|
||||
|
||||
readonly offlineMapManager = OfflineBasemapManager.singleton
|
||||
public readonly autoDownloadOfflineBasemap = UIEventSource.asBoolean(LocalStorageSource.get("autodownload-offline-basemaps", "true"))
|
||||
constructor(theme: ThemeConfig, selectedElement: Store<object>) {
|
||||
const rasterLayer: UIEventSource<RasterLayerPolygon> =
|
||||
new UIEventSource<RasterLayerPolygon>(undefined)
|
||||
|
|
@ -130,6 +136,7 @@ export class UserMapFeatureswitchState extends WithUserRelatedState {
|
|||
this.initHotkeys()
|
||||
this.drawOverlayLayers()
|
||||
this.drawLock()
|
||||
this.downloadOfflineBasemaps()
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -278,4 +285,18 @@ export class UserMapFeatureswitchState extends WithUserRelatedState {
|
|||
metaTags: this.userRelatedState.preferencesAsTags,
|
||||
})
|
||||
}
|
||||
|
||||
private downloadOfflineBasemaps() {
|
||||
const tile = this.mapProperties.location.mapD(l => {
|
||||
if (!IsOnline.isOnline.data || !this.autoDownloadOfflineBasemap.data) {
|
||||
return undefined
|
||||
}
|
||||
const z = Math.min(Math.floor(this.mapProperties.zoom.data), 10)
|
||||
return Tiles.embedded_tile(l.lat, l.lon, z)
|
||||
},
|
||||
[IsOnline.isOnline, this.mapProperties.zoom, this.autoDownloadOfflineBasemap])
|
||||
tile.addCallbackAndRunD(tile => {
|
||||
this.offlineMapManager.autoInstall(tile)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue