tr_transcendent

focus problem

Discussion created by tr_transcendent on Nov 22, 2011
Once the query task has been completed I am attempting to get the map to focus to a particular area which is at the 0 item in the parnums array.   However that map appears to be focusing other elements in that array (I would say about 1 in 5 times give or take) and I am not sure why. 

 <link href="http://serverapi.arcgisonline.com/jsapi/arcgis/2.5/js/dojo/dijit/themes/claro/claro.css" rel="stylesheet" type="text/css" >
    <script type="text/javascript" src="http://serverapi.arcgisonline.com/jsapi/arcgis/?v=2.5"></script>
    <script type="text/javascript">
        dojo.require("esri.tasks.query");
        dojo.require("esri.map");
        var featureCheck = 0;
        var featholding = new Array();
        var parnums = new Array();
        var j = "11006-80,11014-587,11006-80,11006-100,11014-665.B,11006-95.02,11006-78.A,11014-640,11006-107.B,11006-80.A,11006-78.A,11006-100,11006-95.01,11006-80,11006-80.A,11006-88.01,11006-101,11014-645.4,11006-81,11006-96,11006-136.1,11014-649.03,11006-75.03,11006-75.03,11006-162.01,11006-75.02,11006-103.A,11014-645.3,";
        parnums = j.split(",");
        parnums.sort();
        //this was added to make sure this parcel is the first one in the array
        parnums.unshift("11006-80")
        parnums = eliminateDuplicates(parnums);
     

          function init() {
            map = new esri.Map("mapDiv");
            var layer = new esri.layers.ArcGISDynamicMapServiceLayer("http://lrs.co.columbia.wi.us/ArcGIS/rest/services/LRS/TaxParcels_Parcels/MapServer")
            map.addLayer(layer);

            runQuery();
        }

        function runQuery() {
            
            
            for (j = 0; j < parnums.length; j++) {
                queryTask = new esri.tasks.QueryTask("http://lrs.co.columbia.wi.us/ArcGIS/rest/services/LRS/TaxParcels_Parcels/MapServer/1");
                query = new esri.tasks.Query();
                query.returnGeometry = true;
                query.text = parnums[j]
                queryTask.execute(query, gettingResults);
            

            }

           
        }

        function gettingResults(resultFeatures) {
          
       featholding.push(resultFeatures)
            
            
                     //will not show results until it has gone through the array
            if (featholding.length > 0 && featholding.length == parnums.length - 1) {

                showResults();
                // zoom to the feature
                map.setExtent(esri.graphicsExtent(featholding[featureCheck].features).expand(5.2), true);
               
                 }
        }

        function showResults() {
            // console.log('result: ', resultFeatures);
           map.graphics.clear();
           //this starts at 1 so the first parcel will not be hi-lighted per customer
            for (j = 1; j < featholding.length; j++) {
                var resultFeatures1 = featholding[j]
                var symbol = new esri.symbol.SimpleFillSymbol().setColor(new dojo.Color([255, 255, 0, 0.15]));
                for (var i = 0, il = resultFeatures1.features.length; i < il; i++) {
                    var graphic = resultFeatures1.features[i];
                   // this was added  to make sure it focusses on the first parcel
                   if (graphic.attributes.GIS_PIN == "11006-80"){
                        featureCheck = i;
                    }
                    graphic.setSymbol(symbol);
                    map.graphics.add(graphic);
                   
                }

            }

        }

        function eliminateDuplicates(arr) {
            var i,
      len = arr.length,
      out = [],
      obj = {};

            for (i = 0; i < len; i++) {
                obj[arr[i]] = 0;
            }
            for (i in obj) {
                out.push(i);
            }
            return out;
        } 

       
       
        dojo.ready(init);

Outcomes