Skip to content

Commit e40718f

Browse files
author
Rick Saccoccia
committed
Fix addFields and deleteFields
1 parent e2da608 commit e40718f

File tree

4 files changed

+27
-21
lines changed

4 files changed

+27
-21
lines changed

plugins/arcgis/service/package-lock.json

Lines changed: 5 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

plugins/arcgis/service/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
"@esri/arcgis-rest-feature-service": "^4.0.6",
4242
"@esri/arcgis-rest-request": "^4.2.3",
4343
"@terraformer/arcgis": "2.1.2",
44-
"form-data": "^4.0.0"
44+
"form-data": "^4.0.1"
4545
},
4646
"peerDependencies": {
4747
"@ngageoint/mage.service": "^6.2.9 || ^6.3.0-beta",

plugins/arcgis/service/src/FeatureServiceAdmin.ts

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ export class FeatureServiceAdmin {
9292
const eventFields = this.fields(events)
9393
const layerFields = layerInfo.fields
9494

95+
// TODO - better naming: addFields is a boolean, array of fields, and a method. Ditto for deleteFields
9596
if (featureLayer.addFields) {
9697

9798
const layerFieldSet = new Set()
@@ -110,6 +111,7 @@ export class FeatureServiceAdmin {
110111
}
111112
}
112113

114+
// TODO - where does New_field and New_field_2 come from with each startup?
113115
if (addFields.length > 0) {
114116
this.addFields(service, featureLayer, addFields)
115117
}
@@ -462,24 +464,27 @@ export class FeatureServiceAdmin {
462464
*/
463465
private async addFields(service: FeatureServiceConfig, featureLayer: FeatureLayerConfig, fields: Field[]) {
464466

465-
const layer = {} as Layer
466-
layer.fields = fields
467+
const layer = { fields: fields} as Layer
467468

468469
const httpClient = this.httpClient(service)
469470
const identityManager = await getIdentityManager(service, httpClient)
470471
const url = this.adminUrl(service) + featureLayer.layer.toString() + '/addToDefinition'
471472

472473
this._console.info('ArcGIS feature layer addToDefinition (add fields) url ' + url)
473474

474-
const form = new FormData()
475-
form.append('addToDefinition', JSON.stringify(layer))
476-
477-
const postResponse = request(url, {
475+
await request(url, {
478476
authentication: identityManager,
479-
httpMethod: 'POST',
480-
params: form
477+
params: {
478+
addToDefinition: JSON.stringify(layer),
479+
f: "json"
480+
}
481+
}).then((postResponse) => {
482+
console.log('Response: ' + postResponse)
483+
}).catch((error) => {
484+
console.log('Error: ' + error)
481485
});
482-
console.log('Response: ' + postResponse)
486+
487+
console.log('Remove me')
483488

484489
}
485490

@@ -507,14 +512,12 @@ export class FeatureServiceAdmin {
507512

508513
this._console.info('ArcGIS feature layer deleteFromDefinition (delete fields) url ' + url)
509514

510-
const form = new FormData()
511-
form.append('deleteFromDefinition', JSON.stringify(layer))
512-
513-
httpClient.sendPostForm(url, form)
514515
const postResponse = request(url, {
515516
authentication: identityManager,
516517
httpMethod: 'POST',
517-
params: form
518+
params: {
519+
deleteFromDefinition: JSON.stringify(layer)
520+
}
518521
});
519522
console.log('Response: ' + postResponse)
520523
}

plugins/arcgis/service/src/ObservationProcessor.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,8 @@ export class ObservationProcessor {
244244
}
245245

246246
for (const featureLayer of featureServiceConfig.layers) {
247+
// Initiate the feature layer and event fields to sync with the feature service
248+
featureLayer.addFields = true
247249

248250
if (featureLayer.token == null) {
249251
featureLayer.token = featureServiceConfig.auth?.type == AuthType.Token ? featureServiceConfig.auth.token : ""
@@ -311,8 +313,8 @@ export class ObservationProcessor {
311313
const identityManager = await getIdentityManager(featureServiceConfig, new HttpClient(console))
312314
const layerProcessor = new FeatureLayerProcessor(info, config, identityManager,this._console);
313315
this._layerProcessors.push(layerProcessor);
314-
clearTimeout(this._nextTimeout);
315-
this.scheduleNext(config);
316+
clearTimeout(this._nextTimeout); // TODO why is this needed?
317+
// this.scheduleNext(config); // TODO why is this needed when processAndScheduleNext is called upstream and ends with scheduleNext() This causes a query before updateLayer.
316318
}
317319
}
318320

0 commit comments

Comments
 (0)