How to get generate WebJSON from map with JSAPI 4

12-28-2020 09:27 AM
by Anonymous User
Not applicable

I'm trying to create a custom print tool. I'm pretty close to achieving this. I hit a road block and need some help. This is  long shot and can't seem to find to much info on this topic with JSAPI 4x. There is some discussion on this with JSAPI 3x. 

I'm trying to create the JSON for the webmap. Reading the documentation it says it's easy to do but I see nothing about it, which is frustrating. I've seen people talk about some hidden methods called 

printTask._getPrintDefinition(myMap,MyPrintParams)    This thread is the closest I've seen. It looks like it works for the JSAPI 3x but no mention of 4x. I've tried with both map and view for the first arg in the _getPrintDefinition. I keep getting this error PrintTask.js:formatted:602 Uncaught (in promise) TypeError: Cannot read property 'spatialReference' of undefined
at g.m._getPrintDefinition (PrintTask.js:formatted:602) (see image attached)
So my question is how do you grab  the Web_Map_asJSON object. According to ESRI's documentation it says it's easily done with the JS API but I see no clear way to do this ? 





            const printTask = new PrintTask({
            url: printUrl

            const template = new PrintTemplate({
                format: "pdf",
                exportOptions: {
                    dpi: 300
                layout: "a4-portrait",
                layoutOptions: {
                    titleText: "Warren Wilson College Trees",
                    authorText: "Sam"

            const params = new PrintParameters({
                template: template,
                view: view,


            var Web_Map_as_JSON =  printTask._getPrintDefinition(webmap,params);




Tags (2)
0 Replies