jsn

What is wrong with this code? Why it does not zoom?

Discussion created by jsn on May 9, 2014
Latest reply on May 9, 2014 by jeff.pace
Hi all,

What is wrong with this code? Why it does not zoom?

It centersAt and adds graphics, but the  map.setExtent(PointExtent) does not work.

Thanks


 function showResults(results) {
        //symbology for graphics
        var markerSymbol = new esri.symbol.SimpleMarkerSymbol(esri.symbol.SimpleMarkerSymbol.STYLE_SQUARE, 10, new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_SOLID, new dojo.Color([255, 0, 0]), 1), new dojo.Color([0, 255, 0, 0.25]));
        var lineSymbol = new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_DASH, new dojo.Color([255, 0, 0]), 1);
        var polygonSymbol = new esri.symbol.SimpleFillSymbol(esri.symbol.SimpleFillSymbol.STYLE_NONE, new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_DASHDOT, new dojo.Color([255, 0, 0]), 2), new dojo.Color([255, 255, 0, 0.25]));

        //find results return an array of findResult.
        map.graphics.clear();
        var dataForGrid = [];
        var g;
        //Build an array of attribute information and add each found graphic to the map
        dojo.forEach(results, function (result) {
            var graphic = result.feature;
            // dataForGrid.push([result.layerName, result.foundFieldName, result.value]);
            switch (graphic.geometry.type) {
                case "point":
                    graphic.setSymbol(markerSymbol);
                    break;
                case "polyline":
                    graphic.setSymbol(lineSymbol);
                    break;
                case "polygon":
                    graphic.setSymbol(polygonSymbol);
                    break;
            }

            g = graphic;

            map.centerAt(g.geometry, 10)

           

           map.graphics.add(g);


           // Zoom to Pump Station
           //
           if (g.geometry.type == "point") {

               //add this code to set the point extent and zoom in
               var PointExtent = new esri.geometry.Extent();
               PointExtent.xmin = g.geometry.x - .001;
               PointExtent.ymin = g.geometry.y - .001;
               PointExtent.xmax = g.geometry.x + .001;
               PointExtent.ymax = g.geometry.y + .001;

               map.setExtent(PointExtent);


           }
            


        });

     

        var data = {
          items: dataForGrid
        };
        var store = new dojo.data.ItemFileReadStore({
          data: data
        });
        grid.setStore(store);
    }

Outcomes