Skip to content

Commit

Permalink
Merge master into en
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions[bot] authored Dec 26, 2023
2 parents 9466d76 + f2a9833 commit 63a9648
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 35 deletions.
10 changes: 1 addition & 9 deletions commons/Utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -723,15 +723,7 @@ Utils.geo = (function () {
* @returns {number}
*/
function getDistanceFromLatLonInKm(lat1, lon1, lat2, lon2) {
const R = 6371; // Mean radius of the earth in km
const dLat = deg2rad(lat2 - lat1); // deg2rad below
const dLon = deg2rad(lon2 - lon1);
const a = Math.sin(dLat / 2) * Math.sin(dLat / 2) +
Math.cos(deg2rad(lat1)) * Math.cos(deg2rad(lat2)) * Math.sin(dLon / 2) * Math.sin(dLon / 2);
const c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
const d = R * c; // Distance in km

return d;
return turf.distance([lon1, lat1], [lon2, lat2], { units: 'kilometers' });
}

/**
Expand Down
9 changes: 5 additions & 4 deletions controllers/cluster.js
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ export const clusterPhotosAll = async function (params) {
Utils.geo.normalizeCoordinates(cluster.g);

// Link it to photo that will represent cluster.
const dist = Utils.geo.getDistanceFromLatLonInKm(cluster.g[1], cluster.g[0], cluster.geo[1], cluster.geo[0]) * 1000;
const dist = Utils.geo.getDistanceFromLatLonInKm(cluster.g[1], cluster.g[0], cluster.geo[1], cluster.geo[0]) * 2000;

cluster.p = await Photo.findOne({
s: constants.photo.status.PUBLIC,
Expand Down Expand Up @@ -320,10 +320,11 @@ async function clusterRecalcByPhoto(g, zParam, geoPhotos, yearPhotos, isPainting
}

// Limit searching distance to improve $nearSphere performance.
const dist = Utils.geo.getDistanceFromLatLonInKm(g[1], g[0], geoCluster[1], geoCluster[0]) * 1000;
const dist = Utils.geo.getDistanceFromLatLonInKm(g[1], g[0], geoCluster[1], geoCluster[0]) * 2000;
const photo = await Photo.findOne(
{
s: constants.photo.status.PUBLIC, geo: { $nearSphere: { $geometry: { type: 'Point', coordinates: geoCluster }, $maxDistance: dist } },
s: constants.photo.status.PUBLIC,
geo: { $nearSphere: { $geometry: { type: 'Point', coordinates: geoCluster }, $maxDistance: dist } },
type: isPainting ? constants.photo.type.PAINTING : constants.photo.type.PHOTO,
},
{ _id: 0, cid: 1, geo: 1, file: 1, dir: 1, title: 1, year: 1, year2: 1 },
Expand Down Expand Up @@ -512,7 +513,7 @@ export async function getBoundsByYear({ geometry, z, year, year2, isPainting })

async function getClusterPoster(cluster, yearCriteria, isPainting) {
// Limit searching distance to improve $nearSphere performance.
const dist = Utils.geo.getDistanceFromLatLonInKm(cluster.g[1], cluster.g[0], cluster.geo[1], cluster.geo[0]) * 1000;
const dist = Utils.geo.getDistanceFromLatLonInKm(cluster.g[1], cluster.g[0], cluster.geo[1], cluster.geo[0]) * 2000;

cluster.p = await Photo.findOne(
{
Expand Down
22 changes: 0 additions & 22 deletions public/js/lib/Utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -993,27 +993,6 @@ define(['jquery', 'underscore', 'underscore.string', 'lib/geocoordsparser', 'lib
geo: (function () {
'use strict';

/**
* Haversine formula to calculate the distance
*
* @param {number} lat1
* @param {number} lon1
* @param {number} lat2
* @param {number} lon2
* @returns {number}
*/
function getDistanceFromLatLonInKm(lat1, lon1, lat2, lon2) {
const R = 6371; // Mean radius of the earth in km
const dLat = deg2rad(lat2 - lat1); // deg2rad below
const dLon = deg2rad(lon2 - lon1);
// eslint-disable-next-line max-len
const a = Math.sin(dLat / 2) * Math.sin(dLat / 2) + Math.cos(deg2rad(lat1)) * Math.cos(deg2rad(lat2)) * Math.sin(dLon / 2) * Math.sin(dLon / 2);
const c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
const d = R * c; // Distance in km

return d;
}

function deg2rad(deg) {
return deg * (Math.PI / 180);
}
Expand Down Expand Up @@ -1101,7 +1080,6 @@ define(['jquery', 'underscore', 'underscore.string', 'lib/geocoordsparser', 'lib
deg2rad: deg2rad,
geoToPrecision: geoToPrecision,
geoToPrecisionRound: geoToPrecisionRound,
getDistanceFromLatLonInKm: getDistanceFromLatLonInKm,
spinLng: spinLng,
latlngToArr: latlngToArr,
check: check,
Expand Down

0 comments on commit 63a9648

Please sign in to comment.