Restructuring

This commit is contained in:
Pieter Vander Vennet 2020-07-30 00:59:08 +02:00
parent 1af27106f9
commit 5d5cf67820
27 changed files with 220 additions and 247 deletions

6
Logic/Bounds.ts Normal file
View file

@ -0,0 +1,6 @@
export interface Bounds {
north: number,
east: number,
south: number,
west: number
}

View file

@ -1,9 +1,9 @@
import {Basemap} from "./Basemap";
import {Overpass} from "./Overpass";
import {Or, TagsFilter} from "./TagsFilter";
import {UIEventSource} from "../UI/UIEventSource";
import {FilteredLayer} from "./FilteredLayer";
import {Bounds} from "./Bounds";
import {Overpass} from "./Osm/Overpass";
import {Basemap} from "./Leaflet/Basemap";
export class LayerUpdater {
private _map: Basemap;
@ -14,7 +14,7 @@ export class LayerUpdater {
/**
* The previous bounds for which the query has been run
*/
private previousBounds: { north: number, east: number, south: number, west: number };
private previousBounds: Bounds;
private _overpass: Overpass;
private _minzoom: number;
@ -93,10 +93,21 @@ export class LayerUpdater {
if (this.runningQuery.data) {
console.log("Still running a query, skip");
}
var bbox = this.buildBboxFor();
const bounds = this._map.map.getBounds();
const diff =0.07;
const n = bounds.getNorth() + diff;
const e = bounds.getEast() + diff;
const s = bounds.getSouth() - diff;
const w = bounds.getWest() - diff;
this.previousBounds = {north: n, east: e, south: s, west: w};
this.runningQuery.setData(true);
const self = this;
this._overpass.queryGeoJson(bbox,
this._overpass.queryGeoJson(this.previousBounds,
function (data) {
self.handleData(data)
},
@ -107,19 +118,7 @@ export class LayerUpdater {
}
private buildBboxFor(): string {
const b = this._map.map.getBounds();
const diff =0.07;
const n = b.getNorth() + diff;
const e = b.getEast() + diff;
const s = b.getSouth() - diff;
const w = b.getWest() - diff;
this.previousBounds = {north: n, east: e, south: s, west: w};
return "[bbox:" + s + "," + w + "," + n + "," + e + "]";
}
private IsInBounds(): boolean {

View file

@ -1,6 +1,6 @@
import L from "leaflet"
import {UIEventSource} from "../UI/UIEventSource";
import {UIElement} from "../UI/UIElement";
import {UIEventSource} from "../../UI/UIEventSource";
import {UIElement} from "../../UI/UIElement";
export class BaseLayers {

View file

@ -1,8 +1,8 @@
import {Basemap} from "./Basemap";
import {UIEventSource} from "../UI/UIEventSource";
import {UIElement} from "../UI/UIElement";
import L from "leaflet";
import {Helpers} from "../Helpers";
import {UIEventSource} from "../../UI/UIEventSource";
import {UIElement} from "../../UI/UIElement";
import {Helpers} from "../../Helpers";
export class GeoLocationHandler extends UIElement {

View file

@ -1,7 +1,7 @@
import {Basemap} from "./Basemap";
import L from "leaflet";
import {UIEventSource} from "../UI/UIEventSource";
import {UIElement} from "../UI/UIElement";
import {UIEventSource} from "../../UI/UIEventSource";
import {UIElement} from "../../UI/UIElement";
/**
* The stray-click-hanlders adds a marker to the map if no feature was clicked.

View file

@ -2,11 +2,11 @@
* Handles all changes made to OSM.
* Needs an authenticator via OsmConnection
*/
import {UIEventSource} from "../../UI/UIEventSource";
import {OsmConnection} from "./OsmConnection";
import {OsmNode, OsmObject} from "./OsmObject";
import {ElementStorage} from "./ElementStorage";
import {UIEventSource} from "../UI/UIEventSource";
import {And, Tag, TagsFilter} from "./TagsFilter";
import {And, Tag, TagsFilter} from "../TagsFilter";
import {ElementStorage} from "../ElementStorage";
export class Changes {
@ -261,11 +261,4 @@ console.log("Received change",key, value)
});
}
public asQuestions(qs : QuestionDefinition[]){
let ls = [];
for (var i in qs){
ls.push(new Question(this, qs[i]));
}
return ls;
}
}

View file

@ -1,7 +1,5 @@
import * as $ from "jquery"
import {UIEventSource} from "../UI/UIEventSource";
import {Basemap} from "./Basemap";
import {Basemap} from "../Leaflet/Basemap";
import $ from "jquery"
export class Geocoding {
private static readonly host = "https://nominatim.openstreetmap.org/search?";

9
Logic/Osm/Notes.ts Normal file
View file

@ -0,0 +1,9 @@
import {Bounds} from "../Bounds";
export class Notes {
queryGeoJson(bounds: Bounds, continuation: ((any) => void), onFail: ((reason) => void)): void {
}
}

View file

@ -1,6 +1,6 @@
// @ts-ignore
import osmAuth from "osm-auth";
import {UIEventSource} from "../UI/UIEventSource";
import {UIEventSource} from "../../UI/UIEventSource";
export class UserDetails {
@ -26,7 +26,6 @@ export class OsmConnection {
this.auth = new osmAuth({
oauth_consumer_key: 'hivV7ec2o49Two8g9h8Is1VIiVOgxQ1iYexCbvem',
oauth_secret: 'wDBRTCem0vxD7txrg1y6p5r8nvmz8tAhET7zDASI',
oauth_token: oauth_token.data,
singlepage: true,
landing: window.location.href,
auto: true // show a login form if the user is not authenticated and

View file

@ -1,11 +1,11 @@
/**
* Helps in uplaoding, by generating the rigth title, decription and by adding the tag to the changeset
*/
import {UIEventSource} from "../UI/UIEventSource";
import {ImageUploadFlow} from "../UI/ImageUploadFlow";
import {Changes} from "./Changes";
import {UIEventSource} from "../../UI/UIEventSource";
import {ImageUploadFlow} from "../../UI/ImageUploadFlow";
import {UserDetails} from "./OsmConnection";
import {SlideShow} from "../UI/SlideShow";
import {SlideShow} from "../../UI/SlideShow";
export class OsmImageUploadHandler {
private _tags: UIEventSource<any>;

View file

@ -1,11 +1,11 @@
import {TagsFilter} from "./TagsFilter";
import * as OsmToGeoJson from "osmtogeojson";
import * as $ from "jquery";
/**
* Interfaces overpass to get all the latest data
*/
import {Bounds} from "../Bounds";
import {TagsFilter} from "../TagsFilter";
import $ from "jquery"
import * as OsmToGeoJson from "osmtogeojson";
export class Overpass {
private _filter: TagsFilter
public static testUrl: string = null
@ -14,7 +14,8 @@ export class Overpass {
this._filter = filter
}
public buildQuery(bbox: string): string {
private buildQuery(bbox: string): string {
const filters = this._filter.asOverpass()
let filter = ""
for (const filterOr of filters) {
@ -24,9 +25,10 @@ export class Overpass {
'[out:json][timeout:25]' + bbox + ';(' + filter + ');out body;>;out skel qt;'
return "https://overpass-api.de/api/interpreter?data=" + encodeURIComponent(query)
}
queryGeoJson(bbox: string, continuation: ((any) => void), onFail: ((reason) => void)): void {
let query = this.buildQuery(bbox)
queryGeoJson(bounds: Bounds, continuation: ((any) => void), onFail: ((reason) => void)): void {
let query = this.buildQuery( "[bbox:" + bounds.south + "," + bounds.west + "," + bounds.north + "," + bounds.east + "]")
if(Overpass.testUrl !== null){
console.log("Using testing URL")

View file

@ -55,8 +55,8 @@ export class Regex extends TagsFilter {
export class Tag extends TagsFilter {
public key: string | RegExp
public value: string | RegExp
public key: string
public value: string
public invertValue: boolean
constructor(key: string | RegExp, value: string | RegExp, invertValue = false) {
@ -69,7 +69,9 @@ export class Tag extends TagsFilter {
}
super()
// @ts-ignore
this.key = key
// @ts-ignore
this.value = value
this.invertValue = invertValue
}
@ -107,10 +109,14 @@ export class Tag extends TagsFilter {
}
asOverpass(): string[] {
// @ts-ignore
const keyIsRegex = this.key instanceof RegExp
// @ts-ignore
const key = keyIsRegex ? (this.key as RegExp).source : this.key
// @ts-ignore
const valIsRegex = this.value instanceof RegExp
// @ts-ignore
const val = valIsRegex ? (this.value as RegExp).source : this.value
const regexKeyPrefix = keyIsRegex ? '~' : ''