Press n or j to go to the next uncovered block, b, p or k for the previous block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 | 1x 2x 2x 1x 1x 1x 1x | import { Injectable } from '@angular/core'; import { GeographyProvider, GeoAdminProvider } from './geography-providers'; import { HttpClient } from '@angular/common/http'; import { MapDirections, metersPrecision } from './utils'; @Injectable({ providedIn: 'root' }) export class GeographyService { private geographyProvider: GeographyProvider; constructor(private http: HttpClient) { this.geographyProvider = new GeoAdminProvider(this.http); } /** * Get the address or water body nearest to a point on a map. * * @param point An Esri point with WGS84 coordinates near which addresses and water bodies must be searched. * * @returns The name of the address or water body nearest to the input point. */ getAddress(point: __esri.Point): Promise<string> { return this.geographyProvider.getAddress(point); } /** * Get the point (coordinates) of an address. * * @param address The address for which coordinates must be retrieved. * * @returns An Esri point with the WGS84 coordinates of the input address, or * undefined if the address wasn't found. */ getPoint(address: string): Promise<__esri.Point | undefined> { return this.geographyProvider.getPoint(address); } /** * Get directions from a point A to a point B. * * @param pointA The Esri point with WGS84 coordinates from which directions must be computed. * @param pointB The Esri point with WGS84 coordinates to which directions must be computed. * * @returns Directions from A to B: the direction to go from A to B, the distance between the points, ... */ async getDirections(pointA: __esri.Point, pointB: __esri.Point): Promise<MapDirections> { const directionToB = this.geographyProvider.getDirection(pointA, pointB); const distance = await this.geographyProvider.computeDistance(pointA, pointB); if (distance >= 1000) { return { reached: false, direction: directionToB, distance: Math.floor(distance / 1000), unit: 'kilometers' }; } if (distance > metersPrecision) { return { reached: false, direction: directionToB, distance: Math.floor(distance), unit: 'meters' }; } return {reached: true}; } } |