setOrderByFields not working

915
0
06-12-2013 06:03 AM
ManuelPires
New Contributor
I'm using an AssyncTask to search some information from a MapServer. My objective is to show the results ordered by name, but even when I add the option
query.setOrderByFields()
the list comes disordered.

The Layer that I want to query has the option "Supports Advanced Queries: True" and if I use the query editor in the ArcGIS REST Services Directory with the orderBy, the results come oredered.

Here is my code, Is there any thing wrong???

  private class CommunesQueryTask extends
    AsyncTask<String, Void, FeatureSet> {
   ProgressDialog progress;
   boolean isComm;

   protected void onPreExecute() {
    progress = ProgressDialog
      .show(getContext(), "Chargement",
        "Veuillez patienter .... tâche de requête est en cours d'exécution");
   }

   /**
    * First member in parameter array is the query URL; second member
    * is the where clause.
    */
   protected FeatureSet doInBackground(String... queryParams) {
    FeatureSet fs = null;
    Query query = new Query();
    String url;
    if(queryParams.length==0){
     isComm=true;
 
     SpatialReference sr = cadastre.getSpatialReference();
     query.setGeometry(new Envelope(518566.76294912,
       6677527.650037218, 643370.5775897676, 6783333.562810987));
     query.setOutSpatialReference(sr);
     query.setOutFields(new String[] { "*" });
     Map<String,OrderByFields> order = new LinkedHashMap<String,OrderByFields>();
     order.put("nomcom", OrderByFields.ASC);
     query.setOrderByFields(order);
 
     url = cadastre.getUrl().concat("/9");
     
    }else{
     isComm=false;
     url=queryParams[1];
     SpatialReference sr = cadastre.getSpatialReference();
     query.setGeometry(new Envelope(518566.76294912,
       6677527.650037218, 643370.5775897676, 6783333.562810987));
     query.setOutSpatialReference(sr);
     query.setOutFields(new String[] { "*" });
     Map<String,OrderByFields> order = new LinkedHashMap<String,OrderByFields>();
     order.put("libelle", OrderByFields.ASC);
     query.setOrderByFields(order);
     query.setWhere(queryParams[0]);
    }
    
    QueryTask qTask = new QueryTask(url);
    
    try {
     fs = qTask.execute(query);
    } catch (Exception e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
     return fs;
    }

    return fs;
   }

   protected void onPostExecute(FeatureSet result) {
    if (result != null) {
     Log.i(TAG, "Communes with values");
     Graphic[] grs = result.getGraphics();
     if (grs.length > 0) {
      if(isComm){
       String[] comms = new String[grs.length + 1];
       commId = new String[grs.length];
       comms[0] = "Sélectionnez...";
 
       for (int i = 1; i < comms.length; i++) {
        commId[i - 1] = grs[i - 1].getAttributes()
          .get("id_comm").toString();
        comms = grs[i - 1].getAttributes().get("nomcom")
          .toString();
       }
 
       ArrayAdapter<String> spinnerAdapter = new ArrayAdapter<String>(
         getContext(),
         android.R.layout.simple_spinner_item, comms);
       spinnerAdapter
         .setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
       comm.setAdapter(spinnerAdapter);
       Log.i(TAG, "Communes loaded: " + commId.length);
      }else{
       String[] rues = new String[grs.length + 1];
       rueId = new String[grs.length];
       rues[0] = "Sélectionnez...";
 
       for (int i = 1; i < rues.length; i++) {
        rueId[i - 1] = grs[i - 1].getAttributes()
          .get("id_voie").toString();
        rues = grs[i - 1].getAttributes().get("libelle")
          .toString();
       }
 
       rue.setEnabled(true);
       ArrayAdapter<String> spinnerAdapter = new ArrayAdapter<String>(
         getContext(),
         android.R.layout.simple_spinner_item, rues);
       spinnerAdapter
         .setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
       rue.setAdapter(spinnerAdapter);
       Log.i(TAG, "Rues loaded: " + rueId.length);
      }
     }
    }
    progress.dismiss();
   }

  }
0 Kudos
0 Replies