-
-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(frontend): all uploaded submission features/geometries on submis…
…sion instance page (#1931) * fix(main): shift osmStyle to baselayers constant * fix(layer-switcher): user added layer vanish issue on switching to initial selected layer issue solve * fix(clusterLayer): refactor clusterLayer component * fix(submissionsTable): use link instead of useNavigate for redirection to submission instance page * fix(ISubmissions): geojson type add * feat(extractGeojsonFromObject): function to extract geojson from objects * fix(submissionDetials): update logic to display feature on submissionmap * fix(submissionInstanceMap): add clusterLayer to display feature points * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
- Loading branch information
1 parent
e545136
commit 0b6e8b6
Showing
6 changed files
with
170 additions
and
87 deletions.
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
106 changes: 106 additions & 0 deletions
106
src/frontend/src/utilfunctions/extractGeojsonFromObject.ts
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 |
---|---|---|
@@ -0,0 +1,106 @@ | ||
import { featureType, geojsonType } from '@/store/types/ISubmissions'; | ||
|
||
// convert JavaRosa string to a GeoJson | ||
const convertCoordinateStringToFeature = (coordinateString: string) => { | ||
let feature: featureType = { | ||
type: 'Feature', | ||
geometry: {}, | ||
properties: {}, | ||
}; | ||
|
||
// if feature is LineString in JavaRosa format it contains string of array separated by ';' | ||
if (coordinateString?.includes(';')) { | ||
let coordinates = coordinateString?.split(';')?.map((coord) => { | ||
let coordinate = coord | ||
.trim() | ||
.split(' ') | ||
.slice(0, 2) | ||
.map((value: string) => { | ||
return parseFloat(value); | ||
}); | ||
return [coordinate[1], coordinate[0]]; | ||
}); | ||
feature = { ...feature, geometry: { type: 'LineString', coordinates: coordinates } }; | ||
} else { | ||
// if feature is Point in JavaRosa format it contains string of array | ||
const splittedCoord = coordinateString?.split(' '); | ||
let coordinates = [+splittedCoord[1], +splittedCoord[0]]; | ||
feature = { ...feature, geometry: { type: 'Point', coordinates: coordinates } }; | ||
} | ||
return feature; | ||
}; | ||
|
||
export function extractGeojsonFromObject(data: Record<string, any>) { | ||
/*{ all feature of geometry points are stored in clusterLayerGeojson | ||
reason: more than one gps point can be on the exact same coordinate, so clustering and point expand on cluster click is important for visualization | ||
}*/ | ||
let clusterLayerGeojson: geojsonType = { | ||
type: 'FeatureCollection', | ||
features: [], | ||
}; | ||
|
||
// feature other than of geometry type points are stored in vectorLayerGeojson | ||
let vectorLayerGeojson: any = { | ||
type: 'FeatureCollection', | ||
features: [], | ||
}; | ||
|
||
// function called recursively until the object is traversed | ||
function traverse(data: Record<string, any>) { | ||
typeof data === 'object' && | ||
Object.entries(data)?.map(([key, value]) => { | ||
if (value && typeof value === 'object' && Object.keys(value).includes('coordinates')) { | ||
const feature = value as featureType['geometry']; | ||
if (feature?.type === 'Point') { | ||
clusterLayerGeojson = { | ||
...clusterLayerGeojson, | ||
features: [...clusterLayerGeojson.features, { type: 'Feature', geometry: feature, properties: {} }], | ||
}; | ||
} else { | ||
vectorLayerGeojson = { | ||
...vectorLayerGeojson, | ||
features: [...vectorLayerGeojson.features, { type: 'Feature', geometry: value, properties: {} }], | ||
}; | ||
} | ||
} | ||
// if value is object then traverse | ||
else if (value && typeof value === 'object') { | ||
traverse(value); | ||
} | ||
// check if value is JavaRosa LineString | ||
// the JavaRosa LineString is separated by ';' | ||
else if ( | ||
value && | ||
typeof value === 'string' && | ||
value?.includes(';') && | ||
value | ||
?.split(';')?.[0] | ||
?.split(' ') | ||
?.every((item) => !isNaN(+item)) | ||
) { | ||
const convertedFeature = convertCoordinateStringToFeature(value); | ||
vectorLayerGeojson = { | ||
...vectorLayerGeojson, | ||
features: [...vectorLayerGeojson.features, convertedFeature], | ||
}; | ||
} | ||
// check if value is JavaRosa Point | ||
// point contains 4 floating point data | ||
else if ( | ||
value && | ||
typeof value === 'string' && | ||
value?.split(' ')?.every((item) => !isNaN(+item)) && | ||
value?.split(' ')?.length === 4 | ||
) { | ||
const convertedFeature = convertCoordinateStringToFeature(value); | ||
clusterLayerGeojson = { | ||
...clusterLayerGeojson, | ||
features: [...clusterLayerGeojson.features, convertedFeature], | ||
}; | ||
} | ||
}); | ||
} | ||
|
||
traverse(data); | ||
return { clusterLayerGeojson, vectorLayerGeojson }; | ||
} |
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