Show address marker on map

This commit is contained in:
Kimmo Puputti 2017-03-17 13:02:19 +02:00
parent 34d257e3ca
commit 295420868f
4 changed files with 13 additions and 4 deletions

View file

@ -7,6 +7,7 @@ export const Empty = {
component: Map,
props: {
center: new LatLng(60.16502999999999, 24.940064399999983),
address: 'Sharetribe',
zoom: 22,
},
};

View file

@ -7,7 +7,7 @@ class Map extends Component {
if (!mapsLibLoaded) {
throw new Error('Google Maps API must be loaded for the Map component');
}
const { center, zoom } = this.props;
const { center, zoom, address } = this.props;
const centerLocation = { lat: center.lat, lng: center.lng };
const mapOptions = {
center: centerLocation,
@ -16,7 +16,13 @@ class Map extends Component {
// Disable zooming by scrolling
scrollwheel: false,
};
this.map = new window.google.maps.Map(this.el, mapOptions);
const map = new window.google.maps.Map(this.el, mapOptions);
// eslint-disable-next-line no-new
new window.google.maps.Marker({
position: centerLocation,
map,
title: address,
});
}
render() {
const { className, width, height } = this.props;
@ -42,6 +48,7 @@ Map.propTypes = {
width: oneOfType([number, string]),
height: oneOfType([number, string]),
center: propTypes.latlng.isRequired,
address: string.isRequired,
zoom: number,
};

View file

@ -56,9 +56,9 @@ export class ListingPageComponent extends Component {
const title = currentListing ? currentListing.attributes.title : '';
const description = currentListing ? currentListing.attributes.description : '';
const address = currentListing ? currentListing.attributes.address : '';
const geolocation = currentListing ? currentListing.attributes.geolocation : null;
const map = geolocation ? <Map center={geolocation} /> : null;
const map = geolocation ? <Map center={geolocation} address={address} /> : null;
// TODO Responsive image-objects need to be thought through when final image sizes are know
const images = currentListing && currentListing.images

View file

@ -8,6 +8,7 @@ exports[`ListingPage matches snapshot 1`] = `
}
} />
<Map
address="listing1 address"
center={
LatLng {
"lat": 40,