Skip to content

Commit

Permalink
moving things to own files
Browse files Browse the repository at this point in the history
  • Loading branch information
Pablo Lopez committed Aug 28, 2024
1 parent 8a71f87 commit 36afed1
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
[value]="t"
[id]="'layer-' + t"
name="baseLayer"
[checked]="t === defaultLayer"
(click)="updateBaseLayer(t)" />
<label [for]="'layer-' + t">{{ t }}</label>
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { Component } from '@angular/core';
import { NgForOf } from '@angular/common';
import {
baseLayerStyles,
BaseLayerType,
MapConfigState,
} from '../treatment-map/map-config.state';
import { NgForOf } from '@angular/common';
DEFAULT_BASE_MAP,
} from '../treatment-map/map-base-layers';
import { MapConfigState } from '../treatment-map/map-config.state';

@Component({
selector: 'app-map-base-layer',
Expand All @@ -15,6 +16,7 @@ import { NgForOf } from '@angular/common';
})
export class MapBaseLayerComponent {
baseLayers = Object.keys(baseLayerStyles) as BaseLayerType[];
readonly defaultLayer = DEFAULT_BASE_MAP;

constructor(private mapConfigState: MapConfigState) {}

Expand Down
47 changes: 47 additions & 0 deletions src/interface/src/app/treatments/treatment-map/map-base-layers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { MapOptions } from 'maplibre-gl';
import { environment } from '../../../environments/environment';

type StadiaBaseMap = 'road';
type ArcgisRest = 'terrain' | 'satellite';

export const DEFAULT_BASE_MAP: StadiaBaseMap = 'road';
export type BaseLayerType = StadiaBaseMap | ArcgisRest;

export const baseLayerStyles: Record<BaseLayerType, MapOptions['style']> = {
road:
'https://tiles.stadiamaps.com/styles/alidade_smooth.json?api_key=' +
environment.stadiamaps_key,

terrain: rasterSource(
'worldTerrain',
'https://services.arcgisonline.com/ArcGIS/rest/services/World_Terrain_Base/MapServer/tile/{z}/{y}/{x}'
),
satellite: rasterSource(
'restSatellite',
'https://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}'
),
};

function rasterSource(sourceName: string, url: string): MapOptions['style'] {
return {
version: 8,
metadata: {
'mapbox:autocomposite': true,
},
glyphs: 'https://demotiles.maplibre.org/font/{fontstack}/{range}.pbf',
sources: {
[sourceName]: {
type: 'raster',
tiles: [url],
tileSize: 256,
},
},
layers: [
{
id: sourceName + '-layer',
type: 'raster',
source: sourceName,
},
],
};
}
52 changes: 5 additions & 47 deletions src/interface/src/app/treatments/treatment-map/map-config.state.ts
Original file line number Diff line number Diff line change
@@ -1,52 +1,10 @@
import { BehaviorSubject, map } from 'rxjs';
import { Injectable } from '@angular/core';
import { environment } from '../../../environments/environment';
import { MapOptions } from 'maplibre-gl';

type StadiaBaseMap = 'road';
type ArcgisRest = 'terrain' | 'satellite';

const DEFAULT_BASE_MAP: StadiaBaseMap = 'road';
export type BaseLayerType = StadiaBaseMap | ArcgisRest;

function rasterSource(sourceName: string, url: string): MapOptions['style'] {
return {
version: 8,
metadata: {
'mapbox:autocomposite': true,
},
glyphs: 'https://demotiles.maplibre.org/font/{fontstack}/{range}.pbf',
sources: {
[sourceName]: {
type: 'raster',
tiles: [url],
tileSize: 256,
},
},
layers: [
{
id: sourceName + '-layer',
type: 'raster',
source: sourceName,
},
],
};
}

export const baseLayerStyles: Record<BaseLayerType, MapOptions['style']> = {
road:
'https://tiles.stadiamaps.com/styles/alidade_smooth.json?api_key=' +
environment.stadiamaps_key,

terrain: rasterSource(
'worldTerrain',
'https://services.arcgisonline.com/ArcGIS/rest/services/World_Terrain_Base/MapServer/tile/{z}/{y}/{x}'
),
satellite: rasterSource(
'restSatellite',
'https://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}'
),
};
import {
baseLayerStyles,
BaseLayerType,
DEFAULT_BASE_MAP,
} from './map-base-layers';

@Injectable()
export class MapConfigState {
Expand Down

0 comments on commit 36afed1

Please sign in to comment.