Skip to content

Commit

Permalink
+ Graticule update
Browse files Browse the repository at this point in the history
  • Loading branch information
JamesCodesUFG committed Feb 7, 2025
1 parent db4b648 commit 4880b60
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 12 deletions.
25 changes: 14 additions & 11 deletions client/src/app/@core/services/map.service.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { Injectable } from '@angular/core';
import { BehaviorSubject, Observable } from 'rxjs';

import OlMap from 'ol/Map';
import { MapEvent, View } from 'ol';
import { Graticule, MapEvent, View } from 'ol';
import * as Proj from 'ol/proj';
import { defaults as defaultInteractions, Interaction } from 'ol/interaction';
import { Control, defaults as defaultControls } from 'ol/control';
Expand All @@ -15,13 +14,21 @@ const ZOOM_DEFAULT: number = 4.6;
const DEFAULT_LAT = -16.6958288;
const DEFAULT_LON = -49.4443537;

const GRATICULE = new Graticule({
visible: false,
zIndex: 100,
wrapX: false,
showLabels: true
});

export { MapService, ZOOM_LIMIT }

@Injectable({
providedIn: 'root',
})
class MapService {
private _map: OlMap = new OlMap({
layers: [ GRATICULE ],
view: new View({
center: Proj.fromLonLat([DEFAULT_LON, DEFAULT_LAT]),
zoom: ZOOM_DEFAULT,
Expand All @@ -33,10 +40,6 @@ class MapService {
controls: defaultControls({ attribution: false, zoom: false }).extend([]),
});

private _activeLayers: Array<BaseLayer> = [];

private $activeLayers = new BehaviorSubject<Array<BaseLayer>>(this._activeLayers);

constructor() {
this.setEvents();
}
Expand All @@ -45,19 +48,19 @@ class MapService {

get layers() { return this._map.getLayers().getArray(); }

public getActiveLayers(): Observable<BaseLayer[]> {
return this.$activeLayers;
public updateGraticule(visible: boolean) {
this.layers[0].setVisible(visible);
}

public addLayer(layer: BaseLayer): void {
if (!this._map.getLayers().getArray().every(element => element.get('key') != layer.get('key'))) return;
if (!this.layers.every(element => element.get('key') != layer.get('key'))) return;

this._map.addLayer(layer);
}

public addLayers(layers: Array<BaseLayer>): void {
layers.forEach((layer) => {
this._map.addLayer(layer);
layers.forEach((layer: BaseLayer) => {
this.addLayer(layer);
})
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { Subscription } from 'rxjs';

import { InputSwitchOnChangeEvent } from 'primeng/inputswitch';
import {AccordionTabCloseEvent, AccordionTabOpenEvent} from 'primeng/accordion';
import { MapService } from '@core/services/map.service';

const bmapKeys: string[] = ['mapbox', 'mapbox-dark', 'google', 'google-hybrid'];

Expand All @@ -41,10 +42,12 @@ class OptionsSidebarComponent {
{
key: 'graticule',
checked: false,
onChange: (checked: boolean) => this.onChangeGraticule(checked)
},
];

constructor(
private mapService: MapService,
private descriptorService: DescriptorService,
public localizationService: LocalizationService
) {
Expand Down Expand Up @@ -158,10 +161,20 @@ class OptionsSidebarComponent {
*/
public onChangeOption(key: string, event: InputSwitchOnChangeEvent): void {
this.options.forEach((option: any) => {
if (option.key === key) return;
if (option.key === key) {
option.onChange(event.checked);
}

option.checked = false;
});

console.log(event);

//this.mapService.updateGraticule(this.options.checked)
}

public onChangeGraticule(checked: boolean) {
this.mapService.updateGraticule(checked);
}
}

Expand Down

0 comments on commit 4880b60

Please sign in to comment.