Hi, I want to change map service url in Web map as JSON before printing the web map? in other words , I don't want to print map object and want specify other map service url in JSON print parameter?
Solved! Go to Solution.
Not sure if I'm understanding your question 100%, but you can change the parameters of any GP task request before it is sent to the server with the setRequestPreCallback funciton: esri/request | API Reference | ArcGIS API for JavaScript 3.17
To change the URL of an operational layer you can add this to your code where you are specifying the print task:
esriRequest.setRequestPreCallback(function(ioArgs){
// check if request is a web map print request
if (ioArgs.content && ioArgs.content.Web_Map_as_JSON){
var webMapAsJson = ioArgs.content.Web_Map_as_JSON;
var webMapObj = JSON.parse(webMapAsJson);
// iterate through operational layers on the map
for (o in webMapObj.operationalLayers) {
var wmo = webMapObj.operationalLayers;
if (wmo.title = "MyLayer"){
wmo.url = "http://newurl";
}
}
}
return ioArgs;
})
Not sure if I'm understanding your question 100%, but you can change the parameters of any GP task request before it is sent to the server with the setRequestPreCallback funciton: esri/request | API Reference | ArcGIS API for JavaScript 3.17
To change the URL of an operational layer you can add this to your code where you are specifying the print task:
esriRequest.setRequestPreCallback(function(ioArgs){
// check if request is a web map print request
if (ioArgs.content && ioArgs.content.Web_Map_as_JSON){
var webMapAsJson = ioArgs.content.Web_Map_as_JSON;
var webMapObj = JSON.parse(webMapAsJson);
// iterate through operational layers on the map
for (o in webMapObj.operationalLayers) {
var wmo = webMapObj.operationalLayers;
if (wmo.title = "MyLayer"){
wmo.url = "http://newurl";
}
}
}
return ioArgs;
})