Abstract away map provider

This commit is contained in:
Kimmo Puputti 2018-08-13 14:50:54 +03:00
parent afe9cad777
commit ac093bf89e
2 changed files with 10 additions and 8 deletions

View file

@ -0,0 +1,6 @@
export { default as DynamicMap } from './DynamicGoogleMap';
export { default as StaticMap } from './StaticGoogleMap';
export const isMapsLibLoaded = () => {
return typeof window !== 'undefined' && window.google && window.google.maps;
};

View file

@ -3,9 +3,8 @@ import { bool, number, object, string } from 'prop-types';
import classNames from 'classnames';
import { propTypes } from '../../util/types';
import config from '../../config';
import { StaticMap, DynamicMap, isMapsLibLoaded } from './GoogleMap';
import DynamicMap from './DynamicGoogleMap';
import StaticMap from './StaticGoogleMap';
import css from './Map.css';
export class Map extends Component {
@ -34,15 +33,12 @@ export class Map extends Component {
}
const location = coordinatesConfig.fuzzy ? obfuscatedCenter : center;
const centerLocationForGoogleMap = { lat: location.lat, lng: location.lng };
const isMapsLibLoaded = typeof window !== 'undefined' && window.google && window.google.maps;
return !isMapsLibLoaded ? (
return !isMapsLibLoaded() ? (
<div className={classes} />
) : useStaticMap ? (
<StaticMap
center={centerLocationForGoogleMap}
center={location}
zoom={zoom}
address={address}
coordinatesConfig={coordinatesConfig}
@ -51,7 +47,7 @@ export class Map extends Component {
<DynamicMap
containerElement={<div className={classes} onClick={this.onMapClicked} />}
mapElement={<div className={mapClasses} />}
center={centerLocationForGoogleMap}
center={location}
zoom={zoom}
address={address}
coordinatesConfig={coordinatesConfig}