Skip to content

Commit

Permalink
Map: add OpenFreeMap provider (#770)
Browse files Browse the repository at this point in the history
  • Loading branch information
zbycz authored Nov 15, 2024
1 parent 248c7bc commit 48e6eae
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/components/LayerSwitcher/LayerSwitcherContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { osmappLayers } from './osmappLayers';
import { Layer, useMapStateContext, View } from '../utils/MapStateContext';
import { Overlays } from './Overlays';
import { AddUserLayerButton } from './AddLayerButton';
import WarningIcon from '@mui/icons-material/Warning';

type AllLayers = {
basemapLayers: Layer[];
Expand Down Expand Up @@ -90,7 +91,7 @@ export const LayerSwitcherContent = () => {
arrow
placement="top-end"
>
<WrongLocation fontSize="small" color="secondary" />
<WarningIcon fontSize="small" color="secondary" />
</Tooltip>
)}

Expand Down
9 changes: 9 additions & 0 deletions src/components/LayerSwitcher/osmappLayers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,15 @@ export const osmappLayers: Layers = {
Icon: ExploreIcon,
attribution: ['maptiler', 'osm'],
},
basicOfr: {
name: `${t('layers.basic')} OpenFreeMap`,
type: 'basemap',
Icon: ExploreIcon,
attribution: [
'<a href="https://openfreemap.org" target="_blank">OpenFreeMap</a> © <a href="https://www.openmaptiles.org/" target="_blank">OpenMapTiles</a>',
'osm',
],
},
makinaAfrica: {
name: t('layers.makina_africa'),
type: 'basemap',
Expand Down
15 changes: 15 additions & 0 deletions src/components/Map/behaviour/useUpdateStyle.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,25 @@ import { Layer } from '../../utils/MapStateContext';
import { setUpHover } from './featureHover';
import { layersWithOsmId } from '../helpers';

const ofrBasicStyle = {
...basicStyle,
layers: basicStyle.layers.map((layer) =>
(layer as any).source === 'maptiler_planet'
? {
...layer,
source: 'ofr_planet',
}
: layer,
),
};

const getBaseStyle = (key: string): StyleSpecification => {
if (key === 'basic') {
return basicStyle;
}
if (key === 'basicOfr') {
return ofrBasicStyle;
}
if (key === 'makinaAfrica') {
return makinaAfricaStyle;
}
Expand Down
4 changes: 4 additions & 0 deletions src/components/Map/consts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ export const OSMAPP_SOURCES: Record<string, SourceSpecification> = {
type: 'vector' as const,
url: `https://api.maptiler.com/tiles/v3/tiles.json?key=${apiKey}`,
},
ofr_planet: {
type: 'vector' as const,
url: `https://tiles.openfreemap.org/planet`,
},
contours: {
type: 'vector' as const,
url: `https://api.maptiler.com/tiles/contours/tiles.json?key=${apiKey}`,
Expand Down

0 comments on commit 48e6eae

Please sign in to comment.