mpetroff / print-maps

High-resolution maps in the browser, for printing
https://printmaps.mpetroff.net/
MIT License
286 stars 51 forks source link

Write Scale and Attribution directly into PDF or PNG #13

Open roblabs opened 6 years ago

roblabs commented 6 years ago

Following up on use and attribution of downloaded maps —  cf. #12, Handling of attribution to adhere to TOS for Tile Companies

Documenting some research into what it takes to directly write the attribution and scale into the PDF or PNG file. This work would need to planned out with a proper amount of use and test cases.

Example of Map Attribution and Scale in Mapbox GL JS

dom

Research

Attribution

Example,

var attrib = window.document.getElementsByClassName("mapboxgl-ctrl-attrib")[0];
console.log(attrib.innerText)
© 𝘦 π Maps | © USGS | Wilderness.net | © OpenMapTiles © OpenStreetMap contributors

Scale

var scale = window.document.getElementsByClassName("mapboxgl-ctrl-scale")[0];
console.log(scale)
<div class="mapboxgl-ctrl mapboxgl-ctrl-scale" style="width: 77.82px;">1000ft</div>

Writing directly into PDF

doc.text()

doc.fromHTML()

pdf.fromHTML(attrib, 150, 210); // units are mm

pdf

PNG Research