function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
// 内库使用-start
import LocaleUtil from "./../../../../utils/LocaleUtil";
// 内库使用-end

/* 测试使用-start
import { LocaleUtil } from 'seedsui-react'
测试使用-start */

// 搜索附近
function overpassQueryNearby(_ref) {
  var map = _ref.map,
    keyword = _ref.keyword,
    longitude = _ref.longitude,
    latitude = _ref.latitude,
    radius = _ref.radius;
  var nearQuery = radius ? "(around:".concat(radius, ",").concat(latitude, ",").concat(longitude, ")") : '';
  var overpassQuery = "\n        [out:json];\n        node".concat(nearQuery, "[\"").concat(keyword, "\"];\n        out center;\n    ");
  return new Promise(function (resolve) {
    fetch("https://overpass-api.de/api/interpreter?data=".concat(encodeURIComponent(overpassQuery))).then(function (response) {
      return response.json();
    }).then(function (data) {
      var _data$elements;
      // 显示查询结果
      if ((data === null || data === void 0 || (_data$elements = data.elements) === null || _data$elements === void 0 ? void 0 : _data$elements.length) > 0) {
        var list = [];
        var _iterator = _createForOfIteratorHelper(data.elements),
          _step;
        try {
          for (_iterator.s(); !(_step = _iterator.n()).done;) {
            var _item$tags, _item$tags2, _item$tags3, _item$tags4;
            var item = _step.value;
            var name = item.tags.name;
            var address = ((item === null || item === void 0 || (_item$tags = item.tags) === null || _item$tags === void 0 ? void 0 : _item$tags['addr:city']) || '') + ((item === null || item === void 0 || (_item$tags2 = item.tags) === null || _item$tags2 === void 0 ? void 0 : _item$tags2['addr:housename']) || '') + ((item === null || item === void 0 || (_item$tags3 = item.tags) === null || _item$tags3 === void 0 ? void 0 : _item$tags3['addr:postcode']) || '') + ((item === null || item === void 0 || (_item$tags4 = item.tags) === null || _item$tags4 === void 0 ? void 0 : _item$tags4['addr:street']) || '');
            if (!name && !address) continue;
            list.push({
              name: name,
              latitude: item.lat,
              longitude: item.lon,
              address: address,
              type: 'wgs84'
            });
          }
        } catch (err) {
          _iterator.e(err);
        } finally {
          _iterator.f();
        }
        resolve(list);
      } else {
        resolve([]);
      }
    }).catch(function (error) {
      resolve(LocaleUtil.locale('查询失败', 'SeedsUI_query_failed'));
    });
  });
}
export default overpassQueryNearby;