UNPKG

@itwin/core-frontend

Version:
56 lines 2.92 kB
"use strict"; /*--------------------------------------------------------------------------------------------- * Copyright (c) Bentley Systems, Incorporated. All rights reserved. * See LICENSE.md in the project root for license terms and full copyright notice. *--------------------------------------------------------------------------------------------*/ /** @packageDocumentation * @module Tiles */ Object.defineProperty(exports, "__esModule", { value: true }); exports.BingLocationProvider = void 0; const core_common_1 = require("@itwin/core-common"); const Request_1 = require("./request/Request"); const IModelApp_1 = require("./IModelApp"); /** Provides an interface to the [Bing Maps location services](https://docs.microsoft.com/en-us/bingmaps/rest-services/locations/). * @public * @extensions */ class BingLocationProvider { _locationRequestTemplate; constructor() { let bingKey = ""; if (IModelApp_1.IModelApp.mapLayerFormatRegistry.configOptions.BingMaps) { bingKey = IModelApp_1.IModelApp.mapLayerFormatRegistry.configOptions.BingMaps.value; } this._locationRequestTemplate = `https://dev.virtualearth.net/REST/v1/Locations?query={query}&key=${bingKey}`; } /** Return the location of a query (or undefined if not found). The strings "Space Needle" (a landmark) and "1 Microsoft Way Redmond WA" (an address) are examples of query strings with location information. * These strings can be specified as a structured URL parameter or as a query parameter value. See [Bing Location Services documentation](https://docs.microsoft.com/en-us/bingmaps/rest-services/locations/find-a-location-by-query) for additional * information on queries. * @public */ async getLocation(query) { const requestUrl = this._locationRequestTemplate.replace("{query}", query); try { const locationResponse = await (0, Request_1.request)(requestUrl, "json"); const point = locationResponse.resourceSets[0].resources[0].point; const bbox = locationResponse.resourceSets[0].resources[0].bbox; const southLatitude = bbox[0]; const westLongitude = bbox[1]; const northLatitude = bbox[2]; const eastLongitude = bbox[3]; return { center: core_common_1.Cartographic.fromDegrees({ longitude: point.coordinates[1], latitude: point.coordinates[0] }), area: { southwest: core_common_1.Cartographic.fromDegrees({ longitude: westLongitude, latitude: southLatitude }), northeast: core_common_1.Cartographic.fromDegrees({ longitude: eastLongitude, latitude: northLatitude }), }, }; } catch { return undefined; } } } exports.BingLocationProvider = BingLocationProvider; //# sourceMappingURL=BingLocation.js.map