I am using a QueryTask to select data from a Feature Service and pass the attribute values to a dGrid. I am using a where statement (query.where) to select only certain polygons from this service and I would like to also be able to pass a point to the query to further narrow the results. The Feature Service, where statement, and xy coordinates are passed as URL parameters. I am able to query the data using the just a query.where or just the query.geometry, but I am getting no results when I use both query.where and query.geometry (I have checked the data and there is data that satisfies both criteria.
The polygon feature service I am querying has about 10,000 polygons so perhaps it is a memory issue?
Note that I have removed the code to create the grid due to character limits.
require([
"esri/layers/FeatureLayer",
"esri/tasks/QueryTask",
"esri/tasks/query",
"dojo/ready",
"dojo/number",
"dojo/dom",
"dojo/on",
"dojo/parser",
"dojo/_base/array",
"dijit/form/Select",
"dojo/dom-style",
"dojo/dom-construct",
"dojo/_base/connect",
"dojo/_base/declare",
"dojo/store/Memory",
"dojo/store/Observable",
"dojo/number",
"dstore/Trackable",
"dstore/RequestMemory",
"dijit/registry",
"dijit/layout/BorderContainer",
"dijit/layout/ContentPane",
"dgrid/Grid",
"dgrid/editor",
"dgrid/Keyboard",
"dgrid/Selection",
"dgrid/extensions/ColumnHider",
"dgrid/extensions/Pagination",
"esri/geometry/Point",
"esri/SpatialReference",
"esri/geometry/webMercatorUtils",
"dojo/domReady!"
],
function (
FeatureLayer,
QueryTask,
Query,
ready,
number,
dom,
on,
parser,
array,
Select,
domStyle,
domConstruct,
connect,
declare,
Memory,
Observable,
dojoNum,
Trackable,
RequestMemory,
registry,
BorderContainer,
ContentPane,
Grid,
Editor,
Keyboard,
Selection,
ColumnHider,
Pagination,
Point,
SpatialReference,
webMercatorUtils
) {
"use strict";
var memStore, data, mapServ, strHref, strURLParamReturn, URLQuery, coords, newcoords, gsvc, geom, URL, Index, layer, feature, ResFields, ResCols, grid, GMap, AGOL, Street, Search, strQueryString, iParam, aQueryString, aParam, i, MyGrid, qt, query;
mapServ = "https://gisq.in.gov/arcgis/rest/services/ISDH/PHG_Data/FeatureServ";
function getSingleURLParameter(ParamName) {
strURLParamReturn = "";
strHref = window.location.href;
if (strHref.indexOf("?") > -1) {
strQueryString = strHref.substr(strHref.indexOf("?"));
aQueryString = strQueryString.split("&");
for (iParam = 0; iParam < aQueryString.length; iParam++) {
if (aQueryString[iParam].indexOf(ParamName + "=") > -1) {
aParam = aQueryString[iParam].split("=");
//---start patch for equal sign in argument
if (aParam.length > 2) {
for (i = 2; i < aParam.length; i++) {
aParam[1] += '=' + aParam[i];
}
}
//---end patch
strURLParamReturn = aParam[1];
break;
}
}
}
return unescape(strURLParamReturn);
}
URLQuery = getSingleURLParameter("where");
//console.log(URLQuery);
geom = getSingleURLParameter("geom").split(",");
if (geom[0] > 37 && geom[0] < 42 && geom[1] < -84 && geom[1] > -89) {
//coords = new Point("geom", new SpatialReference({wkid: 4326}));
coords = new Point(-87, 41);
coords.setSpatialReference(new SpatialReference({"wkid":8307}));
newcoords = webMercatorUtils.geographicToWebMercator(coords);
}
URL = getSingleURLParameter("url");
if (URL !== "") {
mapServ = URL;
}
Index = getSingleURLParameter("layer");
if (Index === "") {
Index = 0;
}
console.log(Index);
layer = mapServ.concat('/', Index);
feature = new FeatureLayer(layer);
qt = new QueryTask(layer);
console.log(newcoords)
query = new Query();
//console.log(query);
//query.where = URLQuery;
query.text = URLQuery;
query.geometry = newcoords;
query.returnGeometry = true;
query.outFields = ResFields;
console.log(query);
//qt.execute();
qt.execute(query, function (results) {
console.log(results);
});
});