forked from MapComplete/MapComplete
Merge latest develop
This commit is contained in:
commit
17450deb82
386 changed files with 12073 additions and 25528 deletions
|
|
@ -13,60 +13,74 @@ export default class FilteringFeatureSource implements FeatureSource {
|
|||
private readonly _is_dirty = new UIEventSource(false)
|
||||
private readonly _layer: FilteredLayer
|
||||
private previousFeatureSet: Set<any> = undefined
|
||||
private readonly _zoomlevel: Store<number>
|
||||
private readonly _selectedElement: Store<Feature>
|
||||
|
||||
constructor(
|
||||
layer: FilteredLayer,
|
||||
upstream: FeatureSource,
|
||||
fetchStore?: (id: string) => Store<Record<string, string>>,
|
||||
globalFilters?: Store<GlobalFilter[]>,
|
||||
metataggingUpdated?: Store<any>
|
||||
metataggingUpdated?: Store<any>,
|
||||
zoomlevel?: Store<number>,
|
||||
selectedElement?: Store<Feature>
|
||||
) {
|
||||
this.upstream = upstream
|
||||
this._fetchStore = fetchStore
|
||||
this._layer = layer
|
||||
this._globalFilters = globalFilters
|
||||
this._zoomlevel = zoomlevel
|
||||
this._selectedElement = selectedElement
|
||||
|
||||
const self = this
|
||||
upstream.features.addCallback(() => {
|
||||
self.update()
|
||||
this.update()
|
||||
})
|
||||
layer.isDisplayed.addCallback(() => {
|
||||
self.update()
|
||||
this.update()
|
||||
})
|
||||
|
||||
layer.appliedFilters.forEach((value) =>
|
||||
value.addCallback((_) => {
|
||||
self.update()
|
||||
this.update()
|
||||
})
|
||||
)
|
||||
|
||||
this._is_dirty.stabilized(1000).addCallbackAndRunD((dirty) => {
|
||||
if (dirty) {
|
||||
self.update()
|
||||
this.update()
|
||||
}
|
||||
})
|
||||
|
||||
metataggingUpdated?.addCallback((_) => {
|
||||
self._is_dirty.setData(true)
|
||||
metataggingUpdated?.addCallback(() => {
|
||||
this._is_dirty.setData(true)
|
||||
})
|
||||
|
||||
globalFilters?.addCallback((_) => {
|
||||
self.update()
|
||||
globalFilters?.addCallback(() => {
|
||||
this.update()
|
||||
})
|
||||
|
||||
selectedElement?.addCallback(() => this.update())
|
||||
|
||||
zoomlevel?.mapD((z) => Math.floor(z)).addCallback(() => this.update())
|
||||
|
||||
this.update()
|
||||
}
|
||||
|
||||
private update() {
|
||||
const self = this
|
||||
const layer = this._layer
|
||||
const features: Feature[] = this.upstream.features.data ?? []
|
||||
const includedFeatureIds = new Set<string>()
|
||||
const globalFilters = self._globalFilters?.data?.map((f) => f)
|
||||
const globalFilters = this._globalFilters?.data?.map((f) => f)
|
||||
const zoomlevel = this._zoomlevel?.data
|
||||
const selectedElement = this._selectedElement?.data?.properties?.id
|
||||
const newFeatures = (features ?? []).filter((f) => {
|
||||
self.registerCallback(f.properties.id)
|
||||
this.registerCallback(f.properties.id)
|
||||
|
||||
if (!layer.isShown(f.properties, globalFilters)) {
|
||||
if (selectedElement === f.properties.id) {
|
||||
return true
|
||||
}
|
||||
|
||||
if (!layer.isShown(f.properties, globalFilters, zoomlevel)) {
|
||||
return false
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -50,13 +50,16 @@ export default class OverpassFeatureSource implements UpdatableFeatureSource {
|
|||
options?: {
|
||||
padToTiles?: Store<number>
|
||||
isActive?: Store<boolean>
|
||||
ignoreZoom?: boolean
|
||||
}
|
||||
) {
|
||||
this.state = state
|
||||
this._isActive = options?.isActive ?? new ImmutableStore(true)
|
||||
this.padToZoomLevel = options?.padToTiles
|
||||
const self = this
|
||||
this._layersToDownload = state.zoom.map((zoom) => this.layersToDownload(zoom))
|
||||
this._layersToDownload = options?.ignoreZoom
|
||||
? new ImmutableStore(state.layers)
|
||||
: state.zoom.map((zoom) => this.layersToDownload(zoom))
|
||||
|
||||
state.bounds.mapD(
|
||||
(_) => {
|
||||
|
|
@ -103,7 +106,7 @@ export default class OverpassFeatureSource implements UpdatableFeatureSource {
|
|||
* Download the relevant data from overpass. Attempt to use a different server if one fails; only downloads the relevant layers
|
||||
* @private
|
||||
*/
|
||||
public async updateAsync(): Promise<void> {
|
||||
public async updateAsync(overrideBounds?: BBox): Promise<void> {
|
||||
let data: any = undefined
|
||||
let lastUsed = 0
|
||||
const start = new Date()
|
||||
|
|
@ -122,9 +125,11 @@ export default class OverpassFeatureSource implements UpdatableFeatureSource {
|
|||
let bounds: BBox
|
||||
do {
|
||||
try {
|
||||
bounds = this.state.bounds.data
|
||||
?.pad(this.state.widenFactor)
|
||||
?.expandToTileBounds(this.padToZoomLevel?.data)
|
||||
bounds =
|
||||
overrideBounds ??
|
||||
this.state.bounds.data
|
||||
?.pad(this.state.widenFactor)
|
||||
?.expandToTileBounds(this.padToZoomLevel?.data)
|
||||
if (!bounds) {
|
||||
return
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ import { FeatureSource, UpdatableFeatureSource } from "../FeatureSource"
|
|||
import { Or } from "../../Tags/Or"
|
||||
import FeatureSwitchState from "../../State/FeatureSwitchState"
|
||||
import OverpassFeatureSource from "./OverpassFeatureSource"
|
||||
import { Store, UIEventSource } from "../../UIEventSource"
|
||||
import { ImmutableStore, Store, UIEventSource } from "../../UIEventSource"
|
||||
import OsmFeatureSource from "./OsmFeatureSource"
|
||||
import DynamicGeoJsonTileSource from "../TiledFeatureSource/DynamicGeoJsonTileSource"
|
||||
import { BBox } from "../../BBox"
|
||||
|
|
@ -28,6 +28,13 @@ export default class ThemeSource extends FeatureSourceMerger {
|
|||
|
||||
public static readonly fromCacheZoomLevel = 15
|
||||
|
||||
/**
|
||||
* This source is _only_ triggered when the data is downloaded for CSV export
|
||||
* @private
|
||||
*/
|
||||
private readonly _downloadAll: OverpassFeatureSource
|
||||
private readonly _mapBounds: Store<BBox>
|
||||
|
||||
constructor(
|
||||
layers: LayerConfig[],
|
||||
featureSwitches: FeatureSwitchState,
|
||||
|
|
@ -103,11 +110,37 @@ export default class ThemeSource extends FeatureSourceMerger {
|
|||
ThemeSource.setupGeojsonSource(l, mapProperties, isDisplayed(l.id))
|
||||
)
|
||||
|
||||
super(...geojsonSources, ...Array.from(fromCache.values()), ...mvtSources, ...nonMvtSources)
|
||||
const downloadAllBounds: UIEventSource<BBox> = new UIEventSource<BBox>(undefined)
|
||||
const downloadAll = new OverpassFeatureSource(
|
||||
{
|
||||
layers: layers.filter((l) => l.isNormal()),
|
||||
bounds: mapProperties.bounds,
|
||||
zoom: mapProperties.zoom,
|
||||
overpassUrl: featureSwitches.overpassUrl,
|
||||
overpassTimeout: featureSwitches.overpassTimeout,
|
||||
overpassMaxZoom: new ImmutableStore(99),
|
||||
widenFactor: 0,
|
||||
},
|
||||
{
|
||||
ignoreZoom: true,
|
||||
}
|
||||
)
|
||||
|
||||
super(
|
||||
...geojsonSources,
|
||||
...Array.from(fromCache.values()),
|
||||
...mvtSources,
|
||||
...nonMvtSources,
|
||||
downloadAll
|
||||
)
|
||||
|
||||
this.isLoading = isLoading
|
||||
supportsForceDownload.push(...geojsonSources)
|
||||
supportsForceDownload.push(...mvtSources) // Non-mvt sources are handled by overpass
|
||||
|
||||
this._mapBounds = mapProperties.bounds
|
||||
this._downloadAll = downloadAll
|
||||
|
||||
this.supportsForceDownload = supportsForceDownload
|
||||
}
|
||||
|
||||
|
|
@ -211,8 +244,9 @@ export default class ThemeSource extends FeatureSourceMerger {
|
|||
}
|
||||
|
||||
public async downloadAll() {
|
||||
console.log("Downloading all data")
|
||||
await Promise.all(this.supportsForceDownload.map((i) => i.updateAsync()))
|
||||
console.log("Downloading all data:")
|
||||
await this._downloadAll.updateAsync(this._mapBounds.data)
|
||||
// await Promise.all(this.supportsForceDownload.map((i) => i.updateAsync()))
|
||||
console.log("Done")
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -829,7 +829,7 @@ export class GeoOperations {
|
|||
}
|
||||
return undefined
|
||||
default:
|
||||
throw "Unkown location type: " + location + " for feature " + feature.properties.id
|
||||
throw "Unknown location type: " + location + " for feature " + feature.properties.id
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -68,7 +68,7 @@ export default class AllImageProviders {
|
|||
|
||||
private static readonly _cachedImageStores: Record<string, Store<ProvidedImage[]>> = {}
|
||||
/**
|
||||
* Tries to extract all image data for this image. Cachedon tags?.data?.id
|
||||
* Tries to extract all image data for this image. Cached on tags?.data?.id
|
||||
*/
|
||||
public static LoadImagesFor(
|
||||
tags: Store<Record<string, string>>,
|
||||
|
|
@ -78,8 +78,9 @@ export default class AllImageProviders {
|
|||
return undefined
|
||||
}
|
||||
const id = tags?.data?.id
|
||||
if(this._cachedImageStores[id]){
|
||||
return this._cachedImageStores[id]
|
||||
const cachekey = id + (tagKey?.join(";") ?? "")
|
||||
if (this._cachedImageStores[cachekey]) {
|
||||
return this._cachedImageStores[cachekey]
|
||||
}
|
||||
|
||||
const source = new UIEventSource([])
|
||||
|
|
@ -90,6 +91,7 @@ export default class AllImageProviders {
|
|||
However, we override them if a custom image tag is set, e.g. 'image:menu'
|
||||
*/
|
||||
const prefixes = tagKey ?? imageProvider.defaultKeyPrefixes
|
||||
console.log("Prefixes are", tagKey, prefixes)
|
||||
const singleSource = tags.bindD((tags) => imageProvider.getRelevantUrls(tags, prefixes))
|
||||
allSources.push(singleSource)
|
||||
singleSource.addCallbackAndRunD((_) => {
|
||||
|
|
@ -98,21 +100,19 @@ export default class AllImageProviders {
|
|||
source.set(dedup)
|
||||
})
|
||||
}
|
||||
this._cachedImageStores[id] = source
|
||||
this._cachedImageStores[cachekey] = source
|
||||
return source
|
||||
}
|
||||
|
||||
/**
|
||||
* Given a list of URLs, tries to detect the images. Used in e.g. the comments
|
||||
* @param url
|
||||
*/
|
||||
public static loadImagesFrom(urls: string[]): Store<ProvidedImage[]> {
|
||||
const tags = {
|
||||
id: "na",
|
||||
id: urls.join(";"),
|
||||
}
|
||||
for (let i = 0; i < urls.length; i++) {
|
||||
const url = urls[i]
|
||||
tags["image:" + i] = url
|
||||
tags["image:" + i] = urls[i]
|
||||
}
|
||||
return this.LoadImagesFor(new ImmutableStore(tags))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -89,7 +89,7 @@ export default abstract class ImageProvider {
|
|||
|
||||
public abstract apiUrls(): string[]
|
||||
|
||||
public static async offerImageAsDownload(image: ProvidedImage){
|
||||
public static async offerImageAsDownload(image: ProvidedImage) {
|
||||
const response = await fetch(image.url_hd ?? image.url)
|
||||
const blob = await response.blob()
|
||||
Utils.offerContentsAsDownloadableFile(blob, new URL(image.url).pathname.split("/").at(-1), {
|
||||
|
|
|
|||
|
|
@ -157,14 +157,15 @@ export class ImageUploadManager {
|
|||
blob: File,
|
||||
targetKey: string | undefined,
|
||||
noblur: boolean,
|
||||
feature?: Feature
|
||||
feature?: Feature,
|
||||
ignoreGps: boolean = false
|
||||
): Promise<UploadResult> {
|
||||
this.increaseCountFor(this._uploadStarted, featureId)
|
||||
let key: string
|
||||
let value: string
|
||||
let absoluteUrl: string
|
||||
let location: [number, number] = undefined
|
||||
if (this._gps.data) {
|
||||
if (this._gps.data && !ignoreGps) {
|
||||
location = [this._gps.data.longitude, this._gps.data.latitude]
|
||||
}
|
||||
if (location === undefined || location?.some((l) => l === undefined)) {
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ export class Imgur extends ImageProvider {
|
|||
public readonly defaultKeyPrefixes: string[] = ["image"]
|
||||
public static readonly apiUrl = "https://api.imgur.com/3/image"
|
||||
public static readonly supportingUrls = ["https://i.imgur.com"]
|
||||
|
||||
private constructor() {
|
||||
super()
|
||||
}
|
||||
|
|
@ -37,6 +38,37 @@ export class Imgur extends ImageProvider {
|
|||
return undefined
|
||||
}
|
||||
|
||||
public static parseLicense(descr: string) {
|
||||
const data: Record<string, string> = {}
|
||||
|
||||
if (!descr) {
|
||||
return undefined
|
||||
}
|
||||
if (descr.toLowerCase() === "cc0") {
|
||||
data.author = "Unknown"
|
||||
data.license = "CC0"
|
||||
} else {
|
||||
for (const tag of descr.split("\n")) {
|
||||
const kv = tag.split(":")
|
||||
if (kv.length < 2) {
|
||||
continue
|
||||
}
|
||||
const k = kv[0]
|
||||
data[k] = kv[1]?.replace(/\r/g, "")
|
||||
}
|
||||
}
|
||||
if (Object.keys(data).length === 0) {
|
||||
return undefined
|
||||
}
|
||||
|
||||
const licenseInfo = new LicenseInfo()
|
||||
|
||||
licenseInfo.licenseShortName = data.license
|
||||
licenseInfo.artist = data.author
|
||||
|
||||
return licenseInfo
|
||||
}
|
||||
|
||||
/**
|
||||
* Download the attribution and license info for the picture at the given URL
|
||||
*
|
||||
|
|
@ -56,9 +88,14 @@ export class Imgur extends ImageProvider {
|
|||
*
|
||||
*
|
||||
*/
|
||||
public async DownloadAttribution(providedImage: { url: string }): Promise<LicenseInfo> {
|
||||
public async DownloadAttribution(
|
||||
providedImage: {
|
||||
url: string
|
||||
},
|
||||
withResponse?: (obj) => void
|
||||
): Promise<LicenseInfo> {
|
||||
const url = providedImage.url
|
||||
const hash = url.substr("https://i.imgur.com/".length).split(/\.jpe?g/i)[0]
|
||||
const hash = url.substr("https://i.imgur.com/".length).split(/(\.jpe?g)|(\.png)/i)[0]
|
||||
|
||||
const apiUrl = "https://api.imgur.com/3/image/" + hash
|
||||
const response = await Utils.downloadJsonCached<{
|
||||
|
|
@ -66,24 +103,17 @@ export class Imgur extends ImageProvider {
|
|||
}>(apiUrl, 365 * 24 * 60 * 60, {
|
||||
Authorization: "Client-ID " + Constants.ImgurApiKey,
|
||||
})
|
||||
|
||||
const descr = response.data.description ?? ""
|
||||
const data: any = {}
|
||||
const imgurData = response.data
|
||||
|
||||
for (const tag of descr.split("\n")) {
|
||||
const kv = tag.split(":")
|
||||
const k = kv[0]
|
||||
data[k] = kv[1]?.replace(/\r/g, "")
|
||||
if (withResponse) {
|
||||
withResponse(response)
|
||||
}
|
||||
|
||||
const licenseInfo = new LicenseInfo()
|
||||
const imgurData = response.data
|
||||
const license = Imgur.parseLicense(imgurData.description ?? "")
|
||||
if (license) {
|
||||
license.views = imgurData.views
|
||||
license.date = new Date(Number(imgurData.datetime) * 1000)
|
||||
}
|
||||
|
||||
licenseInfo.licenseShortName = data.license
|
||||
licenseInfo.artist = data.author
|
||||
licenseInfo.date = new Date(Number(imgurData.datetime) * 1000)
|
||||
licenseInfo.views = imgurData.views
|
||||
|
||||
return licenseInfo
|
||||
return license
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ import Panoramax_bw from "../../assets/svg/Panoramax_bw.svelte"
|
|||
import Link from "../../UI/Base/Link"
|
||||
|
||||
export default class PanoramaxImageProvider extends ImageProvider {
|
||||
public static readonly singleton = new PanoramaxImageProvider()
|
||||
public static readonly singleton: PanoramaxImageProvider = new PanoramaxImageProvider()
|
||||
private static readonly xyz = new PanoramaxXYZ()
|
||||
private static defaultPanoramax = new AuthorizedPanoramax(
|
||||
Constants.panoramax.url,
|
||||
|
|
@ -126,7 +126,11 @@ export default class PanoramaxImageProvider extends ImageProvider {
|
|||
if (!Panoramax.isId(value)) {
|
||||
return undefined
|
||||
}
|
||||
return [await this.getInfoFor(value).then((r) => this.featureToImage(<any>r))]
|
||||
return [await this.getInfo(value)]
|
||||
}
|
||||
|
||||
public async getInfo(hash: string): Promise<ProvidedImage> {
|
||||
return await this.getInfoFor(hash).then((r) => this.featureToImage(<any>r))
|
||||
}
|
||||
|
||||
getRelevantUrls(tags: Record<string, string>, prefixes: string[]): Store<ProvidedImage[]> {
|
||||
|
|
@ -138,12 +142,14 @@ export default class PanoramaxImageProvider extends ImageProvider {
|
|||
}
|
||||
return data?.some(
|
||||
(img) =>
|
||||
img?.status !== undefined && img?.status !== "ready" && img?.status !== "broken" && img?.status !== "hidden"
|
||||
img?.status !== undefined &&
|
||||
img?.status !== "ready" &&
|
||||
img?.status !== "broken" &&
|
||||
img?.status !== "hidden"
|
||||
)
|
||||
}
|
||||
|
||||
Stores.Chronic(1500, () => hasLoading(source.data)).addCallback((_) => {
|
||||
console.log("Testing panoramax URLS again as some were loading", source.data, hasLoading(source.data))
|
||||
Stores.Chronic(1500, () => hasLoading(source.data)).addCallback(() => {
|
||||
super.getRelevantUrlsFor(tags, prefixes).then((data) => {
|
||||
source.set(data)
|
||||
return !hasLoading(data)
|
||||
|
|
@ -170,12 +176,12 @@ export default class PanoramaxImageProvider extends ImageProvider {
|
|||
return ["https://panoramax.mapcomplete.org", "https://panoramax.xyz"]
|
||||
}
|
||||
|
||||
public static getPanoramaxInstance (host: string){
|
||||
public static getPanoramaxInstance(host: string) {
|
||||
host = new URL(host).host
|
||||
if(new URL(this.defaultPanoramax.host).host === host){
|
||||
if (new URL(this.defaultPanoramax.host).host === host) {
|
||||
return this.defaultPanoramax
|
||||
}
|
||||
if(new URL(this.xyz.host).host === host){
|
||||
if (new URL(this.xyz.host).host === host) {
|
||||
return this.xyz
|
||||
}
|
||||
return new Panoramax(host)
|
||||
|
|
@ -185,9 +191,9 @@ export default class PanoramaxImageProvider extends ImageProvider {
|
|||
export class PanoramaxUploader implements ImageUploader {
|
||||
public readonly panoramax: AuthorizedPanoramax
|
||||
maxFileSizeInMegabytes = 100 * 1000 * 1000 // 100MB
|
||||
private readonly _targetSequence: Store<string>
|
||||
private readonly _targetSequence?: Store<string>
|
||||
|
||||
constructor(url: string, token: string, targetSequence: Store<string>) {
|
||||
constructor(url: string, token: string, targetSequence?: Store<string>) {
|
||||
this._targetSequence = targetSequence
|
||||
this.panoramax = new AuthorizedPanoramax(url, token)
|
||||
}
|
||||
|
|
@ -197,7 +203,8 @@ export class PanoramaxUploader implements ImageUploader {
|
|||
currentGps: [number, number],
|
||||
author: string,
|
||||
noblur: boolean = false,
|
||||
sequenceId?: string
|
||||
sequenceId?: string,
|
||||
datetime?: string
|
||||
): Promise<{
|
||||
key: string
|
||||
value: string
|
||||
|
|
@ -205,22 +212,42 @@ export class PanoramaxUploader implements ImageUploader {
|
|||
}> {
|
||||
// https://panoramax.openstreetmap.fr/api/docs/swagger#/
|
||||
|
||||
let [lon, lat] = currentGps
|
||||
let datetime = new Date().toISOString()
|
||||
let [lon, lat] = currentGps ?? [undefined, undefined]
|
||||
datetime ??= new Date().toISOString()
|
||||
try {
|
||||
const tags = await ExifReader.load(blob)
|
||||
const [[latD], [latM], [latS, latSDenom]] = <
|
||||
[[number, number], [number, number], [number, number]]
|
||||
>tags?.GPSLatitude.value
|
||||
>tags?.GPSLatitude?.value
|
||||
const [[lonD], [lonM], [lonS, lonSDenom]] = <
|
||||
[[number, number], [number, number], [number, number]]
|
||||
>tags?.GPSLongitude.value
|
||||
lat = latD + latM / 60 + latS / (3600 * latSDenom)
|
||||
lon = lonD + lonM / 60 + lonS / (3600 * lonSDenom)
|
||||
|
||||
const [date, time] = tags.DateTime.value[0].split(" ")
|
||||
datetime = new Date(date.replaceAll(":", "-") + "T" + time).toISOString()
|
||||
>tags?.GPSLongitude?.value
|
||||
|
||||
const exifLat = latD + latM / 60 + latS / (3600 * latSDenom)
|
||||
const exifLon = lonD + lonM / 60 + lonS / (3600 * lonSDenom)
|
||||
if (
|
||||
typeof exifLat === "number" &&
|
||||
!isNaN(exifLat) &&
|
||||
typeof exifLon === "number" &&
|
||||
!isNaN(exifLon) &&
|
||||
!(exifLat === 0 && exifLon === 0)
|
||||
) {
|
||||
lat = exifLat
|
||||
lon = exifLon
|
||||
}
|
||||
const [date, time] =( tags.DateTime.value[0] ?? tags.DateTimeOriginal.value[0] ?? tags.GPSDateStamp ?? tags["Date Created"]).split(" ")
|
||||
const exifDatetime = new Date(date.replaceAll(":", "-") + "T" + time)
|
||||
if (exifDatetime.getFullYear() === 1970) {
|
||||
// The data probably got reset to the epoch
|
||||
// we don't use the value
|
||||
console.log(
|
||||
"Datetime from picture is probably invalid:",
|
||||
exifDatetime,
|
||||
"using 'now' instead"
|
||||
)
|
||||
} else {
|
||||
datetime = exifDatetime.toISOString()
|
||||
}
|
||||
console.log("Tags are", tags)
|
||||
} catch (e) {
|
||||
console.error("Could not read EXIF-tags")
|
||||
|
|
|
|||
|
|
@ -532,7 +532,7 @@ export class OsmConnection {
|
|||
this.auth = new osmAuth({
|
||||
client_id: this._oauth_config.oauth_client_id,
|
||||
url: this._oauth_config.url,
|
||||
scope: "read_prefs write_prefs write_api write_gpx write_notes openid",
|
||||
scope: "read_prefs write_prefs write_api write_gpx write_notes",
|
||||
redirect_uri: Utils.runningFromConsole
|
||||
? "https://mapcomplete.org/land.html"
|
||||
: window.location.protocol + "//" + window.location.host + "/land.html",
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ export default class OsmObjectDownloader {
|
|||
readonly isUploading: Store<boolean>
|
||||
}
|
||||
private readonly backend: string
|
||||
private historyCache = new Map<string, UIEventSource<OsmObject[]>>()
|
||||
private historyCache = new Map<string, Promise<OsmObject[]>>()
|
||||
|
||||
constructor(
|
||||
backend: string = "https://api.openstreetmap.org",
|
||||
|
|
@ -75,49 +75,51 @@ export default class OsmObjectDownloader {
|
|||
return await this.applyPendingChanges(obj)
|
||||
}
|
||||
|
||||
public DownloadHistory(id: NodeId): UIEventSource<OsmNode[]>
|
||||
|
||||
public DownloadHistory(id: WayId): UIEventSource<OsmWay[]>
|
||||
|
||||
public DownloadHistory(id: RelationId): UIEventSource<OsmRelation[]>
|
||||
|
||||
public DownloadHistory(id: OsmId): UIEventSource<OsmObject[]>
|
||||
|
||||
public DownloadHistory(id: string): UIEventSource<OsmObject[]> {
|
||||
if (this.historyCache.has(id)) {
|
||||
return this.historyCache.get(id)
|
||||
}
|
||||
private async _downloadHistoryUncached(id: string): Promise<OsmObject[]> {
|
||||
const splitted = id.split("/")
|
||||
const type = splitted[0]
|
||||
const idN = Number(splitted[1])
|
||||
const src = new UIEventSource<OsmObject[]>([])
|
||||
this.historyCache.set(id, src)
|
||||
Utils.downloadJsonCached(
|
||||
const data = await Utils.downloadJsonCached(
|
||||
`${this.backend}api/0.6/${type}/${idN}/history`,
|
||||
10 * 60 * 1000
|
||||
).then((data) => {
|
||||
const elements: any[] = data.elements
|
||||
const osmObjects: OsmObject[] = []
|
||||
for (const element of elements) {
|
||||
let osmObject: OsmObject = null
|
||||
element.nodes = []
|
||||
switch (type) {
|
||||
case "node":
|
||||
osmObject = new OsmNode(idN, element)
|
||||
break
|
||||
case "way":
|
||||
osmObject = new OsmWay(idN, element)
|
||||
break
|
||||
case "relation":
|
||||
osmObject = new OsmRelation(idN, element)
|
||||
break
|
||||
}
|
||||
osmObject?.SaveExtraData(element, [])
|
||||
osmObjects.push(osmObject)
|
||||
)
|
||||
const elements: [] = data["elements"]
|
||||
const osmObjects: OsmObject[] = []
|
||||
for (const element of elements) {
|
||||
let osmObject: OsmObject = null
|
||||
element["nodes"] = []
|
||||
switch (type) {
|
||||
case "node":
|
||||
osmObject = new OsmNode(idN, element)
|
||||
break
|
||||
case "way":
|
||||
osmObject = new OsmWay(idN, element)
|
||||
break
|
||||
case "relation":
|
||||
osmObject = new OsmRelation(idN, element)
|
||||
break
|
||||
}
|
||||
src.setData(osmObjects)
|
||||
})
|
||||
return src
|
||||
osmObject?.SaveExtraData(element, [])
|
||||
osmObjects.push(osmObject)
|
||||
}
|
||||
return osmObjects
|
||||
}
|
||||
|
||||
public downloadHistory(id: NodeId): Promise<OsmNode[]>
|
||||
|
||||
public downloadHistory(id: WayId): Promise<OsmWay[]>
|
||||
|
||||
public downloadHistory(id: RelationId): Promise<OsmRelation[]>
|
||||
|
||||
public downloadHistory(id: OsmId): Promise<OsmObject[]>
|
||||
|
||||
public async downloadHistory(id: string): Promise<OsmObject[]> {
|
||||
if (this.historyCache.has(id)) {
|
||||
return this.historyCache.get(id)
|
||||
}
|
||||
const promise = this._downloadHistoryUncached(id)
|
||||
this.historyCache.set(id, promise)
|
||||
return promise
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -26,7 +26,10 @@ export class Overpass {
|
|||
) {
|
||||
this._timeout = timeout ?? new ImmutableStore<number>(90)
|
||||
this._interpreterUrl = interpreterUrl
|
||||
const optimized = filter.optimize()
|
||||
if (filter === undefined && !extraScripts) {
|
||||
throw "Filter is undefined. This is probably a bug. Alternatively, pass an 'extraScript'"
|
||||
}
|
||||
const optimized = filter?.optimize()
|
||||
if (optimized === true || optimized === false) {
|
||||
throw "Invalid filter: optimizes to true of false"
|
||||
}
|
||||
|
|
@ -85,7 +88,7 @@ export class Overpass {
|
|||
* new Overpass(new Tag("key","value"), [], "").buildScript("{{bbox}}") // => `[out:json][timeout:90]{{bbox}};(nwr["key"="value"];);out body;out meta;>;out skel qt;`
|
||||
*/
|
||||
public buildScript(bbox: string, postCall: string = "", pretty = false): string {
|
||||
const filters = this._filter.asOverpass()
|
||||
const filters = this._filter?.asOverpass() ?? []
|
||||
let filter = ""
|
||||
for (const filterOr of filters) {
|
||||
if (pretty) {
|
||||
|
|
@ -97,12 +100,13 @@ export class Overpass {
|
|||
}
|
||||
}
|
||||
for (const extraScript of this._extraScripts) {
|
||||
filter += "(" + extraScript + ");"
|
||||
filter += extraScript
|
||||
}
|
||||
return `[out:json][timeout:${this._timeout.data}]${bbox};(${filter});out body;${
|
||||
this._includeMeta ? "out meta;" : ""
|
||||
}>;out skel qt;`
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs the actual script to execute on Overpass with geocoding
|
||||
* 'PostCall' can be used to set an extra range, see 'AsOverpassTurboLink'
|
||||
|
|
|
|||
|
|
@ -1,10 +1,5 @@
|
|||
import { Store, Stores, UIEventSource } from "../UIEventSource"
|
||||
import GeocodingProvider, {
|
||||
GeocodeResult,
|
||||
GeocodingOptions,
|
||||
ReverseGeocodingProvider,
|
||||
ReverseGeocodingResult,
|
||||
} from "./GeocodingProvider"
|
||||
import { Store, Stores } from "../UIEventSource"
|
||||
import GeocodingProvider, { GeocodeResult, GeocodingOptions } from "./GeocodingProvider"
|
||||
import { decode as pluscode_decode } from "pluscodes"
|
||||
|
||||
export default class OpenLocationCodeSearch implements GeocodingProvider {
|
||||
|
|
|
|||
|
|
@ -562,4 +562,15 @@ export default class UserRelatedState {
|
|||
|
||||
return amendedPrefs
|
||||
}
|
||||
|
||||
/**
|
||||
* The disabled questions for this theme and layer
|
||||
*/
|
||||
public getThemeDisabled(themeId: string, layerId: string): UIEventSource<string[]> {
|
||||
const flatSource = this.osmConnection.getPreference(
|
||||
"disabled-questions-" + themeId + "-" + layerId,
|
||||
"[]"
|
||||
)
|
||||
return UIEventSource.asObject<string[]>(flatSource, [])
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,6 +18,10 @@ export class And extends TagsFilter {
|
|||
console.error("Assertion failed: invalid subtags:", and)
|
||||
throw "Assertion failed: invalid subtags found"
|
||||
}
|
||||
if (and.some((p) => p === undefined)) {
|
||||
console.error("Assertion failed: invalid subtags:", and)
|
||||
throw "Assertion failed: invalid subtags found (undefined)"
|
||||
}
|
||||
}
|
||||
|
||||
public static construct(and: ReadonlyArray<TagsFilter>): TagsFilter
|
||||
|
|
|
|||
|
|
@ -127,10 +127,9 @@ export class RegexTag extends TagsFilter {
|
|||
return `${this.key}${invert}~${v}`
|
||||
}
|
||||
return `${this.key}${invert}~i~${v}`
|
||||
|
||||
}
|
||||
|
||||
const key :string = RegexTag.source(this.key, false)
|
||||
const key: string = RegexTag.source(this.key, false)
|
||||
return `${key}${invert}~${caseInvariant ? "i~" : ""}~${v}`
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ import { TagConfigJson } from "../../Models/ThemeConfig/Json/TagConfigJson"
|
|||
import key_counts from "../../assets/key_totals.json"
|
||||
|
||||
import { ConversionContext } from "../../Models/ThemeConfig/Conversion/ConversionContext"
|
||||
import { TagsFilterClosed, UploadableTag } from "./TagTypes"
|
||||
import { FlatTag, TagsFilterClosed, UploadableTag } from "./TagTypes"
|
||||
|
||||
type Tags = Record<string, string>
|
||||
|
||||
|
|
@ -102,12 +102,12 @@ export class TagUtils {
|
|||
"~i~~": {
|
||||
name: "Key and value should match a given regex; value is case-invariant",
|
||||
overpassSupport: true,
|
||||
docs: "Similar to ~~, except that the value is case-invariant"
|
||||
docs: "Similar to ~~, except that the value is case-invariant",
|
||||
},
|
||||
"!~i~~": {
|
||||
name: "Key and value should match a given regex; value is case-invariant",
|
||||
overpassSupport: true,
|
||||
docs: "Similar to !~~, except that the value is case-invariant"
|
||||
docs: "Similar to !~~, except that the value is case-invariant",
|
||||
},
|
||||
":=": {
|
||||
name: "Substitute `... {some_key} ...` and match `key`",
|
||||
|
|
@ -504,6 +504,8 @@ export class TagUtils {
|
|||
* regex.matchesProperties({maxspeed: "50 mph"}) // => true
|
||||
*/
|
||||
|
||||
public static Tag(json: string, context?: string | ConversionContext): FlatTag
|
||||
public static Tag(json: TagConfigJson, context?: string | ConversionContext): TagsFilterClosed
|
||||
public static Tag(
|
||||
json: TagConfigJson,
|
||||
context: string | ConversionContext = ""
|
||||
|
|
@ -802,7 +804,7 @@ export class TagUtils {
|
|||
|
||||
if (tag.indexOf("~~") >= 0 || tag.indexOf("~i~~") >= 0) {
|
||||
const caseInvariant = tag.indexOf("~i~~") >= 0
|
||||
const split = Utils.SplitFirst(tag, caseInvariant ? "~i~~" : "~~")
|
||||
const split = Utils.SplitFirst(tag, caseInvariant ? "~i~~" : "~~")
|
||||
let keyRegex: RegExp
|
||||
if (split[0] === "*") {
|
||||
keyRegex = new RegExp(".+", "i")
|
||||
|
|
@ -813,7 +815,7 @@ export class TagUtils {
|
|||
if (split[1] === "*") {
|
||||
valueRegex = new RegExp(".+", "s")
|
||||
} else {
|
||||
valueRegex = new RegExp("^(" + split[1] + ")$",caseInvariant ? "si": "s" )
|
||||
valueRegex = new RegExp("^(" + split[1] + ")$", caseInvariant ? "si" : "s")
|
||||
}
|
||||
return new RegexTag(keyRegex, valueRegex)
|
||||
}
|
||||
|
|
@ -866,7 +868,7 @@ export class TagUtils {
|
|||
tag +
|
||||
". To indicate a missing tag, use '" +
|
||||
split[0] +
|
||||
"!=' instead"
|
||||
"=' instead"
|
||||
)
|
||||
}
|
||||
if (split[1] === "") {
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ export class Stores {
|
|||
const source = new UIEventSource<Date>(undefined)
|
||||
|
||||
function run() {
|
||||
if(asLong !== undefined && !asLong()){
|
||||
if (asLong !== undefined && !asLong()) {
|
||||
return
|
||||
}
|
||||
source.setData(new Date())
|
||||
|
|
@ -727,6 +727,7 @@ export class UIEventSource<T> extends Store<T> implements Writable<T> {
|
|||
}
|
||||
|
||||
/**
|
||||
* Parse the number and round to the nearest int
|
||||
*
|
||||
* @param source
|
||||
* UIEventSource.asInt(new UIEventSource("123")).data // => 123
|
||||
|
|
|
|||
|
|
@ -371,6 +371,10 @@ export default class LinkedDataLoader {
|
|||
const match = maxstay.match(/P([0-9]+)D/)
|
||||
if (match) {
|
||||
const days = Number(match[1])
|
||||
if (days === 30) {
|
||||
// 30 is the default which is set if velopark didn't know the actual value
|
||||
return undefined
|
||||
}
|
||||
if (days === 1) {
|
||||
return "1 day"
|
||||
}
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@ export class LocalStorageSource {
|
|||
}
|
||||
const source = new UIEventSource<string>(saved ?? defaultValue, "localstorage:" + key)
|
||||
|
||||
if(!Utils.runningFromConsole){
|
||||
if (!Utils.runningFromConsole) {
|
||||
source.addCallback((data) => {
|
||||
if (data === undefined || data === "" || data === null) {
|
||||
localStorage.removeItem(key)
|
||||
|
|
|
|||
|
|
@ -80,7 +80,10 @@ export default class VeloparkLoader {
|
|||
1,
|
||||
g.maximumParkingDuration.length - 1
|
||||
)
|
||||
properties.maxstay = duration + " days"
|
||||
if (duration !== "30") {
|
||||
// We don't set maxstay if it is 30, they are the default value that velopark chose for "unknown"
|
||||
properties.maxstay = duration + " days"
|
||||
}
|
||||
}
|
||||
properties.access = g.publicAccess ?? "yes" ? "yes" : "no"
|
||||
const prefix = "http://schema.org/"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue