TileId TileId::fromCoordinates(const GeoDataCoordinates &coords, int zoomLevel) { if ( zoomLevel < 0 ) { return TileId(); } const int maxLat = 90 * 1000000; const int maxLon = 180 * 1000000; int lat = GeoDataCoordinates::normalizeLat( coords.latitude( GeoDataCoordinates::Degree ), GeoDataCoordinates::Degree ) * 1000000; int lon = GeoDataCoordinates::normalizeLon( coords.longitude( GeoDataCoordinates::Degree ), GeoDataCoordinates::Degree ) * 1000000; int x = 0; int y = 0; for( int i=0; i<zoomLevel; ++i ) { const int deltaLat = maxLat >> i; if( lat <= ( maxLat - deltaLat )) { y += 1<<(zoomLevel-i-1); lat += deltaLat; } const int deltaLon = maxLon >> i; if( lon >= ( maxLon - deltaLon )) { x += 1<<(zoomLevel-i-1); } else { lon += deltaLon; } } return TileId(0, zoomLevel, x, y); }
void GosmoreRunner::reverseGeocoding( const GeoDataCoordinates &coordinates ) { if ( !d->m_gosmoreMapFile.exists() ) { emit reverseGeocodingFinished( coordinates, GeoDataPlacemark() ); return; } QString queryString = "flat=%1&flon=%2&tlat=%1&tlon=%2&fastest=1&v=motorcar"; double lon = coordinates.longitude( GeoDataCoordinates::Degree ); double lat = coordinates.latitude( GeoDataCoordinates::Degree ); queryString = queryString.arg( lat, 0, 'f', 8).arg(lon, 0, 'f', 8 ); QByteArray output = d->retrieveWaypoints( queryString ); GeoDataPlacemark placemark; placemark.setCoordinate( coordinates ); QStringList lines = QString::fromUtf8( output ).split( '\r' ); if ( lines.size() > 2 ) { QStringList fields = lines.at( lines.size()-2 ).split(','); if ( fields.size() >= 5 ) { QString road = fields.last().trimmed(); placemark.setAddress( road ); GeoDataExtendedData extendedData; extendedData.addValue( GeoDataData( "road", road ) ); placemark.setExtendedData( extendedData ); } } emit reverseGeocodingFinished( coordinates, placemark ); }
bool MonavMap::containsPoint( const GeoDataCoordinates &point ) const { // If we do not have a bounding box at all, we err on the safe side if ( m_boundingBox.isEmpty() ) { return true; } // Quick check for performance reasons if ( !m_boundingBox.contains( point ) ) { return false; } if ( m_tiles.isEmpty() ) { return true; // Tiles discarded for performance reason } // GeoDataLinearRing does a 3D check, but we only have 2D data for // the map bounding box. Therefore the 3D info of e.g. the GPS position // must be ignored. GeoDataCoordinates flatPosition = point; flatPosition.setAltitude( 0.0 ); foreach( const GeoDataLinearRing & box, m_tiles ) { if ( box.contains( flatPosition ) ) { return true; } } return false; }
void MapScreen::perform_search(QString term, qreal distance) { GeoDataLatLonBox box; GeoDataCoordinates location; setCurrentIndex(indexOf(results_screen)); last_search_term = term; last_search_distance = distance; if (distance > MAX_DISTANCE) { search_manager->findPlacemarks(term); return; } location = navigation_screen->map_widget->focusPoint(); box.setNorth(location.latitude() - km_to_rad(distance)); box.setSouth(location.latitude() + km_to_rad(distance)); box.setEast(location.longitude() - km_to_rad(distance)); box.setWest(location.longitude() + km_to_rad(distance)); qDebug() << "Box north:" << box.north(GeoDataCoordinates::Degree); qDebug() << "Box south:" << box.south(GeoDataCoordinates::Degree); qDebug() << "Box west:" << box.west(GeoDataCoordinates::Degree); qDebug() << "Box east:" << box.east(GeoDataCoordinates::Degree); search_manager->findPlacemarks(term, box); }
void TestGeoDataTrack::removeAfterTest() { GeoDataDocument* dataDocument = parseKml( simpleExampleContent ); GeoDataFolder *folder = dataDocument->folderList().at( 0 ); QCOMPARE( folder->placemarkList().size(), 1 ); GeoDataPlacemark* placemark = folder->placemarkList().at( 0 ); QCOMPARE( placemark->geometry()->geometryId(), GeoDataTrackId ); GeoDataTrack* track = static_cast<GeoDataTrack*>( placemark->geometry() ); QCOMPARE( track->size(), 7 ); track->removeAfter( QDateTime( QDate( 2010, 5, 28 ), QTime( 2, 2, 54 ), Qt::UTC ) ); QCOMPARE( track->size(), 5 ); { QDateTime when = track->whenList().at( 0 ); QCOMPARE( when, QDateTime( QDate( 2010, 5, 28 ), QTime( 2, 2, 9 ), Qt::UTC ) ); } { QDateTime when = track->whenList().at( 4 ); QCOMPARE( when, QDateTime( QDate( 2010, 5, 28 ), QTime( 2, 2, 54 ), Qt::UTC ) ); } { GeoDataCoordinates coord = track->coordinatesList().at( 0 ); QCOMPARE( coord.longitude( GeoDataCoordinates::Degree ), -122.207881 ); QCOMPARE( coord.latitude( GeoDataCoordinates::Degree ), 37.371915 ); QCOMPARE( coord.altitude(), 156.000000 ); } delete dataDocument; }
qreal OsmDatabase::bearing( const GeoDataCoordinates &a, const GeoDataCoordinates &b ) const { qreal delta = b.longitude() - a.longitude(); qreal lat1 = a.latitude(); qreal lat2 = b.latitude(); return fmod( atan2( sin ( delta ) * cos ( lat2 ), cos( lat1 ) * sin( lat2 ) - sin( lat1 ) * cos( lat2 ) * cos ( delta ) ), 2 * M_PI ); }
GeoDataCoordinates MyPaintLayer::approximate(const GeoDataCoordinates &base, qreal angle, qreal dist) const { // This is just a rough estimation that ignores projections. // It only works for short distances. Don't use in real code. GeoDataCoordinates::Unit deg = GeoDataCoordinates::Degree; return GeoDataCoordinates ( base.longitude(deg) + 1.5 * dist * sin(angle), base.latitude(deg) + dist * cos(angle), 0.0, deg); }
GeoDataCoordinates AlternativeRoutesModelPrivate::coordinates( const GeoDataCoordinates &start, qreal distance, qreal bearing ) { qreal lat1 = start.latitude(); qreal lon1 = start.longitude(); qreal lat2 = asin( sin( lat1 ) * cos( distance ) + cos( lat1 ) * sin( distance ) * cos( bearing ) ); qreal lon2 = lon1 + atan2( sin( bearing ) * sin( distance ) * cos( lat1 ), cos( distance ) - sin( lat1 ) * sin( lat2 ) ); return GeoDataCoordinates( lon2, lat2 ); }
qreal AlternativeRoutesModelPrivate::bearing( const GeoDataCoordinates &one, const GeoDataCoordinates &two ) { qreal delta = two.longitude() - one.longitude(); qreal lat1 = one.latitude(); qreal lat2 = two.latitude(); return fmod( atan2( sin ( delta ) * cos ( lat2 ), cos( lat1 ) * sin( lat2 ) - sin( lat1 ) * cos( lat2 ) * cos ( delta ) ), 2 * M_PI ); }
void PlacemarkTextAnnotation::move( const GeoDataCoordinates &source, const GeoDataCoordinates &destination ) { Q_UNUSED( source ); qreal lat = destination.latitude(); qreal lon = destination.longitude(); GeoDataCoordinates::normalizeLonLat( lon, lat ); placemark()->setCoordinate( lon, lat ); }
void CurrentLocationWidgetPrivate::receiveGpsCoordinates( const GeoDataCoordinates &position, qreal speed ) { m_currentPosition = position; QString unitString; QString altitudeUnitString; QString distanceUnitString; qreal unitSpeed = 0.0; qreal altitude = 0.0; qreal length = m_widget->model()->positionTracking()->length( m_widget->model()->planetRadius() ); QString html = "<html><body>"; html += "<table cellspacing=\"2\" cellpadding=\"2\">"; html += "<tr><td>Longitude</td><td><a href=\"http://edu.kde.org/marble\">%1</a></td></tr>"; html += "<tr><td>Latitude</td><td><a href=\"http://edu.kde.org/marble\">%2</a></td></tr>"; html += "<tr><td>Altitude</td><td>%3</td></tr>"; html += "<tr><td>Speed</td><td>%4</td></tr>"; html += "<tr><td>Distance</td><td>%5</td></tr>"; html += "</table>"; html += "</body></html>"; switch ( MarbleGlobal::getInstance()->locale()->measurementSystem() ) { case QLocale::MetricSystem: //kilometers per hour unitString = QObject::tr("km/h"); unitSpeed = speed * HOUR2SEC * METER2KM; altitudeUnitString = QObject::tr("m"); distanceUnitString = QObject::tr("m"); if ( length > 1000.0 ) { length /= 1000.0; distanceUnitString = QObject::tr("km"); } altitude = position.altitude(); break; case QLocale::ImperialSystem: //miles per hour unitString = QObject::tr("m/h"); unitSpeed = speed * HOUR2SEC * METER2KM * KM2MI; altitudeUnitString = QObject::tr("ft"); distanceUnitString = QObject::tr("ft"); altitude = position.altitude() * M2FT; length *= M2FT; break; } // TODO read this value from the incoming signal const QString speedString = QLocale::system().toString( unitSpeed, 'f', 1); const QString altitudeString = QString( "%1 %2" ).arg( altitude, 0, 'f', 1, QChar(' ') ).arg( altitudeUnitString ); const QString distanceString = QString( "%1 %2" ).arg( length, 0, 'f', 1, QChar(' ') ).arg( distanceUnitString ); html = html.arg( position.lonToString() ).arg( position.latToString() ); html = html.arg( altitudeString ).arg( speedString + ' ' + unitString ); html = html.arg( distanceString ); m_currentLocationUi.locationLabel->setText( html ); m_currentLocationUi.showTrackCheckBox->setEnabled( true ); m_currentLocationUi.saveTrackButton->setEnabled( true ); m_currentLocationUi.clearTrackButton->setEnabled( true ); }
bool GeoDataLatLonAltBox::contains( const GeoDataCoordinates &point ) const { if ( !GeoDataLatLonBox::contains( point ) ) return false; if ( point.altitude() < d->m_minAltitude || point.altitude() > d->m_maxAltitude ) { return false; } return true; }
void TourWidgetPrivate::mapCenterOn( const QModelIndex &index ) { QVariant coordinatesVariant = m_widget->model()->treeModel()->data( index, MarblePlacemarkModel::CoordinateRole ); if ( !coordinatesVariant.isNull() ) { GeoDataCoordinates const coordinates = coordinatesVariant.value<GeoDataCoordinates>(); GeoDataLookAt lookat; lookat.setCoordinates( coordinates ); lookat.setRange( coordinates.altitude() ); m_widget->flyTo( lookat, Instant ); } }
void PlasmaRunner::collectMatches(QList<Plasma::QueryMatch> &matches, const QString &query, const GeoDataFolder *folder) { const QString queryLower = query.toLower(); QVector<GeoDataFeature*>::const_iterator it = folder->constBegin(); QVector<GeoDataFeature*>::const_iterator end = folder->constEnd(); for (; it != end; ++it) { GeoDataFolder *folder = dynamic_cast<GeoDataFolder*>(*it); if ( folder ) { collectMatches(matches, query, folder); continue; } GeoDataPlacemark *placemark = dynamic_cast<GeoDataPlacemark*>( *it ); if ( placemark ) { // For short query strings only match exactly, to get a sane number of matches if (query.length() < minContainsMatchLength) { if ( placemark->name().toLower() != queryLower && ( placemark->descriptionIsCDATA() || // TODO: support also with CDATA placemark->description().toLower() != queryLower ) ) { continue; } } else { if ( ! placemark->name().toLower().contains(queryLower) && ( placemark->descriptionIsCDATA() || // TODO: support also with CDATA ! placemark->description().toLower().contains(queryLower) ) ) { continue; } } const GeoDataCoordinates coordinates = placemark->coordinate(); const qreal lon = coordinates.longitude(GeoDataCoordinates::Degree); const qreal lat = coordinates.latitude(GeoDataCoordinates::Degree); const QVariant coordinatesData = QVariantList() << QVariant(lon) << QVariant(lat) << QVariant(placemark->lookAt()->range()*METER2KM); Plasma::QueryMatch match(this); match.setIcon(QIcon::fromTheme(QStringLiteral("marble"))); match.setText(placemark->name()); match.setSubtext(i18n("Show in OpenStreetMap with Marble")); match.setData(coordinatesData); match.setId(placemark->name()+QString::number(lat)+QString::number(lon)); match.setRelevance(1.0); match.setType(Plasma::QueryMatch::ExactMatch); matches << match; } } }
GeoDataLatLonAltBox::GeoDataLatLonAltBox( const GeoDataCoordinates & coordinates ) : GeoDataLatLonBox(), d( new GeoDataLatLonAltBoxPrivate ) { setWest( coordinates.longitude() ); setEast( coordinates.longitude() ); setNorth( coordinates.latitude() ); setSouth( coordinates.latitude() ); d->m_minAltitude = coordinates.altitude(); d->m_maxAltitude = coordinates.altitude(); }
bool ViewportParams::resolves ( const GeoDataCoordinates &coord1, const GeoDataCoordinates &coord2 ) const { qreal lon1, lat1; coord1.geoCoordinates( lon1, lat1 ); qreal lon2, lat2; coord2.geoCoordinates( lon2, lat2 ); // We take the manhattan length as an approximation for the distance return ( fabs( lon2 - lon1 ) + fabs( lat2 - lat1 ) < angularResolution() ); }
void RoutingLayerPrivate::renderRequest( GeoPainter *painter ) { m_regions.clear(); for ( int i = 0; i < m_routeRequest->size(); ++i ) { const GeoDataCoordinates pos = m_routeRequest->at( i ); if ( pos.isValid() ) { QPixmap pixmap = m_routeRequest->pixmap( i ); painter->drawPixmap( pos, pixmap ); QRegion region = painter->regionFromRect( pos, pixmap.width(), pixmap.height() ); m_regions.push_front( RequestRegion( i, region ) ); } } }
bool VerticalPerspectiveProjection::screenCoordinates( const GeoDataCoordinates &coordinates, const ViewportParams *viewport, qreal &x, qreal &y, bool &globeHidesPoint ) const { Q_D(const VerticalPerspectiveProjection); d->calculateConstants(viewport->radius()); const qreal P = d->m_P; const qreal deltaLambda = coordinates.longitude() - viewport->centerLongitude(); const qreal phi = coordinates.latitude(); const qreal phi1 = viewport->centerLatitude(); qreal cosC = qSin( phi1 ) * qSin( phi ) + qCos( phi1 ) * qCos( phi ) * qCos( deltaLambda ); // Don't display placemarks that are below 10km altitude and // are on the Earth's backside (where cosC < 1/P) if (cosC < 1/P && coordinates.altitude() < 10000) { globeHidesPoint = true; return false; } // Let (x, y) be the position on the screen of the placemark .. // First determine the position in unit coordinates: qreal k = (P - 1) / (P - cosC); // scale factor x = ( qCos( phi ) * qSin( deltaLambda ) ) * k; y = ( qCos( phi1 ) * qSin( phi ) - qSin( phi1 ) * qCos( phi ) * qCos( deltaLambda ) ) * k; // Transform to screen coordinates qreal pixelAltitude = (coordinates.altitude() + EARTH_RADIUS) * d->m_altitudeToPixel; x *= pixelAltitude; y *= pixelAltitude; // Don't display satellites that are on the Earth's backside: if (cosC < 1/P && x*x+y*y < viewport->radius() * viewport->radius()) { globeHidesPoint = true; return false; } // The remaining placemarks are definetely not on the Earth's backside globeHidesPoint = false; x += viewport->width() / 2; y = viewport->height() / 2 - y; // Skip placemarks that are outside the screen area if ( x < 0 || x >= viewport->width() || y < 0 || y >= viewport->height() ) { return false; } return true; }
void PopupLayer::popup() { GeoDataCoordinates coords = d->m_popupItem->coordinate(); ViewportParams viewport( d->m_widget->viewport()->projection(), coords.longitude(), coords.latitude(), d->m_widget->viewport()->radius(), d->m_widget->viewport()->size() ); qreal sx, sy, lon, lat; viewport.screenCoordinates( coords, sx, sy ); sx = viewport.radius() < viewport.width() ? 0.5 * (viewport.width() + viewport.radius()) : 0.75 * viewport.width(); viewport.geoCoordinates( sx, sy, lon, lat, GeoDataCoordinates::Radian ); coords.setLatitude( lat ); coords.setLongitude( lon ); d->m_widget->centerOn( coords, true ); setVisible( true ); }
QVariant TargetModel::currentLocationData ( int role ) const { const PositionTracking* tracking = m_marbleModel->positionTracking(); if ( tracking->status() == PositionProviderStatusAvailable ) { GeoDataCoordinates currentLocation = tracking->currentLocation(); switch( role ) { case Qt::DisplayRole: return tr( "Current Location: %1" ).arg( currentLocation.toString() ) ; case Qt::DecorationRole: return QIcon( ":/icons/gps.png" ); case MarblePlacemarkModel::CoordinateRole: { return qVariantFromValue( currentLocation ); } } } return QVariant(); }
void OsmNominatimRunner::reverseGeocoding( const GeoDataCoordinates &coordinates ) { m_coordinates = coordinates; QString base = "http://nominatim.openstreetmap.org/reverse?format=xml&addressdetails=1"; // @todo: Alternative URI with addressdetails=1 could be used for shorther placemark name QString query = "&lon=%1&lat=%2&accept-language=%3"; double lon = coordinates.longitude( GeoDataCoordinates::Degree ); double lat = coordinates.latitude( GeoDataCoordinates::Degree ); QString url = QString( base + query ).arg( lon ).arg( lat ).arg( MarbleLocale::languageCode() ); m_reverseGeocodingRequest.setUrl(QUrl(url)); m_reverseGeocodingRequest.setRawHeader("User-Agent", TinyWebBrowser::userAgent("Browser", "OsmNominatimRunner") ); // @todo FIXME Must currently be done in the main thread, see bug 257376 QTimer::singleShot( 0, this, SLOT( startReverseGeocoding() ) ); }
bool EquirectProjection::screenCoordinates( const GeoDataCoordinates &geopoint, const ViewportParams *viewport, qreal &x, qreal &y, bool &globeHidesPoint ) const { globeHidesPoint = false; // Convenience variables int radius = viewport->radius(); int width = viewport->width(); int height = viewport->height(); qreal lon; qreal lat; qreal rad2Pixel = 2.0 * viewport->radius() / M_PI; const qreal centerLon = viewport->centerLongitude(); const qreal centerLat = viewport->centerLatitude(); geopoint.geoCoordinates( lon, lat ); // Let (x, y) be the position on the screen of the geopoint. x = ((qreal)(viewport->width()) / 2.0 + rad2Pixel * (lon - centerLon)); y = ((qreal)(viewport->height()) / 2.0 - rad2Pixel * (lat - centerLat)); // Return true if the calculated point is inside the screen area, // otherwise return false. return ( ( 0 <= y && y < height ) && ( ( 0 <= x && x < width ) || ( 0 <= x - 4 * radius && x - 4 * radius < width ) || ( 0 <= x + 4 * radius && x + 4 * radius < width ) ) ); }
bool KmlLineStringTagWriter::write( const GeoNode *node, GeoWriter& writer ) const { const GeoDataLineString *lineString = static_cast<const GeoDataLineString*>( node ); if ( lineString->size() > 1 ) { writer.writeStartElement( kml::kmlTag_LineString ); writer.writeStartElement( "coordinates" ); // Write altitude for *all* elements, if *any* element // has altitude information (!= 0.0) bool hasAltitude = false; for ( int i = 0; i < lineString->size(); ++i ) { if ( lineString->at( i ).altitude() ) { hasAltitude = true; break; } } for ( int i = 0; i < lineString->size(); ++i ) { GeoDataCoordinates coordinates = lineString->at( i ); if ( i > 0 ) { writer.writeCharacters( " " ); } qreal lon = coordinates.longitude( GeoDataCoordinates::Degree ); writer.writeCharacters( QString::number( lon, 'f', 10 ) ); writer.writeCharacters( "," ); qreal lat = coordinates.latitude( GeoDataCoordinates::Degree ); writer.writeCharacters( QString::number( lat, 'f', 10 ) ); if ( hasAltitude ) { qreal alt = coordinates.altitude(); writer.writeCharacters( "," ); writer.writeCharacters( QString::number( alt, 'f', 2 ) ); } } writer.writeEndElement(); writer.writeEndElement(); return true; } return false; }
bool SphericalProjection::screenCoordinates( const GeoDataCoordinates &coordinates, const ViewportParams *viewport, qreal &x, qreal &y, bool &globeHidesPoint ) const { qreal absoluteAltitude = coordinates.altitude() + EARTH_RADIUS; Quaternion qpos = coordinates.quaternion(); qpos.rotateAroundAxis( viewport->planetAxisMatrix() ); qreal pixelAltitude = ( ( viewport->radius() ) / EARTH_RADIUS * absoluteAltitude ); if ( coordinates.altitude() < 10000 ) { // Skip placemarks at the other side of the earth. if ( qpos.v[Q_Z] < 0 ) { globeHidesPoint = true; return false; } } else { qreal earthCenteredX = pixelAltitude * qpos.v[Q_X]; qreal earthCenteredY = pixelAltitude * qpos.v[Q_Y]; qreal radius = viewport->radius(); // Don't draw high placemarks (e.g. satellites) that aren't visible. if ( qpos.v[Q_Z] < 0 && ( ( earthCenteredX * earthCenteredX + earthCenteredY * earthCenteredY ) < radius * radius ) ) { globeHidesPoint = true; return false; } } // Let (x, y) be the position on the screen of the placemark.. x = ((qreal)(viewport->width()) / 2 + pixelAltitude * qpos.v[Q_X]); y = ((qreal)(viewport->height()) / 2 - pixelAltitude * qpos.v[Q_Y]); // Skip placemarks that are outside the screen area if ( x < 0 || x >= viewport->width() || y < 0 || y >= viewport->height() ) { globeHidesPoint = false; return false; } globeHidesPoint = false; return true; }
void PlaybackFlyToItem::center( double t ) { Q_ASSERT( t >= 0.0 && t <= 1.0 ); Q_ASSERT( m_before ); if ( m_flyTo->flyToMode() == GeoDataFlyTo::Bounce || !m_before->m_before || !m_next ) { GeoDataCoordinates const a = m_before->m_flyTo->view()->coordinates(); GeoDataCoordinates const b = m_flyTo->view()->coordinates(); emit centerOn( a.interpolate( b, t ) ); } else { Q_ASSERT( m_flyTo->flyToMode() == GeoDataFlyTo::Smooth ); GeoDataCoordinates const a = m_before->m_before->m_flyTo->view()->coordinates(); GeoDataCoordinates const b = m_before->m_flyTo->view()->coordinates(); GeoDataCoordinates const c = m_flyTo->view()->coordinates(); GeoDataCoordinates const d = m_next->m_flyTo->view()->coordinates(); emit centerOn( b.interpolate( a, c, d, t ) ); } }
void GeoDataLineString::pack( QDataStream& stream ) const { GeoDataGeometry::pack( stream ); stream << size(); stream << (qint32)(p()->m_tessellationFlags); for( QVector<GeoDataCoordinates>::const_iterator iterator = p()->m_vector.constBegin(); iterator != p()->m_vector.constEnd(); ++iterator ) { mDebug() << "innerRing: size" << p()->m_vector.size(); GeoDataCoordinates coord = ( *iterator ); coord.pack( stream ); } }
void GeoDataLineStringPrivate::interpolateDateLine( const GeoDataCoordinates & previousCoords, const GeoDataCoordinates & currentCoords, GeoDataCoordinates & previousAtDateLine, GeoDataCoordinates & currentAtDateLine, TessellationFlags f ) { GeoDataCoordinates dateLineCoords; int recursionCounter = 0; // mDebug() << Q_FUNC_INFO; if ( f.testFlag( RespectLatitudeCircle ) && previousCoords.latitude() == currentCoords.latitude() ) { dateLineCoords = currentCoords; } else { dateLineCoords = findDateLine( previousCoords, currentCoords, recursionCounter ); } previousAtDateLine = dateLineCoords; currentAtDateLine = dateLineCoords; if ( previousCoords.longitude() < 0 ) { previousAtDateLine.setLongitude( -M_PI ); currentAtDateLine.setLongitude( +M_PI ); } else { previousAtDateLine.setLongitude( +M_PI ); currentAtDateLine.setLongitude( -M_PI ); } }
void GeoDataLineString::unpack( QDataStream& stream ) { GeoDataGeometry::detach(); GeoDataGeometry::unpack( stream ); qint32 size; qint32 tessellationFlags; stream >> size; stream >> tessellationFlags; p()->m_tessellationFlags = (TessellationFlags)(tessellationFlags); for(qint32 i = 0; i < size; i++ ) { GeoDataCoordinates coord; coord.unpack( stream ); p()->m_vector.append( coord ); } }
void RoutingPluginPrivate::toggleGuidanceMode( bool enabled ) { if( !m_marbleWidget || m_guidanceModeEnabled == enabled ) { return; } m_guidanceModeEnabled = enabled; updateButtonVisibility(); if( enabled ) { QObject::connect( m_routingModel, SIGNAL(positionChanged()), m_parent, SLOT(updateDestinationInformation()) ); } else { QObject::disconnect( m_routingModel, SIGNAL(positionChanged()), m_parent, SLOT(updateDestinationInformation()) ); } if ( enabled ) { QString const text = QObject::tr( "Starting guidance mode, please wait..." ); m_widget.instructionLabel->setText( richText( "%1" ).arg( text ) ); } if ( enabled ) { RouteRequest* request = m_marbleWidget->model()->routingManager()->routeRequest(); if ( request && request->size() > 0 ) { GeoDataCoordinates source = request->source(); if ( source.isValid() ) { GeoDataLookAt view; view.setCoordinates( source ); // By happy coincidence this equals OpenStreetMap tile level 15 view.setRange( 851.807 ); m_marbleWidget->flyTo( view ); } } } m_marbleWidget->model()->routingManager()->setGuidanceModeEnabled( enabled ); if ( enabled ) { m_routeCompleted = false; } forceRepaint(); }
void TestGeoDataTrack::withoutTimeTest() { //"Simple Example" from kmlreference; when elements emptied QString content( "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" "<kml xmlns=\"http://www.opengis.net/kml/2.2\"" " xmlns:gx=\"http://www.google.com/kml/ext/2.2\">" "<Folder>" " <Placemark>" " <gx:Track>" " <when></when>" " <when></when>" " <when></when>" " <when></when>" " <when></when>" " <when></when>" " <when></when>" " <gx:coord>-122.207881 37.371915 156.000000</gx:coord>" " <gx:coord>-122.205712 37.373288 152.000000</gx:coord>" " <gx:coord>-122.204678 37.373939 147.000000</gx:coord>" " <gx:coord>-122.203572 37.374630 142.199997</gx:coord>" " <gx:coord>-122.203451 37.374706 141.800003</gx:coord>" " <gx:coord>-122.203329 37.374780 141.199997</gx:coord>" " <gx:coord>-122.203207 37.374857 140.199997</gx:coord>" " </gx:Track>" " </Placemark>" "</Folder>" "</kml>" ); GeoDataDocument* dataDocument = parseKml( content ); GeoDataFolder *folder = dataDocument->folderList().at( 0 ); QCOMPARE( folder->placemarkList().size(), 1 ); GeoDataPlacemark* placemark = folder->placemarkList().at( 0 ); QCOMPARE( placemark->geometry()->geometryId(), GeoDataTrackId ); GeoDataTrack* track = static_cast<GeoDataTrack*>( placemark->geometry() ); QCOMPARE( track->size(), 7 ); { GeoDataCoordinates coord = track->coordinatesList().at( 0 ); QCOMPARE( coord.longitude( GeoDataCoordinates::Degree ), -122.207881 ); QCOMPARE( coord.latitude( GeoDataCoordinates::Degree ), 37.371915 ); QCOMPARE( coord.altitude(), 156.000000 ); } { const GeoDataLineString *lineString = track->lineString(); QCOMPARE( lineString->size(), 7 ); GeoDataCoordinates coord = lineString->at( 0 ); QCOMPARE( coord.longitude( GeoDataCoordinates::Degree ), -122.207881 ); QCOMPARE( coord.latitude( GeoDataCoordinates::Degree ), 37.371915 ); QCOMPARE( coord.altitude(), 156.000000 ); } delete dataDocument; }