CENTER- ZOOM TO QUERY RESULTS

936
2
08-29-2017 08:17 PM
LauraBusolo2
New Contributor III

                    on(dom.byId("GetAcademies"), "click", executeIndQry);

                    function executeIndQry() {
                        var queryString='';
                        var i=0;
                        // define more than one selection to query from the sector
                        for(option in dom.byId("industrySelectDD").options){
                            if(dom.byId("industrySelectDD").options[option].selected)
                            {
                                if(i==0)
                                {
                                    queryString+="Industry ='" +dom.byId("industrySelectDD").options[option].value+"'";
                                    i+=1;
                                }
                                else
                                {
                                    queryString+=" or Industry ='" +dom.byId("industrySelectDD").options[option].value+"'";
                                }
                            }
                        }
                        query.where = queryString;
                        query.outSpatialReference = mapMain.spatialReference;
                        lyrAcademies.selectFeatures(query, FeatureLayer.SELECTION_NEW, function(results){
                            showResults(results);
                        })
                    }
                };

                //Show the results as highlighted boxes on the map
                function showResults(results) {
                    mapMain.graphics.clear();

                    var selectSymbol = new SimpleMarkerSymbol(
                        SimpleMarkerSymbol.STYLE_SQUARE, 15,
                        new SimpleLineSymbol(
                            SimpleLineSymbol.STYLE_SOLID,
                            new Color([255,0,0]), 1),
                        new Color([0,255,0,0.25])
                    );
                   

Tags (2)
0 Kudos
2 Replies
KenBuja
MVP Esteemed Contributor

Once you have the array of graphics from your query, you can use the esri/graphicsUtils method graphicsExtent to set the map's extent

Than_HtetAung
New Contributor III

Hi Laura,

Update showResults method as below. Modify code is in blue color.

 function showResults(results) {
                    mapMain.graphics.clear();
                     

                     var featureExtent = esri.graphicsExtent(results.features);

                     var targetMapExtent = featureExtent.expand(2.5); //change 2.5 for expand factor

                     mapMain.setExtent(targetMapExtent);


                    var selectSymbol = new SimpleMarkerSymbol(
                        SimpleMarkerSymbol.STYLE_SQUARE, 15,
                        new SimpleLineSymbol(
                            SimpleLineSymbol.STYLE_SOLID,
                            new Color([255,0,0]), 1),
                        new Color([0,255,0,0.25])
                    );

0 Kudos