Update Map.tsx
This commit is contained in:
parent
d1a5138c6e
commit
31406d48e3
@ -39,11 +39,7 @@ export type MapProps = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export function Map({
|
export function Map({
|
||||||
tile = {
|
tile = undefined,
|
||||||
url: 'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',
|
|
||||||
attribution:
|
|
||||||
'© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors',
|
|
||||||
},
|
|
||||||
layers = [
|
layers = [
|
||||||
{
|
{
|
||||||
data: null,
|
data: null,
|
||||||
@ -63,7 +59,7 @@ export function Map({
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
tileEnvVars
|
tileEnvVars
|
||||||
extract all environment variables thats starts with NEXT_PUBLIC_MAP_TILE_.
|
extract all environment variables thats starts with NEXT_PUBLIC_MAP_TILE_PROVIDER_.
|
||||||
the variables names are the same as the TileLayer object properties:
|
the variables names are the same as the TileLayer object properties:
|
||||||
- url:
|
- url:
|
||||||
- attribution
|
- attribution
|
||||||
@ -76,14 +72,22 @@ export function Map({
|
|||||||
see TileLayerOptions inteface
|
see TileLayerOptions inteface
|
||||||
*/
|
*/
|
||||||
const tileEnvVars = Object.keys(process?.env)
|
const tileEnvVars = Object.keys(process?.env)
|
||||||
.filter((key) => key.startsWith('NEXT_PUBLIC_MAP_TILE_'))
|
.filter((key) => key.startsWith('NEXT_PUBLIC_MAP_TILE_PROVIDER_'))
|
||||||
.reduce((obj, key) => {
|
.reduce((obj, key) => {
|
||||||
obj[key.split('NEXT_PUBLIC_MAP_TILE_')[1]] = process.env[key];
|
obj[key.split('NEXT_PUBLIC_MAP_TILE_PROVIDER_')[1]] = process.env[key];
|
||||||
return obj;
|
return obj;
|
||||||
}, {});
|
}, {});
|
||||||
|
|
||||||
//tileData prioritizes properties passed through component over those passed through .env variables
|
//tileData prioritizes properties passed through component over those passed through .env variables
|
||||||
const tileData = Object.assign(tileEnvVars, tile);
|
let tileData = Object.assign(tileEnvVars, tile);
|
||||||
|
|
||||||
|
tileData = tileData.url
|
||||||
|
? tileData
|
||||||
|
: {
|
||||||
|
url: 'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',
|
||||||
|
attribution:
|
||||||
|
'© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors',
|
||||||
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const loadDataPromises = layers.map(async (layer) => {
|
const loadDataPromises = layers.map(async (layer) => {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user