When I select a WMTS baseMap in BasemapGallery widget, and then try to use the Print Widget. The background map is blank when i try to print.
I have made two observations in the WebMap JSON. Firstly, why is the basemap in operationalLayers (see below JSON)? Should'nt it be in a "baseMap": [{}]? Secondly, when looking at ExportWebMap specification—Documentation (10.5) | ArcGIS Enterprise I realize that in order to get my WMTS based background map to work with the Printing GP i need to have it in following format:
{
"type":"wmts",
"url":"<my WMTS server>",
"layer":"<my layer title>",
"format":"image/png",
"tileMatrixSet":"EPSG:900913"
}
Here below is what is being sent from Print Widget to Print GP:
{
"mapOptions":{
"showAttribution":true,
"extent":{
"xmin":1930303.7983142724,
"ymin":8351147.285023411,
"xmax":1989924.6803766293,
"ymax":8386117.225463833,
"spatialReference":{
"wkid":102100
}
},
"spatialReference":{
"wkid":102100
},
"scale":144447.638572
},
"operationalLayers":[
{
"id":"layer2",
"title":"layer2",
"opacity":1,
"minScale":0,
"maxScale":0,
"type":"WebTiledLayer",
"urlTemplate":"http://<my WMTS server>?SERVICE=WMTS&VERSION=1.0.0&REQUEST=GetTile&LAYER=<my layer title>&STYLE=&FORMAT=image/png&TILEMATRIXSET=EPSG:900913&TILEMATRIX={level}&TILEROW={row}&TILECOL={col}",
"credits":""
}
],
"exportOptions":{
"outputSize":[
670,
500
],
"dpi":96
},
"layoutOptions":{
"titleText":"",
"authorText":"",
"copyrightText":"",
"customTextElements":[
{
"Ordernummer":"Number"
},
{
"Name":"Name"
},
{
"Date":"2018-10-10 10:30:42"
}
],
"scaleBarOptions":{
"metricUnit":"esriKilometers",
"metricLabel":"km",
"nonMetricUnit":"esriMiles",
"nonMetricLabel":"mi"
},
"legendOptions":{
"operationalLayers":[
]
}
}
}
There's a somewhat related bug here:
BUG-000094865: Printing GeoServer web map tile service (WMTS) layer..
Hi,
Yes, there is simiarities with this bug,
However, the alternative solution mentioned does not work for me.
I can not simply replace the "WebTiledLayer" type with "wmts".
It does works if I replace the entire section, as I mentioned previously:
i.e I replace this ...
"operationalLayers":[
{
"id":"layer2",
"title":"layer2",
"opacity":1,
"minScale":0,
"maxScale":0,
"type":"WebTiledLayer",
"urlTemplate":"http://<my WMTS server>?SERVICE=WMTS&VERSION=1.0.0&REQUEST=GetTile&LAYER=<my layer title>&STYLE=&FORMAT=image/png&TILEMATRIXSET=EPSG:900913&TILEMATRIX={level}&TILEROW={row}&TILECOL={col}",
"credits":""
}
]
With this instead.
"operationalLayers": [
{
"type" : "wmts",
"url" : "http://<my WMTS server>",
"layer" : " <my layer title>",
"format" : "image/png",
"tileMatrixSet" : "EPSG:900913"
}
],
Another thing is that WMTS background printing works from Portal Map Viewer.
Perhaps this issue was fixed only there?
I do not have time to check if this is a regression, all I can say that it does not work with WAB 2.9 and AGS 10.6.1
By the way, do you know why the background map ends up in operationalLayers?
Should'nt it be in BaseMap?
I've done a very sad workaround in ExportWebMap (The print GP Service), which I look forward to scratching ....
j = json.loads(WebMap_as_JSON)
working_wmts='{ "type" : "wmts", \
"url" : "<min url>", \
"layer" : "<min titel>", \
"format" : "image/png", \
"tileMatrixSet" : "EPSG:900913"}'
for a in j['operationalLayers']:
try:
if a['urlTemplate'].find("<min url>"):
i = j['operationalLayers'].index(a)
j['operationalLayers'][i] = json.loads(working_wmts)
except KeyError:
pass
WebMap_as_JSON = json.dumps(j)
#Convert the webmap to a map document
result = arcpy.mp.ConvertWebMapToArcGISProject(WebMap_as_JSON, layoutTemplate)
Kindest regards
Torbjörn
Actually, I think it is probably better to patch the Print-widget instead, rather than changing the GP-service.
This patch will fix the Web_Map_as_JSON.
diff --git a/server/apps/2/widgets/Print/Print.js b/server/apps/2/widgets/Print/Print.js
index be9b20d2..18c53ca6 100644
--- a/server/apps/2/widgets/Print/Print.js
+++ b/server/apps/2/widgets/Print/Print.js
@@ -9,6 +9,7 @@ define([
"esri/request",
'esri/lang',
'esri/arcgis/utils',
+ 'esri/urlUtils',
'dojo/_base/config',
'dojo/_base/lang',
'dojo/_base/array',
@@ -53,6 +54,7 @@ define([
esriRequest,
esriLang,
arcgisUtils,
+ esriUrlUtils,
dojoConfig,
lang,
array,
@@ -188,6 +190,11 @@ define([
false);
}
if (this.printTask._createOperationalLayers) {
+ aspect.after(
+ this.printTask,
+ '_createOperationalLayers',
+ lang.hitch(this, '_fixWMTS')
+ );
// if opLayers contains markerSymbol of map.infoWindow, the print job will failed
aspect.after(
this.printTask,
@@ -276,6 +283,25 @@ define([
return def;
},
+ _fixWMTS: function(opLayers) {
+ array.forEach(opLayers, function(ol) {
+ if ( ol.urlTemplate && ol.type == "WebTiledLayer" ) {
+ var obj = esriUrlUtils.urlToObject(ol.urlTemplate);
+ if ( obj.query.SERVICE == "WMTS" ) {
+ var k = {};
+ k.type = obj.query.SERVICE;
+ k.url = obj.path;
+ k.layer = obj.query.LAYER;
+ k.style = obj.query.STYLE;
+ k.format = obj.query.FORMAT;
+ k.tileMatrixSet = obj.query.TILEMATRIXSET;
+ ol = k;
+ }
+ }
+ }, this);
+ return opLayers;
+ },
+
_fixInvalidSymbol: function(opLayers) {
array.forEach(opLayers, function(ol) {
if (ol.id === 'map_graphics') {