Skip to content
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

First wms-layer added #1539

Open
wants to merge 2 commits into
base: feature/openLayers
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
209 changes: 209 additions & 0 deletions apps/web-mzima-client/src/app/core/helpers/map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,3 +101,212 @@ export const getMapLayers = () => {
},
};
};

interface WaterLayerParams {
LAYERS: string;
FORMAT: string;
TRANSPARENT: boolean;
TIME: string;
CRS: string;
exceptions: string;
styles: string;
}

interface WaterLayer {
attribution: string;
url: string;
params: WaterLayerParams;
}

export const getWaterLayer = (): WaterLayer[] => {
return [
{
attribution: 'Water Observations from space 2023',
url: 'https://ows.digitalearth.africa/wms?version=1.3.0',
params: {
LAYERS: 'wofs_ls_summary_annual',
FORMAT: 'image/png',
TRANSPARENT: true,
TIME: '2023-01-01',
CRS: 'EPSG:3857',
exceptions: 'XML',
styles: 'wofs_summary_annual_frequency',
},
},
{
attribution: 'Water Observations from space 2013',
url: 'https://ows.digitalearth.africa/wms?version=1.3.0',
params: {
LAYERS: 'wofs_ls_summary_annual',
FORMAT: 'image/png',
TRANSPARENT: true,
TIME: '2013-01-01',
CRS: 'EPSG:3857',
exceptions: 'XML',
styles: 'wofs_summary_annual_frequency',
},
},
];
};

interface RainfallLayer {
attribution: string;
url: string;
params: {
LAYERS: string;
FORMAT: string;
TRANSPARENT: boolean;
TIME: string;
CRS: string;
exceptions: string;
styles: string;
};
}

export const getRainfallLayer = (): RainfallLayer[] => {
return [
{
attribution: 'Rainfall january 1981',
url: 'https://ows.digitalearth.africa/wms?version=1.3.0?',
params: {
LAYERS: 'rainfall_chirps_monthly',
FORMAT: 'image/png',
TRANSPARENT: true,
TIME: '1981-01-01',
CRS: 'EPSG:3857',
exceptions: 'XML',
styles: 'rainfall_monthly',
},
},
{
attribution: 'Rainfall january 1986',
url: 'https://ows.digitalearth.africa/wms?version=1.3.0?',
params: {
LAYERS: 'rainfall_chirps_monthly',
FORMAT: 'image/png',
TRANSPARENT: true,
TIME: '1986-01-01',
CRS: 'EPSG:3857',
exceptions: 'XML',
styles: 'rainfall_monthly',
},
},
{
attribution: 'Rainfall january 1991',
url: 'https://ows.digitalearth.africa/wms?version=1.3.0?',
params: {
LAYERS: 'rainfall_chirps_monthly',
FORMAT: 'image/png',
TRANSPARENT: true,
TIME: '1991-01-01',
CRS: 'EPSG:3857',
exceptions: 'XML',
styles: 'rainfall_monthly',
},
},
{
attribution: 'Rainfall january 1996',
url: 'https://ows.digitalearth.africa/wms?version=1.3.0?',
params: {
LAYERS: 'rainfall_chirps_monthly',
FORMAT: 'image/png',
TRANSPARENT: true,
TIME: '1996-01-01',
CRS: 'EPSG:3857',
exceptions: 'XML',
styles: 'rainfall_monthly',
},
},
{
attribution: 'Rainfall january 2001',
url: 'https://ows.digitalearth.africa/wms?version=1.3.0?',
params: {
LAYERS: 'rainfall_chirps_monthly',
FORMAT: 'image/png',
TRANSPARENT: true,
TIME: '2001-01-01',
CRS: 'EPSG:3857',
exceptions: 'XML',
styles: 'rainfall_monthly',
},
},
{
attribution: 'Rainfall january 2006',
url: 'https://ows.digitalearth.africa/wms?version=1.3.0?',
params: {
LAYERS: 'rainfall_chirps_monthly',
FORMAT: 'image/png',
TRANSPARENT: true,
TIME: '2006-01-01',
CRS: 'EPSG:3857',
exceptions: 'XML',
styles: 'rainfall_monthly',
},
},
{
attribution: 'Rainfall january 2011',
url: 'https://ows.digitalearth.africa/wms?version=1.3.0?',
params: {
LAYERS: 'rainfall_chirps_monthly',
FORMAT: 'image/png',
TRANSPARENT: true,
TIME: '2011-01-01',
CRS: 'EPSG:3857',
exceptions: 'XML',
styles: 'rainfall_monthly',
},
},
{
attribution: 'Rainfall january 2016',
url: 'https://ows.digitalearth.africa/wms?version=1.3.0?',
params: {
LAYERS: 'rainfall_chirps_monthly',
FORMAT: 'image/png',
TRANSPARENT: true,
TIME: '2016-12-01',
CRS: 'EPSG:3857',
exceptions: 'XML',
styles: 'rainfall_monthly',
},
},
{
attribution: 'Rainfall january 2021 ',
url: 'https://ows.digitalearth.africa/wms?version=1.3.0?',
params: {
LAYERS: 'rainfall_chirps_monthly',
FORMAT: 'image/png',
TRANSPARENT: true,
TIME: '2021-12-01',
CRS: 'EPSG:3857',
exceptions: 'XML',
styles: 'rainfall_monthly',
},
},
{
attribution: 'Rainfall january 2024 ',
url: 'https://ows.digitalearth.africa/wms?version=1.3.0?',
params: {
LAYERS: 'rainfall_chirps_monthly',
FORMAT: 'image/png',
TRANSPARENT: true,
TIME: '2024-01-01',
CRS: 'EPSG:3857',
exceptions: 'XML',
styles: 'rainfall_monthly',
},
},
{
attribution: 'Rainfall january 2025 ',
url: 'https://ows.digitalearth.africa/wms?version=1.3.0?',
params: {
LAYERS: 'rainfall_chirps_monthly',
FORMAT: 'image/png',
TRANSPARENT: true,
TIME: '2025-01-01',
CRS: 'EPSG:3857',
exceptions: 'XML',
styles: 'rainfall_monthly',
},
},
];
};
48 changes: 45 additions & 3 deletions apps/web-mzima-client/src/app/map/map.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import Icon from 'ol/style/Icon';
import Overlay from 'ol/Overlay';
import { mapHelper, searchFormHelper } from '@helpers';
import TileWMS from 'ol/source/TileWMS';
import XYZ from 'ol/source/XYZ';
import LayerSwitcher from 'ol-layerswitcher';
import { BaseLayerOptions, GroupLayerOptions } from 'ol-layerswitcher';
Expand Down Expand Up @@ -44,6 +45,10 @@
surveyLayer!: VectorLayer;
post: any;
isPostLoading: boolean;
waterBodies: TileLayer[];
waterLayers: LayerGroup;
rainfallLayer: LayerGroup;
rainfall: TileLayer[];

constructor(
protected override router: Router,
Expand Down Expand Up @@ -73,6 +78,7 @@
ngOnInit(): void {
this.mapConfig = this.sessionService.getMapConfigurations();
this.initBaseLayers();
this.initWMSLayers();
this.initMap();
this.loadData();
}
Expand Down Expand Up @@ -100,6 +106,43 @@
} as GroupLayerOptions);
}

initWMSLayers() {
const wmsWater = mapHelper.getWaterLayer();
this.waterBodies = wmsWater.map((wms: any) => {
const newLayer = new TileLayer({
source: new TileWMS({
url: wms.url,
params: wms.params,
}),
});
newLayer.setProperties({ title: wms.attribution });
return newLayer;
});

this.waterLayers = new LayerGroup({
title: 'Water bodies',
layers: this.waterBodies,
combine: false,
} as GroupLayerOptions);

const wmsRainfall = mapHelper.getRainfallLayer();
this.rainfall = wmsRainfall.map((wms: any) => {
const newLayer = new TileLayer({
source: new TileWMS({
url: wms.url,
params: wms.params,
}),
});
newLayer.setProperties({ title: wms.attribution });
return newLayer;
});
this.rainfallLayer = new LayerGroup({
title: 'Rainfall',
layers: this.rainfall,
combine: false,
} as GroupLayerOptions);
}

initMap() {
const center = [this.mapConfig.default_view?.lon || 0, this.mapConfig.default_view?.lat || 0];
const view = new View({
Expand All @@ -109,15 +152,14 @@

this.map = new Map({
view: view,
layers: [this.baseMaps],
layers: [this.baseMaps, this.waterLayers, this.rainfallLayer],
target: 'ol-map',
});

const layerSwitcher = new LayerSwitcher({
reverse: true,
groupSelectStyle: 'children',
startActive: true,
activationMode: 'click',
startActive: false,
label: '',
collapseLabel: '',
});
Expand All @@ -131,7 +173,7 @@
this.getPostsGeoJson(1, defaultFilters);
}

getPostsGeoJson(pageNumber: number = 1, filter?: any) {

Check failure on line 176 in apps/web-mzima-client/src/app/map/map.component.ts

View workflow job for this annotation

GitHub Actions / test (16)

'pageNumber' is assigned a value but never used
this.postsService
.getGeojson(filter)
.pipe(untilDestroyed(this))
Expand Down
Loading