Skip to content

Commit

Permalink
Toggle map on boundary click (#177)
Browse files Browse the repository at this point in the history
  • Loading branch information
wdantuma authored Aug 30, 2024
1 parent 782d8f8 commit 9832ab9
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 46 deletions.
1 change: 1 addition & 0 deletions src/app/app.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -787,6 +787,7 @@
(exitedMovingMap)="toggleMoveMap($event)"
(focusVessel)="switchActiveVessel($event)"
(info)="featureProperties($event)"
(chartSelected)="skres.chartSelected()"
(menuItemSelected)="
sidemenu.close(); handleContextMenuSelection($event)
"
Expand Down
3 changes: 2 additions & 1 deletion src/app/modules/map/fb-map.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -599,7 +599,8 @@

<!-- chart boundaries-->
@if(app.data.chartBounds) {
<fb-chart-bounds [zIndex]="250" [charts]="dfeat.charts"> </fb-chart-bounds>

<fb-chart-bounds [zIndex]="250" [charts]="dfeat.charts" (chartSelected)="onSelect($event)" > </fb-chart-bounds>
}
</ol-map>

Expand Down
15 changes: 14 additions & 1 deletion src/app/modules/map/fb-map.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ import { Feature as GeoJsonFeature } from 'geojson';

import { Convert } from 'src/app/lib/convert';
import { GeoUtils, Angle } from 'src/app/lib/geoutils';
import { Position } from 'src/app/types';
import { FBChart, FBResourceSelect, Position } from 'src/app/types';

import { AppInfo } from 'src/app/app.info';
import { SettingsMessage } from 'src/app/lib/services';
Expand Down Expand Up @@ -217,6 +217,7 @@ export class FBMapComponent implements OnInit, OnDestroy {
@Output() exitedMovingMap: EventEmitter<boolean> = new EventEmitter();
@Output() focusVessel: EventEmitter<string> = new EventEmitter();
@Output() menuItemSelected: EventEmitter<string> = new EventEmitter();
@Output() chartSelected:EventEmitter<FBResourceSelect> = new EventEmitter<FBResourceSelect>()

@ViewChild(MatMenuTrigger, { static: true }) contextMenu: MatMenuTrigger;

Expand Down Expand Up @@ -1034,6 +1035,18 @@ export class FBMapComponent implements OnInit, OnDestroy {
this.modifyEnd.emit(this.draw.forSave);
}

public onSelect(chart:FBChart) {
let e:boolean = false
this.dfeat.charts.forEach((i: FBChart) => {
if (i === chart) {
i[2] = !i[2];
e=i[2]
}
});
this.chartSelected.emit({ id: chart[0], value: e
});
}

// eslint-disable-next-line @typescript-eslint/no-explicit-any
private updateCoordsMeta(startCoords: any[], endCoords: any[], meta: any[]) {
if (!meta) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,25 @@ import {
OnDestroy,
OnInit,
Output,
SimpleChanges
SimpleChanges,
EventEmitter
} from '@angular/core';
import { Layer } from 'ol/layer';
import { Feature } from 'ol';
import VectorLayer from 'ol/layer/Vector';
import VectorSource from 'ol/source/Vector';
import { Style, Stroke, Fill, Text } from 'ol/style';
import { Style, Stroke, Fill, Text,RegularShape } from 'ol/style';
import { Polygon, Point } from 'ol/geom';
import { MapComponent } from '../map.component';
import { Extent } from '../models';
import { fromLonLatArray, mapifyCoords } from '../util';
import { AsyncSubject } from 'rxjs';
import { SKChart } from 'src/app/modules';
import { FBChart, FBCharts } from 'src/app/types';

const CHART_PROPERTY = "chart"
const COLOR_INDEX_PROPERTY = "colorIndex"
const boundStyles = ['red', 'magenta', 'blue', 'purple', 'green'];


// ** Show Chart bounds on map **
@Component({
Expand All @@ -38,7 +44,7 @@ export class ChartBoundsLayerComponent implements OnInit, OnDestroy, OnChanges {
*/
@Output() layerReady: AsyncSubject<Layer> = new AsyncSubject(); // AsyncSubject will only store the last value, and only publish it when the sequence is completed
// eslint-disable-next-line @typescript-eslint/no-explicit-any
@Input() charts: Array<[string, SKChart, boolean]> = [];
@Input() charts: FBCharts;
@Input() opacity: number;
@Input() visible: boolean;
@Input() extent: Extent;
Expand All @@ -47,8 +53,7 @@ export class ChartBoundsLayerComponent implements OnInit, OnDestroy, OnChanges {
@Input() maxResolution: number;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
@Input() layerProperties: { [index: string]: any };

private boundStyles = ['red', 'magenta', 'blue', 'purple', 'green'];
@Output() chartSelected: EventEmitter<FBChart> = new EventEmitter<FBChart>();

constructor(
protected changeDetectorRef: ChangeDetectorRef,
Expand All @@ -70,9 +75,21 @@ export class ChartBoundsLayerComponent implements OnInit, OnDestroy, OnChanges {
map.render();
this.layerReady.next(this.layer);
this.layerReady.complete();

// select
map.on('singleclick', (e) => {
if(this.layer) {
this.layer.getFeatures(e.pixel).then((f) => {
f.filter((f) => f.get(CHART_PROPERTY)).forEach((f) => {
this.chartSelected.emit(f.get(CHART_PROPERTY))
})
})
}
})
}
}


ngOnChanges(changes: SimpleChanges) {
if (this.layer) {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
Expand Down Expand Up @@ -104,9 +121,9 @@ export class ChartBoundsLayerComponent implements OnInit, OnDestroy, OnChanges {
}
}

parseChartBounds(charts: Array<[string, SKChart, boolean]> = this.charts) {
parseChartBounds(charts: FBCharts) {
const fa: Feature[] = [];
let i = 0;
let colorIndex = 0;

// backdrop
const f = new Feature({
Expand All @@ -125,7 +142,7 @@ export class ChartBoundsLayerComponent implements OnInit, OnDestroy, OnChanges {
f.setStyle(
new Style({
fill: new Fill({
color: 'rgba(255,255,255,0.5 )'
color: 'rgba(255,255,255,0.4 )'
})
})
);
Expand All @@ -138,22 +155,16 @@ export class ChartBoundsLayerComponent implements OnInit, OnDestroy, OnChanges {
// rectangle
const f = new Feature({
geometry: new Polygon(c),
name: w[1].name
name: w[0],
[CHART_PROPERTY]: w,
[COLOR_INDEX_PROPERTY]: colorIndex
});
f.setId('chart-bound.' + w[0]);
f.setStyle(this.buildStyle(i));
f.setStyle(this.buildStyles);
fa.push(f);
// label
const t = new Feature({
geometry: new Point(c[0][3]),
name: w[1].name
});
t.setId('chart-bound-label.' + w[0]);
t.setStyle(this.buildLabelStyle(w[0], i));
fa.push(t);
//
i++;
i = i === this.boundStyles.length ? 0 : i;
colorIndex++;
colorIndex = colorIndex === boundStyles.length ? 0 : colorIndex;
}
this.features = fa;
}
Expand Down Expand Up @@ -184,28 +195,29 @@ export class ChartBoundsLayerComponent implements OnInit, OnDestroy, OnChanges {
}

// build bounds rect style
buildStyle(styleIndex = 0): Style {
return new Style({
stroke: new Stroke({
color: this.boundStyles[styleIndex],
width: 3
})
});
}

// build bounds label style
buildLabelStyle(text: string, styleIndex = 0): Style {
return new Style({
text: new Text({
text: text,
offsetX: 5,
offsetY: 5,
fill: new Fill({
color: this.boundStyles[styleIndex]
buildStyles(feature: Feature): Style[] {
return [
new Style({
stroke: new Stroke({
color: boundStyles[feature.get(COLOR_INDEX_PROPERTY)],
}),
textAlign: 'left',
textBaseline: 'top'
})
});
fill: new Fill({
color: 'rgba(255,255,255,0.0 )' // needed for click
})
}),
new Style({
geometry:new Point((feature.getGeometry() as Polygon).getCoordinates()[0][3]),
text: new Text({
text: feature.get(CHART_PROPERTY)[0] ,
overflow: true,
offsetX: 5,
offsetY: 5,
fill: new Fill({
color: boundStyles[feature.get(COLOR_INDEX_PROPERTY)]
}),
textAlign: 'left',
textBaseline: 'top'
})
})]
}
}
1 change: 0 additions & 1 deletion src/app/modules/skresources/components/charts/chartlist.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,6 @@ export class ChartLayers implements OnInit {
@Component({
selector: 'chart-list',
standalone: true,
changeDetection: ChangeDetectionStrategy.OnPush,
templateUrl: './chartlist.html',
styleUrls: ['../resourcelist.css'],
imports: [
Expand Down

0 comments on commit 9832ab9

Please sign in to comment.