AnsweredAssumed Answered

identify not on the point I click

Question asked by schlot on Sep 26, 2012
Latest reply on Sep 27, 2012 by schlot
I have a map service that contains 3 layers, representing the new house, senate and congressional districts.  I have set up an identify task to open a popupTemplate that will show the district number, photo and link to their web page. 

The identify isn't executing where I click, it's using a point about 20 miles south. This is based on the sample "Display identify results in popup", the 2nd one in the samples list.  Someone needs to rename one of these, there should be two sample by the same name!).

I also want my identify to execute after an address is added.  That seems to be working, but maybe my modifications to make that happen are part of the problem.  I'm attaching my full code, since I might have chopped too much making it fit in this posting.
    <script type="text/javascript">        dojo.require("dijit.layout.BorderContainer");        dojo.require("dijit.layout.ContentPane");        dojo.require("esri.map");        dojo.require("esri.tasks.locator");       dojo.require("esri.dijit.Popup");         dojo.require("esri.dijit.Legend");       dojo.require("dijit.form.CheckBox");                 var map;        var spatialReference;       var locator;       var identifyTask,identifyParams;        var districtLayer;       var pathName = "http://myserver/ArcGIS/rest/services";       var identifyLocator = false;       var senateTemplate;       var houseTemplate;       var congressTemplate;                     function init() {           spatialReference = new esri.SpatialReference({wkid: 102100 });         startExtent = new esri.geometry.Extent(-10583000, 4287025, -9979000, 4980462, spatialReference);         //setup the popup window           var popup = new esri.dijit.Popup({            fillSymbol: new esri.symbol.SimpleFillSymbol(esri.symbol.SimpleFillSymbol.STYLE_SOLID, new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_SOLID, new dojo.Color([255,0,0]), 2), new dojo.Color([255,255,0,0.50]))          }, dojo.create("div"));               map = new esri.Map("map",{            infoWindow:popup,            extent:startExtent          });                   locator = new esri.tasks.Locator("http://tasks.arcgis.com/ArcGIS/rest/services/WorldLocator/GeocodeServer");          dojo.connect(locator, "onAddressToLocationsComplete", showResults);           var basemap = new esri.layers.ArcGISTiledMapServiceLayer("http://server.arcgisonline.com/ArcGIS/rest/services/Canvas/World_Light_Gray_Base/MapServer");          map.addLayer(basemap);              districtLayer = new esri.layers.ArcGISDynamicMapServiceLayer(pathName+"/legisDistrict/MapServer",{id:'districts'});         map.addLayer(districtLayer);                      senateTemplate = new esri.dijit.PopupTemplate({              title: "Senate District {District}",              mediaInfos: [{                  "title": "{District}",                  "caption": "{Name}",                  "type": "image",                  "value": {                  "sourceURL": "{photoLink}",                  "linkURL": "" }               }],             fieldInfos: [                  { fieldName: "webLink", label: "Open Web Page" , visible: true }]             });                   houseTemplate = new esri.dijit.PopupTemplate({                  title: "House District {District}",                  mediaInfos: [{                      "title": "{District}",                      "caption": "{Name}",                      "type": "image",                      "value": {                      "sourceURL": "{photoLink}",                      "linkURL": "" }                   }],                 fieldInfos: [                      { fieldName: "webLink", label: "Open Representatives's Web Page" , visible: true }]                 });               dojo.connect(map,"onLoad",mapReady);        }                function mapReady(map){           //identify task is the same layer as districtLayer added above         identifyTask = new esri.tasks.IdentifyTask(pathName + "/legisDistrict/MapServer");         identifyParams = new esri.tasks.IdentifyParameters();         identifyParams.tolerance = 3; //         identifyParams.returnGeometry = true;         identifyParams.layerIds = [0, 1, 2];         identifyParams.layerOption = esri.tasks.IdentifyParameters.LAYER_OPTION_VISIBLE;         identifyParams.spatialReference = spatialReference;                  identifyParams.width = map.width;         identifyParams.height = map.height;                  dojo.connect(map, "onClick", executeIdentifyTask);                  //resize the map when the browser resizes          dojo.connect(dijit.byId('map'), 'resize', map, map.resize);     }                function executeIdentifyTask(evt) {             identifyParams.mapExtent = map.extent;        identifyParams.geometry = evt.mapPoint;              var deferred = identifyTask.execute(identifyParams);               //identify runs from geocoded point and not just click                if (identifyLocator) { // geometry is coming from address function            identifyParams.geometry = evt;        }          deferred.addCallback(function(response) {                 // response is an array of identify result objects                // Let's return an array of features.            return dojo.map(response, function(result) {              var feature = result.feature;              feature.attributes.layerName = result.layerName;               if(result.layerName === 'senate'){              console.log("Senate District: " & feature.attributes.District);                feature.setInfoTemplate(senateTemplate);              }              else if (result.layerName === 'house'){              console.log("House District: " & feature.attributes.District);               feature.setInfoTemplate(houseTemplate);              } else {                 console.log("congress not defined - create template for it");             }             identifyLocator = false;             return feature;                         });          });          map.infoWindow.setFeatures([ deferred ]);          map.infoWindow.show(evt.mapPoint);             }               dojo.connect(map.infoWindow, "onHide", function() {map.graphics.clear();});       }            dojo.addOnLoad(init);      </script>    </head>        <body class="claro">      <div data-dojo-type="dijit.layout.BorderContainer" data-dojo-props="design:'headline'"  style="width: 100%; height: 100%; margin: 0;">             <div id="mainHeader" dojotype="dijit.layout.ContentPane" region="top" >              Missouri Legislative Districts             <div id="subheader"> 2010 District Boundaries                 <div id="divAddress" style="position:absolute; top:10px; right:25px; z-index:999;">                      <input id="txtAddress" style="width:250px" type="text"  value="Find address or place" class="textBox" onclick="clearTextInput();" />                      <button id="btnGO" dojotype="dijit.form.Button" onClick="locate();">GO</button>                  </div>             </div>            </div>       <div id="map" data-dojo-type="dijit.layout.ContentPane" data-dojo-props="region:'center'" >                               <div dojoType="dijit.form.Button" id="btnHouse" class="togglebutton" onClick="toggleLayer(1);">                       House Districts                   </div>                   <div dojoType="dijit.form.Button" id="btnSenate" class="togglebutton" onClick="toggleLayer(0);">                       Senate Districts                    </div>                   <div dojoType="dijit.form.Button" id="btnCongress" class="togglebutton" onClick="toggleBaseLayer(2);">                       Congressional Districts            </div>                      </div>           </div>     </div>    </body>    </html> 

Attachments

Outcomes