Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Chore]: Technical: Translate geojson-layer #1757

Merged
merged 10 commits into from
Apr 11, 2022
5 changes: 4 additions & 1 deletion src/layers/base-layer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,10 @@ export const colorMaker = generateColor();
class Layer {
id: string;
// TODO: define meta
meta: {};
meta: {
featureTypes?: {polygon: boolean; point: boolean; line: boolean};
fixedRadius?: {};
};
visConfigSettings: {
[key: string]: ValueOf<LayerVisConfigSettings>;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

import React, {Component} from 'react';
import PropTypes from 'prop-types';
import Base from 'components/common/icons/base';
import Base from '../../components/common/icons/base';

export default class GeojsonLayerIcon extends Component {
static propTypes = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,22 @@
import uniq from 'lodash.uniq';
import {DATA_TYPES} from 'type-analyzer';

import Layer, {colorMaker} from '../base-layer';
import Layer, {colorMaker, LayerBaseConfig, LayerColumn} from '../base-layer';
import {GeoJsonLayer as DeckGLGeoJsonLayer} from '@deck.gl/layers';
import {getGeojsonDataMaps, getGeojsonBounds, getGeojsonFeatureTypes} from './geojson-utils';
import GeojsonLayerIcon from './geojson-layer-icon';
import {GEOJSON_FIELDS, HIGHLIGH_COLOR_3D, CHANNEL_SCALES} from 'constants/default-settings';
import {LAYER_VIS_CONFIGS} from 'layers/layer-factory';
import {GEOJSON_FIELDS, HIGHLIGH_COLOR_3D, CHANNEL_SCALES} from '../../constants/default-settings';
import {
LAYER_VIS_CONFIGS,
VisConfigNumber,
VisConfigColorSelect,
VisConfigColorRange,
VisConfigRange,
VisConfigBoolean
} from '../layer-factory';
import {DataContainerInterface} from '../../utils/table-utils/data-container-interface';
import {Merge, RGBColor} from '../../reducers';
import {ColorRange} from '../../constants/color-ranges';

const SUPPORTED_ANALYZER_TYPES = {
[DATA_TYPES.GEOMETRY]: true,
Expand Down Expand Up @@ -60,15 +70,70 @@ export const geojsonVisConfigs = {
wireframe: 'wireframe'
};

export const geoJsonRequiredColumns = ['geojson'];
export const featureAccessor = ({geojson}) => dc => d => dc.valueAt(d.index, geojson.fieldIdx);
export type GeoJsonVisConfigSettings = {
opacity: VisConfigNumber;
strokeOpacity: VisConfigNumber;
thickness: VisConfigNumber;
strokeColor: VisConfigColorSelect;
colorRange: VisConfigColorRange;
strokeColorRange: VisConfigColorRange;
radius: VisConfigNumber;

sizeRange: VisConfigRange;
radiusRange: VisConfigRange;
heightRange: VisConfigRange;
elevationScale: VisConfigNumber;
enableElevationZoomFactor: VisConfigBoolean;
stroked: VisConfigBoolean;
filled: VisConfigBoolean;
enable3d: VisConfigBoolean;
wireframe: VisConfigBoolean;
};

export type GeoJsonLayerColumnsConfig = {
geojson: LayerColumn;
};

export type GeoJsonLayerVisConfig = {
opacity: number;
strokeOpacity: number;
thickness: number;
strokeColor: RGBColor;
colorRange: ColorRange;
strokeColorRange: ColorRange;
radius: number;

sizeRange: [number, number];
radiusRange: [number, number];
heightRange: [number, number];
elevationScale: number;
enableElevationZoomFactor: boolean;
stroked: boolean;
filled: boolean;
enable3d: boolean;
wireframe: boolean;
};

export type GeoJsonLayerConfig = Merge<
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

type GeoJsonLayerVisualChannelConfig = LayerColorConfig & LayerStrokeColorConfig 
LayerSizeConfig & LayerHeightConfig & LayerRadiusConfig

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is meant by LayerRadiusConfig?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can add this to base-layer

export type LayerRadiusConfig = {
  radiusField: VisualChannelField;
  radiusDomain: VisualChannelDomain;
  radiusScale: VisualChannelScale;
};

LayerBaseConfig,
{columns: GeoJsonLayerColumnsConfig; visConfig: GeoJsonLayerVisConfig}
>;

export const geoJsonRequiredColumns: ['geojson'] = ['geojson'];
export const featureAccessor = ({geojson}: GeoJsonLayerColumnsConfig) => (
dc: DataContainerInterface
) => d => dc.valueAt(d.index, geojson.fieldIdx);

// access feature properties from geojson sub layer
export const defaultElevation = 500;
export const defaultLineWidth = 1;
export const defaultRadius = 1;

export default class GeoJsonLayer extends Layer {
declare config: GeoJsonLayerConfig;
declare visConfigSettings: GeoJsonVisConfigSettings;
dataToFeature: {properties?: {radius?: number}}[];
Copy link
Contributor

@heshan0131 heshan0131 Apr 5, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dataToFeature: GeojsonDataMaps See comments in geojson-utils


constructor(props) {
super(props);

Expand All @@ -78,10 +143,13 @@ export default class GeoJsonLayer extends Layer {
}

get type() {
return GeoJsonLayer.type;
}
static get type(): 'geojson' {
return 'geojson';
}

get name() {
get name(): 'Polygon' {
return 'Polygon';
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import wktParser from 'wellknown';
import normalize from '@mapbox/geojson-normalize';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please types below to type the functions in this file

import {KeplerTable} from '../../utils';
import {Feature, BBox} from 'geojson';
import {LayerColumns} from '../index';

type GetFeature = (d: any) => Feature;
type GeojsonDataMaps = Array<Feature | null>;

export enum FeatureTypes {
  Point = 'Point',
  MultiPoint = 'MultiPoint',
  LineString = 'LineString',
  MultiLineString = 'MultiLineString',
  Polygon = 'Polygon',
  MultiPolygon = 'MultiPolygon'
}

type FeatureTypeMap = {
  [key in FeatureTypes]: boolean;
};
export function parseGeoJsonRawFeature(rawFeature: unknown): Feature | null;

export function getGeojsonDataMaps(
  allData: KeplerTable['allData'],
  getFeature: GetFeature
): GeojsonDataMaps;

export function getGeojsonBounds(features: Feature[]): BBox | null;

export function getGeojsonFeatureTypes(allFeatures: Feature[]): FeatureTypeMap;

export function parseGeometryFromString(geoString: string): Feature | null;

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

KeplerTable does not contain property allData

import bbox from '@turf/bbox';

import {getSampleData} from 'utils/data-utils';
import {getSampleData} from '../../utils/data-utils';

export function parseGeoJsonRawFeature(rawFeature) {
if (typeof rawFeature === 'object') {
Expand Down