This repository has been archived by the owner on Apr 24, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #524 from ElektraInitiative/522-map-grid
Grid layer.
- Loading branch information
Showing
26 changed files
with
468 additions
and
31 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Use Case: Grid | ||
|
||
## Summary | ||
|
||
- **Scope:** Grid | ||
- **Level:** User Goal | ||
- **Actors:** App User | ||
- **Brief:** The app will display a fixed scale coordinate grid. | ||
- **Status:** Done | ||
- **Assignee:** Moritz | ||
- **Protocol:** | ||
|
||
## Scenarios | ||
|
||
- **Precondition:** | ||
- User has opened the map. | ||
- **Main success scenario:** | ||
- The user sees a fixed scale coordinate grid with 1 meter spacing. | ||
- **Non-functional Constraints:** | ||
- Support for changing viewport (zoom, position, etc.) | ||
- The functionality is only available in the frontend. |
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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"tooltip": "Raster ein/aus" | ||
} |
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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"tooltip": "Toggle Grid" | ||
} |
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
21 changes: 21 additions & 0 deletions
21
frontend/src/features/map_planning/layers/_frontend_only/grid/GridLayer.tsx
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,21 @@ | ||
import { Grid } from '@/features/map_planning/layers/_frontend_only/grid/groups/Grid'; | ||
import { YardStick } from '@/features/map_planning/layers/_frontend_only/grid/groups/YardStick'; | ||
import useMapStore from '@/features/map_planning/store/MapStore'; | ||
import Konva from 'konva/cmj'; | ||
import { Layer } from 'react-konva'; | ||
|
||
export const GridLayer = (props: Konva.LayerConfig) => { | ||
const mapBounds = useMapStore((state) => state.untrackedState.editorBounds); | ||
|
||
return ( | ||
<Layer listening={false} visible={props.visible} opacity={props.opacity}> | ||
<Grid x={mapBounds.x} y={mapBounds.y} width={mapBounds.width} height={mapBounds.height} /> | ||
<YardStick | ||
x={mapBounds.x} | ||
y={mapBounds.y} | ||
width={mapBounds.width} | ||
height={mapBounds.height} | ||
/> | ||
</Layer> | ||
); | ||
}; |
34 changes: 34 additions & 0 deletions
34
frontend/src/features/map_planning/layers/_frontend_only/grid/groups/Grid.tsx
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,34 @@ | ||
import { calculateGridStep } from '@/features/map_planning/layers/_frontend_only/grid/util/Calculations'; | ||
import { | ||
RELATIVE_DOT_SIZE, | ||
SEA_BLUE_500, | ||
} from '@/features/map_planning/layers/_frontend_only/grid/util/Constants'; | ||
import { BoundsRect } from '@/features/map_planning/store/MapStoreTypes'; | ||
import { Group, Line } from 'react-konva'; | ||
|
||
export const Grid = (rect: BoundsRect) => { | ||
const gridStep = calculateGridStep(rect.width); | ||
|
||
const gridDotSize = rect.width * RELATIVE_DOT_SIZE; | ||
|
||
// Draw the grid larger than necessary to avoid artifacts while panning the viewport. | ||
const startX = -rect.x - rect.width - ((-rect.x - rect.width) % gridStep); | ||
const startY = -rect.y - rect.height - ((-rect.y - rect.height) % gridStep); | ||
|
||
const endX = -rect.x + rect.width * 2; | ||
const endY = -rect.y + rect.height * 2; | ||
|
||
const lines = []; | ||
for (let y = startY; y < endY; y += gridStep) { | ||
lines.push( | ||
<Line | ||
strokeWidth={gridDotSize} | ||
stroke={SEA_BLUE_500} | ||
points={[startX, y, endX, y]} | ||
dash={[gridDotSize, gridStep - gridDotSize]} | ||
></Line>, | ||
); | ||
} | ||
|
||
return <Group>{lines}</Group>; | ||
}; |
Oops, something went wrong.