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

QrCode - a little investigation #1407

Open
OlofSvahnVbg opened this issue Oct 3, 2023 · 8 comments
Open

QrCode - a little investigation #1407

OlofSvahnVbg opened this issue Oct 3, 2023 · 8 comments
Labels
new feature Request for adding/changing functionality
Milestone

Comments

@OlofSvahnVbg
Copy link
Collaborator

OlofSvahnVbg commented Oct 3, 2023

Someone had the idea of adding a qr-code option for print in kommungis. The idea is to have an option for generating a qr-code here:

image

The option would be initially turned off, as to not overlap with logo, scalebar and north arrow. If turned on, the warning for overlapping icons would work the same, of course.

If chosen correctly, however, the qr-code would appear like this:
image

The qr-code is implemented by using QrCode from "qrcode.
Link to library: https://www.npmjs.com/package/qrcode

And a possible logic for this in PrintModel would be this:

  generateQR = async () => {
    try {
      const url = AppModel.anchorModel.getAnchor2();
      return await QRCode.toDataURL(url);
    } catch (err) {
      return "";
    }
  };
      if (options.includeQrCode) {
        try {
          const qrCodeImageData = await this.generateQR();
          let qrCodePlacement = this.getPlacement(
            options.qrCodePlacement,
            20,
            20,
            dim[0],
            dim[1]
          );

          pdf.addImage(
            qrCodeImageData,
            "PNG",
            qrCodePlacement.x,
            qrCodePlacement.y,
            20,
            20
          );
        } catch (error) {
          // The image loading may fail due to e.g. wrong URL, so let's catch the rejected Promise
          this.localObserver.publish("error-loading-qr-image");
        }
      }

However, in testing this, I encountered many problems with generating and updating the url. The AppModel.anchorModel.getAnchor() is not enough for correctly generating a updated url with every layer and and zoom an so on. I guess you would have to copy much of the logic from Anchor to keep it updated.

I'm not sure what the best solution is. Further investigation is needed.

In conclusion, I would say this is a cool feature that is possible to implement. But, the question is if it's worth the trouble. Perhaps not.

@OlofSvahnVbg OlofSvahnVbg added the new feature Request for adding/changing functionality label Oct 3, 2023
@OlofSvahnVbg OlofSvahnVbg added this to the 3.x milestone Oct 3, 2023
@jacobwod
Copy link
Member

jacobwod commented Oct 3, 2023

Great idea.

I would suggest we use the functionality added in #1252 for this. Start by enabling enableAppStateInHash in all your maps (it's an Admin setting). (Ideally, in future releases, this will be made the default functionality. I'm open for enabling it by default. It's stable, we've been using it for 6+ months in production.)

With that enabled, you generate the QR code by taking the current value from window.location.href. That's it. 🚀

@OlofSvahnVbg
Copy link
Collaborator Author

OlofSvahnVbg commented Oct 3, 2023 via email

@Hallbergs
Copy link
Member

I think it would be worth the trouble, QR-codes are cool!

@jacobwod
Copy link
Member

I read this again and saw this from your initial post:

However, in testing this, I encountered many problems with generating and updating the url. The AppModel.anchorModel.getAnchor() is not enough for correctly generating a updated url with every layer and and zoom an so on. I guess you would have to copy much of the logic from Anchor to keep it updated.

Are you sure about this? I had a look at this and the getAnchor method does take all the map View's parameters into account, as well as layers (including group layers), plus current query string in search box, currently visible plugins and current CQL filters (which nobody seems to use anyway 😉).

What else do you need? 😄

@OlofSvahn
Copy link

Yo yo! Im back, and here's a little update on qr code:

Turns out the enableAppStateInHash worked perfectly. Me and Jesper talked about checking for this value to be true before enabling qr code client side. Otherwise it doesnt work with simply using the updated url.

@jacobwod
Copy link
Member

jacobwod commented Mar 4, 2024

Welcome back! 😄 As for enableAppStateInHash, I have a feeling that this will sort out itself in a moment. We're about to merge some client-related changes into develop and I'd propose that we change Hajk's default behaviour to be enableAppStateInHash=true anyway. We've been using it for a couple of years now in production so it's quite battle-tested. @Hallbergs and @jesade-vbg, opinions?

@OlofSvahn
Copy link

Thanks! Good to be back :) Maybe we dont need to check for enableAppState then?

@jacobwod
Copy link
Member

jacobwod commented Mar 5, 2024

I think it's still a good idea to check, just as it's currently done elsewhere, see e.g.

this.props.config.mapConfig.map.enableAppStateInHash === true &&
.

@github-project-automation github-project-automation bot moved this to Approved ideas in Hajk Aug 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
new feature Request for adding/changing functionality
Projects
Status: Approved ideas
Development

No branches or pull requests

4 participants