I'm trying to reproduce the example in https://tomchentw.github.io/react-google-maps/#groundoverlay in a React project created with create-react-app
; what I have so far is at https://github.com/khpeek/trailmaps.
In src/components
, I have a groundOverlay.js
as follows:
import React from 'react';
const { compose } = require("recompose");
const {
withScriptjs,
withGoogleMap,
GoogleMap,
GroundOverlay,
} = require("react-google-maps");
const MapWithGroundOverlay = compose(
withScriptjs,
withGoogleMap
)(props =>
<GoogleMap
defaultZoom={12}
defaultCenter={{lat: 40.740, lng: -74.18}}
>
<GroundOverlay
defaultUrl="https://www.lib.utexas.edu/maps/historical/newark_nj_1922.jpg"
defaultBounds={new google.maps.LatLngBounds(
new google.maps.LatLng(40.712216, -74.22655),
new google.maps.LatLng(40.773941, -74.12544)
)}
defaultOpacity={.5}
/>
</GoogleMap>
);
Then, in App.js
, I have
import React, { Component } from 'react';
import './App.css';
import MapWithAnOverlayView from './components/overlayView';
import MapWithGroundOverlay from './components/groundOverlay';
class App extends Component {
render() {
return (
<div className="App">
<header className="App-header">
<h1 className="App-title">Custom Overlay</h1>
</header>
<MapWithGroundOverlay
googleMapURL="https://maps.googleapis.com/maps/api/js?key=AIzaSyBimnrhiugaGSNN8WnsjpzMNJcrH_T60GI&v=3.exp&libraries=geometry,drawing,places"
loadingElement={<div style={{ height: `100%` }} />}
containerElement={<div style={{ height: `400px` }} />}
mapElement={<div style={{ height: `100%` }} />}
/>
</div>
);
}
}
export default App;
However, I'm getting the following error:
Any idea why this is not working? Is this not the right way to do it?
You need to define for eslint that
google
is the global variable likeYou can put this at the top of the file where you use
To make your code work, you need to also export correctly component from the
groundOverlay.js
file, like this:When you do this, it should work, screen below.
I will create a PR to your repo, so you will can merge it and continue working.
Pull request created: https://github.com/khpeek/trailmaps/pull/1
try to use
declare var google;
before @ComponentExample: