Can someone please help me with the code below.
I have been struggling to find why I am getting "Uncaught TypeError: undefined is not a function" error
at QueryTask.execute(Qry,showResults);
<script>
require([
"esri/map",
"esri/layers/ArcGISDynamicMapServiceLayer",
"esri/dijit/BasemapToggle",
"esri/tasks/FindTask",
"esri/tasks/FindParameters",
"esri/symbols/SimpleMarkerSymbol",
"esri/symbols/SimpleLineSymbol",
"esri/symbols/SimpleFillSymbol",
"esri/Color",
"dojo/on",
"dojo/dom",
"dijit/registry",
"dojo/_base/array",
"dojo/_base/connect",
"dojox/grid/DataGrid",
"dojo/data/ItemFileReadStore",
"dijit/form/Button",
"dojo/parser",
"dijit/form/ComboBox",
"dojo/store/Memory",
"dijit/form/FilteringSelect",
"dijit/layout/BorderContainer",
"dijit/layout/ContentPane",
"dojo/domReady!",
"esri/tasks/query", "esri/tasks/QueryTask"
], function(
Map, ArcGISDynamicMapServiceLayer, BasemapToggle, FindTask, FindParameters, SimpleMarkerSymbol, SimpleLineSymbol, SimpleFillSymbol,
Color, on, dom, registry, arrayUtils, connect, DataGrid, ItemFileReadStore, Button, parser, Memory, FilteringSelect, ComboBox, Query, QueryTask
) {
var findTask, findParams;
var Query, QueryTask;
var map, center, zoom;
var infoTemplate;
var grid, store;
parser.parse();
esri.config.defaults.io.proxyUrl = "http://agstest.prod.loudoun.local/Loudoun/ProxyPage/proxy.ashx";
infoTemplate = new esri.InfoTemplate(
"${PA_MCPI}",
"Available Acres: ${MKTG_AVL_A}<br />Zone: ${ZO_ZONE}<br />Company: ${MKTG_Contact}<br />Contact: ${MKTG_CON_FN} ${MKTG_CON_LN} <br /> ${MKTG_CON_St} ${MKTG_CON_city} ${MKTG_CON_State} ${MKTG_CON_zip}<br /> ${MKTG_CON_ph}<br /> ${MKTG_CON_email}");
registry.byId("search").on("click", doFind);
registry.byId("search1").on("click", doFind1);
registry.byId("searchQry").on("click", QryExe);
center = [-77.4875, 39.0436];
zoom = 11;
map = new esri.Map("map", {
basemap: "topo",
center: center,
zoom: zoom
//infoWindow: infoWindow
});
var toggle = new BasemapToggle({map: map,
basemap: "satellite"}, "BasemapToggle");
toggle.startup();
QueryTask = new QueryTask("http://agstest................................./MapServer/0");
//Create Find Task using the URL of the map service to search
findTask = new FindTask("http://agstest........................./MapServer");
// add dynamic map service layer
var urlDyn = "http://agste................................./MapServer";
var usaLayer = new ArcGISDynamicMapServiceLayer(urlDyn, {
id: "acres",
opacity: 0.45,
visible: true
});
//usaLayer.setVisibleLayers([2]);
map.addLayer(usaLayer);
map.on("load", function () {
Qry = new Query();
Qry.returnGeometry = true
Qry.outFields = ["MKTG_TOTAL", "ZO_ZONE"];
//Create the find parameters
findParams = new FindParameters();
findParams.returnGeometry = true;
findParams.layerIds = [1];
findParams.searchFields = ["ZO_ZONE", "MKTG_CON_1"];
findParams.outSpatialReference = map.spatialReference;
console.log("find sr: ", findParams.outSpatialReference);
});
function doFind() {
//map.infoWindow.hide();
dom.byId("owner").value = dom.byId("owner").defaultValue;
//Set the search text to the value in the box
findParams.searchText = dom.byId("ZoneTyp").value;
findTask.execute(findParams, showResults);
}
function doFind1() {
//map.infoWindow.hide();
dom.byId("ZoneTyp").value = dom.byId("ZoneTyp").defaultValue;
//Set the search text to the value in the box
findParams.searchText = dom.byId("owner").value;
findTask.execute(findParams, showResults);
}
function QryExe() { //getting error on this function....)
// var val = dom.byId("acres").value;
//alert(val);
Qry.where = "ZO_ZONE LIKE 'PDOP'";
//Query.where = "ZO_ZONE LIKE '%" + dojo.byId('acres').value + "%'";
QueryTask.execute(Qry,showResults);
}
function showResults(results) {
//This function works with an array of FindResult that the task returns
map.graphics.clear();
var symbol = new SimpleFillSymbol(
SimpleFillSymbol.STYLE_VERTICAL,
new SimpleLineSymbol(SimpleLineSymbol.STYLE_SOLID, new Color([0, 102, 204]), 3),
new Color([0, 102, 204, 0.5])
);
//create array of attributes
var items = arrayUtils.map(results, function (result) {
var graphic = result.feature;
graphic.setSymbol(symbol);
graphic.setInfoTemplate(infoTemplate);
map.graphics.add(graphic);
return result.feature.attributes;
});
//Create data object to be used in store
var data = {
identifier : "PA_MCPI", //This field needs to have unique values
label : "PARCELID", //Name field for display. Not pertinent to a grid but may be used elsewhere.
items : items
};
//Create data store and bind to grid.
store = new ItemFileReadStore({data : data});
var grid = registry.byId("grid");
grid.setStore(store);
grid.on("rowclick", onRowClickHandler);
//Zoom back to the initial map extent
map.centerAndZoom(center, zoom);
}
//Zoom to the parcel when the user clicks a row
function onRowClickHandler(evt) {
var clickedTaxLotId = evt.grid.getItem(evt.rowIndex).PA_MCPI;
var selectedTaxLot = arrayUtils.filter(map.graphics.graphics, function (graphic) {
return ((graphic.attributes) && graphic.attributes.PA_MCPI === clickedTaxLotId);
//------------------------test-----------------
map.infoWindow.setContent(graphic.getContent());
map.infoWindow.setTitle(graphic.getTitle());
map.infoWindow.show(evt.screenPoint,map.getInfoWindowAnchor(evt.screenPoint));
});
if ( selectedTaxLot.length ) {
map.setExtent(selectedTaxLot[0].geometry.getExtent(), true);
}
}
});
</script>
Solved! Go to Solution.
The first thing I see is your function aliases don't match your require modules. These have to be in the correct order.
"dojo/parser",
"dojo/store/Memory",
"dijit/form/FilteringSelect",
"dijit/form/ComboBox",
"esri/tasks/query",
"esri/tasks/QueryTask",
"dijit/layout/BorderContainer",
"dijit/layout/ContentPane",
"dojo/domReady!"
parser, Memory, FilteringSelect, ComboBox, Query, QueryTask
The first thing I see is your function aliases don't match your require modules. These have to be in the correct order.
"dojo/parser",
"dojo/store/Memory",
"dijit/form/FilteringSelect",
"dijit/form/ComboBox",
"esri/tasks/query",
"esri/tasks/QueryTask",
"dijit/layout/BorderContainer",
"dijit/layout/ContentPane",
"dojo/domReady!"
parser, Memory, FilteringSelect, ComboBox, Query, QueryTask
TThanks Ken! Will fix the order and test.
Thanks! that was it!! Appreciate your help