var _excluded = ["points", "icon", "getAddress", "getLocation", "queryNearby", "onMarkerClick", "onLoad", "ZoomControlProps", "children"];
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
import React, { useEffect, useRef, forwardRef, useImperativeHandle } from 'react';
import MapContainer from "./../../components/MapContainer";
import ZoomControl from "./../../components/ZoomControl";
import Markers from "./../../components/Markers";

// 地图标注
function MapMarkers(_ref, ref) {
  var points = _ref.points,
    icon = _ref.icon,
    getAddress = _ref.getAddress,
    getLocation = _ref.getLocation,
    queryNearby = _ref.queryNearby,
    onMarkerClick = _ref.onMarkerClick,
    _onLoad = _ref.onLoad,
    ZoomControlProps = _ref.ZoomControlProps,
    children = _ref.children,
    props = _objectWithoutProperties(_ref, _excluded);
  // 地图容器
  var mapRef = useRef(null);

  // Expose
  useImperativeHandle(ref, function () {
    return mapRef === null || mapRef === void 0 ? void 0 : mapRef.current;
  });
  useEffect(function () {
    var _mapRef$current, _mapRef$current$panTo;
    if (!points) return;
    (_mapRef$current = mapRef.current) === null || _mapRef$current === void 0 || (_mapRef$current$panTo = _mapRef$current.panTo) === null || _mapRef$current$panTo === void 0 || _mapRef$current$panTo.call(_mapRef$current, points);
    // eslint-disable-next-line
  }, [JSON.stringify(points)]);
  return /*#__PURE__*/React.createElement(MapContainer
  // api
  , _extends({
    ref: mapRef,
    zoom: 14
  }, props, {
    onLoad: function onLoad(map) {
      var _mapRef$current2, _mapRef$current2$panT;
      // value没值时，开启自动定位，则先定位
      if (typeof map === 'string') return;

      // 加载完成后更新视图
      (_mapRef$current2 = mapRef.current) === null || _mapRef$current2 === void 0 || (_mapRef$current2$panT = _mapRef$current2.panTo) === null || _mapRef$current2$panT === void 0 || _mapRef$current2$panT.call(_mapRef$current2, points);
      _onLoad && _onLoad(map);
    }
    // 自定义获取地址和定位
    ,
    getAddress: getAddress,
    getLocation: getLocation,
    queryNearby: queryNearby
  }), /*#__PURE__*/React.createElement(Markers, {
    points: points,
    onClick: onMarkerClick
  }), /*#__PURE__*/React.createElement(ZoomControl, _extends({
    style: {
      bottom: '20px'
    }
  }, ZoomControlProps)), children);
}
export default /*#__PURE__*/forwardRef(MapMarkers);