Q_OBJECT
public:
- NaturalEarthDataLoaderThread()
+ NaturalEarthDataLoaderThread() :
+ m_lineInsertCount(0)
{
connect(this, &QThread::finished, this, &NaturalEarthDataLoaderThread::onFinished);
}
loadNaturalEarthFile("ne_10m_urban_areas.shp", flightgear::PolyLine::URBAN, true);
qDebug() << "loading urban areas took:" << st.elapsedMSec();
-
}
private:
void onFinished()
{
- flightgear::PolyLine::bulkAddToSpatialIndex(m_parsedLines);
- qDebug() << "finished loading Natural Earth data";
- deleteLater(); // commit suicide
+ flightgear::PolyLineList::const_iterator begin = m_parsedLines.begin() + m_lineInsertCount;
+ unsigned int numToAdd = std::min(1000UL, m_parsedLines.size() - m_lineInsertCount);
+ flightgear::PolyLineList::const_iterator end = begin + numToAdd;
+ flightgear::PolyLine::bulkAddToSpatialIndex(begin, end);
+
+ if (end == m_parsedLines.end()) {
+ deleteLater(); // commit suicide
+ } else {
+ m_lineInsertCount += 1000;
+ QTimer::singleShot(50, this, &NaturalEarthDataLoaderThread::onFinished);
+ }
}
void loadNaturalEarthFile(const std::string& aFileName,
}
flightgear::PolyLineList m_parsedLines;
+ unsigned int m_lineInsertCount;
};
} // of anonymous namespace
return new PolyLine(aTy, aRawPoints);
}
-void PolyLine::bulkAddToSpatialIndex(const PolyLineList &lines)
+void PolyLine::bulkAddToSpatialIndex(PolyLineList::const_iterator begin,
+ PolyLineList::const_iterator end)
{
NavDataCache::Transaction txn( NavDataCache::instance());
flightgear::PolyLineList::const_iterator it;
- for (it=lines.begin(); it != lines.end(); ++it) {
+ for (it=begin; it != end; ++it) {
(*it)->addToSpatialIndex();
}
txn.commit();
static PolyLineRef create(Type aTy, const SGGeodVec& aRawPoints);
- static void bulkAddToSpatialIndex(const PolyLineList& lines);
+ static void bulkAddToSpatialIndex(PolyLineList::const_iterator begin,
+ PolyLineList::const_iterator end);
/**
* retrieve all the lines within a range of a search point.