Select to view content in your preferred language

PrintTemplate layout string in TypeScript in v.4.28

466
2
02-09-2024 10:04 AM
MauricioBarrera
New Contributor

Hello everyone.
I'm developing a custom print component using the PrintViewModel and PrintTemplate, with TypeScript.
When creating an instance of PrintTemplate and trying to set in layout a custom layout string from my ArcGIS Enteprise, TypeScript raises an error, saying layout's only possible values are: "map-only"|"a3-landscape"|"a3-portrait"|"a4-landscape"|"a4-portrait"|"letter-ansi-a-landscape"|"letter-ansi-a-portrait"|"tabloid-ansi-b-landscape"|"tabloid-ansi-b-portrait".

In the documentation (PrintTemplate | API Reference | ArcGIS Maps SDK for JavaScript 4.28 | ArcGIS Developers ) it says that "the server administrator can add additional templates to the print service". We've published custom templates in our Enterprise but can set the layout string in the PrintTemplate. 

I found this old post for an old API version, saying it was solved, but I still have the issue in 4.28. (1) Solved: JS API 4.15: Print template issue - Esri Community

What makes me believe this is an error or bug is that I analyzed the requests sent by the default print widget and the custom template name is sent in that property. Also, if I trick TypeScript putting: "layout: "My_Custom_Template" as 'map-only'" in my code, everything works fine.

This workaround solves the issue for now, but I would like to find a more elegant solution.
Thank you in advance!

0 Kudos
2 Replies
ReneRubalcava
Honored Contributor

The Maps SDK typings don't support generics, so you can't pass your custom strings to override the types. I'm not sure of an elegant way to do this, but this works.

 

 

type MyPrintTemplates = __esri.PrintTemplate["layout"] & "My_Custom_Template";
// you don't really need this line, but it shows that your type will now work with the PrintTemplate layout type.
const myTemplate: __esri.PrintTemplate["layout"] = "My_Custom_Template" as MyPrintTemplates;

 

 

 I was thinking how satisfies might be used, but I don't think you can get around a cast here.

Noah-Sager
Esri Regular Contributor

Thank you for posting your question here @MauricioBarrera. Would you be interested in discussing your project, and why you are creating a custom print component?

0 Kudos