Skip to content

Commit

Permalink
Merge pull request #34 from MarshMapper/refactor-place-list
Browse files Browse the repository at this point in the history
Refactor list of features into separate component.  Add
  • Loading branch information
MarshMapper authored Aug 17, 2024
2 parents 9ebf2da + 87cd289 commit 74be72a
Show file tree
Hide file tree
Showing 8 changed files with 174 additions and 61 deletions.
19 changes: 2 additions & 17 deletions src/app/components/arc-map/arc-map.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,8 @@
<mat-tab-group preserveContent>
<mat-tab class="tab-content" label="Places">
<ng-template matTabContent>
<div [ngClass]="getFeatureContainerClass()" id="featureTableContainer">
<table mat-table [dataSource]="dataSource" class="mat-elevation-z8">

<!-- ID Column (Hidden) -->
<ng-container matColumnDef="id">
<td mat-cell *matCellDef="let element"> {{element.id}} </td>
</ng-container>

<!-- Name Column -->
<ng-container matColumnDef="name">
<td class="table-cell" mat-cell *matCellDef="let element"> {{element.name}} </td>
</ng-container>

<tr mat-row *matRowDef="let row; columns: displayedColumns;"></tr>
</table>
</div>
</ng-template>
<app-feature-list [featureLayerView]="protectedLayerViewSubject"></app-feature-list>
</ng-template>
</mat-tab>
<mat-tab class="tab-content" label="Layers"> </mat-tab>
</mat-tab-group>
Expand Down
19 changes: 3 additions & 16 deletions src/app/components/arc-map/arc-map.component.scss
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@
display: grid;
}
.map-container-vertical {
grid-template-rows: 60% 40%;
grid-template-rows: 1fr 40vh;
}
.map-container-horizontal {
grid-template-columns: 1fr 30%;
grid-template-columns: 1fr 34%;
}
.map-container-map-only {
grid-template-columns: 1fr;
Expand All @@ -25,17 +25,4 @@
height: 100%;
overflow: auto;
}
.tab-content {
height: 600px;
}
.feature-table-container-horizontal {
height: calc(100vh - 140px);
}
.feature-table-container-vertical {
height: calc(40vh - 80px);
}
.mat-mdc-row {
height: 24px;
font-size: 14px;
line-height: 18px;
}

38 changes: 10 additions & 28 deletions src/app/components/arc-map/arc-map.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@ import { CommonModule } from '@angular/common';
import { ComponentLibraryModule } from '@arcgis/map-components-angular';
import { BreakpointObserver, Breakpoints } from '@angular/cdk/layout';
import { MatTabsModule } from '@angular/material/tabs';
import { MatSortModule } from '@angular/material/sort';
import { MatPaginatorModule } from '@angular/material/paginator';
import { MatTableModule, MatTableDataSource } from '@angular/material/table';

import { map, shareReplay } from 'rxjs/operators';
import { CalciteComponentsModule } from '@esri/calcite-components-angular';
import { ProtectedAreasService } from '../../services/protected-areas.service';
Expand All @@ -18,15 +16,17 @@ import ImageryTileLayer from '@arcgis/core/layers/ImageryTileLayer';
import FeatureLayer from '@arcgis/core/layers/FeatureLayer';
import View from "@arcgis/core/views/View";
import LayerView from "@arcgis/core/views/layers/LayerView";
import { when, whenOnce } from '@arcgis/core/core/reactiveUtils';
import { whenOnce } from '@arcgis/core/core/reactiveUtils';
import { NjHistoricalMapsService, NjHistoricalMapType } from '../../services/nj-historical-maps.service';
import Layer from '@arcgis/core/layers/Layer';
import { FeatureListComponent } from "../feature-list/feature-list.component";
import { Subject } from 'rxjs';

@Component({
selector: 'app-arc-map',
standalone: true,
imports: [CommonModule, ComponentLibraryModule, CalciteComponentsModule, MatTabsModule, MatTableModule,
MatPaginatorModule, MatSortModule],
imports: [CommonModule, ComponentLibraryModule, CalciteComponentsModule, MatTabsModule, FeatureListComponent],

templateUrl: './arc-map.component.html',
styleUrl: './arc-map.component.scss'
})
Expand All @@ -35,10 +35,7 @@ export class ArcMapComponent implements OnInit {
public showInfoPanel: boolean = true;
public isSmallPortrait: boolean = false;
private breakpointObserver = inject(BreakpointObserver);
// private unprotectedAreasLayer: ImageryTileLayer | undefined;
// private protectedAreasLayer: FeatureLayer | undefined;
displayedColumns: string[] = ['name']; // Only 'name' column is displayed
dataSource = new MatTableDataSource();
public protectedLayerViewSubject: Subject<__esri.FeatureLayerView> = new Subject<__esri.FeatureLayerView>();

isSmallPortrait$ = this.breakpointObserver.observe([
Breakpoints.TabletPortrait,
Expand All @@ -65,7 +62,6 @@ export class ArcMapComponent implements OnInit {
map.add(protectedAreasLayer);
this.protectedAreasService.initializePopup(view);


// add the NJ Historical Maps, but they won't be visible by default
const mapTypes = Object.values(NjHistoricalMapType);
mapTypes.forEach((mapType) => {
Expand All @@ -86,20 +82,8 @@ export class ArcMapComponent implements OnInit {
]).then(([unprotectedView, protectedView]) => {
unprotectedAreasView = unprotectedView;
protectedAreasView = protectedView;
when(
() => !protectedView.updating,
(val) => {
// get all the features in view from the layerView
protectedView.queryFeatures().then((results) => {
let features: any[] = [];
// add to array with just the name for display and the id for selection / tracking
results.features.forEach((feature) => {
features.push({ id: feature.attributes.id, name: feature.attributes.name });
});
features.sort((a, b) => a.name.localeCompare(b.name));
this.dataSource.data = features;
})
});
this.protectedLayerViewSubject.next(protectedView);

return Promise.all(
[
whenOnce(() => !unprotectedAreasView.updating),
Expand All @@ -117,9 +101,7 @@ export class ArcMapComponent implements OnInit {
}
return 'map-container-map-only';
}
getFeatureContainerClass(): string {
return this.isSmallPortrait ? 'feature-table-container-vertical' : 'feature-table-container-horizontal';
}

ngOnInit(): void {
defineCustomElements(window, { resourcesUrl: "https://js.arcgis.com/map-components/4.29/assets" });
defineCalciteElements(window, { resourcesUrl: "https://js.arcgis.com/calcite-components/2.5.1/assets" });
Expand Down
18 changes: 18 additions & 0 deletions src/app/components/feature-list/feature-list.component.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<div [ngClass]="getFeatureContainerClass()" id="featureTableContainer">
<div class="table-container">
<table mat-table [dataSource]="dataSource">
<ng-container matColumnDef="id">
<td mat-cell *matCellDef="let element"> {{element.id}} </td>
</ng-container>
<ng-container matColumnDef="name">
<td class="table-cell" mat-cell *matCellDef="let element"> {{element.name}} </td>
</ng-container>
<tr mat-row *matRowDef="let row; columns: displayedColumns;"></tr>
</table>
</div>
<div class="paginator-container">
<mat-paginator #featurePaginator class="feature-paginator" showFirstLastButtons
[pageSizeOptions]="[5, 10, 20, 50]" pageSize="50" aria-label="Select page">
</mat-paginator>
</div>
</div>
22 changes: 22 additions & 0 deletions src/app/components/feature-list/feature-list.component.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// 64px header, 48px footer, 48px paginator
.feature-table-container-horizontal {
height: calc(100vh - 112px);
display: grid;
grid-template-rows: calc(100vh - 160px) 48px;
}
.feature-table-container-vertical {
height: calc(40vh - 48px);
display: grid;
grid-template-rows: calc(40vh - 96px) 48px;
}
.table-container {
overflow-y: auto;
}
.mat-mdc-row {
height: 24px;
font-size: 14px;
line-height: 18px;
}
.paginator-container {
overflow: hidden;
}
23 changes: 23 additions & 0 deletions src/app/components/feature-list/feature-list.component.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';

import { FeatureListComponent } from './feature-list.component';

describe('FeatureListComponent', () => {
let component: FeatureListComponent;
let fixture: ComponentFixture<FeatureListComponent>;

beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [FeatureListComponent]
})
.compileComponents();

fixture = TestBed.createComponent(FeatureListComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});

it('should create', () => {
expect(component).toBeTruthy();
});
});
82 changes: 82 additions & 0 deletions src/app/components/feature-list/feature-list.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import { CommonModule } from '@angular/common';
import { map, Observable, shareReplay } from 'rxjs';
import { AfterViewInit, Component, inject, Input, OnInit, ViewChild } from '@angular/core';
import { BreakpointObserver, Breakpoints } from '@angular/cdk/layout';
import { MatPaginator, MatPaginatorIntl, MatPaginatorModule } from '@angular/material/paginator';
import { MatTableDataSource, MatTableModule } from '@angular/material/table';
import { MatSortModule } from '@angular/material/sort';
import { when } from '@arcgis/core/core/reactiveUtils';

function getRangeLabel(page: number, pageSize: number, length: number): string {
if (length === 0 || pageSize === 0) {
return `0 of ${length}`;
}
length = Math.max(length, 0);
const startIndex = page * pageSize;
const endIndex = startIndex < length ? Math.min(startIndex + pageSize, length) : startIndex + pageSize;
return `${startIndex + 1}${endIndex}`;
}
function CustomPaginator() {
const customPaginatorIntl = new MatPaginatorIntl();
customPaginatorIntl.itemsPerPageLabel = 'Show:';
customPaginatorIntl.getRangeLabel = getRangeLabel;

return customPaginatorIntl;
}
@Component({
selector: 'app-feature-list',
standalone: true,
imports: [CommonModule, MatPaginatorModule, MatTableModule, MatSortModule ],
providers: [
{ provide: MatPaginatorIntl, useValue: CustomPaginator() }
],
templateUrl: './feature-list.component.html',
styleUrl: './feature-list.component.scss'
})
export class FeatureListComponent implements OnInit, AfterViewInit {
public isSmallPortrait: boolean = false;
private breakpointObserver = inject(BreakpointObserver);
@ViewChild(MatPaginator) paginator!: MatPaginator;
@Input() featureLayerView!: Observable<__esri.FeatureLayerView>;

displayedColumns: string[] = ['name']; // Only 'name' column is displayed
dataSource = new MatTableDataSource();

isSmallPortrait$ = this.breakpointObserver.observe([
Breakpoints.TabletPortrait,
Breakpoints.HandsetPortrait])
.pipe(
map(result => result.matches),
shareReplay()
);
getFeatureContainerClass(): string {
return this.isSmallPortrait ? 'feature-table-container-vertical' : 'feature-table-container-horizontal';
}
ngOnInit(): void {
this.isSmallPortrait$.subscribe((isSmallPortrait) => {
this.isSmallPortrait = isSmallPortrait;
});
// parent component will pass in the featureLayerView observable and emit a new value
// each time the view changes
this.featureLayerView.subscribe((layerView: __esri.FeatureLayerView) => {
when(
() => !layerView.updating,
(val) => {
// get all the features in view from the layerView
layerView.queryFeatures().then((results) => {
let features: any[] = [];
// add to array with just the name for display and the id for selection / tracking
results.features.forEach((feature) => {
features.push({ id: feature.attributes.id, name: feature.attributes.name });
});
// sort the features by name, then update the data table
features.sort((a, b) => a.name.localeCompare(b.name));
this.dataSource.data = features;
})
});
});
}
ngAfterViewInit(): void {
this.dataSource.paginator = this.paginator;
}
}
14 changes: 14 additions & 0 deletions src/styles.scss
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,17 @@ $ngx-arcgis-demo-theme: mat.define-light-theme((

html, body { height: 100%; }
body { margin: 0; font-family: "Noto Sans", "Helvetica Neue", sans-serif; }
.mat-mdc-paginator-container {
flex-wrap: nowrap !important;
min-height: 30px !important;
}
.mat-mdc-paginator {
line-height: 16px !important;
font-size: 12px !important;
--mat-form-field-container-height: 26px !important;
--mat-form-field-container-vertical-padding: 5px !important;
}
.mat-mdc-paginator-range-label {
text-wrap: nowrap !important;
margin: 0 8px 0 8px !important;
}

0 comments on commit 74be72a

Please sign in to comment.