Skip to content

Commit

Permalink
Merge pull request #872 from sharetribe/click-static-map-to-dynamic
Browse files Browse the repository at this point in the history
Click static map to dynamic
  • Loading branch information
Gnito authored Jul 20, 2018
2 parents fbdc110 + 4a9b03f commit e619ea2
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 30 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ way to update this template, but currently, we follow a pattern:

---

## v1.2.2
* [change] Change static map to dynamic map when clicked.
[#871](https://github.com/sharetribe/flex-template-web/pull/871)

## v1.2.1
* [fix] Lazy load map only if the map is near current viewport.
[#871](https://github.com/sharetribe/flex-template-web/pull/871)
Expand Down
22 changes: 13 additions & 9 deletions src/components/Map/DynamicMap.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,21 @@ import config from '../../config';
const DynamicMap = withGoogleMap(props => {
const { center, zoom, address, coordinatesConfig } = props;

const { markerURI, anchorX, anchorY, width, height } = coordinatesConfig.customMarker;
const markerIcon = {
url: markerURI,
const { markerURI, anchorX, anchorY, width, height } = coordinatesConfig.customMarker || {};
const markerIcon = coordinatesConfig.customMarker
? {
icon: {
url: markerURI,

// The origin for this image is (0, 0).
origin: new window.google.maps.Point(0, 0),
size: new window.google.maps.Size(width, height),
anchor: new window.google.maps.Point(anchorX, anchorY),
};
// The origin for this image is (0, 0).
origin: new window.google.maps.Point(0, 0),
size: new window.google.maps.Size(width, height),
anchor: new window.google.maps.Point(anchorX, anchorY),
},
}
: {};

const marker = <Marker position={center} icon={markerIcon} title={address} />;
const marker = <Marker position={center} {...markerIcon} title={address} />;

const circleProps = {
options: coordinatesConfig.circleOptions,
Expand Down
3 changes: 3 additions & 0 deletions src/containers/ListingPage/ListingPage.css
Original file line number Diff line number Diff line change
Expand Up @@ -535,6 +535,9 @@
max-width: 640px;
max-height: 640px;
background-color: #eee;
padding: 0;
border: 0;
cursor: pointer;

@media (--viewportMedium) {
height: 75vh;
Expand Down
54 changes: 33 additions & 21 deletions src/containers/ListingPage/SectionMapMaybe.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react';
import React, { Component } from 'react';
import { string } from 'prop-types';
import { FormattedMessage } from 'react-intl';
import classNames from 'classnames';
Expand All @@ -9,31 +9,43 @@ import config from '../../config';

import css from './ListingPage.css';

const SectionMapMaybe = props => {
const { className, rootClassName, geolocation, publicData, listingId } = props;

if (!geolocation) {
return null;
class SectionMapMaybe extends Component {
constructor(props) {
super(props);
this.state = { isStatic: true };
}

const address = publicData.location ? publicData.location.address : '';
const classes = classNames(rootClassName || css.sectionMap, className);
render() {
const { className, rootClassName, geolocation, publicData, listingId } = this.props;

if (!geolocation) {
return null;
}

const address = publicData.location ? publicData.location.address : '';
const classes = classNames(rootClassName || css.sectionMap, className);

const mapProps = config.coordinates.fuzzy
? { obfuscatedCenter: obfuscatedCoordinates(geolocation, listingId ? listingId.uuid : null) }
: { address, center: geolocation };
const mapProps = config.coordinates.fuzzy
? { obfuscatedCenter: obfuscatedCoordinates(geolocation, listingId ? listingId.uuid : null) }
: { address, center: geolocation };

return (
<div className={classes}>
<h2 className={css.locationTitle}>
<FormattedMessage id="ListingPage.locationTitle" />
</h2>
<div className={css.map}>
<Map {...mapProps} useStaticMap />
return (
<div className={classes}>
<h2 className={css.locationTitle}>
<FormattedMessage id="ListingPage.locationTitle" />
</h2>
<button
className={css.map}
onClick={() => {
this.setState({ isStatic: false });
}}
>
<Map {...mapProps} useStaticMap={this.state.isStatic} />
</button>
</div>
</div>
);
};
);
}
}

SectionMapMaybe.defaultProps = {
rootClassName: null,
Expand Down

0 comments on commit e619ea2

Please sign in to comment.