AnsweredAssumed Answered

How can I use the QueryTask for two different polygons

Question asked by jerry0988 on Aug 24, 2016
Latest reply on Aug 24, 2016 by jgrayson-esristaff

Hi - I want to create a query, if a user click a county anywhere in the states of California or Texas, I would like to highlight the county and state and display a message “you are in the state of CA or TX”, but if they click in any other state, display a message, “you are not in the designated state”, along the county and State name? I can’t get it to query two different states (polygons) and display the message. I am not sure if I am on the right track. I've reviewed most of the samples, but still having some issues. Thanks in advance. Jerry


<!DOCTYPE html>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="viewport" content="initial-scale=1, maximum-scale=1,user-scalable=no" />
<title>Simple Map</title>
<link rel="stylesheet" href="">
html, body, #map {
height: 100%;
margin: 0;
padding: 0;
<script src=""></script>
var map;

require(["esri/map", "esri/layers/ArcGISDynamicMapServiceLayer", "esri/layers/ImageParameters", "esri/tasks/QueryTask", "esri/tasks/query", "esri/symbols/SimpleMarkerSymbol", "esri/InfoTemplate", "dojo/_base/Color", "dojo/domReady!"], function (Map, ArcGISDynamicMapServiceLayer, ImageParameters, QueryTask, Query, SimpleMarkerSymbol, InfoTemplate, Color) {
map = new Map("map", {
basemap: "topo", //For full list of pre-defined basemaps, navigate to
center: [-122.45, 37.75], // longitude, latitude
zoom: 5

//map.on("click", excuteQueryTask);

//var imageParameters = new ImageParameters();
//imageParameters.format = "jpeg"; //set the image type to PNG24, note default is PNG8.

//Takes a URL to a non cached map service.
var dynamicMapServiceLayer = new ArcGISDynamicMapServiceLayer("", {
"opacity": 0.5,
//"imageParameters" : imageParameters,
//"infoTemplate" : infoTemplate


var queryTask = new QueryTask(""); //States
var queryTask1 = new QueryTask(""); //Counties

var query = new Query();
query.returnGeometry = true;
query.outFields = ["*"];

var query1 = new Query();
query.returnGeometry = true;
query.outFields = ["NAME", "STATE_NAME", "POP2000"]

var infoTemplate = new InfoTemplate("${*}");
var infoTemplate1 = new InfoTemplate("${Name}", "State Name : ${STATE_NAME}");

var symbol = new SimpleMarkerSymbol();
symbol.setColor(new Color([255, 255, 0, 0.5]));

map.on("click", excuteQueryTask);

function excuteQueryTask(evt) {

mappoint = evt.mapPoint;
query.geometry = mappoint;
queryTask.execute(query, showResults);
queryTask1.execute(query1, showResults1);


function showResults(featureSet) {
//remove all graphics on the maps graphics layer;

//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[i];

//Set the infoTemplate.

//Add graphic to the map graphics layer.

function showResults1(featureSet1) {;

var resultFeatures1 = featureSet1.features;
for (var i = 0, il = resultFeatures1.length; i < il; i++) {

// alert(" you are in the state " );

<div id="map"></div>