diff --git a/src/GoogleMapControl.cpp b/src/GoogleMapControl.cpp index 6bf2fdbcc..72a95b63a 100644 --- a/src/GoogleMapControl.cpp +++ b/src/GoogleMapControl.cpp @@ -1,5 +1,6 @@ /* * Copyright (c) 2009 Greg Lonnon (greg.lonnon@gmail.com) + * 2011 Mark Liversedge (liversedge@gmail.com) * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the Free @@ -17,6 +18,7 @@ */ #include "GoogleMapControl.h" + #include "RideItem.h" #include "RideFile.h" #include "MainWindow.h" @@ -28,15 +30,6 @@ #include - -#include -#include -#include -#include -#include - -using namespace std; - GoogleMapControl::GoogleMapControl(MainWindow *mw) : GcWindow(mw), main(mw), range(-1), current(NULL) { setInstanceName("Google Map"); @@ -55,28 +48,14 @@ GoogleMapControl::GoogleMapControl(MainWindow *mw) : GcWindow(mw), main(mw), ran view->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); layout->addWidget(view); - // we redraw on resize after a timeout - // to let the user move splitter etc - // without an immediate redraw, since it - // makes the UI unresponsive - delay = new QTimer(this); - delay->setSingleShot(true); - webBridge = new WebBridge(mw, this); - //connect(parent, SIGNAL(rideSelected()), this, SLOT(rideSelected())); connect(this, SIGNAL(rideItemChanged(RideItem*)), this, SLOT(rideSelected())); connect(view->page()->mainFrame(), SIGNAL(javaScriptWindowObjectCleared()), this, SLOT(updateFrame())); - connect(view, SIGNAL(loadStarted()), this, SLOT(loadStarted())); - connect(view, SIGNAL(loadFinished(bool)), this, SLOT(loadFinished(bool))); - connect(delay, SIGNAL(timeout()), this, SLOT(loadRide())); connect(mw, SIGNAL(intervalsChanged()), webBridge, SLOT(intervalsChanged())); connect(mw, SIGNAL(intervalSelected()), webBridge, SLOT(intervalsChanged())); first = true; - loadingPage = false; - newRideToLoad = false; - } void @@ -95,51 +74,13 @@ GoogleMapControl::rideSelected() if(range < 0) rideCP = 300; // default cp to 300 watts else rideCP = ride->zones->getCP(range); - newRideToLoad = true; loadRide(); } -void GoogleMapControl::resizeEvent(QResizeEvent * ) -{ - // XXX v3 API removes the need to do all this nonsense - // since the map is enlarged as neccessary - return; - - //XXX kept old code, just in case we decide - // we still want to redraw on resize - if (!amVisible()) return; - - if (first == true) { - first = false; - return; - } - - newRideToLoad = true; - delay->stop(); - delay->start(1000); -} - -void GoogleMapControl::loadStarted() -{ - loadingPage = true; -} - -/// called after the load is finished -void GoogleMapControl::loadFinished(bool) -{ - loadingPage = false; -} - void GoogleMapControl::loadRide() { - if(loadingPage == true) return; - - if(newRideToLoad == true) { - newRideToLoad = false; - loadingPage = true; - createHtml(); - view->page()->mainFrame()->setHtml(currentPage); - } + createHtml(); + view->page()->mainFrame()->setHtml(currentPage); } void GoogleMapControl::updateFrame() @@ -181,11 +122,6 @@ void GoogleMapControl::createHtml() " \n" " \n"); -#if 0 // XXX overlay routine only works with MAPS api v2 - // add in our library routines - currentPage += createMapToolTipJavaScript(); -#endif - // local functions currentPage += QString("\n").arg(minLat,0,'g',11).arg(minLon,0,'g',11).arg(maxLat,0,'g',11).arg(maxLon,0,'g',11); + "}\n" + "\n").arg(minLat,0,'g',11).arg(minLon,0,'g',11).arg(maxLat,0,'g',11).arg(maxLon,0,'g',11); // the main page is rather trivial - currentPage += QString("\n" + currentPage += QString("\n" "\n" "
\n" - "\n" + "\n" "\n"); } @@ -322,8 +258,7 @@ QColor GoogleMapControl::GetColor(int watts) else return zoneColor(main->zones()->whichZone(range, watts), 7); } - -/// create the ride line +// create the ride line void GoogleMapControl::drawShadedRoute() { @@ -369,22 +304,7 @@ GoogleMapControl::drawShadedRoute() " zIndex: 0,\n" "}\n" "polyline.setOptions(polyOptions);\n" - -#if 0 //XXX map.{add,remove}Overlay is deprecated.. - // tooltip - "google.maps.event.addListener(polyline, 'mouseover', function() {\n" - " var tooltip_text = '30s Power: %2';\n" - " this.overlay = new MapTooltip(this,tooltip_text);\n" - " map.addOverlay(this.overlay);\n" - "});\n" - "google.maps.event.addListener(polyline, 'mouseout', function() {\n" - " map.removeOverlay(this.overlay);\n" - "});\n" -#endif "}\n").arg(color.name()); -#if 0 //XXX map.{add,remove}Overlay is deprecated.. -.arg(avgWatts); -#endif view->page()->mainFrame()->evaluateJavaScript(code); } @@ -430,20 +350,20 @@ GoogleMapControl::createMarkers() if (loop) { - code = QString("{ var latlng = new google.maps.LatLng(%1,%2);" + code = QString("{ var latlng = new google.maps.LatLng(%1,%2);" "var image = new google.maps.MarkerImage('qrc:images/maps/loop.png');" "var marker = new google.maps.Marker({ icon: image, animation: google.maps.Animation.DROP, position: latlng });" "marker.setMap(map); }").arg(points[0]->lat,0,'g',11).arg(points[0]->lon,0,'g',11); view->page()->mainFrame()->evaluateJavaScript(code); } else { // start / finish markers - code = QString("{ var latlng = new google.maps.LatLng(%1,%2);" + code = QString("{ var latlng = new google.maps.LatLng(%1,%2);" "var image = new google.maps.MarkerImage('qrc:images/maps/cycling.png');" "var marker = new google.maps.Marker({ icon: image, animation: google.maps.Animation.DROP, position: latlng });" "marker.setMap(map); }").arg(points[0]->lat,0,'g',11).arg(points[0]->lon,0,'g',11); view->page()->mainFrame()->evaluateJavaScript(code); - code = QString("{ var latlng = new google.maps.LatLng(%1,%2);" + code = QString("{ var latlng = new google.maps.LatLng(%1,%2);" "var image = new google.maps.MarkerImage('qrc:images/maps/finish.png');" "var marker = new google.maps.Marker({ icon: image, animation: google.maps.Animation.DROP, position: latlng });" "marker.setMap(map); }").arg(points[points.count()-1]->lat,0,'g',11).arg(points[points.count()-1]->lon,0,'g',11); @@ -488,7 +408,7 @@ GoogleMapControl::createMarkers() lastlat = stoplat; lastlon = stoplon; code = QString( - "{ var latlng = new google.maps.LatLng(%1,%2);" + "{ var latlng = new google.maps.LatLng(%1,%2);" "var image = new google.maps.MarkerImage('qrc:images/maps/cycling_feed.png');" "var marker = new google.maps.Marker({ icon: image, animation: google.maps.Animation.DROP, position: latlng });" "marker.setMap(map);" @@ -512,7 +432,7 @@ GoogleMapControl::createMarkers() int offset = myRideItem->ride()->intervalBegin(x); code = QString( "{" - " var latlng = new google.maps.LatLng(%1,%2);" + " var latlng = new google.maps.LatLng(%1,%2);" " var marker = new google.maps.Marker({ title: '%3', animation: google.maps.Animation.DROP, position: latlng });" " marker.setMap(map);" " markerList.push(marker);" // keep track of those suckers @@ -525,79 +445,13 @@ GoogleMapControl::createMarkers() view->page()->mainFrame()->evaluateJavaScript(code); interval++; } - - return; -} -QString GoogleMapControl::createMapToolTipJavaScript() -{ - return("\n"); + return; } // quick diag, used to debug code only void WebBridge::call(int count) { qDebug()<<"webBridge call:"<