I need help getting Placemarks to show on my MarbleWidget with addGeoDataString
-
I believe I've got the correct function to put Placemarks on my MarbleWidget:
@void addGeoDataString (const QString &data, const QString &key="data")@
to put the Point indicated in this kml string onto my MarbleWidget
@<?xml version="1.0" encoding="UTF-8"?>
<kml>
<Document>
<Placemark>
<name>Houlton International Airport</name>
<description>Weather Station</description>
<Point>
<coordinates>-67.8,46.12,150</coordinates>
</Point>
</Placemark>
</Document>
</kml>@but I'm getting nothing to appear.
( "xmlns="http://www.opengis.net/kml/2.2"" keeps getting cropped out of my kml open tag )Is my kml correct?
Do I need to call another function on MarbleWidget to display the newly added Points in the model?
I've left the second parameter empty, as it has a default, and frankly (from the "documentation":http://api.kde.org/4.6-api/kdeedu-apidocs/marble/html/classMarble_1_1MarbleWidget.html#a429644198835fbfc15982e552c41cc62)
@Parameters:
data- the string containing the Placemarks.
key- the string needed to identify the data@I don't know what "data" is supposed to indicate.
I've gone back in MarbleWidget source code, where the parameters flip-flopped places enough times to tangle me up.Mostly, I think this is probably a simple thing, and that I'm overlooking something obvious.
Anyone have a clue for me? -
I think you will get more and better replies on a question on Marble in a "mailinglist":https://mail.kde.org/mailman/listinfo/marble-devel dedicated to it.
-
Andre, Thanks, you are correct. I also asked there, and got this reply...
(I'll include for anyone else looking for this response)
[quote]
Hi,I think that you need to update the data model so that the new placemark
appears on the mapwidget. A call to
@
marblewidget->model()->treeModel()->update()
@
(working with the latest code on git) should do it, but it maybe slow if you need to add many placemarks.I am working on adding a function "addFeature" to GeoDataTreeModel which will work the same way as addDocument, updating only the data you replaced, which should work better if you have a large number of placemarks to add. It works fine in single-threaded mode (see attached file for a patch).
If you want to give it a try, you will have to create your kml tree, something like:
@
Marble::GeoDataDocument *mydoc=new Marble::GeoDataDocument();
mydoc->setFileName("mydocument.kml"); //Will identify the document internally, must be unique
mydoc->setName("My_GeoDataDocument"); //Name for visualisation in MarbleWidgetMarble::GeoDataFolder *myfolder=new Marble::GeoDataFolder; myfolder->setName("My first folder"); //(setName from base class GeoDataFeature, inherited from GeoDataContainer) Marble::GeoDataPlacemark *myplacemark=new Marble::GeoDataPlacemark; myplacemark->setName("A placemark in a folder"); marblewidget->model()->treeModel()->addDocument(mydoc); marblewidget->model()->treeModel()->addFeature(mydoc, myfolder); marblewidget->model()->treeModel()->addFeature(myfolder, myplacemark);
@
You can also retrieve an existing element GeoData... structure from its QModelIndex (for instance, if you loaded an existing document with a
call to MarbleWidget::addDocument(QString) ):
@
GeoDataObject* geoobject = static_cast<GeoDataObject*>( modelindex.internalPointer()
@I have added GeoDataTreeModel::index(GeoDataFeature*) function to recover the QModelIndex of a feature already present in the treemodel, I am not sure if there is an easier way to get the model (I go through up the tree upto top-level node m_rootDocument, and then build the index downwards, any ideas?).
The attached code is work in progress. My plan is to include:
- Implement a removeFeature function
- Reimplement calls to addDocument and removeDocument with calls to new functions addFeature and removeFeature (so that all the code to do the update is centered in a single function).
- Add protection for multithreaded operation. With code on svn (and my patch as it is) a single call to addDocument from a thread different of the main thread causes the application to crash.
I am having some trouble with multithreading, I will send a message to the list asking for help on this later.
I will be glad to hear any feedback you may have on the patch, I will submit it to reviewboard when it is complete.
Hth
Javier[/quote]Edit: added a bit of markup. Especially on code sections, could you please use @ tags to properly format them?; Andre