From 4c3be24907b5f619510324c5f834aee13dcb8647 Mon Sep 17 00:00:00 2001 From: John Hauck Date: Thu, 9 Nov 2023 12:41:33 -0700 Subject: [PATCH] support multiple ids --- src/components.d.ts | 24 +++++++------- .../crowdsource-manager.tsx | 32 +++++++++++++++++-- .../crowdsource-reporter.tsx | 4 +-- src/components/crowdsource-reporter/readme.md | 2 +- src/components/layer-table/layer-table.tsx | 28 ++++++++-------- src/components/layer-table/readme.md | 4 +-- src/utils/queryUtils.ts | 6 ++-- 7 files changed, 65 insertions(+), 35 deletions(-) diff --git a/src/components.d.ts b/src/components.d.ts index 6176f8c46..fd0b3a915 100644 --- a/src/components.d.ts +++ b/src/components.d.ts @@ -186,13 +186,13 @@ export namespace Components { */ "layers": string[]; /** - * esri/views/MapView: https://developers.arcgis.com/javascript/latest/api-reference/esri-views-MapView.html + * string: The text that will display at the top of the landing page */ - "mapView": __esri.MapView; + "loginTitle": string; /** - * string: The text that will display at the top of the landing page + * esri/views/MapView: https://developers.arcgis.com/javascript/latest/api-reference/esri-views-MapView.html */ - "title": string; + "mapView": __esri.MapView; } interface DeductCalculator { } @@ -293,7 +293,7 @@ export namespace Components { /** * string: Global ID of the feature to select */ - "defaultGlobalId": string; + "defaultGlobalId": string[]; /** * string: when provided this layer ID will be used when the app loads */ @@ -301,7 +301,7 @@ export namespace Components { /** * number: when provided this will be used to select a feature in the table by default */ - "defaultOid": number; + "defaultOid": number[]; /** * boolean: when true the layer table will auto refresh the data */ @@ -1738,13 +1738,13 @@ declare namespace LocalJSX { */ "layers"?: string[]; /** - * esri/views/MapView: https://developers.arcgis.com/javascript/latest/api-reference/esri-views-MapView.html + * string: The text that will display at the top of the landing page */ - "mapView"?: __esri.MapView; + "loginTitle"?: string; /** - * string: The text that will display at the top of the landing page + * esri/views/MapView: https://developers.arcgis.com/javascript/latest/api-reference/esri-views-MapView.html */ - "title"?: string; + "mapView"?: __esri.MapView; } interface DeductCalculator { /** @@ -1836,7 +1836,7 @@ declare namespace LocalJSX { /** * string: Global ID of the feature to select */ - "defaultGlobalId"?: string; + "defaultGlobalId"?: string[]; /** * string: when provided this layer ID will be used when the app loads */ @@ -1844,7 +1844,7 @@ declare namespace LocalJSX { /** * number: when provided this will be used to select a feature in the table by default */ - "defaultOid"?: number; + "defaultOid"?: number[]; /** * boolean: when true the layer table will auto refresh the data */ diff --git a/src/components/crowdsource-manager/crowdsource-manager.tsx b/src/components/crowdsource-manager/crowdsource-manager.tsx index 774641773..5f7d85343 100644 --- a/src/components/crowdsource-manager/crowdsource-manager.tsx +++ b/src/components/crowdsource-manager/crowdsource-manager.tsx @@ -191,6 +191,16 @@ export class CrowdsourceManager { // //-------------------------------------------------------------------------- + /** + * string[]: List of global ids that should be selected by default + */ + protected _defaultGlobalId: string[]; + + /** + * number[]: List of ids that should be selected by default + */ + protected _defaultOid: number[]; + /** * IMapChange: The current map change details */ @@ -213,6 +223,24 @@ export class CrowdsourceManager { // //-------------------------------------------------------------------------- + /** + * Watch for globalid url param to be set + */ + @Watch("defaultGlobalId") + defaultGlobalIdWatchHandler(): void { + this._defaultGlobalId = !this.defaultGlobalId ? undefined : + this.defaultGlobalId.indexOf(",") > -1 ? this.defaultGlobalId.split(",") : [this.defaultGlobalId]; + } + + /** + * Watch for oid url param to be set + */ + @Watch("defaultOid") + defaultOidWatchHandler(): void { + this._defaultOid = !this.defaultOid ? undefined : + this.defaultOid.indexOf(",") > -1 ? this.defaultOid.split(",").map(o => parseInt(o, 10)) : [parseInt(this.defaultOid, 10)]; + } + /** * When true the map zoom tools will be available */ @@ -631,9 +659,9 @@ export class CrowdsourceManager {
- {this.title + this.description} + {this.loginTitle + this.description} ); diff --git a/src/components/crowdsource-reporter/readme.md b/src/components/crowdsource-reporter/readme.md index db760f8f7..8e25eb6d8 100644 --- a/src/components/crowdsource-reporter/readme.md +++ b/src/components/crowdsource-reporter/readme.md @@ -12,8 +12,8 @@ | `description` | `description` | string: The text that will display under the title on the landing page | `string` | `undefined` | | `image` | `image` | string: landing page image | `string` | `undefined` | | `layers` | -- | string[]: list of layer ids | `string[]` | `undefined` | +| `loginTitle` | `login-title` | string: The text that will display at the top of the landing page | `string` | `undefined` | | `mapView` | -- | esri/views/MapView: https://developers.arcgis.com/javascript/latest/api-reference/esri-views-MapView.html | `MapView` | `undefined` | -| `title` | `title` | string: The text that will display at the top of the landing page | `string` | `undefined` | ---------------------------------------------- diff --git a/src/components/layer-table/layer-table.tsx b/src/components/layer-table/layer-table.tsx index 31d7c4f1a..f8283f325 100644 --- a/src/components/layer-table/layer-table.tsx +++ b/src/components/layer-table/layer-table.tsx @@ -50,12 +50,12 @@ export class LayerTable { /** * string: Global ID of the feature to select */ - @Prop() defaultGlobalId: string; + @Prop() defaultGlobalId: string[]; /** * number: when provided this will be used to select a feature in the table by default */ - @Prop() defaultOid: number; + @Prop() defaultOid: number[]; /** * boolean: when true the layer table will auto refresh the data @@ -1118,15 +1118,17 @@ export class LayerTable { this._table.highlightIds.removeAll(); this._table.clearSelectionFilter(); - if (!this._defaultOidHonored && this.defaultOid > -1) { + if (!this._defaultOidHonored && this.defaultOid?.length > 0 && this.defaultOid[0] > -1) { this._selectDefaultFeature(this.defaultOid); this._defaultOidHonored = true } - if (!this._defaultGlobalIdHonored && this.defaultGlobalId) { + if (!this._defaultGlobalIdHonored && this.defaultGlobalId?.length > 0) { const features = await queryFeaturesByGlobalID(this.defaultGlobalId, this._layer); - const oid = features?.length > 0 ? features[0].getObjectId() : -1; - this._selectDefaultFeature(oid); + const oids = features?.length > 0 ? features.map(f => f.getObjectId()) : undefined; + if (oids) { + this._selectDefaultFeature(oids); + } this._defaultGlobalIdHonored = true; } }); @@ -1142,14 +1144,14 @@ export class LayerTable { * @returns void */ protected _selectDefaultFeature( - oid: number + oids: number[] ): void { - if (oid > -1) { - this._table.highlightIds.add(oid); - setTimeout(() => { - const i = this._table.viewModel.getObjectIdIndex(oid); - this._table.scrollToIndex(i); - }, 500); + if (oids.length > 0) { + this._table.highlightIds.addMany(oids); + void this._table.when(() => { + const i = this._table.viewModel.getObjectIdIndex(oids[0]); + this._table.viewModel.scrollToIndex(i); + }); } } diff --git a/src/components/layer-table/readme.md b/src/components/layer-table/readme.md index a094fd42f..3698a0398 100644 --- a/src/components/layer-table/readme.md +++ b/src/components/layer-table/readme.md @@ -9,9 +9,9 @@ | Property | Attribute | Description | Type | Default | | ------------------------- | ----------------------------- | ------------------------------------------------------------------------------------------------------------------ | ---------- | ----------- | -| `defaultGlobalId` | `default-global-id` | string: Global ID of the feature to select | `string` | `undefined` | +| `defaultGlobalId` | -- | string: Global ID of the feature to select | `string[]` | `undefined` | | `defaultLayerId` | `default-layer-id` | string: when provided this layer ID will be used when the app loads | `string` | `undefined` | -| `defaultOid` | `default-oid` | number: when provided this will be used to select a feature in the table by default | `number` | `undefined` | +| `defaultOid` | -- | number: when provided this will be used to select a feature in the table by default | `number[]` | `undefined` | | `enableAutoRefresh` | `enable-auto-refresh` | boolean: when true the layer table will auto refresh the data | `boolean` | `undefined` | | `enableCSV` | `enable-c-s-v` | boolean: when true the export to csv button will be available | `boolean` | `undefined` | | `enableInlineEdit` | `enable-inline-edit` | boolean: when true edits can be applied directly within the table | `boolean` | `undefined` | diff --git a/src/utils/queryUtils.ts b/src/utils/queryUtils.ts index 2a82358df..b548829aa 100644 --- a/src/utils/queryUtils.ts +++ b/src/utils/queryUtils.ts @@ -163,7 +163,7 @@ export async function queryFeaturesByID( * @returns Promise with the featureSet from the layer that match the provided globalId */ export async function queryFeaturesByGlobalID( - globalId: string, + globalIds: string[], layer: __esri.FeatureLayer ): Promise<__esri.Graphic[]> { const globalIdField = (layer as any).globalIdField; @@ -173,8 +173,8 @@ export async function queryFeaturesByGlobalID( const q = layer.createQuery(); q.returnGeometry = false; - q.outFields = [layer.objectIdField] - q.where = `${globalIdField} = '${globalId}'` + q.outFields = [layer.objectIdField]; + q.where = globalIds.map(g => `${globalIdField} = '${g}'`).join(" or "); const result = await layer.queryFeatures(q); return result.features;