From 6f979b48edf0e264a209e99d2164c7b4e8d925f4 Mon Sep 17 00:00:00 2001 From: Dirk Hohndel Date: Wed, 5 Jun 2013 11:46:57 +0900 Subject: Show locations with same name on the map if they are more than 50m apart Not showing them at all was a little too blunt of an instrument. There likely are dive spots with the same name at different resorts. And even at the same resort you could have multiple morings for the same dive site. Signed-off-by: Dirk Hohndel --- qt-ui/globe.cpp | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) (limited to 'qt-ui/globe.cpp') diff --git a/qt-ui/globe.cpp b/qt-ui/globe.cpp index 67a4fcd73..0bd2db423 100644 --- a/qt-ui/globe.cpp +++ b/qt-ui/globe.cpp @@ -11,6 +11,7 @@ #include #include #include +#include #if INCOMPLETE_MARBLE #include "marble/GeoDataTreeModel.h" #else @@ -69,19 +70,28 @@ void GlobeGPS::reload() } loadedDives = new GeoDataDocument; + QMap locationMap; - diveLocations.clear(); int idx = 0; struct dive *dive; for_each_dive(idx, dive) { if (dive_has_gps_location(dive)) { - // don't add dive locations twice. - if (diveLocations.contains(QString(dive->location))) - continue; - - diveLocations.append(QString(dive->location)); GeoDataPlacemark *place = new GeoDataPlacemark(dive->location); place->setCoordinate(dive->longitude.udeg / 1000000.0,dive->latitude.udeg / 1000000.0 , 0, GeoDataCoordinates::Degree); + // don't add dive locations twice, unless they are at least 50m apart + if (locationMap[QString(dive->location)]) { + GeoDataPoint existingLocation = locationMap[QString(dive->location)]->coordinate(); + GeoDataLineString segment = GeoDataLineString(); + segment.append(existingLocation); + GeoDataPoint newLocation = place->coordinate(); + segment.append(newLocation); + double dist = segment.length(6371); + // the dist is scaled to the radius given - so with 6371km as radius + // 50m turns into 0.05 as threashold + if (dist < 0.05) + continue; + } + locationMap[QString(dive->location)] = place; loadedDives->append(place); } } -- cgit v1.2.3-70-g09d2