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

Write Scale and Attribution directly into PDF or PNG #13

Open
1 of 2 tasks
roblabs opened this issue Dec 4, 2017 · 0 comments
Open
1 of 2 tasks

Write Scale and Attribution directly into PDF or PNG #13

roblabs opened this issue Dec 4, 2017 · 0 comments

Comments

@roblabs
Copy link
Contributor

roblabs commented Dec 4, 2017

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

  • How to write attribution into PDF.
  • Done — see an example on how to write an attribution to a US Letter sized PDF, 36c4726
  • Get the Attribution by accessing the class where its held in Mapbox GL JS
    • Then access the data with attrib.innerText or attrib.innerHTML
  • The class is called mapboxgl-ctrl-attrib

Example,

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

Scale

  • How to write scale directly into PDF
  • The scale takes a bit more work as you need to make use of two numbers.
    • The width of the scale control in pixels, e.g., width: 77.82px;
    • convert using device dependent pixels using Media Queries, cf. W3C Units
    • The physical measurement , e.g, 1000ft
    • Write the measurement to the PDF similar to how the attribution was done
  • The class is called mapboxgl-ctrl-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

  • jsPDF has two examples that show how to write text.

doc.text()

  • Position of where to write is dependent on landscape vs. portrait of PDF
  • Text can be right aligned. Need to verify if HTML links are preserved in written PDF
  • Example, doc.text(200, 100, attrib, null, null, 'right'); // units are mm

doc.fromHTML()

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

  • Issue is how to compute the proper x dimension of wheres to start writing the attribution.
  • In this example, a guess was chosen and would need to iterate on final position. As you can see the final words are cut off.
  • Unicode is not supported, so ignore the garbled symbols 𝘦 π Maps, they didn't make it into the final PDF.

pdf


PNG Research

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

No branches or pull requests

1 participant