Select to view content in your preferred language

Query Relationships Problem

801
2
08-04-2012 07:19 AM
DavidGutenberg
New Contributor
Howdy folks,

Having trouble conducting a spatial query where a county is clicked and adjacent counties are also selected through the SPATIAL_REL_TOUCHES query. I basically copied the code found in the esri query adjacent polygon sample, but used different layers to query. I'm thinking the problem has to do with either the proxy page reference (line 62-63) or the feature geometry reference (line 90). Any ideas? Thanks in advance!

-David
Code below:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>

<head>
<meta name="generator" content="HTML Tidy, see www.w3.org">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<!--The viewport meta tag is used to improve the presentation and behavior of the samples
on iOS devices-->
<meta name="viewport" content="initial-scale=1, maximum-scale=1,user-scalable=no"/>
<title>Full Map Layout</title>
<link rel="stylesheet" type="text/css" href="http://serverapi.arcgisonline.com/jsapi/arcgis/2.1/js/dojo/dijit/themes/claro/claro.css">
<style type="text/css">
html, body {
height: 100%; width: 100%; margin: 0; padding: 0;
}
body{
background-color:#777; overflow:hidden; font-family: "Trebuchet MS";
}
#map{
overflow:hidden;
padding:0;
}
</style>
<script type="text/javascript">
var djConfig = {
parseOnLoad: true
};
</script>
<script type="text/javascript" src="http://serverapi.arcgisonline.com/jsapi/arcgis/?v=2.1">
</script>
<script type="text/javascript">
dojo.require("dijit.dijit"); // optimize: load dijit layer
dojo.require("dijit.layout.BorderContainer");
dojo.require("dijit.layout.ContentPane");
dojo.require("esri.map");
dojo.require("esri.tasks.query");
dojo.require("esri.tasks.geometry");

var map, queryMedIncmTract, queryTask3, tractIncome, symbol, currentPoly;


function init() {
map = new esri.Map("map", {
extent: new esri.geometry.Extent(-140, 20, -55, 55, new esri.SpatialReference({wkid:4326}))});
var streetMap = new esri.layers.ArcGISTiledMapServiceLayer("http://server.arcgisonline.com/ArcGIS/rest/services/ESRI_StreetMap_World_2D/MapServer");
dojo.connect(map, 'onLoad', function(map) {
dojo.connect(dijit.byId('map'), 'resize', resizeMap);
});
var referenceLayer = new esri.layers.ArcGISDynamicMapServiceLayer("http://server.arcgisonline.com/ArcGIS/rest/services/Demographics/USA_Median_Household_Income/MapServ...");
map.addLayer(streetMap);
map.addLayer(referenceLayer);
//listen for when map is loaded and then add query functionality
dojo.connect(map, "onLoad", initFunctionality);
}

function initFunctionality(map) {
var queryTask = new esri.tasks.QueryTask("http://server.arcgisonline.com/ArcGIS/rest/services/Demographics/USA_Median_Household_Income/MapServ...");
var queryTaskTouches = new esri.tasks.QueryTask("http://server.arcgisonline.com/ArcGIS/rest/services/Demographics/USA_Median_Household_Income/MapServ...");

//identify proxy page to use if the toJson payload to the geometry service is greater than 2000 characters.
//If this null or not available the buffer operation will not work. Otherwise it will do a http post to the proxy.
esriConfig.defaults.io.proxyUrl = "/arcgisserver/apis/javascript/proxy/proxy.ashx";
esriConfig.defaults.io.alwaysUseProxy = false;

// Query
var query = new esri.tasks.Query();
query.returnGeometry = true;
query.outFields = ["MEDHINC_CY"];


var currentClick = null;
// +++++Listen for map onClick event+++++
dojo.connect(map, "onClick", function(evt) {
map.graphics.clear();
currentClick = query.geometry = evt.mapPoint;

query.spatialRelationship = esri.tasks.Query.SPATIAL_REL_INTERSECTS;
queryTask.execute(query);
dojo.byId('messages').innerHTML = "<b>Executing Point Intersection Query...</b>";

});

var firstGraphic = null;
// +++++Listen for QueryTask onComplete event+++++
dojo.connect(queryTask, "onComplete", function(graphics) {
firstGraphic = graphics.features[0];
var symbol = new esri.symbol.SimpleFillSymbol(esri.symbol.SimpleFillSymbol.STYLE_SOLID, new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleFillSymbol.STYLE_SOLID, new dojo.Color([100,100,100]), 3), new dojo.Color([255,0,0,0.20]));
firstGraphic.setSymbol(symbol);
map.graphics.add(firstGraphic);
query.geometry = firstGraphic.geometry;
query.spatialRelationship = esri.tasks.Query.SPATIAL_REL_TOUCHES;
queryTaskTouches.execute(query);
dojo.byId('messages').innerHTML = "<b>Executing Polygon Touches Query...</b>";

});



// +++++Listen for QueryTask executecomplete event+++++
dojo.connect(queryTaskTouches, "onComplete", function(fset) {
var symbol = new esri.symbol.SimpleFillSymbol(esri.symbol.SimpleFillSymbol.STYLE_SOLID, new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleFillSymbol.STYLE_SOLID, new dojo.Color([100,100,100]), 2), new dojo.Color([0,0,255,0.20]));

var resultFeatures = fset.features;
for (var i=0, il=resultFeatures.length; i<il; i++) {
var graphic = resultFeatures;
graphic.setSymbol(symbol);
map.graphics.add(graphic);
}
dojo.byId('messages').innerHTML = "";

});
}
function resizeMap() {
//resize the map when the browser resizes - view the 'Resizing and repositioning the map' section in
//the following help
var resizeTimer;
clearTimeout(resizeTimer);
resizeTimer = setTimeout(function() {
map.resize();
map.reposition();
}, 500);
}
//show map on load
dojo.addOnLoad(init);
</script>
</head>
<body class="claro">
<div dojotype="dijit.layout.BorderContainer" design="headline" gutters="false"
style="width: 100%; height: 100%; margin: 0;">
<div id="map" dojotype="dijit.layout.ContentPane" region="center">
<span id="messages"></span>

</div>
</div>
</body>

</html>
0 Kudos
2 Replies
StephenLead
Honored Contributor
Hi David,

Welcome to the forums! It'll be easier to get help if you can do a couple of things:

- when you post a code sample, use the # option at the top right of the editor page. Otherwise, the formatting is stripped off, making the code much harder to read at a glance.

- install Firefox and the Firebug debug tools. These will let you step through your running code, and pinpoint exactly where the problem lies.

[LEFT]I'm thinking the problem has to do with either the proxy page reference (line 62-63) or the feature geometry reference (line 90).


So you could try putting a breakpoint just before those lines (eg, break on the line "firstGraphic = graphics.features[0];" and ensure that you have a valid pointer to firstGraphic).

Then step through your code, to see if that is indeed the error. Once you know that, it'll be a lot easier to debug, for everyone involved.

Cheers,
Steve
[/LEFT]
0 Kudos
JohnGravois
Deactivated User
esriConfig.defaults.io.proxyUrl = "/arcgisserver/apis/javascript/proxy/proxy.ashx";


i think youre probably on the right track regarding the proxy. the line of code above is looking in a location relative to the web application on the same server, but I recognize it as the location of the proxy in use for our published applications.

example:
http://[servername.domain.com]/webapplication.html
[servername.domain.com]/arcgisserver/apis/javascript/proxy/proxy.ashx


see the following article for more information about installing/configuring proxies and the situations in which they are required:
http://help.arcgis.com/en/webapi/javascript/arcgis/help/jshelp/ags_proxy.htm
0 Kudos