Skip to content

Conversation

@DeviateFish
Copy link

@DeviateFish DeviateFish commented May 22, 2022

This contains what's essentially a rewrite of the leaflet-image plugin. That plugin mostly worked, but didn't handle fractional zooms and some of the transforms that (newer versions of?) Leaflet uses.

Note that this only exports the map tile layer and the overlay layer. Markers are not exported. They're html markers that contain svg elements, which don't seem to be easy to render to a canvas. I can probably figure out how to include them in the future, but this seemed like a good start.

  • Extends TileLayer to provide the ability to render to a canvas
  • Extends Map to composite any tile layers and overlays as canvases
  • Add a control that uses map.exportToCanvas to get an canvas representation of the current viewport. This will save as export.png when no save is loaded, or as <save name>.png if there is a save
    • This is a little janky at the moment, and could probably be improved somewhat. The only thing that has knowledge of both the map and the save game is the global SCIM object, which seems strange to access from a control installed by GameMap

This addresses the core functionality of #219. There's a lot more I could do here to enable automation of multiple save games, etc, but I figured this was a good starting point.

A screenshot (captured with the OS screenshot tool) of the test map with some random zooms/pans applied after loading:

image

Note the new button!

The exported image of the same viewport, created by clicking the new button:

CREATIVE TEST

Note about the above images: I captured the first screenshot on a Mac with a retina display, so it's "upscaled" . The display size of both images is actually identical on the device itself.

@DeviateFish DeviateFish marked this pull request as ready for review May 22, 2022 03:53
- Extends `TileLayer` to provide the ability to render to a canvas
- Extends `Map` to composite any tile layers and overlays as canvases
- Add a control that uses `map.exportToCanvas` to get an canvas representation of the current viewport.  This will save as `export.png` when no save is loaded, or as `<save name>.png` if there is a save
  - This is a little janky at the moment, and could probably be improved somewhat.  The only thing that has knowledge of both the map and the save game is the global `SCIM` object, which seems strange to access from a control installed by `GameMap`
- Make styles internally consistent
- Add some documentation and JSDoc for methods
- Add some attribution for the rendering of the `overlayPane`
@DeviateFish DeviateFish force-pushed the export-viewport-to-png branch from d57a6bf to 3b64a4a Compare June 15, 2022 07:53
@AnthorNet AnthorNet changed the base branch from main to dev June 20, 2022 05:35
@ZachGoldberg
Copy link

@AnthorNet Curious your thoughts on this PR? Do you like the direction taken for implementatin?

@wtodom
Copy link

wtodom commented Dec 2, 2024

@AnthorNet given that you closed mine as a dup (which is understandable), do you have any comments on this? I doubt it's mergeable as-is since it's quite old now, but I'd love to hear if this sort of functionality is something that you'd consider merging or not. You've clearly got people who want to help add a feature that I think a lot of people would use and enjoy, we just need some insight into whether or not it's a direction you want your project to go.

@AnthorNet
Copy link
Owner

Not closing it as it could be a cool feature, but not a top priority because we still have a lot to finish for 1.0 !
But I'll take a look for sure.

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.

4 participants