This forum has been archived. All content is frozen. Please use KDE Discuss instead.

MarbleWidget::whichFeatureAt and GeoDataPlacemark

Tags: None
(comma "," separated)
vfr
Registered Member
Posts
3
Karma
0
Hello

I'm using MarbleWidget (Qt 5.4, Marble 4.14) and added some placemarks to my map, using GeoDataDocument::append(). Further I extendend the widget's pop-up menu with an action to show additional information depending on the placemarks name.

Snippet from the slot called by the popup menu action:
Code: Select all
...
    QPoint mousePos = m_pPopupMenu->mousePosition();
    QVector<const GeoDataPlacemark *> placeMark = m_pMapWidget->whichFeatureAt(mousePos);
    if (placeMark.empty())
    {
        return;  // no placemark at this position
    }
    QString airportId = placeMark.first()->name();
    QUrl url = QUrl(urlBase.arg(airportId));
...

This works fine.

I further added GeoDataPlacemarks with a more complex geometry, using the GeoDataLinearRing object and GeoDataPlacemark::setGeometry(), as described in https://techbase.kde.org/Projects/Marbl ... aPlacemark. These polygons are shown perfectly on the map as well.

How I create and add Placemarks with polygon geometry:
Code: Select all

    Marble::GeoDataPolyStyle polyStyle( QColor( 0, 0, 0, 255 ) ); 
    polyStyle.setFill( true );
    Marble::GeoDataStyle *styleClassD = new Marble::GeoDataStyle;
    Marble::GeoDataLineStyle lineStyleD( QColor( 0, 0, 200, 90 ) );
    lineStyleD.setWidth ( 8 );
    styleClassD->setLineStyle( lineStyleD );
    styleClassD->setPolyStyle( polyStyle );
    Marble::GeoDataPlacemark *placemarkTemp = new Marble::GeoDataPlacemark();
    QStringList polygon = query.value(1).toString().split(",");
    Marble::GeoDataLinearRing *ring = new Marble::GeoDataLinearRing;
    for (int i = 0; i < polygon.size(); i++) {
        QStringList coord = polygon.at(i).trimmed().split(" ");
        *ring << Marble::GeoDataCoordinates(coord.at(0).toFloat(), coord.at(1).toFloat(), 0, Marble::GeoDataCoordinates::Degree);
    }
    placemarkTemp->setGeometry(ring);
    placemarkTemp->setStyle(styleClassD);
    document.append(placemarkTemp);



But they do not appear in the vector returned by whichFeatureAt(mousePos)! I already tried with setFill(true) and setFill(false), but no difference.
How can I trigger a mouse event on one of these GeoDataPlacemark polygons?

Thanks a lot!
User avatar
tackat
KDE Developer
Posts
131
Karma
0
OS
Looking at the source code I'm afraid this hasn't been implemented yet.
The method

QVector<const GeoDataFeature*> MarbleWidget::whichFeatureAt( const QPoint &curpos ) const

is supposed to return features. And while geometries like polygons, rings and linestrings might be associated to features we don't take them into consideration (yet).
In addition to this there is a method

:QVector<const GeoDataFeature*> GeometryLayer::whichFeatureAt(const QPoint& curpos , const ViewportParams *viewport)

which gets called by the same method inside MarbleWidget however in this one the geometries aren't taken into consideration yet either.

It might be nice to add this (possibly as a specialized whichGeometryAt() method). Implementing this could be a matter of testing for the latLonBox of each geometry and if that returns true recheck by checking whether the cursorPosition is contained inside GeoPainter::regionFromPolygon()). All this would require someone to create a patch :-)


Bookmarks



Who is online

Registered users: Bing [Bot], daret, Google [Bot], Sogou [Bot]