Select to view content in your preferred language

outSpatialReference of esri/rest/support/Query

1655
5
Jump to solution
11-08-2021 02:06 AM
GuillaumeArnaud
Frequent Contributor

Hi,

In ArcGIS Experience, I try to develop an app with Query. My data has WKID = 2154 and I need to have his geometry with 4326 WKID.

I try many and many things : 

getApiModule = () => {
//Va cherche l'API Js pour dessiner
return new Promise(resolve => {loadArcGISJSAPIModules(['esri/Graphic''esri/rest/support/Query''esri/geometry/Polygon''esri/geometry/SpatialReference']).then(modules => {[
        this.graphicApi, this.queryApi, this.polygonApi, this.spatialReferenceApi] = modules;
resolve('ok');
});});}
 
recupRequete = () => {
//Si besoin de cherche l'API de requête
if (!this.queryApi) {
this.getApiModule().then(() => { this.recupRequete() })
    } else {
//Construit la requête
const q = new this.queryApi({
where: '1=1',
outFields: ['*'],
returnGeometry: true,
outSpatialReference: { 'wkid': 4326 }
      });
console.log(q);
//Stocke la requête dans le state
this.query = q.toJSON();
    }
}
I also try with q.outSpatialReference after new. and i try in place of  { 'wkid': 4326 }
this.spatialReferenceApi.WGS84 , 4326 . 
 
The URL sent to ArcGIS server didn't have outSR parameter like I enter it directly in ArcGIS Server.
 
My ArcGIS Server is in 10.6.1
 
Thanks.
 
Guillaume ARNAUD
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
Noah-Sager
Esri Regular Contributor

Hi @GuillaumeArnaud, thanks for posting your question here. I'm not 100% sure what the issue is based on your code snippet here, but I put together an example of using query with a featureLayer in a different spatial reference:

https://codepen.io/noash/pen/gOxjarN?editors=1000

I think the confusion might be between esri/rest/query and esri/rest/support/Query, hopefully the sample above makes it more clear.

https://developers.arcgis.com/javascript/latest/api-reference/esri-rest-query.html

https://developers.arcgis.com/javascript/latest/api-reference/esri-rest-support-Query.html

If this doesn't help, can you post more of your relevant code so I can better diagnose?

View solution in original post

0 Kudos
5 Replies
Noah-Sager
Esri Regular Contributor

Hi @GuillaumeArnaud, thanks for posting your question here. I'm not 100% sure what the issue is based on your code snippet here, but I put together an example of using query with a featureLayer in a different spatial reference:

https://codepen.io/noash/pen/gOxjarN?editors=1000

I think the confusion might be between esri/rest/query and esri/rest/support/Query, hopefully the sample above makes it more clear.

https://developers.arcgis.com/javascript/latest/api-reference/esri-rest-query.html

https://developers.arcgis.com/javascript/latest/api-reference/esri-rest-support-Query.html

If this doesn't help, can you post more of your relevant code so I can better diagnose?

0 Kudos
GuillaumeArnaud
Frequent Contributor

Hi, 

If I understand your sample esri/rest/query is esri/tasks/QueryTask and esri/rest/support/Query is esri/tasks/query of API3.

I will try it Friday. If I remember, it's knew to execute Query without QueryTask and like it's work (not totally) I don't search QueryTask item on API ref 

Thanks.

When I'll try your answer I'll accept it.

Guillaume

GuillaumeArnaud
Frequent Contributor

Hi @Noah-Sager,

In Experience Builder, it seems that it is the dataSourceComponent which bring the request :

In render part :

<DataSourceComponent
useDataSource={this.props.useDataSources[0]}
widgetId={this.props.id}
query={this.query}
queryCount={true}
onDataSourceCreated={this.onDataSourceCreated}
>
    {this.recupDonnees}
</DataSourceComponent>
the functions :
onDataSourceCreated = (ds: DataSource) => {
//Récupère la datasource lors de sa création
this.queryDs = ds;
  }

recupDonnees = (ds: DataSource, info: IMDataSourceInfo) => {
//Partie temporaire du stockage des options de la liste déroulante
let tmp = [];
//Si la datasource est chargée
if (info.status === DataSourceStatus.Loaded) {
//Parcours les résultats de la requête
this.queryDs.getRecords().map((r: any) => {
//Construit le label e foncton des champs choisis
let label = '';
if (this.props.useDataSources[0].fields?.length == 0 || !this.props.useDataSources[0].fields) {
label += r.getData()['objectid'];
        } else {
for (let j = 0; j < this.props.useDataSources[0].fields.length; j++) {
if (j != 0) {
label += '-';
            }
label += r.getData()[this.props.useDataSources[0].fields[0]];
          }
        }
//Ajoute la donnée dans le contenu de la liste déroulante
tmp.push({ label: label, value: r.getData()['objectid'] + label, info: r });
      })
    }
//définie par défaut les coordonnées du premier enregistrement
this.destinationChange(tmp[0]);
//Remplace le contenu de la liste déroulante
this.setState({ destinations: tmp });
return null;
  }
 To get the same result with API javascript (and the projection works), You're right, I need to change recup result by : 
  recupDonnees = (ds: any, info: IMDataSourceInfo) => {
 
    if (info.status === DataSourceStatus.Loaded) {
if (ds.dataSourceJson?.query?.where?.sql) {
//get the filter apply on ds in ExB
this.query2.where += ' AND ' + ds.dataSourceJson.query.where.sql
        }
//apply the query 
this.queryTaskApi.executeQueryJSON(ds.url, this.query2).then(function (results) {
console.log("query results: ", results);
//STATE_ABBR should be "ID"
console.log("STATE_ABBR: ", results.features);
        });
}
}
 Is there a mean to do this directly on the DataSourceComponent of ExB ?
 
Thanks.
 
Guillaume
0 Kudos
Noah-Sager
Esri Regular Contributor

Good question, unfortunately I don't much about the ArcGIS Experience Builder. I do see they have a separate channel here: https://community.esri.com/t5/arcgis-experience-builder/ct-p/arcgis-experience-builder

0 Kudos
GuillaumeArnaud
Frequent Contributor

I know and now, as I know it's an experience issue I will post there !

Thanks