POST
|
Here is the complete solution from the generic esri print widget with some custom code added, by moving the code outside of a for loop, I got better results... //define a dojo class define([ 'dojo/_base/declare', //defines dojo classes //this simulates class based inheritance 'dijit/_WidgetBase', 'dijit/_TemplatedMixin', 'dijit/_WidgetsInTemplateMixin', 'esri/tasks/PrintTask', 'esri/tasks/PrintParameters', ... var PrintDijit = declare([_WidgetBase, _TemplatedMixin, _WidgetsInTemplateMixin], { ... print: function() { if (this.printSettingsFormDijit.isValid()) { ... //query for parcel address var query = new esriQuery(); var queryTask = new esriQueryTask("https://gis.test.slco.org/slcogis/rest/services/Assessor/Parcel_Viewer_external/MapServer/5"); query.where = "PARCEL = '0136400001'"; query.returnGeometry = false; query.outFields = ["ADDRESS"]; queryTask.execute(query, lang.hitch(this, function(results) { console.log(results.features); }));
... View more
05-01-2018
03:32 PM
|
0
|
0
|
517
|
POST
|
as I've browsed other posts regarding this same problem, here's what I've found queryTask.execute in a standard html page uses a separate function Execute a QueryTask on page load queryTask.execute in JavaScript 4x uses .then QueryTask | API Reference | ArcGIS API for JavaScript 4.7 queryTaks.execute from JavaScript 3x in a Dojo esri widget uses lang.hitch ( this, function ... https://community.esri.com/thread/177370 Example queryTask.execute(query, lang.hitch(this, function(results) { console.log(results.features); }));
... View more
05-01-2018
03:29 PM
|
0
|
0
|
517
|
POST
|
FILE attachment shows full script This code sample is based on the Wab Dev Edition 2.7 print widget, specifically the print.js file. I'm attempting to add custom queries inside the existing print.js code. The print: function() is a method on the var PrintDijit = declare([_WidgetBase, _TemplatedMixin, _WidgetsInTemplateMixin], { declaration from a dojo AMD style class. See attached file for full print.js code. I'm using the debug tools in a Chrome browser, and when attempting to execute queryTask.execute(query, resultsFunction); the execute request skips the call back function call to resultsFunction and simply steps over the call back function, so this code block is bypassed Any help is appreciated, Thanks Matt var query = new esriQuery(); var queryTask = new esriQueryTask("https://......./rest/services/Assessor/Parcel_Viewer_external/MapServer/5"); query.where = "PARCEL = '0136400001'"; query.returnGeometry = false; query.outFields = ["ADDRESS"]; queryTask.execute(query, resFunction); <<debugger executes this line, and skips the callback "resFunction" function <<results function here is skipped function resFunction(results){ console.log(results.features); for (var i = 0; i < results.features.length; i++){ var attsObject = results.features.attributes; console.log(attsObject); } }; COMPLETE SAMPLE CODE FUNCTION LISTED HERE: print: function() { if (this.printSettingsFormDijit.isValid()) { //"advanced" form //get entered values var form = this.printSettingsFormDijit.get('value'); lang.mixin(form, this.layoutMetadataDijit.get('value')); //cte array of custom text layout elements lang.mixin(form, this.labelsFormDijit.get('value')); this.preserve = this.preserveFormDijit.get('value'); lang.mixin(form, this.preserve); this.layoutForm = this.layoutFormDijit.get('value'); var mapQualityForm = this.mapQualityFormDijit.get('value'); var mapOnlyForm = this.mapOnlyFormDijit.get('value'); lang.mixin(mapOnlyForm, mapQualityForm); //get custom text elements, loop, query and tag related parcels - as entered by user var elementsObj = this.customTextElementsDijit.get('value'); //get elements var cteArray = [], cte = {}, hasDate = false, locale = dojoConfig.locale || 'en'; for (var p in elementsObj) { //console.log(elementsObj ) Subject Parcel: 1231321 <<< returns //console.log(p) Subject Parcel: <<<returns 32132132 //query for parcel address var query = new esriQuery(); var queryTask = new esriQueryTask("https://......./rest/services/ServiceName/MapServer/5"); query.where = "PARCEL = '0136400001'"; query.returnGeometry = false; query.outFields = ["ADDRESS"]; queryTask.execute(query, resFunction); function resFunction(results){ //results is FeatureSet.features returns graphic[] array console.log(results.features); for (var i = 0; i < results.features.length; i++){ //graphic[] .length full graphics array "features" var attsObject = results.features.attributes; //graphic[0].attributes individual graphic atts "features[0]", atts=Object (of field/val pairs) console.log(attsObject); } }; if (p === 'Date') { // is date cte = new Date().toLocaleString(locale); // create date hasDate = true; } else { // not date cte = "T1 " + elementsObj + " AddressHere"; } cteArray.push(cte); //add cte to Array } //if date never found add it now to array if(!hasDate) { cteArray.push({ Date: new Date().toLocaleString(locale) }); } //setup print template var templateInfo = this._currentTemplateInfo; var hasAuthorText = lang.getObject('layoutOptions.hasAuthorText', false, templateInfo); var hasCopyrightText = lang.getObject('layoutOptions.hasCopyrightText', false, templateInfo); var hasTitleText = lang.getObject('layoutOptions.hasTitleText', false, templateInfo); var template = new PrintTemplate(); template.format = form.format; //pdf template.layout = form.layout; //layout selected template.preserveScale = (form.preserveScale === 'true' || form.preserveScale === 'force'); template.label = form.title; template.exportOptions = mapOnlyForm; template.showLabels = form.showLabels && form.showLabels[0]; template.layoutOptions = { authorText: hasAuthorText ? form.author : "", copyrightText: hasCopyrightText ? (form.copyright || this._getMapAttribution()) : "", legendLayers: this._getLegendLayers(), titleText: hasTitleText ? form.title : "", customTextElements: cteArray }; //execute print task this.printparams.template = template; this.printparams.extraParameters = { printFlag: true }; var fileHandel = this.printTask.execute(this.printparams); var result = new printResultDijit({ count: this.count.toString(), icon: (form.format === "PDF") ? this.pdfIcon : this.imageIcon, docName: form.title, title: form.format + ', ' + form.layout, fileHandle: fileHandel, nls: this.nls }).placeAt(this.printResultsNode, 'last'); result.startup(); domStyle.set(this.clearActionBarNode, 'display', 'block'); this.count++; } // end of advanced form is valid // if advanced form is not valid else { this.printSettingsFormDijit.validate(); } }, //end of print function
... View more
04-30-2018
02:15 PM
|
0
|
3
|
1122
|
Online Status |
Offline
|
Date Last Visited |
Tuesday
|