@hackoregon/component-library
Version:
Official repo for Hack Oregon React component library
118 lines (111 loc) • 4.2 kB
JavaScript
import React from "react";
import { PolygonLayer } from "deck.gl";
import shortid from "shortid";
import { number, string, bool, func, arrayOf, shape } from "prop-types";
import { createColorScale, updateQuantileScale, updateEqualScale, createSizeScale } from "./createLayers";
var MultiChoroplethMap = function MultiChoroplethMap(props) {
var id = props.id,
data = props.data,
_props$pickable = props.pickable,
pickable = _props$pickable === void 0 ? true : _props$pickable,
_props$opacity = props.opacity,
opacity = _props$opacity === void 0 ? 0.7 : _props$opacity,
_props$civicColor = props.civicColor,
civicColor = _props$civicColor === void 0 ? "thermal" : _props$civicColor,
_props$getPolygon = props.getPolygon,
getPolygon = _props$getPolygon === void 0 ? function (f) {
return f.geometry.coordinates;
} : _props$getPolygon,
_props$filled = props.filled,
filled = _props$filled === void 0 ? true : _props$filled,
_props$stroked = props.stroked,
stroked = _props$stroked === void 0 ? true : _props$stroked,
_props$polygonWidth = props.polygonWidth,
polygonWidth = _props$polygonWidth === void 0 ? 1 : _props$polygonWidth,
_props$polygonLineCol = props.polygonLineColor,
polygonLineColor = _props$polygonLineCol === void 0 ? [169, 169, 169] : _props$polygonLineCol,
_props$autoHighlight = props.autoHighlight,
autoHighlight = _props$autoHighlight === void 0 ? true : _props$autoHighlight,
_props$highlightColor = props.highlightColor,
highlightColor = _props$highlightColor === void 0 ? [255, 255, 0, 100] : _props$highlightColor,
onHoverSlide = props.onHoverSlide,
onLayerClick = props.onLayerClick,
_props$scaleType = props.scaleType,
scaleType = _props$scaleType === void 0 ? {
color: "equal"
} : _props$scaleType,
fieldName = props.fieldName,
_props$dataRange = props.dataRange,
dataRange = _props$dataRange === void 0 ? [] : _props$dataRange,
_props$colorRange = props.colorRange,
colorRange = _props$colorRange === void 0 ? [] : _props$colorRange;
var choroplethColorScale = createColorScale(civicColor, scaleType, dataRange, colorRange);
if (scaleType.color === "equal") {
choroplethColorScale = updateEqualScale(data, choroplethColorScale, civicColor, dataRange, colorRange, fieldName);
}
if (scaleType.color === "quantile") {
choroplethColorScale = updateQuantileScale(data, choroplethColorScale, civicColor, colorRange, fieldName);
}
var getFillColor = function getFillColor(feature) {
var fieldNameColor = fieldName.color;
var value = feature.properties[fieldNameColor];
return value ? choroplethColorScale(value) : [0, 0, 0, 128];
};
var getLineColor = function getLineColor() {
return polygonLineColor;
};
var getLineWidth = createSizeScale(polygonWidth);
return React.createElement(PolygonLayer, {
key: shortid.generate(),
id: id,
pickable: pickable,
data: data,
opacity: opacity,
getPolygon: getPolygon,
filled: filled,
getFillColor: getFillColor,
stroked: stroked,
getLineColor: getLineColor,
getLineWidth: getLineWidth,
lineWidthMinPixels: 1,
lineWidthScale: 1,
lineJointRounded: false,
onHover: onHoverSlide,
onClick: onLayerClick,
autoHighlight: autoHighlight,
highlightColor: highlightColor,
parameters: {
depthTest: false
},
updateTriggers: {
getFillColor: getFillColor,
getLineColor: getLineColor,
getLineWidth: getLineWidth
}
});
};
MultiChoroplethMap.propTypes = {
id: string.isRequired,
data: arrayOf(shape({})).isRequired,
pickable: bool,
civicColor: string,
opacity: number,
getPolygon: func,
filled: bool,
stroked: bool,
polygonWidth: number,
polygonLineColor: arrayOf(number),
autoHighlight: bool,
highlightColor: arrayOf(number),
onHoverSlide: func,
onLayerClick: func,
scaleType: shape({
color: string
}),
fieldName: shape({
color: string
}).isRequired,
dataRange: arrayOf(string),
colorRange: arrayOf(arrayOf(number))
};
export default MultiChoroplethMap;