-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
HeimEndyd
merged 10 commits into
master
from
ms/js_to_ts_convertion/layers/geojson-layer
Apr 11, 2022
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
31dc997
Renamed js files
HeimEndyd 2c4cc4c
Fixed ts errors
HeimEndyd 9235b65
Declared config for GeoJsonLayer
HeimEndyd cf9edad
Declared visConfigSettings
HeimEndyd deb7409
Declared required types
HeimEndyd e5e4d4a
Merge branch 'master' into ms/js_to_ts_convertion/layers/geojson-layer
HeimEndyd 6634a18
Merge branch 'master' into ms/js_to_ts_convertion/layers/geojson-layer
HeimEndyd 46440a8
Applied suggested changes
HeimEndyd 6f7deb4
Added exports
HeimEndyd 11ceeca
Added LayerRadiusConfig
HeimEndyd File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,9 +22,26 @@ import wktParser from 'wellknown'; | |
import normalize from '@mapbox/geojson-normalize'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; There was a problem hiding this comment. Choose a reason for hiding this commentThe 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'; | ||
import {Feature, BBox} from 'geojson'; | ||
|
||
export type GetFeature = (d: any) => Feature; | ||
export 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) { | ||
export function parseGeoJsonRawFeature(rawFeature: unknown): Feature | null { | ||
if (typeof rawFeature === 'object') { | ||
// Support GeoJson feature as object | ||
// probably need to normalize it as well | ||
|
@@ -45,7 +62,8 @@ export function parseGeoJsonRawFeature(rawFeature) { | |
// why do we need to flip it... | ||
coordinates: rawFeature.map(pts => [pts[1], pts[0]]), | ||
type: 'LineString' | ||
} | ||
}, | ||
properties: {} | ||
}; | ||
} | ||
|
||
|
@@ -57,7 +75,7 @@ export function parseGeoJsonRawFeature(rawFeature) { | |
* @param getFeature | ||
* @returns {{}} | ||
*/ | ||
export function getGeojsonDataMaps(dataContainer, getFeature) { | ||
export function getGeojsonDataMaps(dataContainer: any, getFeature: GetFeature): GeojsonDataMaps { | ||
const acceptableTypes = [ | ||
'Point', | ||
'MultiPoint', | ||
|
@@ -68,7 +86,7 @@ export function getGeojsonDataMaps(dataContainer, getFeature) { | |
'GeometryCollection' | ||
]; | ||
|
||
const dataToFeature = []; | ||
const dataToFeature: (Feature | null)[] = []; | ||
|
||
for (let index = 0; index < dataContainer.numRows(); index++) { | ||
const feature = parseGeoJsonRawFeature(getFeature({index})); | ||
|
@@ -97,7 +115,7 @@ export function getGeojsonDataMaps(dataContainer, getFeature) { | |
* @param {String} geoString | ||
* @returns {null | Object} geojson object or null if failed | ||
*/ | ||
export function parseGeometryFromString(geoString) { | ||
export function parseGeometryFromString(geoString: string): Feature | null { | ||
let parsedGeo; | ||
|
||
// try parse as geojson string | ||
|
@@ -131,7 +149,7 @@ export function parseGeometryFromString(geoString) { | |
return normalized.features[0]; | ||
} | ||
|
||
export function getGeojsonBounds(features = []) { | ||
export function getGeojsonBounds(features: Feature[] = []): BBox | null { | ||
// 70 ms for 10,000 polygons | ||
// here we only pick couple | ||
const maxCount = 10000; | ||
|
@@ -165,8 +183,9 @@ export const featureToDeckGlGeoType = { | |
* @param {Array<Object>} allFeatures | ||
* @returns {Object} mapping of feature type existence | ||
*/ | ||
export function getGeojsonFeatureTypes(allFeatures) { | ||
const featureTypes = {}; | ||
export function getGeojsonFeatureTypes(allFeatures: Feature[]): FeatureTypeMap { | ||
// @ts-expect-error | ||
const featureTypes: FeatureTypeMap = {}; | ||
for (let f = 0; f < allFeatures.length; f++) { | ||
const feature = allFeatures[f]; | ||
const geoType = featureToDeckGlGeoType[feature && feature.geometry && feature.geometry.type]; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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