duckett45

Query one layer by another not returning results for second layer

Discussion created by duckett45 on Apr 15, 2011
Can I query by polygons using different map services? I'm trying a query to list all of the features inside  a county.  The query is executing, but I'm not getting any results.

Here's my code:
______________

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <meta http-equiv="X-UA-Compatible" content="IE=7" />
    <!--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>QueryTask with query geometry from another task</title>
    <link rel="stylesheet" type="text/css" href="http://serverapi.arcgisonline.com/jsapi/arcgis/2.2/js/dojo/dijit/themes/claro/claro.css">
    <script type="text/javascript" src="http://serverapi.arcgisonline.com/jsapi/arcgis/?v=2.2"></script>

    <script type="text/javascript">
      dojo.require("esri.map");
      dojo.require("esri.tasks.query");
      dojo.require("esri.tasks.geometry");

      var map;
      /*Initialize map, buffer, & query params*/
    function init() {
    var startExtent = new esri.geometry.Extent({"xmin":3336800.8350631,"ymin":2636200.25720764,"xmax":6477996.0793392,"ymax":5025218.13686783,"spatialReference":{"wkid":3089}});
    var map = new esri.Map("mapDiv", {extent:startExtent});
    //listen for when map is loaded and then add query functionality
        dojo.connect(map, "onLoad", initFunctionality);
  //after map loads, connect to listen to mouse move & drag events
          dojo.connect(map, "onMouseMove", showCoordinates);
        var streetMap = new esri.layers.ArcGISDynamicMapServiceLayer("http://dingo.gapanalysisprogram.com/ArcGIS/rest/services/PADUS/PADUS_status/MapServer");
        map.addLayer(streetMap);
       
         
var gap = new esri.layers.ArcGISDynamicMapServiceLayer("http://dingo.gapanalysisprogram.com/ArcGIS/rest/services/PADUS/Ancillary/MapServer");
       map.addLayer(gap);
       }

      function initFunctionality(map) {
        var queryTask = new esri.tasks.QueryTask("http://dingo.gapanalysisprogram.com/ArcGIS/rest/services/PADUS/Ancillary/MapServer/2");
        var queryTaskTouches = new esri.tasks.QueryTask("http://dingo.gapanalysisprogram.com/ArcGIS/rest/services/PADUS/PADUS_owner/MapServer/0");

        //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.proxyUrl = "http://dingo.gapanalysisprogram.com/proxy/proxy.ashx";

esriConfig.defaults.io.alwaysUseProxy = false;

        // Query
        var query = new esri.tasks.Query();
        query.returnGeometry = true;
          //query.outFields =  ["P_Des_Nm","P_Loc_Nm","Own_Name","Mang_Name"];
          query.outFields =  ["FID"];
  query.outSpatialReference = {"wkid":3089};
        var infoTempContent = "FID = ${FID}"+ "Remove Selected Features";
//Create InfoTemplate for styling the result infowindow.
var infoTemplate = new esri.InfoTemplate("County: ${FID}", infoTempContent);
map.infoWindow.resize(275,190);
      

        var currentClick = null;
        // +++++Listen for map onClick event+++++
        dojo.connect(map, "onClick", function(evt) {
          map.graphics.clear();
          map.infoWindow.hide();
          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);
          firstGraphic.setInfoTemplate(infoTemplate);

          map.graphics.add(firstGraphic);
          query.geometry = esri.geometry.webMercatorToGeographic(firstGraphic.geometry);
          query.spatialRelationship = esri.tasks.Query.SPATIAL_REL_IN;
          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[i];
            graphic.setSymbol(symbol);
            graphic.setInfoTemplate(infoTemplate);
            map.graphics.add(graphic);
          }
          //map.infoWindow.setTitle("Comparing " + firstGraphic.attributes.OBJECTID + " census block group with surrounding block groups");
//var content = "HI";
          map.infoWindow.setTitle(firstGraphic.attributes.FID);
          var content = "<table border='1'><th><td>Selected</td></th>"
             + "<tr><td>Name</td><td>" + firstGraphic.attributes.P_Des_Nm + "</td></tr>"
            + "<tr><td>Owner</td><td>" + firstGraphic.attributes.Own_Type + "</td></tr>"
              + "<tr><td>Location</td><td>" + firstGraphic.attributes.P_Loc_Nm + "</td></tr>"
             + "<tr><td>Category</td><td>" + firstGraphic.attributes.Category + "</td></tr>"
             + "</table>";
          map.infoWindow.setContent(content);
          map.infoWindow.show(map.toScreen(currentClick),map.getInfoWindowAnchor(map.toScreen(currentClick)));
         
          dojo.byId('messages').innerHTML = "";
        });
      }

     function showCoordinates(evt) {
        //get mapPoint from event
        var mp = evt.mapPoint;
        //display mouse coordinates
        dojo.byId("info").innerHTML = mp.x + ", " + mp.y;
      }


      dojo.addOnLoad(init);
    </script>
  </head>

  <body class="claro">
    Click on map to select census block group that intersects the map click and all block groups that touch selected group.
    <div id="mapDiv" style="width: 850px; height:500px; position:relative;">
       <span id="info" style="position:absolute; right:25px; bottom:5px; color:#000; z-index:50;"></span>
   </div>
    <span id="messages"></span>
  </body>
</html>

Outcomes