kepler.gl.geoiq
Version:
kepler.gl is a webgl based application to visualize large scale location data in the browser
195 lines (176 loc) • 5.2 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 Layer from '../base-layer';
import MVTLayerIcon from './mvt-layer-icon';
export const mvtRequiredUrl = ['url'];
export const mvtVisConfigs = {
opacity: 'opacity',
thickness: {
type: 'number',
defaultValue: 0.5,
label: 'Stroke Width',
isRanged: false,
range: [0, 100],
step: 0.1,
group: 'stroke',
property: 'thickness'
},
colorRange: 'colorRange',
radius: 'radius',
sizeRange: 'strokeWidthRange',
radiusRange: 'radiusRange',
heightRange: 'elevationRange',
elevationScale: 'elevationScale',
'hi-precision': 'hi-precision',
stroked: 'stroked',
filled: 'filled',
enable3d: 'enable3d',
wireframe: 'wireframe'
};
export default class MVTLayer extends Layer {
constructor(props) {
super(props);
this.dataToFeature = {};
this.registerVisConfig(mvtVisConfigs);
}
get type() {
return 'tile';
}
get name() {
return 'tile';
}
get layerIcon() {
return MVTLayerIcon;
}
get requiredLayerColumns() {
return mvtRequiredUrl;
}
get visualChannels() {
return {
...super.visualChannels,
size: {
...super.visualChannels.size,
property: 'stroke',
condition: config => config.visConfig.stroked
},
height: {
property: 'height',
field: 'heightField',
scale: 'heightScale',
domain: 'heightDomain',
range: 'heightRange',
key: 'height',
channelScaleType: 'size',
condition: config => config.visConfig.enable3d
},
radius: {
property: 'radius',
field: 'radiusField',
scale: 'radiusScale',
domain: 'radiusDomain',
range: 'radiusRange',
key: 'radius',
channelScaleType: 'radius'
}
};
}
getDefaultLayerConfig(props = {}) {
return {
...super.getDefaultLayerConfig(props),
// add height visual channel
heightField: null,
heightDomain: [0, 1],
heightScale: 'linear',
// add radius visual channel
radiusField: null,
radiusDomain: [0, 1],
radiusScale: 'linear'
};
}
getHoverData(object, allData) {
// index of allData is saved to feature.properties
return allData[object.properties.index];
}
formatLayerData() {}
renderLayer({idx, objectHovered, datasets, loadEDLinkData}) {
var cfg = this.config;
// {"field":"Population","operand":"BETWEEN","values":[90,630]}
this.updateLayerConfig({
colorField: {
format: '',
id: 'population',
name: 'Population',
tableFieldIndex: 2,
type: 'integer'
}
});
this.updateLayerDomain(datasets[this.config.dataId]);
const colorField = {
format: '',
id: 'population',
name: 'Population',
tableFieldIndex: 1,
type: 'integer'
};
const cScale =
colorField &&
this.getVisChannelScale(
'quantize',
this.config.colorDomain,
colorRange.colors.map(hexToRgb)
);
// const getFillColor = d => {
// console.log('d', d);
// cScale
// ? this.getEncodedChannelValue(cScale, d.properties[0], colorField)
// : [128, 128, 128];
// };
var tempLayr = new DeckGLMVTLayer({
id: this.id,
idx,
url: this.config.dataId,
filters: datasets[this.config.dataId].filters,
cScale,
colorField,
getEncodedChannelValue: (cScale, props, colorField) =>
this.getEncodedChannelValue(cScale, props, colorField),
loadEDLinkData
});
return [
tempLayr,
...(this.isLayerHovered(objectHovered)
? [
new DeckGLGeoJsonLayer({
id: `${this.id}-hovered`,
data: [objectHovered.object],
getLineWidth: 1,
getRadius: 23,
getElevation: 45,
getLineColor: [255, 255, 0],
getFillColor: [0, 255, 255],
stroked: true,
pickable: false,
filled: false
})
]
: [])
];
}
}