Select to view content in your preferred language

Print Widget (JSON based web map print)

2891
1
Jump to solution
06-29-2016 12:00 AM
AnjulPandey
Regular Contributor

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?

Tags (1)
0 Kudos
1 Solution

Accepted Solutions
FC_Basson
MVP Alum

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;
})

View solution in original post

1 Reply
FC_Basson
MVP Alum

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;
})