-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Revert "chore(searchSource): deletion of cadastre search source (#1152)" This reverts commit b55613f. * 1.15.4
- Loading branch information
Showing
15 changed files
with
217 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
packages/geo/src/lib/search/shared/sources/cadastre.providers.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { HttpClient } from '@angular/common/http'; | ||
|
||
import { ConfigService, LanguageService, StorageService } from '@igo2/core'; | ||
|
||
import { SearchSource } from './source'; | ||
import { CadastreSearchSource } from './cadastre'; | ||
|
||
/** | ||
* Cadastre search source factory | ||
* @ignore | ||
*/ | ||
export function cadastreSearchSourceFactory( | ||
http: HttpClient, | ||
languageService: LanguageService, | ||
storageService: StorageService, | ||
config: ConfigService | ||
) { | ||
return new CadastreSearchSource( | ||
http, | ||
languageService, | ||
storageService, | ||
config.getConfig(`searchSources.${CadastreSearchSource.id}`), | ||
); | ||
} | ||
|
||
/** | ||
* Function that returns a provider for the Cadastre search source | ||
*/ | ||
export function provideCadastreSearchSource() { | ||
return { | ||
provide: SearchSource, | ||
useFactory: cadastreSearchSourceFactory, | ||
multi: true, | ||
deps: [HttpClient, LanguageService, StorageService, ConfigService] | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,147 @@ | ||
import { Injectable, Inject } from '@angular/core'; | ||
import { HttpClient, HttpParams } from '@angular/common/http'; | ||
|
||
import { Observable, of } from 'rxjs'; | ||
import { map } from 'rxjs/operators'; | ||
|
||
import olWKT from 'ol/format/WKT'; | ||
|
||
import { FEATURE, Feature, FeatureGeometry } from '../../../feature'; | ||
|
||
import { SearchResult } from '../search.interfaces'; | ||
import { SearchSource, TextSearch } from './source'; | ||
import { SearchSourceOptions, TextSearchOptions } from './source.interfaces'; | ||
|
||
import { LanguageService, StorageService } from '@igo2/core'; | ||
import { computeTermSimilarity } from '../search.utils'; | ||
import { Cacheable } from 'ts-cacheable'; | ||
import { GeoJsonGeometryTypes } from 'geojson'; | ||
|
||
/** | ||
* Cadastre search source | ||
*/ | ||
@Injectable() | ||
export class CadastreSearchSource extends SearchSource implements TextSearch { | ||
static id = 'cadastre'; | ||
static type = FEATURE; | ||
|
||
constructor( | ||
private http: HttpClient, | ||
private languageService: LanguageService, | ||
storageService: StorageService, | ||
@Inject('options') options: SearchSourceOptions | ||
) { | ||
super(options, storageService); | ||
} | ||
|
||
getId(): string { | ||
return CadastreSearchSource.id; | ||
} | ||
|
||
getType(): string { | ||
return CadastreSearchSource.type; | ||
} | ||
|
||
/* | ||
* Source : https://wiki.openstreetmap.org/wiki/Key:amenity | ||
*/ | ||
protected getDefaultOptions(): SearchSourceOptions { | ||
return { | ||
title: 'Cadastre (Québec)', | ||
searchUrl: 'https://carto.cptaq.gouv.qc.ca/php/find_lot_v1.php?' | ||
}; | ||
} | ||
|
||
/** | ||
* Search a place by name | ||
* @param term Place name | ||
* @returns Observable of <SearchResult<Feature>[] | ||
*/ | ||
@Cacheable({ | ||
maxCacheCount: 20 | ||
}) | ||
search( | ||
term: string | undefined, | ||
options?: TextSearchOptions | ||
): Observable<SearchResult<Feature>[]> { | ||
term = term.endsWith(',') ? term.slice(0, -1) : term; | ||
term = term.startsWith(',') ? term.substr(1) : term; | ||
term = term.replace(/ /g, ''); | ||
|
||
const params = this.computeSearchRequestParams(term, options || {}); | ||
if (!params.get('numero') || !params.get('numero').match(/^[0-9,]+$/g)) { | ||
return of([]); | ||
} | ||
return this.http | ||
.get(this.searchUrl, { params, responseType: 'text' }) | ||
.pipe(map((response: string) => this.extractResults(response, term))); | ||
} | ||
|
||
private computeSearchRequestParams( | ||
term: string, | ||
options: TextSearchOptions | ||
): HttpParams { | ||
return new HttpParams({ | ||
fromObject: Object.assign( | ||
{ | ||
numero: term, | ||
epsg: '4326' | ||
}, | ||
this.params, | ||
options.params || {} | ||
) | ||
}); | ||
} | ||
|
||
private extractResults(response: string, term: string): SearchResult<Feature>[] { | ||
return response | ||
.split('<br />') | ||
.filter((lot: string) => lot.length > 0) | ||
.map((lot: string) => this.dataToResult(lot, term)); | ||
} | ||
|
||
private dataToResult(data: string, term: string): SearchResult<Feature> { | ||
const lot = data.split(';'); | ||
const numero = lot[0]; | ||
const wkt = lot[7]; | ||
const geometry = this.computeGeometry(wkt); | ||
|
||
const properties = { | ||
NoLot: numero, | ||
Route: '<span class="routing"> <u>' + this.languageService.translate.instant('igo.geo.seeRouting') + '</u> </span>' | ||
}; | ||
const id = [this.getId(), 'cadastre', numero].join('.'); | ||
|
||
return { | ||
source: this, | ||
meta: { | ||
dataType: FEATURE, | ||
id, | ||
title: numero, | ||
score: computeTermSimilarity(term.trim(), numero), | ||
icon: 'map-marker' | ||
}, | ||
data: { | ||
type: FEATURE, | ||
projection: 'EPSG:4326', | ||
geometry, | ||
properties, | ||
meta: { | ||
id, | ||
title: numero | ||
} | ||
} | ||
}; | ||
} | ||
|
||
private computeGeometry(wkt: string): FeatureGeometry { | ||
const feature = new olWKT().readFeature(wkt, { | ||
dataProjection: 'EPSG:4326', | ||
featureProjection: 'EPSG:4326' | ||
}); | ||
return { | ||
type: feature.getGeometry().getType() as GeoJsonGeometryTypes, | ||
coordinates: (feature.getGeometry() as any).getCoordinates() | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters