Select to view content in your preferred language

printTask.execute not working on hosted application

562
0
07-08-2020 04:23 AM
NovicaJosifovski
Occasional Contributor

I am trying to figure out why my printTask is not working when I host my .NET Core app on a server. It works locally, when I run the code via Visual Studio but not when I publish and host the app. 

For example, it works on line 12 in the code below. queryTask.execute(query).then(zoomToRoute) works but it does not work. I am not sure how or why it works when I run the app via Visual Studio but all I know is, it doesn't work when I host the app. Anyone with any insight will help me out, so please feel free to share any opinion.

function printMap() {
            require(["dojo/on", "esri/config", "esri/tasks/QueryTask", "esri/tasks/query", 'esri/symbols/SimpleMarkerSymbol', "esri/symbols/SimpleLineSymbol", "esri/Color", 'esri/geometry/Extent', "esri/tasks/PrintTask", "esri/tasks/PrintParameters", "esri/tasks/PrintTemplate", "dojo/domReady!"],
                function (on, esriConfig, QueryTask, Query, SimpleMarkerSymbol, SimpleLineSymbol, Color, Extent, PrintTask, PrintParameters, PrintTemplate) {
                    console.log("globalParcel :: " + globalParcel + " reportType :: " + reportType + " globalScale :: " + sentScale);
                    //esriConfig.defaults.io.corsEnabledServers.push("http://localhost:60024");
                    var queryTask = new QueryTask("https://app.gdi.mk:6443/arcgis/rest/services/karpos/Karpos_Vector_Izvodi/MapServer/1");
                    var query = new Query();
                    query.where = "code ='" + globalParcel + "'";
                    query.outSpatialReference = map.spatialReference;
                    query.returnGeometry = true;
                    query.outFields = ["*"];
                    queryTask.execute(query).then(zoomToRoute);


                    // ZOOM TO ROUTE
                    function zoomToRoute(features) {
                        console.log("zoomtoroute start" );

                        var map = this.map;
                        map.graphics.clear();

                        var pointSymbolNew = new SimpleMarkerSymbol(SimpleMarkerSymbol.STYLE_CIRCLE, 10, new SimpleLineSymbol(SimpleLineSymbol.STYLE_SOLID, new Color([255, 255, 255]), 1), new Color([255, 0, 127, 1]));
                        var selectedFeature = features.features;
                        selectedFeature[0].setSymbol(pointSymbolNew);
                        map.graphics.add(selectedFeature[0]);

                        map.setScale(sentScale);
                        map.centerAt(selectedFeature[0].geometry);
                        setTimeout(printImage, 1000);
                        console.log("zoomtoroute end");

                    }
                    // ZOOM TO ROUTE


                    // SET COOKIE
                    function setCookie(cname, cvalue, exdays) {
                        var d = new Date();
                        d.setTime(d.getTime() + (exdays * 24 * 60 * 60 * 1000));
                        var expires = "expires=" + d.toGMTString();
                        document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/";
                    }
                    // SET COOKIE

                    // PRINT IMAGE
                    function printImage() {
                        console.log("printImage start");

                        var printTask;
                        var params = new PrintParameters();

                        if (sentScale == 1000) {

                            printTask = new PrintTask('https://app.gdi.mk:6443/arcgis/rest/services/karpos/Print_Karpos/GPServer/Export%20Web%20Map');
                            params.map = map;
                        }
                        else if (sentScale == 2500) {

                            printTask = new PrintTask('https://app.gdi.mk:6443/arcgis/rest/services/karpos/Print_Karpos/GPServer/Export%20Web%20Map');
                            params.map = map;
                        }

                        var template = new PrintTemplate();
                        template.format = 'JPG';
                        template.layout = 'MAP_ONLY';
                        template.preserveScale = false;
                        params.template = template;

                        //printTask.execute(params).then(printResult);
                        printTask.execute(params, printResult);

                        console.log("printImage end");
                        console.log("params", params);

                    }
                    // PRINT IMAGE



                    // PRINT RESULT
                    function printResult(evt) {
                        console.log("printResult start")

                        imageUrl = evt.url;
                        setCookie('imageUrl', imageUrl, 1);

                        if (reportType == 1) {
                            console.log("reportType == 1")

                            printReport();
                        }
                        if (reportType == 2) {
                            console.log("reportType == 2")

                            var printTaskLegend;
                            var printPars = new PrintParameters();
                            printPars.map = map;

                            if (sentScale == 1000) {
                                console.log("sentScale == 1000")
                                printTaskLegend = new PrintTask('https://app.gdi.mk:6443/arcgis/rest/services/karpos/Print_Karpos/GPServer/Export%20Web%20Map');
                                printPars.map = map;
                            }
                            else if (sentScale == 2500) {
                                console.log("sentScale == 2500")
                                printTaskLegend = new PrintTask('https://app.gdi.mk:6443/arcgis/rest/services/karpos/Print_Karpos/GPServer/Export%20Web%20Map');
                                printPars.map = map;
                            }

                            var template = new PrintTemplate();
                            template.format = 'JPG';
                            template.layout = 'Print_legend_included';
                            template.preserveScale = true;
                            printPars.template = template;
                            printTaskLegend.execute(printPars, printImageLegend);
                            //printTaskLegend.execute(printPars).then(printImageLegend);
                            console.log("printTaskLegend.execute")
                            console.log("printResult end")


                        }
                    }
0 Kudos
0 Replies