"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports["default"] = void 0;

var _propTypes = _interopRequireDefault(require("prop-types"));

var _react = _interopRequireDefault(require("react"));

var _deck = _interopRequireWildcard(require("deck.gl"));

function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj["default"] = obj; return newObj; } }

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }

function _extends() { _extends = Object.assign || 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); }

var IconMap = function IconMap(props) {
  var viewport = props.viewport,
      data = props.data,
      opacity = props.opacity,
      iconAtlas = props.iconAtlas,
      iconMapping = props.iconMapping,
      iconSizeScale = props.iconSizeScale,
      getPosition = props.getPosition,
      getIcon = props.getIcon,
      getSize = props.getSize,
      getColor = props.getColor,
      autoHighlight = props.autoHighlight,
      onLayerClick = props.onLayerClick,
      visible = props.visible,
      tooltipInfo = props.tooltipInfo,
      x = props.x,
      y = props.y,
      onHover = props.onHover,
      children = props.children;
  var zoom = viewport.zoom;
  var sizeScale = iconSizeScale(zoom);

  var tooltip = _react["default"].Children.map(children, function (child) {
    return _react["default"].cloneElement(child, {
      tooltipInfo: tooltipInfo,
      x: x,
      y: y
    });
  });

  var tooltipRender = tooltipInfo && x && y ? tooltip : null;
  return _react["default"].createElement("div", null, _react["default"].createElement(_deck["default"], _extends({
    className: "DeckGL"
  }, viewport, {
    getCursor: function getCursor() {
      return "crosshair";
    }
  }), _react["default"].createElement(_deck.IconLayer, {
    id: "icon-layer",
    className: "IconMap",
    pickable: true,
    data: data,
    opacity: opacity,
    iconAtlas: iconAtlas,
    iconMapping: iconMapping,
    sizeScale: sizeScale,
    getPosition: getPosition,
    getIcon: getIcon,
    getSize: getSize,
    getColor: getColor,
    autoHighlight: autoHighlight,
    onClick: onLayerClick,
    onHover: onHover,
    visible: visible,
    updateTriggers: {
      getSize: getSize
    }
  })), tooltipRender);
};

IconMap.propTypes = {
  viewport: _propTypes["default"].shape({}),
  data: _propTypes["default"].arrayOf(_propTypes["default"].shape({})).isRequired,
  opacity: _propTypes["default"].number,
  iconAtlas: _propTypes["default"].string,
  iconMapping: _propTypes["default"].shape({}),
  iconSizeScale: _propTypes["default"].func,
  sizeScale: _propTypes["default"].number,
  getPosition: _propTypes["default"].func,
  getIcon: _propTypes["default"].func,
  getSize: _propTypes["default"].func,
  getColor: _propTypes["default"].func,
  autoHighlight: _propTypes["default"].bool,
  onLayerClick: _propTypes["default"].func,
  onClick: _propTypes["default"].func,
  visible: _propTypes["default"].bool,
  tooltipInfo: _propTypes["default"].shape({}),
  x: _propTypes["default"].number,
  y: _propTypes["default"].number,
  onHover: _propTypes["default"].func,
  children: _propTypes["default"].node
};
IconMap.defaultProps = {
  opacity: 1,
  sizeScale: 1,
  getPosition: function getPosition(d) {
    return d.geometry.coordinates;
  },
  getSize: function getSize() {
    return 10;
  },
  getColor: function getColor() {
    return [0, 0, 0];
  },
  visible: true
};
var _default = IconMap;
exports["default"] = _default;