diff --git a/front/src/app/components/josm-button/josm-button.component.ts b/front/src/app/components/josm-button/josm-button.component.ts index 753f429c91e2f8e7d2858e89a5e202103e11f49d..095f4f95ffb6a324998a28effb453274ff6d40cf 100644 --- a/front/src/app/components/josm-button/josm-button.component.ts +++ b/front/src/app/components/josm-button/josm-button.component.ts @@ -37,7 +37,6 @@ export class JosmButtonComponent extends Unsubscriber { disabled: false, }; tooltip = ''; - overpassAPI = 'https://overpass-api.de/api/interpreter?data='; @Input() osmID: number; private _city: CityDTO; @@ -70,15 +69,6 @@ export class JosmButtonComponent extends Unsubscriber { super(); } - generateOverpassQuery(name: string) { - return `[out:xml][timeout:600]; - {{geocodeArea:"${name}, France"}}->.searchArea; - ( - nwr(area.searchArea); - ); - out meta; >; out meta qt;`; - } - @HostListener('document:keydown.j') onClick() { this.options.active = true; const onEnd = () => { @@ -87,24 +77,7 @@ export class JosmButtonComponent extends Unsubscriber { this.changeDetector.detectChanges(); }; - const obs$ = (this._city.josm_ready ? this.conflateCity() : this.prepareCity()).pipe( - catchError(error => { - // use overpass query to download when city is too big for JOSM - if (error && error.status === 502) { - const encodedUrl = - this.overpassAPI + encodeURIComponent(this.generateOverpassQuery(this._city.name)); - - return this.josmService.josmUrlImport$( - encodedUrl, - false, - false, - this.josmService.getOsmLayer(this._city) - ); - } - - throw error; - }) - ); + const obs$ = (this._city.josm_ready ? this.conflateCity() : this.prepareCity()); this.autoUnsubscribe( obs$.subscribe( diff --git a/front/src/app/services/josm.service.ts b/front/src/app/services/josm.service.ts index 7832be9018a9d5a99081aef281617b84d42d7307..48c1af7a00aa38b0ea5a0d685ca164e80590eb7c 100644 --- a/front/src/app/services/josm.service.ts +++ b/front/src/app/services/josm.service.ts @@ -13,6 +13,16 @@ export class JosmService { private readonly JOSM_URL_BASE = 'http://127.0.0.1:8111/'; private readonly JOSM_URL_VERSION = `${this.JOSM_URL_BASE}version`; + overpassAPI = 'https://overpass-api.de/api/interpreter?data='; + generateOverpassQuery(name: string) { + return `[out:xml][timeout:600]; + {{geocodeArea:"${name}, France"}}->.searchArea; + ( + nwr(area.searchArea); + ); + out meta; >; out meta qt;`; + } + constructor(private readonly http: HttpClient) {} isStarted(): Observable { @@ -45,7 +55,7 @@ export class JosmService { // for OSM data first we create the layer, then we try to load data // cf https://gitlab.com/bagage/batimap/-/issues/70 const osm$ = this.josmUrlLoadObject$(`r${osmID}`, this.getOsmLayer(city)).pipe( - switchMap(() => + switchMap(() => { this.josmUrlLoadAndZoom$( false, undefined, @@ -53,8 +63,24 @@ export class JosmService { dto.bbox[1].toString(), dto.bbox[2].toString(), dto.bbox[3].toString() - ) - ) + ).pipe( + catchError(error => { + // use overpass query to download when city is too big for JOSM + if (error && error.status === 502) { + const encodedUrl = + this.overpassAPI + encodeURIComponent(this.generateOverpassQuery(city.name)); + + return this.josmUrlImport$( + encodedUrl, + false, + false, + "true", + this.getOsmLayer(city) + ); + } + }) + ); + }) ); return forkJoin([imagery$, segmented$, buildings$]).pipe(switchMap(() => osm$));