Map graphic does not display as a result of a query

740
8
Jump to solution
08-20-2017 03:43 PM
LauraBusolo2
New Contributor III

Hi,

I have an application where the query result should be displayed on a table as well as highlight points that meet the query on the map. I am having a challenge as to why the points are not highlighted. Kindly assist. Here is a snippet of the query section of the code.

ArcGIS API for JavaScript‌ queryitems‌ grahpics‌ 

                        query.where = queryString;
                        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
1 Solution

Accepted Solutions
RobertScheitlin__GISP
MVP Emeritus

Laura,

   So the issue was you were not setting the query outSpatialReference:

Added line 16.

          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);
            })
          }

View solution in original post

8 Replies
RobertScheitlin__GISP
MVP Emeritus

Laura,

   In your showResults function make this change:

                    //creating an array of attributes from the results queried
                    var GridItems = arrayUtils.map(results, function (result) {
                        var geo = result.geometry;
                        mapMain.graphics.add(new Graphic(geo, selectSymbol));
                        return result.attributes;
                    });

                    // for (result in results){
                    //     var geo= results[result].geometry;
                    //     mapMain.graphics.add(new Graphic(geo, selectSymbol))
                    // }‍‍‍‍‍‍‍‍‍‍‍
0 Kudos
LauraBusolo2
New Contributor III

Thanks, rscheitlin I have tried that but there's still nothing on display

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Laura,

   Are there any errors in the web console? Are you getting results in the grid?

0 Kudos
LauraBusolo2
New Contributor III

Yes, I am getting results in the grid, but nothing that displays the highlighted graphic/symbol on the map. I don't see any errors. Unless there's something, in particular, i should check for in the console.

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Laura,

   So the issue was you were not setting the query outSpatialReference:

Added line 16.

          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);
            })
          }
LauraBusolo2
New Contributor III

Thank you!

It worked

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Laura,

  OK, I got it. I will take a look.

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Laura,

 Don't forget to mark this question as answered by clicking on the "Correct Answer" link on the reply that answered your question.