@hackoregon/component-library
Version:
Official repo for Hack Oregon React component library
132 lines (123 loc) • 5.09 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); }
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _nonIterableSpread(); }
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance"); }
function _iterableToArray(iter) { if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter); }
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } }
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; var ownKeys = Object.keys(source); if (typeof Object.getOwnPropertySymbols === 'function') { ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) { return Object.getOwnPropertyDescriptor(source, sym).enumerable; })); } ownKeys.forEach(function (key) { _defineProperty(target, key, source[key]); }); } return target; }
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
import React from "react";
import { shape, bool, number, func, node, oneOfType, arrayOf, string } from "prop-types";
import DeckGL, { GeoJsonLayer } from "deck.gl";
import centerOfMass from "@turf/center-of-mass";
var MapOverlay = function MapOverlay(props) {
var id = props.id,
viewport = props.viewport,
children = props.children,
data = props.data,
pickable = props.pickable,
opacity = props.opacity,
filled = props.filled,
getFillColor = props.getFillColor,
stroked = props.stroked,
getLineColor = props.getLineColor,
getLineWidth = props.getLineWidth,
extruded = props.extruded,
getElevation = props.getElevation,
circleFieldName = props.circleFieldName,
getRadius = props.getRadius,
radiusScale = props.radiusScale,
autoHighlight = props.autoHighlight,
highlightColor = props.highlightColor,
onLayerClick = props.onLayerClick,
onHover = props.onHover,
tooltipInfo = props.tooltipInfo,
x = props.x,
y = props.y;
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;
var centroidData = circleFieldName ? data.map(function (d) {
return centerOfMass(d.geometry, {
properties: _objectSpread({}, d.properties)
});
}) : [];
var radius = circleFieldName ? function (f) {
return Math.sqrt(+f.properties[circleFieldName]);
} : getRadius || 10;
return React.createElement("div", null, React.createElement(DeckGL, _extends({}, viewport, {
className: "DeckGL",
getCursor: function getCursor() {
return "crosshair";
}
}), React.createElement(GeoJsonLayer, {
id: id,
className: "GeoJSONMap",
pickable: pickable,
data: [].concat(_toConsumableArray(data), _toConsumableArray(centroidData)),
opacity: opacity,
filled: filled,
getFillColor: getFillColor,
stroked: stroked,
getLineColor: getLineColor,
getLineWidth: getLineWidth,
lineWidthMinPixels: 1,
extruded: extruded,
getElevation: getElevation,
circleFieldName: circleFieldName,
getRadius: radius,
pointRadiusScale: radiusScale,
pointRadiusMinPixels: 1,
autoHighlight: autoHighlight,
highlightColor: highlightColor,
onClick: onLayerClick,
onHover: onHover,
updateTriggers: {
getFillColor: getFillColor,
getLineColor: getLineColor,
getLineWidth: getLineWidth,
getRadius: getRadius
}
})), tooltipRender);
};
MapOverlay.propTypes = {
viewport: shape({}),
children: node,
id: string,
data: arrayOf(shape({})).isRequired,
pickable: bool,
opacity: number,
filled: bool,
getFillColor: oneOfType([arrayOf(number), func]),
stroked: bool,
getLineColor: oneOfType([arrayOf(number), func]),
getLineWidth: oneOfType([number, func]),
extruded: bool,
getElevation: oneOfType([number, func]),
circleFieldName: string,
getRadius: oneOfType([number, func]),
radiusScale: number,
autoHighlight: bool,
highlightColor: arrayOf(number),
onLayerClick: func,
onHover: func,
tooltipInfo: shape({}),
x: number,
y: number
};
MapOverlay.defaultProps = {
pickable: true,
opacity: 0.8,
filled: true,
getFillColor: [0, 0, 0],
stroked: true,
getLineColor: [112, 122, 122, 100],
getLineWidth: 10,
extruded: false,
autoHighlight: false
};
export default MapOverlay;