SC-InteractiveMap
SC-InteractiveMap copied to clipboard
Add a button to the minimap to export the current view as an image (#219)
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
TileLayerto provide the ability to render to a canvas - Extends
Mapto composite any tile layers and overlays as canvases - Add a control that uses
map.exportToCanvasto get an canvas representation of the current viewport. This will save asexport.pngwhen no save is loaded, or as<save name>.pngif 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
SCIMobject, which seems strange to access from a control installed byGameMap
- 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
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:
Note the new button!
The exported image of the same viewport, created by clicking the new button:

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.
@AnthorNet Curious your thoughts on this PR? Do you like the direction taken for implementatin?
@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.
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.