mirror of
https://github.com/GoldenCheetah/GoldenCheetah.git
synced 2026-02-15 17:09:56 +00:00
Add Zoom to Interval on Maps
Can now zoom to a specific interval on the map views; * Google Map * Bing Map
This commit is contained in:
@@ -55,6 +55,7 @@ GoogleMapControl::GoogleMapControl(MainWindow *mw) : GcWindow(mw), main(mw), ran
|
||||
connect(view->page()->mainFrame(), SIGNAL(javaScriptWindowObjectCleared()), this, SLOT(updateFrame()));
|
||||
connect(mw, SIGNAL(intervalsChanged()), webBridge, SLOT(intervalsChanged()));
|
||||
connect(mw, SIGNAL(intervalSelected()), webBridge, SLOT(intervalsChanged()));
|
||||
connect(mw, SIGNAL(intervalZoom(IntervalItem*)), this, SLOT(zoomInterval(IntervalItem*)));
|
||||
|
||||
first = true;
|
||||
}
|
||||
@@ -450,6 +451,48 @@ GoogleMapControl::createMarkers()
|
||||
return;
|
||||
}
|
||||
|
||||
void GoogleMapControl::zoomInterval(IntervalItem *which)
|
||||
{
|
||||
RideItem *ride = myRideItem;
|
||||
|
||||
// null ride
|
||||
if (!ride || !ride->ride()) return;
|
||||
|
||||
int start = ride->ride()->timeIndex(which->start);
|
||||
int end = ride->ride()->timeIndex(which->stop);
|
||||
|
||||
// out of bounds
|
||||
if (start < 0 || start > ride->ride()->dataPoints().count()-1 ||
|
||||
end < 0 || end > ride->ride()->dataPoints().count()-1) return;
|
||||
|
||||
// Get the bounding rectangle for this interval
|
||||
double minLat, minLon, maxLat, maxLon;
|
||||
minLat = minLon = 1000;
|
||||
maxLat = maxLon = -1000; // larger than 360
|
||||
|
||||
// get bounding co-ordinates for ride
|
||||
for(int i=start; i<= end; i++) {
|
||||
RideFilePoint *rfp = ride->ride()->dataPoints().at(i);
|
||||
if (rfp->lat || rfp->lon) {
|
||||
minLat = std::min(minLat,rfp->lat);
|
||||
maxLat = std::max(maxLat,rfp->lat);
|
||||
minLon = std::min(minLon,rfp->lon);
|
||||
maxLon = std::max(maxLon,rfp->lon);
|
||||
}
|
||||
}
|
||||
|
||||
// now zoom to interval
|
||||
QString code = QString("{ var southwest = new google.maps.LatLng(%1, %2);\n"
|
||||
"var northeast = new google.maps.LatLng(%3, %4);\n"
|
||||
"var bounds = new google.maps.LatLngBounds(southwest, northeast);\n"
|
||||
"map.fitBounds(bounds);\n }")
|
||||
.arg(minLat,0,'g',11)
|
||||
.arg(minLon,0,'g',11)
|
||||
.arg(maxLat,0,'g',11)
|
||||
.arg(maxLon,0,'g',11);
|
||||
view->page()->mainFrame()->evaluateJavaScript(code);
|
||||
}
|
||||
|
||||
// quick diag, used to debug code only
|
||||
void WebBridge::call(int count) { qDebug()<<"webBridge call:"<<count; }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user