kepler.gl.geoiq
Version:
kepler.gl is a webgl based application to visualize large scale location data in the browser
198 lines (177 loc) • 6.76 kB
JavaScript
// Copyright (c) 2019 Uber Technologies, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
import React, {Component} from 'react';
import styled from 'styled-components';
import PropTypes from 'prop-types';
import {sortable} from 'react-anything-sortable';
import LayerConfigurator from './layer-configurator';
import LayerPanelHeader from './layer-panel-header';
import LoadingSpinner from 'components/common/loading-spinner';
const PanelWrapper = styled.div`
font-size: 12px;
border-radius: 1px;
margin-bottom: 8px;
&.dragging {
cursor: move;
}
`;
function LayerPanelFactory() {
@sortable
class LayerPanel extends Component {
static propTypes = {
layer: PropTypes.object.isRequired,
datasets: PropTypes.object.isRequired,
idx: PropTypes.number.isRequired,
layerConfigChange: PropTypes.func.isRequired,
layerTypeChange: PropTypes.func.isRequired,
openModal: PropTypes.func.isRequired,
removeLayer: PropTypes.func.isRequired,
updateLayerData: PropTypes.func.isRequired,
axiosAPICAll: PropTypes.func.isRequired,
onCloseConfig: PropTypes.func,
layerTypeOptions: PropTypes.arrayOf(PropTypes.any),
layerVisConfigChange: PropTypes.func,
layerVisualChannelConfigChange: PropTypes.func
};
componentWillReceiveProps(nextProps) {
// console.log(nextProps.layer.config.boundaryAggregation);
// console.log(this.props.layer.config.boundaryAggregation);
const {config} = nextProps.layer;
const {columns, boundaryAggregation, apiCallRequest} = config;
if (
nextProps.layer &&
config &&
boundaryAggregation &&
apiCallRequest === true &&
columns[Object.keys(columns)[0]].fieldIdx !== -1
) {
// console.log(nextProps.layer.config.apiCallRequest);
nextProps.layerConfigChange(nextProps.layer, {
apiCallRequest: false,
apiCallLoader: true
});
const result = nextProps.layer.axiosApiCall(nextProps.datasets);
// console.log(result);
result.then(function(result) {
// console.log(result);
nextProps.layerConfigChange(nextProps.layer, {apiCallLoader: false});
nextProps.updateLayerData(nextProps.layer, result);
});
}
}
updateLayerConfig = newProp => {
this.props.layerConfigChange(this.props.layer, newProp);
};
updateLayerType = newType => {
this.props.layerTypeChange(this.props.layer, newType);
};
updateLayerVisConfig = newVisConfig => {
this.props.layerVisConfigChange(this.props.layer, newVisConfig);
};
updateLayerVisualChannelConfig = (newConfig, channel, scaleKey) => {
this.props.layerVisualChannelConfigChange(
this.props.layer,
newConfig,
channel,
scaleKey
);
};
_updateLayerLabel = ({target: {value}}) => {
this.updateLayerConfig({label: value});
};
_toggleVisibility = e => {
e.stopPropagation();
const isVisible = !this.props.layer.config.isVisible;
this.updateLayerConfig({isVisible});
};
_toggleEnableConfig = e => {
e.stopPropagation();
const {
layer: {
config: {isConfigActive}
}
} = this.props;
this.updateLayerConfig({isConfigActive: !isConfigActive});
};
_removeLayer = e => {
e.stopPropagation();
this.props.removeLayer(this.props.idx);
};
filterLayerOptions = ['grid', 'hexagon', 'boundary'];
render() {
const {layer, idx, datasets, updateLayerData} = this.props;
var {layerTypeOptions} = this.props;
const externalData =
datasets[layer.config.dataId] && layer.config.dataId
? datasets[layer.config.dataId].externalData
: undefined;
layerTypeOptions =
externalData && externalData === true
? layerTypeOptions.filter(
lto => this.filterLayerOptions.indexOf(lto.id) >= 0
)
: layerTypeOptions;
const {config} = layer;
const {isConfigActive, apiCallLoader} = config;
// console.log('layerPanel datasetsColor,', datasets[config.dataId].color);
return (
<PanelWrapper
active={isConfigActive}
className={`layer-panel ${this.props.className}`}
style={this.props.style}
onMouseDown={this.props.onMouseDown}
onTouchStart={this.props.onTouchStart}
>
<LayerPanelHeader
isConfigActive={isConfigActive}
apiCallLoader={apiCallLoader}
id={layer.id}
idx={idx}
isVisible={config.isVisible}
label={config.label}
labelRCGColorValues={datasets[config.dataId].color}
layerType={layer.name}
onToggleEnableConfig={this._toggleEnableConfig}
onToggleVisibility={this._toggleVisibility}
onUpdateLayerLabel={this._updateLayerLabel}
onRemoveLayer={this._removeLayer}
/>
{isConfigActive && (
<LayerConfigurator
layer={layer}
datasets={datasets}
updateLayerData={updateLayerData}
layerTypeOptions={layerTypeOptions}
openModal={this.props.openModal}
updateLayerConfig={this.updateLayerConfig}
updateLayerVisualChannelConfig={
this.updateLayerVisualChannelConfig
}
updateLayerType={this.updateLayerType}
updateLayerVisConfig={this.updateLayerVisConfig}
/>
)}
</PanelWrapper>
);
}
}
return LayerPanel;
}
export default LayerPanelFactory;