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 368c799933
5 changed files with 23 additions and 14 deletions

View File

@ -254,9 +254,13 @@ export default {
}, },
onMoveEnd() { onMoveEnd() {
const view = this.map.getView(); const view = this.map.getView();
if (this.onMapCenterManualUpdate && !this.isProgrammaticMove) { if (this.onMapCenterUpdate) {
const mapCenterLonLat = toLonLat(view.getCenter()); 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 // Show recenter button and call the callback if zoom is updated manually
const zoom = view.getZoom(); const zoom = view.getZoom();
@ -486,7 +490,7 @@ export default {
heading: Number, // in degrees, clockwise wrt north heading: Number, // in degrees, clockwise wrt north
markers: Array, markers: Array,
onPress: Function, onPress: Function,
onMapCenterManualUpdate: Function, onMapCenterUpdate: Function,
onMapZoomManualUpdate: Function, onMapZoomManualUpdate: Function,
polyline: Array, polyline: Array,
positionLatLng: Array, positionLatLng: Array,
@ -601,10 +605,14 @@ export default {
// TODO: Take into account the history of positions for the direction // TODO: Take into account the history of positions for the direction
if (closestReport.id !== -1) { if (closestReport.id !== -1) {
// Only open the details if the box was not just closed // 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 }); this.$store.dispatch('showReportDetails', { id: closestReport.id, userAsked: false });
} }
} else { } else if (isReportDetailsAlreadyShown) {
this.$store.dispatch('hideReportDetails'); 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); commit(IS_LOADING);
return api.getActiveReports() return api.getActiveReports()
.then((reports) => { .then((reports) => {
@ -167,7 +167,7 @@ export function fetchReports({ commit, state }) {
} }
return pointToPointDistance( return pointToPointDistance(
[report.attributes.lat, report.attributes.lng], [report.attributes.lat, report.attributes.lng],
state.map.center, center,
) < 10000; ) < 10000;
}, },
); );

View File

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

View File

@ -152,7 +152,7 @@ describe('Geometry tools', function() {
}); });
it('should return correct distance for a polygon', 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); assert(Math.abs(geometry.pointToGeometryDistance([48.82787, 2.32686], polygon) - 900) / 900 < 1 / 100);
}); });

View File

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