Fix report fetching and closest report emphasis

This commit is contained in:
Lucas Verney 2019-01-17 22:43:13 +01:00
parent a8f99cbaeb
commit 60e3565561
5 changed files with 23 additions and 14 deletions

View File

@ -254,9 +254,13 @@ export default {
},
onMoveEnd() {
const view = this.map.getView();
if (this.onMapCenterManualUpdate && !this.isProgrammaticMove) {
if (this.onMapCenterUpdate) {
const mapCenterLonLat = toLonLat(view.getCenter());
this.onMapCenterManualUpdate([mapCenterLonLat[1], mapCenterLonLat[0]]);
const center = [mapCenterLonLat[1], mapCenterLonLat[0]];
this.onMapCenterUpdate(center);
if (!this.isProgrammaticMove) {
this.$store.dispatch('setCurrentMapCenter', { center });
}
}
// Show recenter button and call the callback if zoom is updated manually
const zoom = view.getZoom();
@ -486,7 +490,7 @@ export default {
heading: Number, // in degrees, clockwise wrt north
markers: Array,
onPress: Function,
onMapCenterManualUpdate: Function,
onMapCenterUpdate: Function,
onMapZoomManualUpdate: Function,
polyline: Array,
positionLatLng: Array,
@ -601,10 +605,14 @@ export default {
// TODO: Take into account the history of positions for the direction
if (closestReport.id !== -1) {
// Only open the details if the box was not just closed
if (this.$store.state.reportDetails.previousId !== closestReport.id) {
// Don't dispatch useless actions if emphasized report is not updated
if (
this.$store.state.reportDetails.previousId !== closestReport.id
&& this.$store.state.reportDetails.id !== closestReport.id
) {
this.$store.dispatch('showReportDetails', { id: closestReport.id, userAsked: false });
}
} else {
} else if (isReportDetailsAlreadyShown) {
this.$store.dispatch('hideReportDetails');
}
}

View File

@ -155,7 +155,7 @@ export function populateInitialStateFromStorage({ commit }) {
});
}
export function fetchReports({ commit, state }) {
export function fetchReports({ commit }, { center }) {
commit(IS_LOADING);
return api.getActiveReports()
.then((reports) => {
@ -167,7 +167,7 @@ export function fetchReports({ commit, state }) {
}
return pointToPointDistance(
[report.attributes.lat, report.attributes.lng],
state.map.center,
center,
) < 10000;
},
);

View File

@ -275,7 +275,10 @@ export function pointToGeometryDistance(latLng, geometry) {
}
if (geometry.type === 'Polygon') {
return pointToPolygonDistance(latLng, lngLatCoordinates.map(item => item.reverse()));
return pointToPolygonDistance(
latLng,
lngLatCoordinates[0].map(item => Array.concat([], item).reverse()),
);
}
// Unsupported geometry

View File

@ -152,7 +152,7 @@ describe('Geometry tools', function() {
});
it('should return correct distance for a polygon', function () {
var polygon = { type: 'Polygon', coordinates: [[2.3190774, 48.809982], [2.3320935, 48.8176872], [2.3323712, 48.8182127], [2.3143633, 48.8222148], [2.314133, 48.8222632], [2.3002323, 48.8115136], [2.3000166, 48.8113242], [2.3190774, 48.809982]] };
var polygon = { type: 'Polygon', coordinates: [[[2.3190774, 48.809982], [2.3320935, 48.8176872], [2.3323712, 48.8182127], [2.3143633, 48.8222148], [2.314133, 48.8222632], [2.3002323, 48.8115136], [2.3000166, 48.8113242], [2.3190774, 48.809982]]] };
assert(Math.abs(geometry.pointToGeometryDistance([48.82787, 2.32686], polygon) - 900) / 900 < 1 / 100);
});

View File

@ -16,7 +16,7 @@
:hasGeolocationTracking="!hasCenterProvidedByRoute && hasGeolocationTracking"
:heading="currentLocation.heading"
:markers="reportsMarkers"
:onMapCenterManualUpdate="onMapCenterManualUpdate"
:onMapCenterUpdate="onMapCenterUpdate"
:onMapZoomManualUpdate="onMapZoomManualUpdate"
:onPress="showReportDialog"
:polyline="positionHistory"
@ -260,7 +260,7 @@ export default {
this.hasPromptedGeolocation = true;
this.$store.dispatch('setLocationWatcherId', { id: watchID });
},
onMapCenterManualUpdate(center) {
onMapCenterUpdate(center) {
// Update reports by default
let distanceFromPreviousPoint = constants.UPDATE_REPORTS_DISTANCE_THRESHOLD + 1;
@ -282,10 +282,8 @@ export default {
store.dispatch('setLastReportFetchingLocation', {
locationLatLng: center,
});
store.dispatch('fetchReports');
store.dispatch('fetchReports', { center });
}
this.$store.dispatch('setCurrentMapCenter', { center });
},
onMapZoomManualUpdate(zoom) {
this.$store.dispatch('setCurrentMapZoom', { zoom });