AnsweredAssumed Answered

Map prints on double click?

Question asked by novica.josifovskigdi-net-esridist Employee on Jun 25, 2020
Latest reply on Jun 25, 2020 by NSager-esristaff

So, I'm printing a map on the click of a button. I am zooming at a certain point but the map is showing on the second click on the print button. This is my code where I am querying the map, zooming, printing the image, etc.

What could be the issue for the map? 

 

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

var queryTask = new QueryTask("https://service.com");
var query = new Query();
query.where = "code ='" + globalParcel + "'";
query.outSpatialReference = map.spatialReference;
query.returnGeometry = true;
query.outFields = ["*"];
queryTask.execute(query, zoomToRoute);

// ZOOM TO ROUTE
function zoomToRoute(features) {

var num = features.features.length;
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]);
var lat = selectedFeature[0].geometry.x; //getLatitude();
var longs = selectedFeature[0].geometry.y; //getLongitude();

var point = new esri.geometry.Point({
latitude: lat,
longitude: longs
});

map.centerAt(point);

var factor = 3; //some factor for converting point to extent -->
var extent = new Extent(lat - factor, longs - factor, lat + factor, longs + factor, map.spatialReference);

map.setExtent(extent);
map.setScale(sentScale);
setTimeout(printImage, 1000);
}
// 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() {

var printTask;
var params = new PrintParameters();

if (sentScale == 1000) {

printTask = new PrintTask('https://service.com/GPServer/Export%20Web%20Map');
params.map = map;
}
else if (sentScale == 2500) {

printTask = new PrintTask('https://service.com/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, printResult);

}
// PRINT IMAGE

 

// PRINT RESULT
function printResult(evt) {

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

if (reportType == 1) {
printReport();
}
if (reportType == 2) {

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

if (sentScale == 1000) {
printTaskLegend = new PrintTask('https://service.com/GPServer/Export%20Web%20Map');
printPars.map = map;
}
else if (sentScale == 2500) {

printTaskLegend = new PrintTask('https://service.com/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);


}
}
// PRINT RESULT


// PRINT IMAGE LEGEND
function printImageLegend(evt) {

imageLegendUrl = evt.url;
setCookie('imageLegendUrl', imageLegendUrl, 1);
console.log("image legend url :: " + imageLegendUrl);
printReport();
}
// PRINT IMAGE LEGEND

});
}

Outcomes