Hello,
I have been trying to query a layer and show the results in the map but I can't make it work, this is my try:
define([ 'jimu/BaseWidget', 'dojo/_base/connect', 'dojo/_base/declare', 'dojo/_base/lang', 'dojo/_base/array', 'dojo/_base/html', 'dojo/dom', 'dojo/on', 'dojo/query', 'esri/tasks/QueryTask', 'dijit/registry', 'esri/layers/FeatureLayer', 'esri/layers/Field','esri/request', 'dojo/store/Memory','jimu/LayerInfos/LayerInfos' ],
function (BaseWidget, connect, declare, lang, array, html, dom, on, Query, QueryTask, registry, FeatureLayer, field, esriRequest, Memory, LayerInfos) { return declare([BaseWidget], {
baseClass: 'jimu-widget-mywidget',
startup: function () {
this.inherited(arguments);
console.log('startup');
var map = this.map;
queryTask = new QueryTask("http://10.81.6.16:6080/arcgis/rest/services/MyLayer/FeatureServer/0");
query = new Query();
query.returnGeometry = true;
query.outFields = ["OBJECTID"];
if (map.loaded) {
query.where = "OBJECTID = 1";
queryTask.execute(query, showResults);
} else {
map.on("load", function () {
query.where = "OBJECTID = 1";
queryTask.execute(query, showResults);
});
}
function showResults(featureSet) {
map.graphics.clear();
//Performance enhancer - assign featureSet array to a single variable.
var resultFeatures = featureSet.features;
//Loop through each feature returned
for (var i=0, il=resultFeatures.length; i<il; i++) {
//Get the current feature from the featureSet.
//Feature is a graphic
var graphic = resultFeatures;
graphic.setSymbol(symbol);
//Set the infoTemplate.
graphic.setInfoTemplate(infoTemplate);
//Add graphic to the map graphics layer.
map.graphics.add(graphic);
}
}
},
(......)
I get this mistake:
TypeError: a.toJson is not a function
...nction(){},onExecuteRelationshipQueryComplete:function(){},onExecuteForIdsComple...
Can any one tell me if I am using query and querytask in the correct way? I have been following other threats of this forum to write this piece of code.
Thanks!
Marga