[Marble-devel] Re: Drawing Placemarks - with a name.

Thibaut GRIDEL tgridel at free.fr
Wed Dec 22 23:11:43 CET 2010


Hello Miguel,

* Miguel Chavez Gamboa [2010-12-22 04:22]:
>    Hi,
>    Im using marble lib from the svn, latest revision, and I would like to
>    know about the placemarks.
>    I want to set Placemarks on the marble widget with the names of points in
>    a route (programatically), like the runners example in the techbase to
>    mark a point somewhere with a label and a dot.

The Runners api is one way to write custom search or provider for
placemarks/routes/geocoding. Their goal in the end is to populate a list
of placemark in the search list result (and clicking on them would
display something on the map).

If I understand your need, you would rather want to provide a list of
placemarks for them to be rendered.

The code for this usecase is still under rework atm, what works
already for some apps is providing a kml/gpx file through the
addGeoDataFile call. This should display your placemark points and
geometries, relying on marble internal rendering code (PlacemarkLayout
and GeometryLayer if you want to track that code).

Depending on your choice, you may want either to provide such file to
marble and render those with internal drawing, or also implement a
(plugin or not) render layer with your own drawing
(plugins like aprs, and online services do just that)

In other words, using the Runner api is good to _fetch_ data, but
rendering is not easily adressed: the api is either limited
(provide a kml file), or too much DIY (do your own layer).

For sure we will be working on this front in next versions, the need is
all too common.

The existing code is:
- widget parses xml file (geodata parser within marble internals)
- GeoDataDocument is appended to FileManager (current way of handling
  placemark files)
- Model/View expose this geodata (GeoDataTreeModel in this latest version)
- layers draw this ( GeometryLayer for polygons... PlacemarkLayout for
  points)

The road for improvement is:
file reading is only one case to provide GeoData
(placemarks/polygons... you name it)

expose data in a consistent model/view way

render using layer framework (and do perfo optimisations as well)

bring plugins wherever we want genericity, keep internal when we don't
expect custom needs.

>    I have viewed the marble code and the techbase runners Example to get some
>    clues, and I wrote the next code:
> 
>  void MainWindow::setPlaces()
> 
>  {
> 
>      QVector<GeoDataPlacemark *> *vector = new QVector<GeoDataPlacemark *>;
> 
>      foreach ( LCDestinationInfo point, viaPoints ) {
> 
>          GeoDataPlacemark *placemark = new GeoDataPlacemark( point.name );

...
you may want to use popularity, visibility as well, look in
PlacemarkLayout code if/what filters drawing.

> 
>          vector->append( placemark );
> 
>      }
> 
>      MarblePlacemarkModel *placemarkModel = static_cast<MarblePlacemarkModel*>( theMap->placemarkModel() );
> 
>      placemarkModel->setPlacemarkContainer( vector );


Ouch.
The PlacemarkModel is only intended for read access, and work is going on
to remove its ugly container management.
Your code bypasses all model/view checks around, therefore is sure to
crash libmarble. The MarbleRunnerManager and PlacemarkManager manipulate it
in a consistent way.

>  The code runs without problems, nothing is painted on the map at the locations. After the application's window lost focus (i launch a calculator or show the yakuake window), the program crashes.This make me think about an update in the marble widget and the inserted placemarks making some unexpected thing together.
> 
>    Maybe im not using the right class (GeoDataPlacemark). I have seen on the
>    documentation the classes VisiblePlacemark, PlacemarkLayout, and
>    PlacemarkPainter, but i could not find how to use them.

GeoDataPlacemark and GeoData classes in general is the api of choice to
represent your data.
We try to keep the other as internal rendering code only.

The solution if you want custom painting is to implement a layer.

>    I also tried to use marbleWidget's addPlacemarkFile() method (and did
>    further tests with marble -the application- A opening a kml file) with
>    sample xml from google kml documentation, but nothing is rendered on the
>    map (i think the placemarks are not visible or not drawn, just added
>    invisible placemarks -like bookmarks-). I noted that if i placed
>    placemarks with a pathA the path is drawn on the map (with the
>    addPlacemarkFile() method), which makes me think that drawing Placemarks
>    is not implemented in marble when loading placemarks from kml
>    files.

Placemarks should be drawn indeed. There are some reasons however that
drawing is not happening: you use a map theme which disables placemark
rendering (osm does filter those unless you have the "Places of interest"
checked in the legend)

Another reason is the filtering happening in PlacemarkLayout is not in
your favour. (Popularity/Population/limit on placemarks displayed ...)

>    I also foundA PlacemarkTextAnnotation class, and the osmannotate plugin
>    but this is not compiled (commented on the CMakeLists.txt). Is it not
>    finished?

It was a proof of concept as part of a google summer of code. That code
is currently disabled indeed as it went the easy way of mixing model
data and rendering in the same classes.

Shoud you need more help, do not hesitate to ask here, in #marble on
freenode, and also have a look at techbase.kde.org/Projects/Marble

Best Regards,

Thibaut


More information about the Marble-devel mailing list