forked from MapComplete/MapComplete
Preparatory steps to query OSM-api directly, add precise input to bench and waste basket, add waste types
This commit is contained in:
parent
3c51c28157
commit
b39a2b2f6e
7 changed files with 108 additions and 14 deletions
|
@ -23,6 +23,7 @@ export default class OverpassFeatureSource implements FeatureSource {
|
|||
public readonly sufficientlyZoomed: UIEventSource<boolean>;
|
||||
public readonly runningQuery: UIEventSource<boolean> = new UIEventSource<boolean>(false);
|
||||
public readonly timeout: UIEventSource<number> = new UIEventSource<number>(0);
|
||||
|
||||
private readonly retries: UIEventSource<number> = new UIEventSource<number>(0);
|
||||
/**
|
||||
* The previous bounds for which the query has been run at the given zoom level
|
||||
|
@ -46,7 +47,8 @@ export default class OverpassFeatureSource implements FeatureSource {
|
|||
layoutToUse: UIEventSource<LayoutConfig>,
|
||||
leafletMap: UIEventSource<L.Map>,
|
||||
interpreterUrl: UIEventSource<string>,
|
||||
timeout: UIEventSource<number>,) {
|
||||
timeout: UIEventSource<number>,
|
||||
maxZoom = undefined) {
|
||||
this._location = location;
|
||||
this._layoutToUse = layoutToUse;
|
||||
this._leafletMap = leafletMap;
|
||||
|
@ -59,7 +61,14 @@ export default class OverpassFeatureSource implements FeatureSource {
|
|||
return false;
|
||||
}
|
||||
let minzoom = Math.min(...layoutToUse.data.layers.map(layer => layer.minzoom ?? 18));
|
||||
return location.zoom >= minzoom;
|
||||
if(location.zoom < minzoom){
|
||||
return false;
|
||||
}
|
||||
if(maxZoom !== undefined && location.zoom > maxZoom){
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}, [layoutToUse]
|
||||
);
|
||||
for (let i = 0; i < 25; i++) {
|
||||
|
|
|
@ -1,16 +1,34 @@
|
|||
import FeatureSource from "./FeatureSource";
|
||||
import {UIEventSource} from "../UIEventSource";
|
||||
import {OsmObject} from "../Osm/OsmObject";
|
||||
import State from "../../State";
|
||||
import {Utils} from "../../Utils";
|
||||
import Loc from "../../Models/Loc";
|
||||
import FilteredLayer from "../../Models/FilteredLayer";
|
||||
import Constants from "../../Models/Constants";
|
||||
|
||||
|
||||
export default class OsmApiFeatureSource implements FeatureSource {
|
||||
public readonly features: UIEventSource<{ feature: any; freshness: Date }[]> = new UIEventSource<{ feature: any; freshness: Date }[]>([]);
|
||||
public readonly name: string = "OsmApiFeatureSource";
|
||||
private readonly loadedTiles: Set<string> = new Set<string>();
|
||||
private readonly _state: {
|
||||
leafletMap: UIEventSource<any>;
|
||||
locationControl: UIEventSource<Loc>, filteredLayers: UIEventSource<FilteredLayer[]>};
|
||||
|
||||
constructor() {
|
||||
constructor(minZoom = undefined, state: {locationControl: UIEventSource<Loc>, filteredLayers: UIEventSource<FilteredLayer[]>, leafletMap: UIEventSource<any>}) {
|
||||
this._state = state;
|
||||
if(minZoom !== undefined){
|
||||
if(minZoom < 14){
|
||||
throw "MinZoom should be at least 14 or higher, OSM-api won't work otherwise"
|
||||
}
|
||||
const self = this;
|
||||
state.locationControl.addCallbackAndRunD(location => {
|
||||
if(location.zoom > minZoom){
|
||||
return;
|
||||
}
|
||||
self.loadArea()
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -34,21 +52,21 @@ export default class OsmApiFeatureSource implements FeatureSource {
|
|||
/**
|
||||
* Loads the current inview-area
|
||||
*/
|
||||
public loadArea(z: number = 16): boolean {
|
||||
const layers = State.state.filteredLayers.data;
|
||||
public loadArea(z: number = 14): boolean {
|
||||
const layers = this._state.filteredLayers.data;
|
||||
|
||||
const disabledLayers = layers.filter(layer => layer.layerDef.source.overpassScript !== undefined || layer.layerDef.source.geojsonSource !== undefined)
|
||||
if (disabledLayers.length > 0) {
|
||||
return false;
|
||||
}
|
||||
const loc = State.state.locationControl.data;
|
||||
if (loc.zoom < 16) {
|
||||
const loc = this._state.locationControl.data;
|
||||
if (loc.zoom < Constants.useOsmApiAt) {
|
||||
return false;
|
||||
}
|
||||
if (State.state.leafletMap.data === undefined) {
|
||||
if (this._state.leafletMap.data === undefined) {
|
||||
return false; // Not yet inited
|
||||
}
|
||||
const bounds = State.state.leafletMap.data.getBounds()
|
||||
const bounds = this._state.leafletMap.data.getBounds()
|
||||
const tileRange = Utils.TileRangeBetween(z, bounds.getNorth(), bounds.getEast(), bounds.getSouth(), bounds.getWest())
|
||||
const self = this;
|
||||
Utils.MapRange(tileRange, (x, y) => {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue