Provides the logic for the Print widget.
Known Limitations
See print for a detailed list of known limitations.
- See also:
let view = new MapView({
container: "viewDiv",
map: map
});
let print = new Print({
viewModel: new PrintVM({
view: view
})
});
Constructors
-
new PrintViewModel(properties)
-
Parameter:properties Objectoptional
See the properties for a list of all the properties that may be passed into the constructor.
Property Overview
Name | Type | Summary | Class | |
---|---|---|---|---|
String|String[] | more details Specify the print output file format(s) that the user can select based on the options available from the print service. | more details | PrintViewModel | |
String|String[] | more details Specify the print output layout(s) that the user can select based on the options available from the print service. | more details | PrintViewModel | |
String | more details The name of the class. | more details | Accessor | |
Collection<CustomTemplate> | more details A collection of print templates defined on the Portal. | more details | PrintViewModel | |
String | more details The effective URL of the REST endpoint of the Export Web Map Task. | more details | PrintViewModel | |
Object[] | more details Returns an array of objects of all print templates available on the custom print service to see which templates were published with | more details | PrintViewModel | |
Object | more details This option allows passing extra parameters to the print (export webmap) requests. | more details | extraParameters | |
Boolean | more details Indicates whether or not to include defaultTemplates. | more details | PrintViewModel | |
Portal | more details It is possible to search a specified portal instance's locator services. | more details | PrintViewModel | |
String | more details The URL of the REST endpoint of the Export Web Map Task. | more details | PrintViewModel | |
Boolean | more details Define whether the printed map should preserve map scale or map extent. | more details | PrintViewModel | |
String | more details The view model's state. | more details | PrintViewModel | |
Object[] | more details An object containing an array of | more details | PrintViewModel | |
Object | more details The service metadata that contains the format and layout information for the printout. | more details | PrintViewModel | |
Number | more details The time interval in milliseconds between each job status request sent to an asynchronous GP task. | more details | PrintViewModel | |
MapView | more details The view from which the widget will operate. | more details | PrintViewModel |
Property Details
-
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"});
-
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"});
-
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>readonlySince: 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.
-
Since: ArcGIS API 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 Print widget UI, or programmatically using the templateCustomTextElements property.The PrintViewModel calls the
Get Layout Templates Info
task on the GPServer to discover available templates. If theGet 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 supportcustomTextElements
. In this scenario, we recommend republishing the print service to use the standardGet Layout Templates Info
name.
-
extraParameters ObjectinnerSince: ArcGIS API for JavaScript 4.20
-
This option allows passing extra parameters to the print (export webmap) requests.
-
includeDefaultTemplates BooleanSince: ArcGIS API for JavaScript 4.18
-
Indicates whether or not to include defaultTemplates.
- Default Value:true
-
portal PortalSince: 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 BooleanDeprecated since version 4.22. Instead, use TemplateOptions if using the Print widget, or PrintTemplate if calling print() directly.
-
Define whether the printed map should preserve map scale or map extent. When
true
, scale is preserved in the printed map. Whenfalse
, extent is preserved.- Default Value:false
-
state Stringreadonly
-
The view model's state.
Possible Values:"disabled"|"initializing"|"ready"|"error"
- Default Value:disabled
-
Since: ArcGIS API 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 possiblecustomTextElements
values for each template. The name of the task must matchGet Layout Templates Info
, templates must be published withcustomTextElements
, and values must be strings. Values found there will be populated in the Print widget underAdvanced options
. These values can be overwritten in the Print widget UI, or programmatically using this property. To list all print templates available on the print service to see see which templates were published withcustomTextElements
, use the effectiveTemplateCustomTextElements property.Example:const printWidget = new Print({ viewModel: new PrintVM({ 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" } ] } }) });
-
templatesInfo Objectreadonly
-
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
Name | Return Type | Summary | Class | |
---|---|---|---|---|
Promise | more details This method should be called to load the view model's printing resources. | more details | PrintViewModel | |
Promise<Object> | more details Prints (exports) the current MapView according to selected options. | more details | PrintViewModel |
Method Details
-
load(){Promise}
-
This method should be called to load the view model's printing resources.
Returns:Type Description Promise When resolved, the view model has loaded the print service metadata necessary for printing.
-
Prints (exports) the current MapView according to selected options.
Parameter:printTemplate PrintTemplateThe PrintTemplate is used to specify the layout template options which is then used by the PrintTask to generate the print page.
Returns:Type Description Promise<Object> Resolves to an object with the following properties: Property Type Description url String URL to the exported printout.