CenterInMyPosition and refactor

This commit is contained in:
vjrj 2017-12-06 19:24:42 +01:00
parent 93d9ca43f1
commit 3dc8edb4a8
10 changed files with 102 additions and 32 deletions

View file

@ -0,0 +1,45 @@
import React from 'react';
import './CenterInMyPosition.scss';
import { Button } from 'react-bootstrap';
import { translate } from 'react-i18next';
class CenterInMyPosition extends React.Component {
constructor(props) {
super(props);
}
onClick = (event) => {
console.log("Click?");
// this.props.onClick(event);
// https://atmospherejs.com/mdg/geolocation
// only with SSL:
// https://developer.mozilla.org/en-US/docs/Web/API/Geolocation/getCurrentPosition
// https://stackoverflow.com/questions/31608579/somethings-wrong-with-my-meteor-geolocation-functions
var userGeoLocation = new ReactiveVar(null);
var self = this;
Tracker.autorun(function (computation) {
userGeoLocation.set(Geolocation.latLng());
if (userGeoLocation.get()) {
//stop the tracker if we got something
var viewport = {
center: [userGeoLocation.get().lat, userGeoLocation.get().lng],
zoom: 11
}
self.props.onClick(viewport);
// self.onViewportChanged(viewport);
computation.stop();
}
});
}
render() {
return (
<Button bsStyle="default" onClick={(event) => this.onClick(event)}>
<i className="location"/>{this.props.t("Centrar el mapa en tu ubicación")}
</Button>
)
}
}
export default translate([], { wait: true }) (CenterInMyPosition);

View file

@ -0,0 +1,9 @@
i.location {
background: url(/my_location.svg) no-repeat top left;
background-size: contain;
cursor: pointer;
display: inline-block;
height: 30px;
width: 35px;
vertical-align: middle;
}