kepler.gl.geoiq
Version:
kepler.gl is a webgl based application to visualize large scale location data in the browser
107 lines (99 loc) • 3.63 kB
JavaScript
// 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 {
PanelLabel,
SidePanelSection
} from 'components/common/styled-components';
import ItemSelector from 'components/common/item-selector/item-selector';
import {createSelector} from 'reselect';
export default class WidgetLayerSelector extends Component {
static proptypes = {};
layersSelector = props => props.layers;
dataIdSelector = props => props.widget.config.dataId;
lsOptionsSelector = createSelector(
this.layersSelector,
this.dataIdSelector,
(layers, dataId) =>
Object.values(layers).map(ls => {
if (ls.config.dataId === dataId) {
return {
label: ls.config.label,
value: {id: ls.id, label: ls.config.label}
};
}
})
);
_widgetLayerOptions(layers, dataId) {
var options = [];
layers.map(lidget => {
const {config} = lidget;
const LayerDataId = config.dataId;
if (LayerDataId === dataId) {
options.push({
label: lidget.config.label,
value: {id: lidget.id, label: lidget.config.label}
});
}
});
return options;
}
_renderPlaceholder(id) {
var placeholder = this.props.layers.map(l => {
if (l.id === id) {
return l.config.label;
}
});
return placeholder;
}
render() {
const {layers, widget, dataId, onSelect} = this.props;
const {config} = widget;
var selectedLayer;
selectedLayer = config.selectedLayer;
// console.log(selectedLayer);
// console.log('lsoptions in widgetLayerSelector', lsOptions);
// console.log('selected layer is ', typeof selectedLayer);
// console.log('layers widgetLayerSelector', layers);
// console.log('options', this._widgetLayerOptions(layers, dataId));
// console.log('layers', layers);
return (
<SidePanelSection className="layer-selector">
<PanelLabel>Layers</PanelLabel>
<ItemSelector
placeholder={
selectedLayer
? this._renderPlaceholder(selectedLayer.id)
: 'Select A Layer'
}
// selectedItems={selectedLayer}
// options={this._widgetLayerOptions(layers, dataId)}
options={this._widgetLayerOptions(layers, dataId)}
multiSelect={false}
getOptionValue={'value'}
multiSelect={false}
onChange={onSelect}
displayOption={'label'}
searchable={false}
/>
</SidePanelSection>
);
}
}