Skip to content

Commit

Permalink
timespan in geojson
Browse files Browse the repository at this point in the history
  • Loading branch information
jvde-github committed Aug 15, 2024
1 parent b787f6c commit 592365a
Showing 1 changed file with 25 additions and 24 deletions.
49 changes: 25 additions & 24 deletions Ships/DB.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -372,32 +372,33 @@ std::string DB::getKML()

std::string DB::getGeoJSON()
{
std::lock_guard<std::mutex> lock(mtx);

std::string s = "{\"type\":\"FeatureCollection\",\"features\":[";
int ptr = first;
std::time_t tm = time(nullptr);

bool addcomma = false;
while (ptr != -1)
{
const Ship &ship = ships[ptr];
if (ship.mmsi != 0)
{
long int delta_time = (long int)tm - (long int)ship.last_signal;
if (delta_time > TIME_HISTORY)
break;

if (addcomma)
s += ",";
addcomma = ship.getGeoJSON(s);
}
ptr = ships[ptr].next;
}
s += "]}";
return s;
std::lock_guard<std::mutex> lock(mtx);

std::string s = "{\"type\":\"FeatureCollection\",\"time_span\":" + std::to_string(TIME_HISTORY) + ",\"features\":[";
int ptr = first;
std::time_t tm = time(nullptr);

bool addcomma = false;
while (ptr != -1)
{
const Ship &ship = ships[ptr];
if (ship.mmsi != 0)
{
long int delta_time = (long int)tm - (long int)ship.last_signal;
if (delta_time > TIME_HISTORY)
break;

if (addcomma)
s += ",";
addcomma = ship.getGeoJSON(s);
}
ptr = ships[ptr].next;
}
s += "]}";
return s;
}


// needs fix, content is defined locally and in getSinglePathJSON member content is used as helper
std::string DB::getAllPathJSON()
{
Expand Down

0 comments on commit 592365a

Please sign in to comment.