Skip to content

Commit

Permalink
feat(examples): restore the original api key mechanism
Browse files Browse the repository at this point in the history
  • Loading branch information
mrMetalWood committed Nov 7, 2023
1 parent cc98827 commit bf106e9
Show file tree
Hide file tree
Showing 11 changed files with 71 additions and 41 deletions.
4 changes: 3 additions & 1 deletion examples/_template/src/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ import {createRoot} from 'react-dom/client';

import {APIProvider, Map} from '@vis.gl/react-google-maps';

const App = () => <APIProvider apiKey=""></APIProvider>;
const API_KEY = process.env.GOOGLE_MAPS_API_KEY as string;

const App = () => <APIProvider apiKey={API_KEY}></APIProvider>;

export default App;

Expand Down
18 changes: 11 additions & 7 deletions examples/_template/vite.config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
export default {
define: {
'process.env.GOOGLE_MAPS_API_KEY': JSON.stringify(
process.env.GOOGLE_MAPS_API_KEY
)
}
};
import {defineConfig, loadEnv} from 'vite';

export default defineConfig(({mode}) => {
const {GOOGLE_MAPS_API_KEY = ''} = loadEnv(mode, process.cwd(), '');

return {
define: {
'process.env.GOOGLE_MAPS_API_KEY': JSON.stringify(GOOGLE_MAPS_API_KEY)
}
};
});
4 changes: 3 additions & 1 deletion examples/basic-map/src/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ import {createRoot} from 'react-dom/client';
import {APIProvider, Map} from '@vis.gl/react-google-maps';
import ControlPanel from './control-panel';

const API_KEY = process.env.GOOGLE_MAPS_API_KEY as string;

const App = () => (
<APIProvider apiKey="">
<APIProvider apiKey={API_KEY}>
<Map
zoom={3}
center={{lat: 22.54992, lng: 0}}
Expand Down
18 changes: 11 additions & 7 deletions examples/basic-map/vite.config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
export default {
define: {
'process.env.GOOGLE_MAPS_API_KEY': JSON.stringify(
process.env.GOOGLE_MAPS_API_KEY
)
}
};
import {defineConfig, loadEnv} from 'vite';

export default defineConfig(({mode}) => {
const {GOOGLE_MAPS_API_KEY = ''} = loadEnv(mode, process.cwd(), '');

return {
define: {
'process.env.GOOGLE_MAPS_API_KEY': JSON.stringify(GOOGLE_MAPS_API_KEY)
}
};
});
4 changes: 3 additions & 1 deletion examples/change-map-id/src/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,15 @@ const MAP_CONFIGS: MapConfig[] = [
}
];

const API_KEY = process.env.GOOGLE_MAPS_API_KEY as string;

const App = () => {
const [mapConfig, setMapConfig] = useState<MapConfig>(MAP_CONFIGS[0]);
const [infowindowOpen, setInfowindowOpen] = useState(true);
const [markerRef, marker] = useMarkerRef();

return (
<APIProvider apiKey="">
<APIProvider apiKey={API_KEY}>
<Map
mapId={mapConfig.mapId}
mapTypeId={mapConfig.mapTypeId}
Expand Down
18 changes: 11 additions & 7 deletions examples/change-map-id/vite.config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
export default {
define: {
'process.env.GOOGLE_MAPS_API_KEY': JSON.stringify(
process.env.GOOGLE_MAPS_API_KEY
)
}
};
import {defineConfig, loadEnv} from 'vite';

export default defineConfig(({mode}) => {
const {GOOGLE_MAPS_API_KEY = ''} = loadEnv(mode, process.cwd(), '');

return {
define: {
'process.env.GOOGLE_MAPS_API_KEY': JSON.stringify(GOOGLE_MAPS_API_KEY)
}
};
});
4 changes: 3 additions & 1 deletion examples/deckgl-overlay/src/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ const DATA_URL =
import type {Feature, GeoJSON} from 'geojson';
import ControlPanel from './control-panel';

const API_KEY = process.env.GOOGLE_MAPS_API_KEY as string;

const App = () => {
const [data, setData] = useState<GeoJSON | null>(null);

Expand All @@ -22,7 +24,7 @@ const App = () => {
}, []);

return (
<APIProvider apiKey="">
<APIProvider apiKey={API_KEY}>
<Map
center={{lat: 37.74, lng: -122.4}}
zoom={11}
Expand Down
18 changes: 11 additions & 7 deletions examples/deckgl-overlay/vite.config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
export default {
define: {
'process.env.GOOGLE_MAPS_API_KEY': JSON.stringify(
process.env.GOOGLE_MAPS_API_KEY
)
}
};
import {defineConfig, loadEnv} from 'vite';

export default defineConfig(({mode}) => {
const {GOOGLE_MAPS_API_KEY = ''} = loadEnv(mode, process.cwd(), '');

return {
define: {
'process.env.GOOGLE_MAPS_API_KEY': JSON.stringify(GOOGLE_MAPS_API_KEY)
}
};
});
4 changes: 3 additions & 1 deletion examples/markers-and-infowindows/src/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@ import ControlPanel from './control-panel';
import {MovingMarker} from './moving-marker';
import {MarkerWithInfowindow} from './marker-with-infowindow';

const API_KEY = process.env.GOOGLE_MAPS_API_KEY as string;

const App = () => {
return (
<APIProvider apiKey="" libraries={['marker']}>
<APIProvider apiKey={API_KEY} libraries={['marker']}>
<Map
mapId={'bf51a910020fa25a'}
zoom={3}
Expand Down
18 changes: 11 additions & 7 deletions examples/markers-and-infowindows/vite.config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
export default {
define: {
'process.env.GOOGLE_MAPS_API_KEY': JSON.stringify(
process.env.GOOGLE_MAPS_API_KEY
)
}
};
import {defineConfig, loadEnv} from 'vite';

export default defineConfig(({mode}) => {
const {GOOGLE_MAPS_API_KEY = ''} = loadEnv(mode, process.cwd(), '');

return {
define: {
'process.env.GOOGLE_MAPS_API_KEY': JSON.stringify(GOOGLE_MAPS_API_KEY)
}
};
});
2 changes: 1 addition & 1 deletion examples/vite.config.local.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {defineConfig, loadEnv} from 'vite';
import {resolve} from 'node:path';

export default defineConfig(({mode}) => {
const {GOOGLE_MAPS_API_KEY} = loadEnv(mode, process.cwd(), '');
const {GOOGLE_MAPS_API_KEY = ''} = loadEnv(mode, process.cwd(), '');

return {
define: {
Expand Down

0 comments on commit bf106e9

Please sign in to comment.