OSM plugin: dataset_deliverer now re-fetches data if the URL has changed
This commit is contained in:
parent
f8fec4ab88
commit
4aba853d7a
5 changed files with 42 additions and 9 deletions
|
@ -3,6 +3,7 @@
|
|||
#include <sstream>
|
||||
|
||||
osm_dataset * dataset_deliverer::dataset=NULL;
|
||||
std::string dataset_deliverer::last_bbox = "";
|
||||
|
||||
osm_dataset* dataset_deliverer::load_from_file(const string& file,
|
||||
const string& parser)
|
||||
|
@ -22,12 +23,23 @@ osm_dataset* dataset_deliverer::load_from_file(const string& file,
|
|||
osm_dataset* dataset_deliverer::load_from_url
|
||||
(const string& url,const string& bbox,const string& parser)
|
||||
{
|
||||
|
||||
if(dataset==NULL)
|
||||
{
|
||||
dataset = new osm_dataset;
|
||||
if(dataset->load_from_url(url.c_str(),bbox,parser)==false)
|
||||
return NULL;
|
||||
atexit(dataset_deliverer::release);
|
||||
last_bbox = bbox;
|
||||
}
|
||||
return dataset;
|
||||
else if (bbox != last_bbox)
|
||||
{
|
||||
cerr<<"BBOXES ARE DIFFERENT: " << last_bbox<<","<<bbox<<endl;
|
||||
// Reload the dataset
|
||||
dataset->clear();
|
||||
if(dataset->load_from_url(url.c_str(),bbox,parser)==false)
|
||||
return NULL;
|
||||
last_bbox = bbox;
|
||||
}
|
||||
return dataset;
|
||||
}
|
||||
|
|
|
@ -7,16 +7,17 @@ using namespace std;
|
|||
class dataset_deliverer
|
||||
{
|
||||
private:
|
||||
static osm_dataset* dataset;
|
||||
static osm_dataset* dataset;
|
||||
static std::string last_bbox;
|
||||
|
||||
public:
|
||||
static osm_dataset *load_from_file(const string&,const string&);
|
||||
static osm_dataset *load_from_url
|
||||
(const string&,const string&,const string&);
|
||||
static osm_dataset *load_from_file(const string&,const string&);
|
||||
static osm_dataset *load_from_url
|
||||
(const string&,const string&,const string&);
|
||||
|
||||
static void release()
|
||||
{
|
||||
delete dataset;
|
||||
}
|
||||
static void release()
|
||||
{
|
||||
delete dataset;
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -53,10 +53,28 @@ bool osm_dataset::load_from_url(const std::string& url,
|
|||
|
||||
osm_dataset::~osm_dataset()
|
||||
{
|
||||
clear();
|
||||
}
|
||||
|
||||
void osm_dataset::clear()
|
||||
{
|
||||
cerr<<"osm_dataset::clear()"<<endl;
|
||||
cerr<<"deleting ways"<<endl;
|
||||
for(unsigned int count=0; count<ways.size(); count++)
|
||||
{
|
||||
delete ways[count];
|
||||
ways[count]=NULL;
|
||||
}
|
||||
cerr<<"deleting nodes"<<endl;
|
||||
for(unsigned int count=0; count<nodes.size(); count++)
|
||||
{
|
||||
delete nodes[count];
|
||||
nodes[count]=NULL;
|
||||
}
|
||||
cerr<<"Clearing ways/nodes"<<endl;
|
||||
ways.clear();
|
||||
nodes.clear();
|
||||
cerr<<"Done"<<endl;
|
||||
}
|
||||
|
||||
std::string osm_dataset::to_string()
|
||||
|
|
|
@ -84,6 +84,7 @@ public:
|
|||
bool load_from_url(const std::string&,const std::string&,
|
||||
const std::string& parser="libxml2");
|
||||
~osm_dataset();
|
||||
void clear();
|
||||
void add_node(osm_node* n) { nodes.push_back(n); }
|
||||
void add_way(osm_way* w) { ways.push_back(w); }
|
||||
std::string to_string();
|
||||
|
|
|
@ -62,6 +62,7 @@ osm_datasource::osm_datasource(const parameters ¶ms)
|
|||
if (url!="" && bbox!="")
|
||||
{
|
||||
// otherwise if we supplied a url and a bounding box, load from the url
|
||||
cerr<<"loading_from_rul: url="<<url << " bbox="<<bbox<<endl;
|
||||
if((osm_data_=dataset_deliverer::load_from_url
|
||||
(url,bbox,parser))==NULL)
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue