import PrintViewModel from "@arcgis/core/widgets/Print/PrintViewModel.js";const PrintViewModel = await $arcgis.import("@arcgis/core/widgets/Print/PrintViewModel.js");- Inheritance:
- PrintViewModel→
Accessor
- Since
- ArcGIS Maps SDK for JavaScript 4.2
Provides the logic for the Print widget and component.
Known Limitations
See print for a detailed list of known limitations.
- See also
Print widget - Deprecated since 4.33. Use the Print component instead.
Constructors
Constructor
Parameters
| Parameter | Type | Description | Required |
|---|---|---|---|
| properties | | |
Properties
| Property | Type | Class |
|---|---|---|
| | ||
| | ||
browseTemplates readonly | | |
declaredClass readonly inherited | ||
defaultTemplate readonly | | |
defaultTemplates readonly | | |
effectivePrintServiceUrl readonly | | |
effectiveTemplateCustomTextElements readonly | | |
error readonly | | |
| | ||
| | ||
| | ||
loadError readonly inherited | ||
loadStatus readonly inherited | "not-loaded" | "loading" | "failed" | "loaded" | |
loadWarnings readonly inherited | any[] | |
| | ||
| | ||
portalTemplateIds deprecated readonly | string[] | |
printServiceTemplates readonly | | |
| | ||
| | ||
| | ||
state readonly | | |
| | ||
| | ||
templatesInfo readonly | | |
| | ||
| |
allowedFormats
- Type
- Formats
- Since
- ArcGIS Maps SDK for JavaScript 4.15
Specify the print output file format(s) that the user can select based on the options available from the print service. This property can take a string value or an array of string values.
When this value is "all" (default value), all the print service formats are available to be used.
When an array of string values is used, only those values that match the options available from the print service will be used.
If none of the input string values match those available from the print service, allowedFormats will fallback to default behavior.
- See also
- Default value
- "all"
Example
const print = new Print({ view: view, printServiceUrl: url});
print.viewModel.allowedFormats = ["jpg", "png8", "png32"];
view.ui.add(print, {position: "top-right"}); allowedLayouts
- Type
- Layouts
- Since
- ArcGIS Maps SDK for JavaScript 4.15
Specify the print output layout(s) that the user can select based on the options available from the print service. This property can take a string value or an array of string values.
When this value is "all" (default value), all the print service layouts are available to be used.
When an array of string values is used, only those values that match the options available from the print service will be used.
If none of the input string values match those available from the print service, allowedLayouts will fallback to default behavior.
- See also
- Default value
- "all"
Example
const print = new Print({ view: view, printServiceUrl: url});
print.viewModel.allowedLayouts = ["a3-landscape", "a3-portrait"];
view.ui.add(print, {position: "top-right"}); browseTemplates
- Type
- Collection<CustomTemplate>
- Since
- ArcGIS Maps SDK for JavaScript 4.33
A collection of print templates defined on the Portal.
Print templates are used to apply pre-defined values to existing print options.
defaultTemplate
- Type
- CustomTemplate | null | undefined
- Since
- ArcGIS Maps SDK for JavaScript 4.33
The template which defines the default print template.
defaultTemplates
- Type
- Collection<CustomTemplate>
- Since
- ArcGIS Maps SDK for JavaScript 4.18
A collection of print templates defined on the Portal.
Print templates are used to apply pre-defined values to existing print options.
effectiveTemplateCustomTextElements
- Since
- ArcGIS Maps SDK for JavaScript 4.22
Returns an array of objects of all print templates available on the custom print
service to see which templates were published with customTextElements. These
values can be overwritten in the UI, or programmatically using the
templateCustomTextElements property.
The PrintViewModel calls the Get Layout Templates Info task on the GPServer
to discover available templates. If the Get Layout Templates Info task is named
differently on the custom print service, then no values will be returned, and it
will not be possible to support customTextElements. In this scenario, we recommend
republishing the print service to use the standard Get Layout Templates Info name.
exportedLinks
- Type
- Collection<FileLink>
- Since
- ArcGIS Maps SDK for JavaScript 4.33
The collection of links exported from Print.
includeDefaultTemplates
- Type
- boolean
- Since
- ArcGIS Maps SDK for JavaScript 4.18
Indicates whether or not to include defaultTemplates.
- Default value
- true
loadError
The Error object returned if an error occurred while loading.
loadStatus
- Type
- "not-loaded" | "loading" | "failed" | "loaded"
Represents the status of a load() operation.
| Value | Description |
|---|---|
| not-loaded | The object's resources have not loaded. |
| loading | The object's resources are currently loading. |
| loaded | The object's resources have loaded without errors. |
| failed | The object's resources failed to load. See loadError for more details. |
- Default value
- "not-loaded"
loadWarnings
- Type
- any[]
A list of warnings which occurred while loading.
outSpatialReference
- Type
- SpatialReference | null | undefined
- Since
- ArcGIS Maps SDK for JavaScript 4.33
The spatial reference used to render the printed map on the server.
portal
- Type
- Portal
- Since
- ArcGIS Maps SDK for JavaScript 4.18
It is possible to search a specified portal instance's locator services. Use this property to set this ArcGIS Portal instance to search. This is especially helpful when working with a custom print template.
If this property is set, it is not necessary to set the printServiceUrl property.
- See also
portalTemplateIds
- Type
- string[]
- Since
- ArcGIS Maps SDK for JavaScript 4.33
An array of portalItem Ids that are used to identify the print templates using layoutItem Id.
printServiceTemplates
- Type
- Collection<CustomTemplate>
- Since
- ArcGIS Maps SDK for JavaScript 4.33
A collection of print templates defined on the Portal.
Print templates are used to apply pre-defined values to existing print options.
printTimeout
- Type
- number
- Since
- ArcGIS Maps SDK for JavaScript 4.28
Print timeout value in milliseconds.
- Default value
- 120000
showPrintAreaEnabled
- Type
- boolean
- Since
- ArcGIS Maps SDK for JavaScript 4.30
The initial state of the print area toggle in the UI.
When set to true, the print area toggle is enabled by default.
When set to false, the print area toggle is disabled by default.
- See also
- Default value
- false
templateCustomTextElements
- Type
- TemplateCustomTextElements | null | undefined
- Since
- ArcGIS Maps SDK for JavaScript 4.22
An object containing an array of customTextElements name-value pair objects
for each print template in a custom print service. Use this property to update
the text for custom text elements on the page layout.
The PrintViewModel calls the Get Layout Templates Info task on the GPServer
to discover possible customTextElements values for each template. The name of
the task must match Get Layout Templates Info, templates must be published
with customTextElements, and values must be strings. Values found there will be
populated under Advanced options. These values can be
overwritten in the UI, or programmatically using this property.
To list all print templates available on the print service to see
which templates were published with customTextElements, use the
effectiveTemplateCustomTextElements property.
Example
const printViewModel = new PrintViewModel({ view: view, // specify your custom print service printServiceUrl: "", // `customTextElements` are defined per print template // this example has one template with `customTextElements` templateCustomTextElements: { // if there were more applicable templates, then we would // create another object with the template name containing // an array of more name-value pairs "Portrait_TextElements": [ // the possible values are defined in the print service { "headquarters": "Tampa, Florida" }, { "division": "NFC South" }, { "founded": "1976" } ] } }); templateOptions
- Type
- TemplateOptions
- Since
- ArcGIS Maps SDK for JavaScript 4.33
Defines the layout template options to generate the print page.
templatesInfo
- Type
- TemplatesInfo | null | undefined
- Since
- ArcGIS Maps SDK for JavaScript 4.33
The service metadata that contains the TemplateOptions.format and TemplateOptions.layout information for the printout.
Example
const print = new Print({ view: view, printServiceUrl: url});
view.ui.add(print, {position: "top-right"});
console.log("PrintViewModel templatesInfo Formats: ", print.viewModel.templatesInfo.format.choiceList);console.log("PrintViewModel templatesInfo Layouts: ", print.viewModel.templatesInfo.layout.choiceList); updateDelay
- Type
- number
The time interval in milliseconds between each job status request sent to an asynchronous GP task.
- Default value
- 1000
Methods
| Method | Signature | Class |
|---|---|---|
addPortalTemplate(portalItem: PortalItem): Promise<void> | | |
applyTemplate(template: CustomTemplate | "map-only" | null | undefined): Promise<void> | | |
cancelLoad inherited | cancelLoad(): this | |
createExportedFileLink(fileName: string): FileLink | | |
emit inherited | emit<Type extends EventNames<this>>(type: Type, event?: this["@eventTypes"][Type]): boolean | |
export(fileName: string): PrintExport | | |
getLayoutTemplateById(id: string | null | undefined): CustomTemplate | null | undefined | | |
hasEventListener inherited | hasEventListener<Type extends EventNames<this>>(type: Type): boolean | |
isFulfilled inherited | isFulfilled(): boolean | |
isRejected inherited | isRejected(): boolean | |
isResolved inherited | isResolved(): boolean | |
load(): Promise<this> | | |
on inherited | on<Type extends EventNames<this>>(type: Type, listener: EventedCallback<this["@eventTypes"][Type]>): ResourceHandle | |
print(template: PrintTemplate): Promise<PrintResponse> | | |
removePortalTemplate(template: CustomTemplate): void | | |
toPrintTemplate(templateOptions: TemplateOptions): PrintTemplate | | |
when inherited | when<TResult1 = this, TResult2 = never>(onFulfilled?: OnFulfilledCallback<this, TResult1> | null | undefined, onRejected?: OnRejectedCallback<TResult2> | null | undefined): Promise<TResult1 | TResult2> |
addPortalTemplate
- Signature
-
addPortalTemplate (portalItem: PortalItem): Promise<void>
Adds a template to a portal.
Parameters
| Parameter | Type | Description | Required |
|---|---|---|---|
| portalItem | The
PortalItem used to create a print template.
This template will be added to the | |
applyTemplate
- Signature
-
applyTemplate (template: CustomTemplate | "map-only" | null | undefined): Promise<void>
Applies the specified print template to the templateOptions property.
This method updates the layout, custom text elements, and other template-specific
options based on the provided template. If the template is "map-only", it sets
the layout to "map-only" and skips additional processing.
If the provided template is invalid or not supported, the method falls back to
the default template (if available) or resets the templateOptions to their
initial state.
Parameters
| Parameter | Type | Description | Required |
|---|---|---|---|
| template | CustomTemplate | "map-only" | null | undefined | The CustomTemplate will be applied. | |
cancelLoad
- Signature
-
cancelLoad (): this
Cancels a load() operation if it is already in progress.
- Returns
- this
createExportedFileLink
- Signature
-
createExportedFileLink (fileName: string): FileLink
Creates a new FileLink object for the given file name. This method generates a unique file name with the appropriate extension based on the selected print template format and updates the internal file name map to track the number of exports with the same name.
emit
- Signature
-
emit <Type extends EventNames<this>>(type: Type, event?: this["@eventTypes"][Type]): boolean
- Type parameters
- <Type extends EventNames<this>>
- Since
- ArcGIS Maps SDK for JavaScript 4.5
Emits an event on the instance. This method should only be used when creating subclasses of this class.
export
- Signature
-
export (fileName: string): PrintExport
Exports the current print template to a file.
This method generates a file link and initiates the export process using the current
print template options. The returned object contains a FileLink instance and a promise
that resolves when the export is complete.
Parameters
| Parameter | Type | Description | Required |
|---|---|---|---|
| fileName | The name of the file to export (without extension). | |
- Returns
- PrintExport
An object containing: -
link: A FileLink object representing the exported file. -promise: A promise that resolves to theFileLinkwhen the export is complete.
getLayoutTemplateById
- Signature
-
getLayoutTemplateById (id: string | null | undefined): CustomTemplate | null | undefined
Returns a CustomTemplate with the specified id. The associated properties are
useful for print considerations.
Parameters
- Returns
- CustomTemplate | null | undefined
Returns a CustomTemplate, which contains both
layoutTemplateInfoandmapSurroundInfoOptions.
Example
this.viewModel.getLayoutTemplateById(this.templateOptions.id); hasEventListener
- Signature
-
hasEventListener <Type extends EventNames<this>>(type: Type): boolean
- Type parameters
- <Type extends EventNames<this>>
Indicates whether there is an event listener on the instance that matches the provided event name.
Parameters
| Parameter | Type | Description | Required |
|---|---|---|---|
| type | Type | The name of the event. | |
- Returns
- boolean
Returns true if the class supports the input event.
isFulfilled
- Signature
-
isFulfilled (): boolean
isFulfilled() may be used to verify if creating an instance of the class is fulfilled (either resolved or rejected).
If it is fulfilled, true will be returned.
- Returns
- boolean
Indicates whether creating an instance of the class has been fulfilled (either resolved or rejected).
isRejected
- Signature
-
isRejected (): boolean
isRejected() may be used to verify if creating an instance of the class is rejected.
If it is rejected, true will be returned.
- Returns
- boolean
Indicates whether creating an instance of the class has been rejected.
isResolved
- Signature
-
isResolved (): boolean
isResolved() may be used to verify if creating an instance of the class is resolved.
If it is resolved, true will be returned.
- Returns
- boolean
Indicates whether creating an instance of the class has been resolved.
on
- Signature
-
on <Type extends EventNames<this>>(type: Type, listener: EventedCallback<this["@eventTypes"][Type]>): ResourceHandle
- Type parameters
- <Type extends EventNames<this>>
Registers an event handler on the instance. Call this method to hook an event with a listener.
Parameters
| Parameter | Type | Description | Required |
|---|---|---|---|
| type | Type | An event or an array of events to listen for. | |
| listener | EventedCallback<this["@eventTypes"][Type]> | The function to call when the event fires. | |
- Returns
- ResourceHandle
Returns an event handler with a
remove()method that should be called to stop listening for the event(s).Property Type Description remove Function When called, removes the listener from the event.
Example
view.on("click", function(event){ // event is the event handle returned after the event fires. console.log(event.mapPoint);}); print
- Signature
-
print (template: PrintTemplate): Promise<PrintResponse>
Prints (exports) the current MapView according to selected options.
Parameters
| Parameter | Type | Description | Required |
|---|---|---|---|
| template | The PrintTemplate is used to specify the layout template options which is then used by the PrintTask to generate the print page. | |
- Returns
- Promise<PrintResponse>
Resolves to an object with the following properties:
Property Type Description url String URL to the exported printout.
removePortalTemplate
- Signature
-
removePortalTemplate (template: CustomTemplate): void
Removes Template from browseTemplates.
Parameters
| Parameter | Type | Description | Required |
|---|---|---|---|
| template | The CustomTemplate will be removed. | |
- Returns
- void
Resolves when the template is removed.
toPrintTemplate
- Signature
-
toPrintTemplate (templateOptions: TemplateOptions): PrintTemplate
Helper method to create print templates from a template options object.
Parameters
| Parameter | Type | Description | Required |
|---|---|---|---|
| templateOptions | | |
- Returns
- PrintTemplate
when
- Signature
-
when <TResult1 = this, TResult2 = never>(onFulfilled?: OnFulfilledCallback<this, TResult1> | null | undefined, onRejected?: OnRejectedCallback<TResult2> | null | undefined): Promise<TResult1 | TResult2>
- Since
- ArcGIS Maps SDK for JavaScript 4.6
when() may be leveraged once an instance of the class is created. This method takes two input parameters: an onFulfilled function and an onRejected function.
The onFulfilled executes when the instance of the class loads. The
onRejected executes if the instance of the class fails to load.
Parameters
| Parameter | Type | Description | Required |
|---|---|---|---|
| onFulfilled | OnFulfilledCallback<this, TResult1> | null | undefined | The function to call when the promise resolves. | |
| onRejected | The function to execute when the promise fails. | |
- Returns
- Promise<TResult1 | TResult2>
Returns a new promise for the result of
onFulfilledthat may be used to chain additional functions.
Example
// Although this example uses MapView, any class instance that is a promise may use when() in the same waylet view = new MapView();view.when(function(){ // This function will execute once the promise is resolved}, function(error){ // This function will execute if the promise is rejected due to an error});