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:
Mark Liversedge
2011-08-29 12:54:51 +01:00
parent fb3ce4b2f4
commit ac88659b9e
4 changed files with 89 additions and 0 deletions

View File

@@ -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; }