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 dessinerreturn 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êteif (!this.queryApi) {this.getApiModule().then(() => { this.recupRequete() })} else {//Construit la requêteconst q = new this.queryApi({where: '1=1',outFields: ['*'],returnGeometry: true,outSpatialReference: { 'wkid': 4326 }});console.log(q);//Stocke la requête dans le statethis.query = q.toJSON();}}
Solved! Go to Solution.
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?
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?
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
Hi @Noah-Sager,
In Experience Builder, it seems that it is the dataSourceComponent which bring the request :
In render part :
<DataSourceComponentuseDataSource={this.props.useDataSources[0]}widgetId={this.props.id}query={this.query}queryCount={true}onDataSourceCreated={this.onDataSourceCreated}>{this.recupDonnees}</DataSourceComponent>
onDataSourceCreated = (ds: DataSource) => {//Récupère la datasource lors de sa créationthis.queryDs = ds;}recupDonnees = (ds: DataSource, info: IMDataSourceInfo) => {//Partie temporaire du stockage des options de la liste déroulantelet tmp = [];//Si la datasource est chargéeif (info.status === DataSourceStatus.Loaded) {//Parcours les résultats de la requêtethis.queryDs.getRecords().map((r: any) => {//Construit le label e foncton des champs choisislet 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éroulantetmp.push({ label: label, value: r.getData()['objectid'] + label, info: r });})}//définie par défaut les coordonnées du premier enregistrementthis.destinationChange(tmp[0]);//Remplace le contenu de la liste déroulantethis.setState({ destinations: tmp });return null;}
recupDonnees = (ds: any, info: IMDataSourceInfo) => {if (info.status === DataSourceStatus.Loaded) {if (ds.dataSourceJson?.query?.where?.sql) {//get the filter apply on ds in ExBthis.query2.where += ' AND ' + ds.dataSourceJson.query.where.sql}//apply the querythis.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);});}}
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
I know and now, as I know it's an experience issue I will post there !
Thanks