GeocoderService.js 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. import Credit from "./Credit.js";
  2. import defined from "./defined.js";
  3. import DeveloperError from "./DeveloperError.js";
  4. /**
  5. * @typedef {object} GeocoderService.Result
  6. * @property {string} displayName The display name for a location
  7. * @property {Rectangle|Cartesian3} destination The bounding box for a location
  8. * @property {object[]} [attributions]
  9. */
  10. /**
  11. * Provides geocoding through an external service. This type describes an interface and
  12. * is not intended to be used.
  13. * @alias GeocoderService
  14. * @constructor
  15. *
  16. * @see BingMapsGeocoderService
  17. * @see PeliasGeocoderService
  18. * @see OpenCageGeocoderService
  19. */
  20. function GeocoderService() {
  21. DeveloperError.throwInstantiationError();
  22. }
  23. Object.defineProperties(GeocoderService.prototype, {
  24. /**
  25. * Gets the credit to display after a geocode is performed. Typically this is used to credit
  26. * the geocoder service.
  27. * @memberof GeocoderService.prototype
  28. * @type {Credit|undefined}
  29. * @readonly
  30. */
  31. credit: {
  32. get: DeveloperError.throwInstantiationError,
  33. },
  34. });
  35. /**
  36. * Parses credits from the geocoder result attributions, if present.
  37. * @param {GeocoderService.Result} geocoderResult The geocoder result
  38. * @returns {Credit[]|undefined} A list of credits if present in the result, otherwise undefined
  39. */
  40. GeocoderService.getCreditsFromResult = function (geocoderResult) {
  41. if (defined(geocoderResult.attributions)) {
  42. return geocoderResult.attributions.map(Credit.getIonCredit);
  43. }
  44. return undefined;
  45. };
  46. /**
  47. * @function
  48. *
  49. * @param {string} query The query to be sent to the geocoder service
  50. * @param {GeocodeType} [type=GeocodeType.SEARCH] The type of geocode to perform.
  51. * @returns {Promise<GeocoderService.Result[]>}
  52. */
  53. GeocoderService.prototype.geocode = DeveloperError.throwInstantiationError;
  54. export default GeocoderService;