-
Notifications
You must be signed in to change notification settings - Fork 10
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
Copy the map image to clipboard #428
base: main
Are you sure you want to change the base?
Conversation
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.
Please align your branch with main first. Then I'll do another review.
CHANGES.md
Outdated
* Users can now copy snapshots of a map into the clipboard by clicking a new camera icon on a map's action bar.(#290) | ||
|
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.
This is the section for the changes of version 1.3, which has already been release. Please align your branch with main
first. Then I'll do another review.
Also limit lines to 80 characters in markdown.
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.
Done
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.
tested from a user perspective:
- feature works fine (tested with Firefox and Edge)
- explanation in the docs might be necessary. Because the function does not work like Ctrl+C, the images must first be copied into a document in order to be saved. This can be a bit confusing at first.
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.
Tested from a user perspective. For me it works as expected. The tooltip "copy snapshot to clipboard" is explaining well the behaviour. @clarasb, for me it worked well with taking the snapshot and then pasting the image somewhere with Ctrl + V. I would not expect it to save e.g. a png automatically.
|
src/components/SnapshotButton.tsx
Outdated
elementRef?: RefObject<HTMLDivElement | null>; | ||
mapRef?: string; |
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.
Property elementRef
was correct, property mapRef
is not appropriate here.
src/components/SnapshotButton.tsx
Outdated
|
||
import i18n from "@/i18n"; | ||
import { WithLocale } from "@/util/lang"; | ||
import { MessageType } from "@/states/messageLogState"; | ||
import { exportElement } from "@/util/export"; | ||
import ToolButton from "@/components/ToolButton"; | ||
import { MAP_OBJECTS } from "@/states/controlState"; |
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.
Wrong dependency. Create a higher level component MapSnapshotButton
instead that uses SnapshotButton
.
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.
Make MapSnapshotButton
a private component of MapInteractionsBar
.
src/components/SnapshotButton.tsx
Outdated
const targetElement: HTMLElement | null = mapRef && MAP_OBJECTS[mapRef] | ||
? (MAP_OBJECTS[mapRef] as OlMap).getTargetElement() | ||
: elementRef?.current || null; | ||
const controlDiv: HTMLElement | null = targetElement | ||
? targetElement.querySelector(".ol-unselectable.ol-control.MuiBox-root.css-0") | ||
: null; | ||
const zoomDiv: HTMLElement | null = targetElement | ||
? targetElement.querySelector(".ol-zoom.ol-unselectable.ol-control") | ||
: null; |
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.
Code not appropriate here.
const source = layer.getSource() as OlTileSource & { crossOrigin?: string }; | ||
if (source && 'crossOrigin' in source) { | ||
source.crossOrigin = "Anonymous"; | ||
} |
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.
Please add a comment that explains why this is needed. Add a link to the source too.
@@ -837,6 +837,7 @@ function getOlXYZSource( | |||
// level at minZoom when zooming out! | |||
// minZoom: tileLevelMin, | |||
maxZoom: tileLevelMax, | |||
crossOrigin: "Anonymous", |
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.
Comment why this is needed.
src/util/export.ts
Outdated
controlDiv?: HTMLElement | null; | ||
zoomDiv?: HTMLElement | null; |
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.
Not appropriate here. Add an array parameter instead providing the elements that may be excluded from the export.
src/util/export.ts
Outdated
@@ -37,6 +37,9 @@ export interface ExportOptions { | |||
height?: number; | |||
handleSuccess?: () => void; | |||
handleError?: (error: unknown) => void; | |||
pixelratio?: number; |
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.
pixelratio?: number; | |
pixelRatio?: number; |
@@ -124,6 +128,7 @@ export default function MapInteractionsBar({ | |||
<FileUploadIcon /> | |||
</Tooltip> | |||
</ToggleButton> | |||
<SnapshotButton mapRef={"map"} postMessage={postMessage} fontSize="medium" isToggle={true} /> |
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.
mapRef
not appropriate here
Please align your branch again with main. |
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.
Tested from a user-perspective.
Works fine !
This PR implements the map export feature which closes #290 .
The camera icon button on map's action bar allows user to take the snapshot of current state of map and copy it to the clipboard.