@trailstash/ultra
Version:
A web based tool for making MapLibre GL maps with data from sources such as Overpass, GeoJSON, GPX, KML, TCX, etc
58 lines (50 loc) • 1.72 kB
JavaScript
export default class AutoProvider {
constructor(providers = {}) {
//super();
this.
}
async source(query, controller, { server, bounds }) {
console.log(Array.from(Object.keys(this.
for (const [type, provider] of Object.entries(this.
if (!provider.detect) {
continue;
}
console.log("trying", type);
if (await Promise.resolve(provider.detect(query, bounds))) {
console.log("detected", type);
this.
this.
this.
this.
this.
return provider.source(query, controller, { server, bounds });
}
}
throw new Error("Could not determine query type!");
}
get fitBounds() {
return this.
}
get layers() {
return this.
}
get popupContextBuilder() {
return this.
}
get popupTemplate() {
return this.
}
get invalidateCacheOnBBox() {
// This isn't ideal, because this is called _before_ `source`, but it will work because it's either:
// * undefined & the first run, so bc first run it always will execute anyway
// * different type, which might mean a different invalidateCacheOnBBox value, but we always run on new type anyway
// * type unchanged, & subsequent run, so actually valid value
return this.
}
}