"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;
var _themed = require("@rneui/themed");
var _maps = _interopRequireDefault(require("@rnmapbox/maps"));
var _reactNative = require("react-native");
var _config = require("../config");
var _react = _interopRequireWildcard(require("react"));
var _MapContext = require("../modules/MapContext");
var _MSlot = _interopRequireDefault(require("./slots/MSlot"));
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
/**
 * Location props
 * @category Props
 */

/**
 *用户定位
 * @example
 * ```
 * <Mapa.Location locateWhenInit={true} visible={true} style="right-bottom" />
 * ```
 *
 * @category Component
 */
const Location = props => {
  const {
    visible = true,
    locateWhenInit = false,
    onChange,
    style = 'right'
  } = props;
  const {
    map
  } = (0, _react.useContext)(_MapContext.MapContext);
  // const containerStyle: StyleProp<ViewStyle> = props.style
  //     ? { ...(props.style as any), position: 'absolute' }
  //     : styles.container;

  const locate = async () => {
    const location = await map?.locationManager.getLastKnownLocation();
    if (location) {
      const center = [location.coords.longitude, location.coords.latitude];
      map.flyTo(center);
    }
  };
  if (visible) {
    // 启动位置监听
    map.locationManager.start();
    if (locateWhenInit) {
      map.on('loaded', async () => {
        await locate();
      });
    }
    if (onChange) {
      map.locationManager.on('locationChange', onChange);
    }
  }
  const onPress = async () => {
    await locate();
  };
  return /*#__PURE__*/_react.default.createElement(_MSlot.default, {
    style: style
  }, /*#__PURE__*/_react.default.createElement(_reactNative.View, null, /*#__PURE__*/_react.default.createElement(_themed.Button, {
    type: "outline",
    style: styles.button,
    size: "md",
    onPress: onPress
  }, /*#__PURE__*/_react.default.createElement(_themed.Icon, {
    name: "locate",
    type: "ionicon",
    size: _config.buttonSize
  }))), /*#__PURE__*/_react.default.createElement(_maps.default.LocationPuck, {
    visible: visible,
    puckBearing: 'heading',
    puckBearingEnabled: true
  }));
};
var _default = exports.default = Location;
const styles = _reactNative.StyleSheet.create({
  container: {
    position: 'absolute',
    right: 5,
    bottom: 5
  },
  button: {
    backgroundColor: '#fff'
  }
});
//# sourceMappingURL=Location.js.map