Skip to content

Instantly share code, notes, and snippets.

@gearmobile
Created April 24, 2019 07:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gearmobile/a3ba7181aa2a3e9b44b4676aee7cc315 to your computer and use it in GitHub Desktop.
Save gearmobile/a3ba7181aa2a3e9b44b4676aee7cc315 to your computer and use it in GitHub Desktop.
class Site extends React.Component {
constructor(props) {
super(props);
this.state = {
offices: []
};
this.getOffices = this.getOffices.bind(this);
}
componentDidMount() {
this.getOffices();
}
render() {
return (
<div>
<header className="info">
<h1>Одна большая компания</h1>
<p>Будем рады видеть вас в одном из наших офисов</p>
</header>
<main className="map map-container">
<Map points={this.state.offices} numberToShowMap={5} />
</main>
<button className="button" onClick={this.getOffices}>
Обновить местоположение офисов
</button>
</div>
);
}
getOffices() {
this.setState({
offices: new Array(random(1, 15, false))
.fill(0)
.map(() => ({ lon: random(-180, 180), lat: random(-90, 90) }))
});
}
}
const random = (lower = 0, upper = 1, floating = true) =>
floating
? Math.min(lower + Math.random() * (upper - lower), upper)
: lower + Math.floor(Math.random() * (upper - lower + 1));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment