Skip to content

Commit

Permalink
front: fix warpedMap bug
Browse files Browse the repository at this point in the history
  • Loading branch information
clarani authored and flomonster committed Dec 11, 2023
1 parent 73d34cd commit ff14422
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
7 changes: 5 additions & 2 deletions front/src/common/Map/WarpedMap/SimulationWarpedMap.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,8 @@ const SimulationWarpedMap: FC<{ collapsed?: boolean }> = ({ collapsed }) => {
const chartEnd = !rotate ? y(l) : x(l);
const size = !rotate ? height : width;

const transformedPath = transform(path) as typeof path;
// we don't clip the path
const transformedPath = transform(path, false) as typeof path;
const latStart = (first(transformedPath.geometry.coordinates) as Position)[1];
const latEnd = (last(transformedPath.geometry.coordinates) as Position)[1];

Expand Down Expand Up @@ -175,7 +176,9 @@ const SimulationWarpedMap: FC<{ collapsed?: boolean }> = ({ collapsed }) => {
}, [selectedTrain, state.type, simulation]);
const warpedItinerary = useMemo(() => {
const itinerary = getAsyncMemoData(itineraryState);
if (itinerary && state.type === 'dataLoaded') return state.transform(itinerary) || undefined;
if (itinerary && state.type === 'dataLoaded')
// we don't clip the path
return state.transform(itinerary, false) || undefined;
return undefined;
}, [itineraryState, state]);

Expand Down
9 changes: 6 additions & 3 deletions front/src/common/Map/WarpedMap/core/projection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,19 +150,22 @@ export function projectGeometry<G extends Geometry = Geometry>(
export function clipAndProjectGeoJSON<T extends Geometry | Feature | FeatureCollection>(
geojson: T,
projection: Projection,
zone: Zone
zone: Zone,
shouldClip: boolean
): T | null {
if (geojson.type === 'FeatureCollection')
return {
...geojson,
features: geojson.features.flatMap((f) => {
const res = clipAndProjectGeoJSON(f, projection, zone);
const res = clipAndProjectGeoJSON(f, projection, zone, shouldClip);
return res ? [res] : [];
}),
};

if (geojson.type === 'Feature') {
const clippedFeature = clip(geojson, zone) as Feature | null;
const clippedFeature = shouldClip
? (clip(geojson, zone) as Feature | null)
: (geojson as Feature);

if (clippedFeature) {
const newGeometry = projectGeometry(clippedFeature.geometry, projection);
Expand Down
4 changes: 2 additions & 2 deletions front/src/common/Map/WarpedMap/getWarping.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export default function getWarping(warpPath: Feature<LineString>) {
// regular grid:
return {
warpedBBox: bbox(warped) as BBox2d,
transform: <T extends Geometry | Feature | FeatureCollection>(f: T): T | null =>
clipAndProjectGeoJSON(f, projection, zone),
transform: <T extends Geometry | Feature | FeatureCollection>(f: T, clip = true): T | null =>
clipAndProjectGeoJSON(f, projection, zone, clip),
};
}

0 comments on commit ff14422

Please sign in to comment.