When titles are listed, display their distance from here, if this information is known

This commit is contained in:
mossroy 2014-04-01 17:23:39 +02:00
parent b29968fbce
commit c1527f2afd

View File

@ -405,8 +405,18 @@ define(function(require) {
var titleListDivHtml = ""; var titleListDivHtml = "";
for (var i = 0; i < titleArray.length; i++) { for (var i = 0; i < titleArray.length; i++) {
var title = titleArray[i]; var title = titleArray[i];
var distanceFromHereHtml = "";
if (title._geolocation && currentCoordinates) {
// If we know the current position and the title position, we display the distance
var distanceKm = (currentCoordinates.distance(title._geolocation) * 6371).toFixed(1);
distanceFromHereHtml = " (" + distanceKm + " km)";
}
titleListDivHtml += "<a href='#' titleid='" + title.toStringId() titleListDivHtml += "<a href='#' titleid='" + title.toStringId()
+ "' class='list-group-item'>" + title.getReadableName() + "</a>"; + "' class='list-group-item'>" + title.getReadableName()
+ distanceFromHereHtml
+ "</a>";
} }
titleListDiv.html(titleListDivHtml); titleListDiv.html(titleListDivHtml);
$("#titleList a").on("click",handleTitleClick); $("#titleList a").on("click",handleTitleClick);
@ -614,6 +624,8 @@ define(function(require) {
}); });
} }
var currentCoordinates = null;
/** /**
* Looks for titles located around where the device is geolocated * Looks for titles located around where the device is geolocated
*/ */
@ -640,9 +652,11 @@ define(function(require) {
$('#geolocationProgress').html("Found your location : latitude=" + crd.latitude + ", longitude=" + crd.longitude $('#geolocationProgress').html("Found your location : latitude=" + crd.latitude + ", longitude=" + crd.longitude
+ "<br/>Now looking for articles around this location..."); + "<br/>Now looking for articles around this location...");
currentCoordinates = new geometry.point(crd.latitude, crd.longitude);
var rectangle = new geometry.rect( var rectangle = new geometry.rect(
crd.latitude - maxDistanceArticlesNearbySearch, currentCoordinates.x - maxDistanceArticlesNearbySearch,
crd.longitude - maxDistanceArticlesNearbySearch, currentCoordinates.y - maxDistanceArticlesNearbySearch,
maxDistanceArticlesNearbySearch * 2, maxDistanceArticlesNearbySearch * 2,
maxDistanceArticlesNearbySearch * 2); maxDistanceArticlesNearbySearch * 2);