@hackoregon/component-library
Version:
Official repo for Hack Oregon React component library
101 lines (98 loc) • 3 kB
JavaScript
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); }
import PropTypes from "prop-types";
import React from "react";
import DeckGL, { IconLayer } from "deck.gl";
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.Children.map(children, function (child) {
return React.cloneElement(child, {
tooltipInfo: tooltipInfo,
x: x,
y: y
});
});
var tooltipRender = tooltipInfo && x && y ? tooltip : null;
return React.createElement("div", null, React.createElement(DeckGL, _extends({
className: "DeckGL"
}, viewport, {
getCursor: function getCursor() {
return "crosshair";
}
}), React.createElement(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.shape({}),
data: PropTypes.arrayOf(PropTypes.shape({})).isRequired,
opacity: PropTypes.number,
iconAtlas: PropTypes.string,
iconMapping: PropTypes.shape({}),
iconSizeScale: PropTypes.func,
sizeScale: PropTypes.number,
getPosition: PropTypes.func,
getIcon: PropTypes.func,
getSize: PropTypes.func,
getColor: PropTypes.func,
autoHighlight: PropTypes.bool,
onLayerClick: PropTypes.func,
onClick: PropTypes.func,
visible: PropTypes.bool,
tooltipInfo: PropTypes.shape({}),
x: PropTypes.number,
y: PropTypes.number,
onHover: PropTypes.func,
children: PropTypes.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
};
export default IconMap;