When titles are searched nearby, keep the geolocation of each title

This commit is contained in:
mossroy 2014-04-01 17:01:30 +02:00
parent 75c7c8a218
commit b29968fbce
3 changed files with 19 additions and 8 deletions

View File

@ -341,7 +341,7 @@ define(function(require) {
}); });
asyncTest("check articles found nearby London", function() { asyncTest("check articles found nearby London", function() {
expect(3); expect(5);
var callbackTitlesNearbyLondonFound = function(titleList) { var callbackTitlesNearbyLondonFound = function(titleList) {
ok(titleList !== null, "Some titles should be found"); ok(titleList !== null, "Some titles should be found");
equal(titleList.length, 1, "1 title should be found"); equal(titleList.length, 1, "1 title should be found");
@ -353,6 +353,12 @@ define(function(require) {
} }
} }
ok(titleLondon !== null, "The title 'London' should be found"); ok(titleLondon !== null, "The title 'London' should be found");
// Check coordinates of London
var x = titleLondon._geolocation.x;
var y = titleLondon._geolocation.y;
equal(x, 51.50777816772461, "London should be at latitude 51.50777816772461");
equal(y, -0.12805555760860443, "London should be at longitude -0.12805555760860443");
start(); start();
}; };

View File

@ -27,6 +27,7 @@ define(function(require) {
var util = require('util'); var util = require('util');
var geometry = require('geometry'); var geometry = require('geometry');
var jQuery = require('jquery'); var jQuery = require('jquery');
var evopediaTitle = require('title');
var titleIterators = require('titleIterators'); var titleIterators = require('titleIterators');
// Declare the webworker that can uncompress with bzip2 algorithm // Declare the webworker that can uncompress with bzip2 algorithm
@ -698,10 +699,13 @@ define(function(require) {
* @param {type} callbackFunction * @param {type} callbackFunction
*/ */
LocalArchive.readTitlesFromTitleCoordsInTitleFile = function (localArchive, titlePositionsFound, i, titlesFound, maxTitles, callbackFunction) { LocalArchive.readTitlesFromTitleCoordsInTitleFile = function (localArchive, titlePositionsFound, i, titlesFound, maxTitles, callbackFunction) {
var titleOffset = titlePositionsFound[i]; var titleOffset = titlePositionsFound[i]._titleOffset;
var geolocation = titlePositionsFound[i]._geolocation;
localArchive.getTitlesStartingAtOffset(titleOffset, 1, function(titleList) { localArchive.getTitlesStartingAtOffset(titleOffset, 1, function(titleList) {
if (titleList && titleList.length === 1) { if (titleList && titleList.length === 1) {
titlesFound.push(titleList[0]); var title = titleList[0];
title._geolocation = geolocation;
titlesFound.push(title);
i++; i++;
if (i<titlePositionsFound.length) { if (i<titlePositionsFound.length) {
LocalArchive.readTitlesFromTitleCoordsInTitleFile(localArchive, titlePositionsFound, i, titlesFound, maxTitles, callbackFunction); LocalArchive.readTitlesFromTitleCoordsInTitleFile(localArchive, titlePositionsFound, i, titlesFound, maxTitles, callbackFunction);
@ -810,11 +814,11 @@ define(function(require) {
if (!targetRect.containsPoint(articleCoordinates)) { if (!targetRect.containsPoint(articleCoordinates)) {
continue; continue;
} }
// We currently do not use the article coordinates
// so it's no use putting it in the result list : we only put
// the position in title list
if (maxTitles >= 0 && titlePositionsFound.length < maxTitles) { if (maxTitles >= 0 && titlePositionsFound.length < maxTitles) {
titlePositionsFound.push(title_pos); var title = new evopediaTitle.Title();
title._titleOffset = title_pos;
title._geolocation = articleCoordinates;
titlePositionsFound.push(title);
} }
} }
} }

View File

@ -37,6 +37,7 @@ define(function(require) {
this._archive = null; this._archive = null;
this._titleOffset = null; this._titleOffset = null;
this._titleEntryLength = null; this._titleEntryLength = null;
this._geolocation = null;
}; };
Title.prototype.getReadableName = function() { Title.prototype.getReadableName = function() {
@ -137,7 +138,7 @@ define(function(require) {
* Serialize the title in a readable way * Serialize the title in a readable way
*/ */
Title.prototype.toString = function() { Title.prototype.toString = function() {
return "title.id = " + this.toStringId() + "title.name = " + this._name + " title.fileNr = " + this._fileNr + " title.blockStart = " + this._blockStart + " title.blockOffset = " + this._blockOffset + " title.articleLength = " + this._articleLength; return "title.id = " + this.toStringId() + " title.name = " + this._name + " title.fileNr = " + this._fileNr + " title.blockStart = " + this._blockStart + " title.blockOffset = " + this._blockOffset + " title.articleLength = " + this._articleLength;
}; };
/** /**