feat(maps): init google maps

This commit is contained in:
2021-01-21 21:17:12 +00:00
parent 9907861e00
commit 3e5c6b16a0
7 changed files with 65 additions and 1 deletions

View File

@@ -1,10 +1,12 @@
const path = require("path"); const path = require("path");
const { GMAPS_APIKEY } = process.env;
module.exports = { module.exports = {
siteMetadata: { siteMetadata: {
title: `ABC Project Design`, title: `ABC Project Design`,
description: `Easy as ABC`, description: `Easy as ABC`,
keywords: `Foo bar baz`, keywords: `Foo bar baz`,
secrets: { GMAPS_APIKEY },
navData: [ navData: [
{ {
title: "Home", title: "Home",

5
package-lock.json generated
View File

@@ -9663,6 +9663,11 @@
} }
} }
}, },
"google-maps-react": {
"version": "2.0.6",
"resolved": "https://registry.npmjs.org/google-maps-react/-/google-maps-react-2.0.6.tgz",
"integrity": "sha512-M8Eo9WndfQEfxcmm6yRq03qdJgw1x6rQmJ9DN+a+xPQ3K7yNDGkVDbinrf4/8vcox7nELbeopbm4bpefKewWfQ=="
},
"got": { "got": {
"version": "8.3.2", "version": "8.3.2",
"resolved": "https://registry.npmjs.org/got/-/got-8.3.2.tgz", "resolved": "https://registry.npmjs.org/got/-/got-8.3.2.tgz",

View File

@@ -29,6 +29,7 @@
"gatsby-plugin-sharp": "^2.11.2", "gatsby-plugin-sharp": "^2.11.2",
"gatsby-source-filesystem": "^2.8.1", "gatsby-source-filesystem": "^2.8.1",
"gatsby-transformer-sharp": "^2.9.0", "gatsby-transformer-sharp": "^2.9.0",
"google-maps-react": "^2.0.6",
"react": "^17.0.1", "react": "^17.0.1",
"react-dom": "^17.0.1", "react-dom": "^17.0.1",
"react-helmet": "^6.1.0", "react-helmet": "^6.1.0",

View File

@@ -9,6 +9,7 @@ export { default as Icon } from "./icon";
export { default as IconWithContent } from "./icon-with-content"; export { default as IconWithContent } from "./icon-with-content";
export { default as InputText } from "./input-text"; export { default as InputText } from "./input-text";
export { default as Link } from "./link"; export { default as Link } from "./link";
export { default as Map } from "./map";
export { default as MenuButton } from "./menu-button"; export { default as MenuButton } from "./menu-button";
export { default as NavItem } from "./nav-item"; export { default as NavItem } from "./nav-item";
export { default as NavLink } from "./nav-link"; export { default as NavLink } from "./nav-link";

33
src/components/map.js Normal file
View File

@@ -0,0 +1,33 @@
import React from "react";
import { useStaticQuery, graphql } from "gatsby";
import { GoogleApiWrapper, Map } from "google-maps-react";
const MapContainer = ({ children, google, height = "300px", ...other }) => (
<Map
style={{ height }}
containerStyle={{ position: "relative", height }}
google={google}
{...other}
>
{children}
</Map>
);
export default function CustomMap({ ...other }) {
const data = useStaticQuery(graphql`
query {
site {
siteMetadata {
secrets {
GMAPS_APIKEY
}
}
}
}
`);
const Wrapper = GoogleApiWrapper({
apiKey: data.site.siteMetadata.secrets.GMAPS_APIKEY
})(MapContainer);
return <Wrapper {...other} />;
}

View File

@@ -127,7 +127,7 @@ export default function Layout({ children }) {
styles={ styles={
navOpen && { navOpen && {
body: { body: {
"overflow-y": "hidden" overflowY: "hidden"
} }
} }
} }

View File

@@ -1,5 +1,6 @@
import React, { useState } from "react"; import React, { useState } from "react";
import { graphql } from "gatsby"; import { graphql } from "gatsby";
import { Marker } from "google-maps-react";
import Layout from "../layout"; import Layout from "../layout";
import { import {
Button, Button,
@@ -8,6 +9,7 @@ import {
IconWithContent, IconWithContent,
InputText, InputText,
Link, Link,
Map,
Section, Section,
Text Text
} from "../components"; } from "../components";
@@ -129,6 +131,26 @@ export default function Index({ data }) {
)} )}
</div> </div>
</Section> </Section>
<Map
initialCenter={{
lat: 51.5614,
lng: 0.1071
}}
zoom={10}
scrollwheel={false}
draggable={false}
keyboardShortcuts={false}
disableDoubleClickZoom={false}
zoomControl={false}
mapTypeContol={false}
scaleControl={false}
streetViewControl={false}
panControl={false}
rotateControl={false}
fullscreenControl={false}
>
<Marker title={"ABC Project Design Ltd"} />
</Map>
</Layout> </Layout>
); );
} }