Skip to content

Commit

Permalink
support multiple ids
Browse files Browse the repository at this point in the history
  • Loading branch information
jmhauck committed Nov 9, 2023
1 parent c0f8e47 commit 4c3be24
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 35 deletions.
24 changes: 12 additions & 12 deletions src/components.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
}
Expand Down Expand Up @@ -293,15 +293,15 @@ 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
*/
"defaultLayerId": string;
/**
* 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
*/
Expand Down Expand Up @@ -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 {
/**
Expand Down Expand Up @@ -1836,15 +1836,15 @@ 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
*/
"defaultLayerId"?: string;
/**
* 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
*/
Expand Down
32 changes: 30 additions & 2 deletions src/components/crowdsource-manager/crowdsource-manager.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand All @@ -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
*/
Expand Down Expand Up @@ -631,9 +659,9 @@ export class CrowdsourceManager {
</calcite-action-bar>
<div class="width-full height-full position-relative">
<layer-table
defaultGlobalId={hasMapAndLayer ? this.defaultGlobalId : ""}
defaultGlobalId={hasMapAndLayer ? this._defaultGlobalId : undefined}
defaultLayerId={hasMapAndLayer ? this.defaultLayer : ""}
defaultOid={hasMapAndLayer && !this.defaultGlobalId ? parseInt(this.defaultOid, 10) : undefined}
defaultOid={hasMapAndLayer && !this.defaultGlobalId ? this._defaultOid : undefined}
enableAutoRefresh={this.enableAutoRefresh}
enableCSV={this.enableCSV}
enableInlineEdit={this.enableInlineEdit}
Expand Down
4 changes: 2 additions & 2 deletions src/components/crowdsource-reporter/crowdsource-reporter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export class CrowdsourceReporter {
/**
* string: The text that will display at the top of the landing page
*/
@Prop() title: string;
@Prop() loginTitle: string;

/**
* esri/views/MapView: https://developers.arcgis.com/javascript/latest/api-reference/esri-views-MapView.html
Expand Down Expand Up @@ -115,7 +115,7 @@ export class CrowdsourceReporter {
return (
<Host>
<slot>
{this.title + this.description}
{this.loginTitle + this.description}
</slot>
</Host>
);
Expand Down
2 changes: 1 addition & 1 deletion src/components/crowdsource-reporter/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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` |


----------------------------------------------
Expand Down
28 changes: 15 additions & 13 deletions src/components/layer-table/layer-table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
}
});
Expand All @@ -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);
});
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/components/layer-table/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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` |
Expand Down
6 changes: 3 additions & 3 deletions src/utils/queryUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down

0 comments on commit 4c3be24

Please sign in to comment.