forked from MapComplete/MapComplete
Add button to reload the cache in the import helper
This commit is contained in:
parent
50a7597c5a
commit
34e7a98d5d
3 changed files with 37 additions and 19 deletions
|
@ -47,6 +47,27 @@ export default class ConflationChecker extends Combine implements FlowStep<{ fea
|
|||
const toImport: {features: any[]} = params;
|
||||
let overpassStatus = new UIEventSource<{ error: string } | "running" | "success" | "idle" | "cached">("idle")
|
||||
const cacheAge = new UIEventSource<number>(undefined);
|
||||
|
||||
|
||||
function loadDataFromOverpass(){
|
||||
// Load the data!
|
||||
const url = Constants.defaultOverpassUrls[1]
|
||||
const relationTracker = new RelationsTracker()
|
||||
const overpass = new Overpass(params.layer.source.osmTags, [], url, new UIEventSource<number>(180), relationTracker, true)
|
||||
console.log("Loading from overpass!")
|
||||
overpassStatus.setData("running")
|
||||
overpass.queryGeoJson(bbox).then(
|
||||
([data, date]) => {
|
||||
console.log("Received overpass-data: ", data.features.length, "features are loaded at ", date);
|
||||
overpassStatus.setData("success")
|
||||
fromLocalStorage.setData([data, date])
|
||||
},
|
||||
(error) => {
|
||||
overpassStatus.setData({error})
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
const fromLocalStorage = IdbLocalStorage.Get<[any, Date]>("importer-overpass-cache-" + layer.id, {
|
||||
|
||||
whenLoaded: (v) => {
|
||||
|
@ -63,22 +84,7 @@ export default class ConflationChecker extends Combine implements FlowStep<{ fea
|
|||
}
|
||||
cacheAge.setData(-1)
|
||||
}
|
||||
// Load the data!
|
||||
const url = Constants.defaultOverpassUrls[1]
|
||||
const relationTracker = new RelationsTracker()
|
||||
const overpass = new Overpass(params.layer.source.osmTags, [], url, new UIEventSource<number>(180), relationTracker, true)
|
||||
console.log("Loading from overpass!")
|
||||
overpassStatus.setData("running")
|
||||
overpass.queryGeoJson(bbox).then(
|
||||
([data, date]) => {
|
||||
console.log("Received overpass-data: ", data.features.length, "features are loaded at ", date);
|
||||
overpassStatus.setData("success")
|
||||
fromLocalStorage.setData([data, date])
|
||||
},
|
||||
(error) => {
|
||||
overpassStatus.setData({error})
|
||||
})
|
||||
|
||||
loadDataFromOverpass()
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -166,7 +172,7 @@ export default class ConflationChecker extends Combine implements FlowStep<{ fea
|
|||
return osmData.features.filter(f =>
|
||||
toImport.features.some(imp =>
|
||||
maxDist >= GeoOperations.distanceBetween(imp.geometry.coordinates, GeoOperations.centerpointCoordinates(f))))
|
||||
}, [nearbyCutoff.GetValue()]), false);
|
||||
}, [nearbyCutoff.GetValue().stabilized(500)]), false);
|
||||
const paritionedImport = ImportUtils.partitionFeaturesIfNearby(toImport, geojson, nearbyCutoff.GetValue().map(Number));
|
||||
|
||||
// Featuresource showing OSM-features which are nearby a toImport-feature
|
||||
|
@ -211,7 +217,11 @@ export default class ConflationChecker extends Combine implements FlowStep<{ fea
|
|||
if (age < 0) {
|
||||
return t.cacheExpired
|
||||
}
|
||||
return t.loadedDataAge.Subs({age: Utils.toHumanTime(age)})
|
||||
return new Combine([t.loadedDataAge.Subs({age: Utils.toHumanTime(age)}),
|
||||
new SubtleButton(Svg.reload_svg().SetClass("h-8"), t.reloadTheCache)
|
||||
.onClick(loadDataFromOverpass)
|
||||
.SetClass("h-12")
|
||||
])
|
||||
})),
|
||||
|
||||
new Title(t.titleLive),
|
||||
|
|
|
@ -321,6 +321,7 @@
|
|||
"nearbyWarn": "The {count} red elements on the following map will <b>not</b> be imported!",
|
||||
"nothingLoaded": "No elements are loaded from OpenStreetMap which match the current layer {name}",
|
||||
"osmLoaded": "{count} elements are loaded from OpenStreetMap which match the layer <b>{name}</b>.",
|
||||
"reloadTheCache": "Clear the cache and query overpass again",
|
||||
"setRangeToZero": "Set the range to 0 or 1 if you want to import them all",
|
||||
"states": {
|
||||
"error": "Could not load latest data from overpass due to {error}",
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
import * as fs from "fs";
|
||||
import {TagUtils} from "../Logic/Tags/TagUtils";
|
||||
import {writeFileSync} from "fs";
|
||||
import {TagsFilter} from "../Logic/Tags/TagsFilter";
|
||||
|
||||
function main(args) {
|
||||
if (args.length < 2) {
|
||||
|
@ -13,7 +14,13 @@ function main(args) {
|
|||
const output = args[2]
|
||||
|
||||
const data = JSON.parse(fs.readFileSync(path, "UTF8"))
|
||||
const filter = TagUtils.Tag(JSON.parse(spec))
|
||||
let filter : TagsFilter ;
|
||||
try{
|
||||
filter = TagUtils.Tag(JSON.parse(spec))
|
||||
|
||||
}catch(e){
|
||||
filter = TagUtils.Tag(spec)
|
||||
}
|
||||
const features = data.features.filter(f => filter.matchesProperties(f.properties))
|
||||
|
||||
if(features.length === 0){
|
||||
|
|
Loading…
Reference in a new issue