I have a very basic scenario where my map scale is either 1:1000 or 1:2500, so I made two radio buttons. Something like this
<div class="col-sm-6">
<label for="">Scale</label>
<select class="form-control" id="scale" name="scale">
<option value="1" selected>1:1000</option>
<option value="2">1:2500</option>
</select>
</div>Then, depending on the option selected, I either set a global variable to 1000 or 2500, like so
//global variable
var sentScale;
//check which button is clicked and set the variable with the selected value
var scaleDiv = $("#scale option:selected").val();
if (scaleDiv == 1) {
sentScale = 1000;
} else {
sentScale = 2500;
}And then, I set the map scale, like so
// ZOOM TO ROUTE
function zoomToRoute(features) {
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, 5000);
}And then I use printTask to print out the map
// PRINT RESULT
function printResult(evt) {
imageUrl = evt.url;
setCookie('imageUrl', imageUrl, 1);
if (reportType == 1) {
printReport();
}
if (reportType == 2) {
var printTaskLegend;
var printPars = new PrintParameters();
printPars.map = map;
if (sentScale == 1000) {
printTaskLegend = new PrintTask('http://10.0.0.10:6080/arcgis/rest/services/Print_legend_included/GPServer/Export%20Web%20Map');
printPars.map = map;
}
else if (sentScale == 2500) {
printTaskLegend = new PrintTask('http://10.0.0.10:6080/arcgis/rest/services/Print_legend_included/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);
}So I am printing the report, everything is fine and then the clients get back in touch with me, saying the scale is incorrect. 1:1000 is incorrect, 1:2500 is incorrect. Is this not a good way to set the map scale?