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

feat: Printing #263

Merged
merged 2 commits into from
Feb 24, 2023
Merged

feat: Printing #263

merged 2 commits into from
Feb 24, 2023

Conversation

DafyddLlyr
Copy link
Contributor

@DafyddLlyr DafyddLlyr commented Feb 15, 2023

Apologies that this one has taken so long to see any daylight 🌤️ I kept coming back and tweaking... it's pretty hacky in places.

I'm using ol-ext/printDialog (docs) to allow the map to be printed to PDF/PNG/JPG at set scales.

The documentation is pretty poor for ol-ext so there's been a lot of figuring out and reverse engineering.

This meets the requirements of the following ticket (and then some) - https://trello.com/c/jVS79IdF/2230-can-automatically-generated-location-plan-click-to-standard-scales

image

image

To do...

  • Pitsby docs
  • Unsquash print compass
  • Handle imperfect scales
  • Style: Handle button position if "Reset" button not present

@netlify
Copy link

netlify bot commented Feb 15, 2023

Deploy Preview for oslmap ready!

Name Link
🔨 Latest commit 86a2a55
🔍 Latest deploy log https://app.netlify.com/sites/oslmap/deploys/63f8b4e98cce72000865b639
😎 Deploy Preview https://deploy-preview-263--oslmap.netlify.app/
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

@DafyddLlyr DafyddLlyr requested a review from a team February 15, 2023 22:06
@@ -39,11 +39,11 @@
}
</style> -->
</head>
<body>
<body style="font-family:Inter,Helvetica,sans-serif;">
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was moved to test that font style is inherited in the PrintDialog

@@ -48,3 +54,115 @@ export function resetControl(listener: any, icon: string) {

return new Control({ element: element });
}

PrintDialog.prototype.scales = {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's no way of setting this within the class - Viglino/ol-ext#766 (comment)

* This can not natively be done with this element, but it has all the inherited
* functions from OL ScaleLine to allow us to set this
*/
private syncScaleText() {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I spent a good while trying to make this a method on the CanvasScaleLine class (or rather a child class) as really that's where it belongs and you can access the this.element without query selectors etc.

The problem I hit was getting the correct map context from within than class, even when explicitly passing this.map into the constructor.

@@ -35,6 +35,7 @@ function makeOSRasterBaseMap(
source: new XYZ({
url: tileServiceURL,
attributions: [copyright],
crossOrigin: "anonymous",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a requirement for the canvas to access tiles - Viglino/ol-ext#673 (comment)

@DafyddLlyr DafyddLlyr marked this pull request as ready for review February 16, 2023 08:04
Copy link

@builditben builditben left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I definitely don't understand how this works but the code you've added looks good.

I've added a couple of comments/questions but no show-stoppers.

src/components/my-map/index.ts Outdated Show resolved Hide resolved
src/components/my-map/controls.ts Show resolved Hide resolved
src/components/my-map/controls.ts Show resolved Hide resolved
Copy link
Member

@jessicamcinchak jessicamcinchak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm sorry it's taken me so long to properly get to this one - I've looked at it many times and failed to hit "comment"!

Overall I'm happy with this solution and it functions perfectly for me, it's actually a lot less code than I expected it would be too. Solid work for a big-feeling feature 🖨️ 🎉

A couple general comments / questions (happy to chat about any of these outloud, please don't feel any pressure to type responses):

  • You added "Pitsby docs" in the todo's, but I wonder if there's actually a case to intentionally omit an expample of the print button from docs because otherwise anyone could theoretically print OS basemaps via the "Sandbox" using our proxy endpoint to fetch vector tiles? Alastair commented about this legal difference in web maps versus print a bit ago if you recall? Obviously someone could still find their own way to this, but at least we wouldn't be advertising it?
  • I'm curious about reasons you chose ol-ext, rather than say using the html2canvas & jsPDF approach in the openlayers examples https://openlayers.org/en/latest/examples/print-to-scale.html (obvious downside being would need to roll our own dialog inputs I guess)? With the funny scale issue going on, I'm curious about effort involved to sense check against a different library and see if clears it up - or if it's just a quirk of printing we're going to live with (I'm also totally OK with this if councils are and will be curious to see if it gets noticed in UAT)

@DafyddLlyr
Copy link
Contributor Author

@jessicamcinchak To summarise our conversation on this -

  • No docs (for now) is the way to go as there's just a single specific use case
  • ol-ext gives us a nice dialog and preview map, and allows for a decent amount of customisation without too much overhead. I had thought that canvas scale bars would be an issue, but this isn't actually the case in the linked example.

@DafyddLlyr DafyddLlyr merged commit d613f6c into main Feb 24, 2023
@DafyddLlyr DafyddLlyr deleted the dp/ol-ext-print branch February 24, 2023 13:25
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.

3 participants