Skip to content

Commit

Permalink
Merge pull request #27 from SEED-platform/upload_btns
Browse files Browse the repository at this point in the history
1st iteration of property and tax lot upload buttons
  • Loading branch information
axelstudios authored Oct 14, 2020
2 parents 1523a5b + 542cea4 commit 6d0836f
Show file tree
Hide file tree
Showing 12 changed files with 170 additions and 10 deletions.
6 changes: 5 additions & 1 deletion src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import { MaterialModule } from './material-module';
import { SharedModule } from './shared/shared.module';
import { MapComponent } from './map/map.component';
import { InventoryComponent } from './inventory/inventory.component';
import { PropertiesUploadComponent } from './properties-upload/properties-upload.component';
import { TaxlotsUploadComponent } from './taxlots-upload/taxlots-upload.component';

// AoT requires an exported function for factories
export function HttpLoaderFactory(http: HttpClient): TranslateHttpLoader {
Expand All @@ -33,7 +35,9 @@ export function HttpLoaderFactory(http: HttpClient): TranslateHttpLoader {
HeaderComponent,
LeftNavComponent,
MapComponent,
InventoryComponent
InventoryComponent,
PropertiesUploadComponent,
TaxlotsUploadComponent
],
imports: [
AppRoutingModule,
Expand Down
3 changes: 3 additions & 0 deletions src/app/home/home.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,7 @@ <h1 class="title">Running: {{ status.running }}</h1>
</div>

<textarea disabled>{{ latestQueryResult }}</textarea>

<app-properties-upload></app-properties-upload>
<app-taxlots-upload></app-taxlots-upload>
</div>
2 changes: 1 addition & 1 deletion src/app/home/home.component.scss
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@

textarea {
width: 600px;
height: 400px;
height: 200px;
}
18 changes: 10 additions & 8 deletions src/app/map/map.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,12 @@ export class MapComponent implements OnInit {
values[0].forEach(property => {
if (property.footprint) {
const footprintCoords = property.footprint.coordinates[0].map(coords => {
return new Microsoft.Maps.Location(...coords)
return new Microsoft.Maps.Location(...coords.reverse())
})
const polygon = new Microsoft.Maps.Polygon(footprintCoords);
const infobox = new Microsoft.Maps.Infobox(footprintCoords[0], {
title: 'Property Information',
description: property.ubid,
description: JSON.stringify(property.extra_data),
visible: false
});
infobox.setMap(this.map);
Expand All @@ -80,12 +80,12 @@ export class MapComponent implements OnInit {
values[1].forEach(taxlot => {
if (taxlot.footprint) {
const footprintCoords = taxlot.footprint.coordinates[0].map(coords => {
return new Microsoft.Maps.Location(...coords)
return new Microsoft.Maps.Location(...coords.reverse())
})
const polygon = new Microsoft.Maps.Polygon(footprintCoords, this.styles.polygonOptions);
const infobox = new Microsoft.Maps.Infobox(footprintCoords[0], {
title: 'Tax Lot Information',
description: taxlot.ulid,
description: JSON.stringify(taxlot.extra_data),
visible: false
});
infobox.setMap(this.map);
Expand All @@ -106,10 +106,12 @@ export class MapComponent implements OnInit {
this.map.layers.insert(propertyLayer);
this.map.layers.insert(taxlotLayer);

// allFootprints used because can't find attribute of map or layers to get shapes
this.map.setView({
bounds: new Microsoft.Maps.LocationRect.fromShapes(allFootprints)
})
if (allFootprints.length) {
// allFootprints used because can't find attribute of map or layers to get shapes
this.map.setView({
bounds: new Microsoft.Maps.LocationRect.fromShapes(allFootprints)
});
}
})
}
}
8 changes: 8 additions & 0 deletions src/app/properties-upload/properties-upload.component.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<div>
<label for="file">Choose building GeoJSON file</label>
<input
type="file"
id="file"
accept=".geojson"
(change)="handleFileInput($event.target.files)">
</div>
Empty file.
25 changes: 25 additions & 0 deletions src/app/properties-upload/properties-upload.component.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';

import { PropertiesUploadComponent } from './properties-upload.component';

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

beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ PropertiesUploadComponent ]
})
.compileComponents();
}));

beforeEach(() => {
fixture = TestBed.createComponent(PropertiesUploadComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});

it('should create', () => {
expect(component).toBeTruthy();
});
});
43 changes: 43 additions & 0 deletions src/app/properties-upload/properties-upload.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { Component, OnInit } from '@angular/core';
import { PropertyService } from '../core/services/property/property.service';


@Component({
selector: 'app-properties-upload',
templateUrl: './properties-upload.component.html',
styleUrls: ['./properties-upload.component.scss']
})
export class PropertiesUploadComponent implements OnInit {

constructor(private propertyService: PropertyService) { }

ngOnInit(): void {
}

handleFileInput(files: FileList): void {
if (files[0]) {
files[0].text().then(text => {
const geojson = JSON.parse(text);
const crs = geojson.crs ? geojson.crs : { type: 'name', properties: { name: 'EPSG:4326'} };

geojson.features.forEach(feature => {
const extra_data = feature.properties;
feature.geometry.crs = crs;

// extract non-extra_data attributes
const ubid = extra_data.UBID;
delete extra_data.UBID;

this.propertyService.model.create({
extra_data: extra_data,
footprint: feature.geometry,
ubid: ubid
}).catch((err) => {
console.error(err);
});
});
})
}
}

}
8 changes: 8 additions & 0 deletions src/app/taxlots-upload/taxlots-upload.component.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<div>
<label for="file">Choose tax lot GeoJSON file</label>
<input
type="file"
id="file"
accept=".geojson"
(change)="handleFileInput($event.target.files)">
</div>
Empty file.
25 changes: 25 additions & 0 deletions src/app/taxlots-upload/taxlots-upload.component.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';

import { TaxlotsUploadComponent } from './taxlots-upload.component';

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

beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ TaxlotsUploadComponent ]
})
.compileComponents();
}));

beforeEach(() => {
fixture = TestBed.createComponent(TaxlotsUploadComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});

it('should create', () => {
expect(component).toBeTruthy();
});
});
42 changes: 42 additions & 0 deletions src/app/taxlots-upload/taxlots-upload.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { Component, OnInit } from '@angular/core';
import { TaxLotService } from '../core/services/tax-lot/tax-lot.service';

@Component({
selector: 'app-taxlots-upload',
templateUrl: './taxlots-upload.component.html',
styleUrls: ['./taxlots-upload.component.scss']
})
export class TaxlotsUploadComponent implements OnInit {

constructor(private taxlotService: TaxLotService) { }

ngOnInit(): void {
}

handleFileInput(files: FileList): void {
if (files[0]) {
files[0].text().then(text => {
const geojson = JSON.parse(text);
const crs = geojson.crs ? geojson.crs : { type: 'name', properties: { name: 'EPSG:4326'} };

geojson.features.forEach(feature => {
const extra_data = feature.properties;
feature.geometry.crs = crs;

// extract non-extra_data attributes
const ubid = extra_data.UBID;
delete extra_data.UBID;

this.taxlotService.model.create({
extra_data: extra_data,
footprint: feature.geometry,
ulid: ubid
}).catch((err) => {
console.error(err);
});
});
})
}
}

}

0 comments on commit 6d0836f

Please sign in to comment.