我的任务是为ArcGIS的Web App Builder开发自定义窗口小部件,并且我一直在尝试使用ArcGIS Javascript API 3.28来使查询正常工作,因此我可以使用图层信息构建报告。但是在尝试通过按钮测试查询时,出现TypeError:this._url未定义。
define(['dojo/_base/declare', 'jimu/BaseWidget',
'jimu/dijit/Report', 'esri/layers/FeatureLayer',
'jimu/dijit/PageUtils', 'dijit/_WidgetsInTemplateMixin', 'esri/tasks/IdentifyTask',
'esri/tasks/IdentifyParameters', 'esri/symbols/SimpleFillSymbol', 'esri/symbols/SimpleLineSymbol',
'esri/graphic', 'esri/Color', 'dojo/_base/lang',
'dojo/_base/html', 'dojo/on', 'dojo/domReady!',
'esri/tasks/QueryTask', 'esri/tasks/query'],
function(declare, BaseWidget, Report, FeatureLayer,
PageUtils, _WidgetsInTemplateMixin, IdentifyTask, IdentifyParameters,
SimpleFillSymbol, SimpleLineSymbol, Graphic,
Color, lang, on, Query, QueryTaskTest) {
var baseWidgetClass = declare([BaseWidget], {
baseClass: 'jimu-widget-demo',
postCreate: function() { // POST CREATE!
this.inherited(arguments);
this.map.infoWindow.hide();
},
startup: function() {
this.inherited(arguments);
console.log('startup');
},
onClose: function(){
console.log('onClose');
},
_onBtnPrintClicked: function(){
console.log("Begin query test");
var queryUrl = "https://webportalurl/arcgis/rest/services/ServiceName/MapServer/0";
var queryTask = new QueryTaskTest(queryUrl);
var query = new Query();
query.returnGeometry = false;
query.outFields = ["*"];
query.where = "HAB_IPTU = 2089358";
console.log("Running execute");
queryTask.execute(query).then(function(results){
console.log(results.features[0]);
});
}
});
return baseWidgetClass;
});
答案 0 :(得分:2)
QueryTask期望url为 String :https://developers.arcgis.com/javascript/3/jsapi/querytask-amd.html#querytask1
尝试一下:
var queryTask = new QueryTask(queryUrl);
或
var queryTask = new QueryTask("MapServerUrl");
答案 1 :(得分:1)
该问题与QueryTask或您如何调用无关。 define语句和函数定义中的参数不匹配。
'dojo / _base / lang',与函数中的lang匹配,但随后的'dojo / _base / html'与on匹配,'dojo / on'与Query匹配,最后是'dojo / domReady!”。与QueryTaskTest匹配。在定义列表的末尾使用不需要相应构造函数的模块,否则必须将它们包括在函数定义中以保留顺序。
像这样
define(['dojo/_base/declare',
'jimu/BaseWidget',
'jimu/dijit/Report',
'esri/layers/FeatureLayer',
'jimu/dijit/PageUtils',
'dijit/_WidgetsInTemplateMixin',
'esri/tasks/IdentifyTask',
'esri/tasks/IdentifyParameters',
'esri/symbols/SimpleFillSymbol',
'esri/symbols/SimpleLineSymbol',
'esri/graphic',
'esri/Color',
'dojo/_base/lang',
'dojo/on',
'esri/tasks/query',
'esri/tasks/QueryTask',
'dojo/_base/html', //these last two are at the end
'dojo/domReady!'], //because they don't need to be called or instantiated directly.
function(declare,
BaseWidget,
Report,
FeatureLayer,
PageUtils,
_WidgetsInTemplateMixin,
IdentifyTask,
IdentifyParameters,
SimpleFillSymbol,
SimpleLineSymbol,
Graphic,
Color,
lang,
on,
Query,
QueryTaskTest) { ....});