Helen,
Here is how your code should look like in a WAB widget.
define([
'dojo/_base/declare',
'jimu/BaseWidget',
'dijit/_WidgetsInTemplateMixin',
'esri/graphic',
'esri/layers/GraphicsLayer',
'esri/Color',
'esri/symbols/SimpleLineSymbol',
'esri/symbols/SimpleFillSymbol',
'esri/tasks/query',
'esri/tasks/QueryTask',
'dojo/on',
'jimu/dijit/DrawBox'
], function(
declare,
BaseWidget,
_WidgetsInTemplateMixin,
Graphic,
GraphicsLayer,
Color,
SimpleLineSymbol,
SimpleFillSymbol,
Query,
QueryTask,
on,
DrawBox
){
return declare([BaseWidget, _WidgetsInTemplateMixin], {
baseClass: 'jimu-widget-myvalidate',
name: 'MyValidate',
_graphicsLayer: null,
_polygonLayer: null,
drawBox: null,
postCreate: function() {
this.inherited(arguments);
this._initLayers();
this.drawBox.setMap(this.map);
this.own(on(this.drawBox, 'DrawEnd', lang.hitch(this, this._onDrawComplete)));
},
startup: function() {
this.inherited(arguments);
},
_initLayers: function() {
this._graphicsLayer = new GraphicsLayer();
this.map.addLayer(this._graphicsLayer);
},
_onDrawComplete: function(graphic) {
var geometry = graphic.geometry;
queryTask = new QueryTask("https://mapsdev02.os.uga.edu:6443/arcgis/rest/services/test_internal/test2/MapServer/1");
query = new Query();
query.returnGeometry = true;
query.outFields = ["*"];
query.outSpatialReference = map.SPATIAL_REL_INTERSECTS;
query.geometry = geometry;
console.log("geometry " + JSON.stringify(geometry));
console.log("query " + JSON.stringify(query));
queryTask.execute(query);
queryTask.on("complete", lang.hitch(this, function(evt) {
var fset = evt.featureSet;
var resultFeatures = fset.features;
if(resultFeatures.length == 0) {
alert("Polygon is outside of Georgia boundary. ");
return;
}
var newSymbol = new SimpleFillSymbol(SimpleFillSymbol.STYLE_SOLID,
new SimpleLineSymbol(SimpleLineSymbol.STYLE_SOLID,
new Color([0, 38, 115, 1]), 2), new Color([0, 112, 255, 0.37]));
this._graphicsLayer.add(new Graphic(geometry, newSymbol));
}));
}
});
});