Skip to content
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

Open
wants to merge 21 commits into
base: main
Choose a base branch
from
Open

Conversation

ruchimotwaniBC
Copy link
Contributor

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.

@forman forman assigned forman and unassigned forman Sep 17, 2024
Copy link
Member

@forman forman left a 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
Comment on lines 34 to 35
* Users can now copy snapshots of a map into the clipboard by clicking a new camera icon on a map's action bar.(#290)

Copy link
Member

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@ruchimotwaniBC ruchimotwaniBC marked this pull request as draft September 18, 2024 08:49
@ruchimotwaniBC ruchimotwaniBC removed the request for review from forman September 18, 2024 08:49
@ruchimotwaniBC ruchimotwaniBC marked this pull request as ready for review September 18, 2024 08:58
Copy link
Collaborator

@clarasb clarasb left a 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.

Copy link
Contributor

@AliceBalfanz AliceBalfanz left a 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.

@ruchimotwaniBC
Copy link
Contributor Author

ruchimotwaniBC commented Oct 30, 2024

  • 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.
  • Yes it wont work like Ctrl + C but after clicking on the snapshot button you can use Ctrl+ V to paste it in any document( eg: paint, word)

Comment on lines 37 to 38
elementRef?: RefObject<HTMLDivElement | null>;
mapRef?: string;
Copy link
Member

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.


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";
Copy link
Member

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.

Copy link
Member

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.

Comment on lines 64 to 72
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;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code not appropriate here.

Comment on lines +75 to +78
const source = layer.getSource() as OlTileSource & { crossOrigin?: string };
if (source && 'crossOrigin' in source) {
source.crossOrigin = "Anonymous";
}
Copy link
Member

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",
Copy link
Member

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.

Comment on lines 41 to 42
controlDiv?: HTMLElement | null;
zoomDiv?: HTMLElement | null;
Copy link
Member

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.

@@ -37,6 +37,9 @@ export interface ExportOptions {
height?: number;
handleSuccess?: () => void;
handleError?: (error: unknown) => void;
pixelratio?: number;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
pixelratio?: number;
pixelRatio?: number;

@@ -124,6 +128,7 @@ export default function MapInteractionsBar({
<FileUploadIcon />
</Tooltip>
</ToggleButton>
<SnapshotButton mapRef={"map"} postMessage={postMessage} fontSize="medium" isToggle={true} />
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mapRef not appropriate here

@forman
Copy link
Member

forman commented Nov 13, 2024

Please align your branch again with main.

Copy link
Collaborator

@clarasb clarasb left a 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 !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Export map and time series plot as image
4 participants