Update map components
This commit is contained in:
parent
bdcb9a6de9
commit
2ef2fee802
2 changed files with 20 additions and 9 deletions
|
|
@ -58,10 +58,13 @@ class SelectionMap extends Component {
|
||||||
|
|
||||||
updatePosition() {
|
updatePosition() {
|
||||||
const { lat, lng } = this.marker.leafletElement.getLatLng();
|
const { lat, lng } = this.marker.leafletElement.getLatLng();
|
||||||
|
const currentDistance = this.state.distance;
|
||||||
this.setState({
|
this.setState({
|
||||||
marker: [lat, lng],
|
marker: [lat, lng],
|
||||||
modified: true
|
modified: true
|
||||||
});
|
});
|
||||||
|
console.log(currentDistance);
|
||||||
|
this.props.onSelection({ lat, lng, currentDistance });
|
||||||
this.fit();
|
this.fit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -73,11 +76,12 @@ class SelectionMap extends Component {
|
||||||
addScale() {
|
addScale() {
|
||||||
// https://www.npmjs.com/package/leaflet-graphicscale
|
// https://www.npmjs.com/package/leaflet-graphicscale
|
||||||
const map = this.getMap();
|
const map = this.getMap();
|
||||||
var options = {
|
const options = {
|
||||||
fill: 'fill',
|
fill: 'fill',
|
||||||
showSubunits: true
|
showSubunits: true
|
||||||
};
|
};
|
||||||
var graphicScale = L.control.graphicScale([options]).addTo(map);
|
// var graphicScale =
|
||||||
|
Leaflet.control.graphicScale([options]).addTo(map);
|
||||||
}
|
}
|
||||||
|
|
||||||
doSubs() { // event param not used
|
doSubs() { // event param not used
|
||||||
|
|
@ -88,11 +92,9 @@ class SelectionMap extends Component {
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
this.state.center = !this.state.modified && this.props.lat?
|
this.state.center = !this.state.modified && this.props.lat? [this.props.lat, this.props.lng]: this.state.center;
|
||||||
[this.props.lat, this.props.lng]: this.state.center;
|
this.state.marker = !this.state.modified && this.props.lat? [this.props.lat, this.props.lng]: this.state.marker;
|
||||||
this.state.marker = !this.state.modified && this.props.lat?
|
this.state.distance = !this.state.modified? this.props.distance: this.state.distance;
|
||||||
[this.props.lat, this.props.lng]: this.state.marker;
|
|
||||||
this.state.distance = this.props.distance;
|
|
||||||
this.state.modified = false;
|
this.state.modified = false;
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
|
|
@ -142,12 +144,16 @@ class SelectionMap extends Component {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
SelectionMap.defaultProps = {
|
||||||
|
distance: 10
|
||||||
|
};
|
||||||
|
|
||||||
SelectionMap.propTypes = {
|
SelectionMap.propTypes = {
|
||||||
history: PropTypes.object.isRequired,
|
history: PropTypes.object.isRequired,
|
||||||
lat: PropTypes.number,
|
lat: PropTypes.number,
|
||||||
lng: PropTypes.number,
|
lng: PropTypes.number,
|
||||||
distance: PropTypes.number
|
distance: PropTypes.number,
|
||||||
|
onSelection: PropTypes.func.isRequired
|
||||||
};
|
};
|
||||||
|
|
||||||
export default translate([], { wait: true })(SelectionMap);
|
export default translate([], { wait: true })(SelectionMap);
|
||||||
|
|
|
||||||
|
|
@ -36,6 +36,10 @@ class FireSubscription extends React.Component {
|
||||||
this.setState(update(this.state, {$merge: {distance: value}}));
|
this.setState(update(this.state, {$merge: {distance: value}}));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
onSelection(value) {
|
||||||
|
this.setState(update(this.state, {$merge: {lat: value.lat, lng: value.lng, distance: value.distance}}));
|
||||||
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
// https://developers.google.com/places/web-service/search
|
// https://developers.google.com/places/web-service/search
|
||||||
// https://github.com/kenny-hibino/react-places-autocomplete/blob/master/demo/Demo.js
|
// https://github.com/kenny-hibino/react-places-autocomplete/blob/master/demo/Demo.js
|
||||||
|
|
@ -65,8 +69,9 @@ class FireSubscription extends React.Component {
|
||||||
<SelectionMap
|
<SelectionMap
|
||||||
lat={this.state.lat}
|
lat={this.state.lat}
|
||||||
lng={this.state.lng}
|
lng={this.state.lng}
|
||||||
distance={this.state.distance || 10}
|
distance={this.state.distance}
|
||||||
history={this.props.history}
|
history={this.props.history}
|
||||||
|
onSelection={(state) => this.onSelection(state)}
|
||||||
/>
|
/>
|
||||||
</Row>
|
</Row>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue