-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Scenario project areas #1699
Scenario project areas #1699
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<mgl-vector-source | ||
id="scenarioProjectAreas" | ||
[tiles]="[vectorLayerUrl]"></mgl-vector-source> | ||
|
||
<mgl-layer | ||
id="map-project-areas-line" | ||
type="line" | ||
source="scenarioProjectAreas" | ||
[sourceLayer]="layerName" | ||
[paint]="{ | ||
'line-color': '#333', | ||
'line-width': 2 | ||
}"></mgl-layer> | ||
|
||
<mgl-layer | ||
id="map-project-areas-fill" | ||
type="fill" | ||
source="scenarioProjectAreas" | ||
[sourceLayer]="layerName" | ||
[paint]="paint"></mgl-layer> | ||
|
||
<mgl-layer | ||
id="map-project-areas-labels" | ||
type="symbol" | ||
source="scenarioProjectAreas" | ||
[sourceLayer]="layerName" | ||
[layout]="{ | ||
'text-field': ['get', 'rank'], | ||
'text-size': 14, | ||
'text-anchor': 'center', | ||
'text-justify': 'center' | ||
}" | ||
[paint]="{ | ||
'text-color': '#000', | ||
'text-halo-color': '#fff', | ||
'text-halo-width': 2 | ||
}"></mgl-layer> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { ComponentFixture, TestBed } from '@angular/core/testing'; | ||
|
||
import { MapProjectAreasComponent } from './map-project-areas.component'; | ||
import { MockDeclarations } from 'ng-mocks'; | ||
import { | ||
LayerComponent, | ||
VectorSourceComponent, | ||
} from '@maplibre/ngx-maplibre-gl'; | ||
|
||
describe('MapProjectAreasComponent', () => { | ||
let component: MapProjectAreasComponent; | ||
let fixture: ComponentFixture<MapProjectAreasComponent>; | ||
|
||
beforeEach(async () => { | ||
await TestBed.configureTestingModule({ | ||
imports: [MapProjectAreasComponent], | ||
declarations: MockDeclarations(VectorSourceComponent, LayerComponent), | ||
}).compileComponents(); | ||
|
||
fixture = TestBed.createComponent(MapProjectAreasComponent); | ||
component = fixture.componentInstance; | ||
fixture.detectChanges(); | ||
}); | ||
|
||
it('should create', () => { | ||
expect(component).toBeTruthy(); | ||
}); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import { Component, Input } from '@angular/core'; | ||
import { | ||
FeatureComponent, | ||
GeoJSONSourceComponent, | ||
LayerComponent, | ||
VectorSourceComponent, | ||
} from '@maplibre/ngx-maplibre-gl'; | ||
import { NgForOf } from '@angular/common'; | ||
import { getColorForProjectPosition } from '../../plan/plan-helpers'; | ||
import { LayerSpecification, Map as MapLibreMap } from 'maplibre-gl'; | ||
import { environment } from '../../../environments/environment'; | ||
|
||
@Component({ | ||
selector: 'app-map-project-areas', | ||
standalone: true, | ||
imports: [ | ||
FeatureComponent, | ||
GeoJSONSourceComponent, | ||
NgForOf, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are you still using this NgForOf? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. good catch |
||
LayerComponent, | ||
VectorSourceComponent, | ||
], | ||
templateUrl: './map-project-areas.component.html', | ||
styleUrl: './map-project-areas.component.scss', | ||
}) | ||
export class MapProjectAreasComponent { | ||
@Input() scenarioId!: number; | ||
@Input() mapLibreMap!: MapLibreMap; | ||
|
||
readonly layerName = 'project_areas_by_scenario'; | ||
readonly tilesUrl = | ||
environment.martin_server + 'project_areas_by_scenario/{z}/{x}/{y}'; | ||
|
||
constructor() {} | ||
|
||
get vectorLayerUrl() { | ||
return this.tilesUrl + `?scenario_id=${this.scenarioId}`; | ||
} | ||
|
||
paint: LayerSpecification['paint'] = { | ||
'fill-outline-color': '#000', | ||
'fill-color': this.getFillColors() as any, | ||
'fill-opacity': 0.5, | ||
}; | ||
|
||
getFillColors() { | ||
const defaultColor = '#00000050'; | ||
const matchExpression: (number | string | string[])[] = [ | ||
'match', | ||
['get', 'rank'], | ||
]; | ||
for (let i = 1; i < 11; i++) { | ||
matchExpression.push(i.toString(), getColorForProjectPosition(i)); | ||
} | ||
matchExpression.push(defaultColor); | ||
return matchExpression; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
<app-treatment-summary | ||
[treatmentPlanId]="treatmentPlanId"></app-treatment-summary> | ||
|
||
<app-treatment-map [treatmentPlanId]="treatmentPlanId"></app-treatment-map> | ||
<app-treatment-map | ||
[treatmentPlanId]="treatmentPlanId" | ||
[scenarioId]="scenarioId"></app-treatment-map> |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -41,7 +41,8 @@ export interface ScenarioResult { | |
status: ScenarioResultStatus; | ||
completed_at: string; | ||
result: { | ||
features: FeatureCollection[]; | ||
// this is the FeatureCollection[] | ||
features: FeatureCollection[]; // TODO this is actually Features[] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you need to update this before merging? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. no, i think that change will require a pr on its own |
||
type: string; | ||
}; | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit:I imagine we should talk about eventually storing these styles in a central place.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yep, not sure what's the best place yet but happy to do a second pass to centralize this!