UNPKG

kepler.gl.geoiq

Version:

kepler.gl is a webgl based application to visualize large scale location data in the browser

303 lines (273 loc) 10 kB
// Copyright (c) 2023 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 LayerConfiguratorFactory from './layer-configurator'; import LayerPanelHeader from './layer-panel-header'; import WebMercatorViewport from 'viewport-mercator-project'; import _ from 'lodash'; import layer from 'react-map-gl/dist/es5/components/layer'; import {labelColor} from 'styles'; import {addLayer} from 'actions'; const PanelWrapper = styled.div` font-size: 12px; border-radius: 1px; margin-bottom: 8px; z-index: 1000; &.dragging { cursor: move; } `; LayerPanelFactory.deps = [LayerConfiguratorFactory]; function LayerPanelFactory(LayerConfigurator) { 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.isRequired, layerVisualChannelConfigChange: PropTypes.func.isRequired, layerColorUIChange: PropTypes.func.isRequired, updateAnimationTime: PropTypes.func, updateLayerAnimationSpeed: PropTypes.func }; // inDebounce = 0; // componentWillReceiveProps(nextProps) { // const {config} = nextProps.layer; // const {columns, boundaryAggregation, apiCallRequest} = config; // if ( // nextProps.layer.type === 'dynamic' || // nextProps.layer.type === 'geoHash' || // nextProps.layer.type === 'point' // ) { // if ( // !_.isEqual(this.props.mapState, nextProps.mapState) // // && // // nextProps.layers // // nextProps.widget.config.bounds // ) { // nextProps.layerConfigChange(nextProps.layer, { // apiCallRequest: true // }); // } // } // if ( // nextProps.layer && // config && // apiCallRequest === true // // columns[Object.keys(columns)[0]].fieldIdx !== -1 // ) { // nextProps.layerConfigChange(nextProps.layer, { // apiCallRequest: false, // apiCallLoader: true // }); // clearTimeout(this.inDebounce); // this.inDebounce = setTimeout(() => { // const result = nextProps.layer.axiosApiCall( // nextProps.datasets, // this.getViewport(nextProps.mapState), // nextProps.mapState.zoom, // nextProps.filters // ); // result.then(function(result) { // nextProps.layerConfigChange(nextProps.layer, { // apiCallLoader: false // }); // nextProps.updateLayerData(nextProps.layer, result); // }); // clearTimeout(this.inDebounce); // this.inDebounce = 0; // }, 300); // } // } // getViewport(mapState) { // const { // longitude, // latitude, // height, // width, // zoom, // pitch, // bearing // } = mapState; // // let boundingBox = geoViewport.bounds([longitude, latitude], zoom, [ // // width, // // height // // ]); // const viewport = new WebMercatorViewport({ // width: width, // height: height, // longitude: longitude, // latitude: latitude, // zoom: zoom, // pitch: pitch, // bearing: bearing // }); // let cUL = viewport.unproject([0, 0]); // let cUR = viewport.unproject([width, 0]); // let cLR = viewport.unproject([width, height]); // let cLL = viewport.unproject([0, height]); // let latRange = [...new Set([cLL[1], cUR[1], cLR[1], cUL[1]])].sort( // (a, b) => a - b // ); // let lngRange = [...new Set([cLL[0], cUR[0], cLR[0], cUL[0]])].sort( // (a, b) => a - b // ); // return [lngRange[0], lngRange[1], latRange[0], latRange[1]]; // } componentWillReceiveProps(nextProps) { if ( this.props.layer.config.dataId && nextProps.layer.config.dataId && this.props.layer.config.dataId !== nextProps.layer.config.dataId ) { if (layer.name !== 'boundary' && layer.name !== 'pincode') { this.props.layerConfigChange(nextProps.layer, { apiCallRequest: true }); } } } updateLayerConfig = newProp => { this.props.layerConfigChange(this.props.layer, newProp); }; updateLayerType = newType => { this.props.layerTypeChange(this.props.layer, newType); // this.props.layerConfigChange(this.props.layer, {apiCallRequest: true}); }; updateLayerVisConfig = newVisConfig => { this.props.layerVisConfigChange(this.props.layer, newVisConfig); }; updateLayerColorUI = (...args) => { this.props.layerColorUIChange(this.props.layer, ...args); }; updateLayerTextLabel = (...args) => { this.props.layerTextLabelChange(this.props.layer, ...args); }; 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']; filterLargeDataOptions = [ 'backendPoint', 'backendGeojson', 'geoHash', 'dynamic' ]; filterSmallDataOptions = ['backendPoint', 'backendGeojson']; render() { const {layer, idx, datasets, updateLayerData} = this.props; var {layerTypeOptions} = this.props; const largeData = datasets[layer.config.dataId] && layer.config.dataId ? datasets[layer.config.dataId].isLargeCategory : undefined; layerTypeOptions = largeData && largeData === true ? layerTypeOptions.filter( lto => this.filterLargeDataOptions.indexOf(lto.id) >= 0 ) : layerTypeOptions.filter( lto => this.filterSmallDataOptions.indexOf(lto.id) === -1 ); const {config} = layer; const {isConfigActive, apiCallLoader} = config; 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} showLoader={layer.showLoader} 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} updateLayerColorUI={this.updateLayerColorUI} updateLayerConfig={this.updateLayerConfig} updateLayerVisualChannelConfig={ this.updateLayerVisualChannelConfig } updateLayerType={this.updateLayerType} updateLayerTextLabel={this.updateLayerTextLabel} updateLayerVisConfig={this.updateLayerVisConfig} /> )} </PanelWrapper> ); } } return LayerPanel; } export default LayerPanelFactory;