-
Notifications
You must be signed in to change notification settings - Fork 14
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
Rd 286: screenshots #107
Merged
Merged
Rd 286: screenshots #107
Changes from 15 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
ca3a8da
Updated MapLibre version and adjusted MaptilerGeolocateControl
jonathanlurie e304805
removed the zoomAdjust unnecesary value in minimap
jonathanlurie e5f27fa
Adding sky examples
jonathanlurie ca18208
Now passing the options to the control
jonathanlurie 348c2d3
Updated xmldom dep
jonathanlurie 7aae950
Add screenshot helper
jonathanlurie 08a617a
adding screenshot helper and readme
jonathanlurie b67f409
Adding whole page screenshot
jonathanlurie d9bb106
removed an old async keyword
jonathanlurie bd538ce
removed an old async keyword
jonathanlurie f4a8c7f
removed an old async keyword
jonathanlurie 380a8bf
linting
jonathanlurie 5577e7c
adapt UMD bundle name to prod or dev mode
jonathanlurie 87005ce
resolve git merge conflicts
jonathanlurie 2bfe8c4
removing whole page screenshot
jonathanlurie 9782872
fix typo
jonathanlurie File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import type { Map as MapSDK } from "../Map"; | ||
|
||
/** | ||
* Takes a screenshot (PNG file) of the curent map view. | ||
* Depending on the options, this function can automatically trigger a download of te file. | ||
*/ | ||
export async function takeScreenshot( | ||
map: MapSDK, | ||
options: { | ||
/** | ||
* If `true`, this function will trigger a download in addition to returning a blob. | ||
* Default: `false` | ||
*/ | ||
download?: boolean; | ||
|
||
/** | ||
* Only if `options.download` is `true`. Indicates the filename under which | ||
* the file will be downloaded. | ||
* Default: `"maptiler_screenshot.png"` | ||
*/ | ||
filename?: string; | ||
} = {}, | ||
): Promise<Blob> { | ||
const download = options.download ?? false; | ||
const blob = await getMapScreenshotBlob(map); | ||
|
||
if (download) { | ||
const filename = options.filename ?? "maptiler_screenshot.png"; | ||
|
||
const link = document.createElement("a"); | ||
link.style.display = "none"; | ||
document.body.appendChild(link); | ||
link.href = URL.createObjectURL(blob); | ||
link.download = filename; | ||
link.click(); | ||
|
||
// Cleaning after event loop | ||
setTimeout(() => { | ||
document.body.removeChild(link); | ||
URL.revokeObjectURL(link.href); | ||
}, 0); | ||
} | ||
|
||
return blob; | ||
} | ||
|
||
function getMapScreenshotBlob(map: MapSDK): Promise<Blob> { | ||
return new Promise((resolve, reject) => { | ||
map.redraw(); | ||
|
||
map.once("idle", () => { | ||
map.getCanvas().toBlob((blob) => { | ||
if (!blob) { | ||
return reject(Error("Screenshot could not be created.")); | ||
} | ||
|
||
resolve(blob); | ||
}, "image/png"); | ||
}); | ||
}); | ||
} |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
"sceenshot"