PrintViewModel

require(["esri/widgets/Print/PrintViewModel"], function(PrintVM) { /* code goes here */ });
Class: esri/widgets/Print/PrintViewModel
Inheritance: PrintViewModel Accessor
Since: ArcGIS API for JavaScript 4.2

Provides the logic for the Print widget.

See also:
Example:
var view = new MapView({
  container: "viewDiv",
  map: map
});

var print = new Print({
  viewModel: new PrintVM({
    view: view
  })
});

Constructors

new PrintViewModel(properties)
Parameter:
properties Object
optional

See the properties for a list of all the properties that may be passed into the constructor.

Property Overview

Any properties can be set, retrieved or listened to. See the Working with Properties topic.
NameTypeSummaryClass
String|String[]

Specify the print output file format(s) that the user can select based on the options available from the print service.

more details
more detailsPrintViewModel
String|String[]

Specify the print output layout(s) that the user can select based on the options available from the print service.

more details
more detailsPrintViewModel
String

The name of the class.

more details
more detailsAccessor
Collection<CustomTemplate>

A collection of print templates defined on the Portal.

more details
more detailsPrintViewModel
String

The effective URL of the REST endpoint of the Export Web Map Task.

more details
more detailsPrintViewModel
Boolean

Indicates whether or not to include defaultTemplates.

more details
more detailsPrintViewModel
Portal

It is possible to search a specified portal instance's locator services.

more details
more detailsPrintViewModel
String

The URL of the REST endpoint of the Export Web Map Task.

more details
more detailsPrintViewModel
Boolean

When true, scale is used in the printed map.

more details
more detailsPrintViewModel
String

The view model's state.

more details
more detailsPrintViewModel
Object

The service metadata that contains the format and layout information for the printout.

more details
more detailsPrintViewModel
Number

The time interval in milliseconds between each job status request sent to an asynchronous GP task.

more details
more detailsPrintViewModel
MapView

The view from which the widget will operate.

more details
more detailsPrintViewModel

Property Details

allowedFormats String|String[]
Since: ArcGIS API 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.

Default Value:"all"
See also:
Example:
const print = new Print({
  view: view,
  printServiceUrl: url
});

print.viewModel.allowedFormats = ["jpg", "png8", "png32"];

view.ui.add(print, {position: "top-right"});
allowedLayouts String|String[]
Since: ArcGIS API 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.

Default Value:"all"
See also:
Example:
const print = new Print({
  view: view,
  printServiceUrl: url
});

print.viewModel.allowedLayouts = ["a3-landscape", "a3-portrait"];

view.ui.add(print, {position: "top-right"});
declaredClass Stringreadonly inherited
Since: ArcGIS API for JavaScript 4.7

The name of the class. The declared class name is formatted as esri.folder.className.

defaultTemplates Collection<CustomTemplate>readonly
Since: ArcGIS API 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.

effectivePrintServiceUrl Stringreadonly

The effective URL of the REST endpoint of the Export Web Map Task.

includeDefaultTemplates Boolean
Since: ArcGIS API for JavaScript 4.18

Indicates whether or not to include defaultTemplates.

Default Value:true
portal Portal
Since: ArcGIS API 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:
printServiceUrl String

The URL of the REST endpoint of the Export Web Map Task. If the portal property is set, it is not necessary to set this property.

scaleEnabled Boolean

When true, scale is used in the printed map.

Default Value:false
state Stringreadonly

The view model's state.

Possible Values:"disabled"|"initializing"|"ready"|"error"

Default Value:disabled
templatesInfo Objectreadonly

The service metadata that contains the format and 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 Number

The time interval in milliseconds between each job status request sent to an asynchronous GP task.

Default Value:1000
view MapView

The view from which the widget will operate.

Method Overview

NameReturn TypeSummaryClass
PrintViewModel
Promise

This method should be called to load the view model's printing resources.

more details
more detailsPrintViewModel
Promise<Object>

Prints (exports) the current MapView according to selected options.

more details
more detailsPrintViewModel

Method Details

get()inner
load(){Promise}

This method should be called to load the view model's printing resources.

Returns:
TypeDescription
PromiseWhen resolved, the view model has loaded the print service metadata necessary for printing.
print(printTemplate){Promise<Object>}

Prints (exports) the current MapView according to selected options.

Parameter:
printTemplate PrintTemplate

The PrintTemplate is used to specify the layout template options which is then used by the PrintTask to generate the print page.

Returns:
TypeDescription
Promise<Object>Resolves to an object with the following properties:
PropertyTypeDescription
urlStringURL to the exported printout.

API Reference search results

NameTypeModule
Loading...