Defer projection init

This commit is contained in:
Artem Pavlenko 2021-03-15 18:09:21 +00:00
parent 6099804559
commit 387d54fe9d
2 changed files with 30 additions and 30 deletions

View file

@ -421,11 +421,11 @@ void MainWindow::set_default_extent(double x0,double y0, double x1, double y1)
if (map_ptr) if (map_ptr)
{ {
mapnik::projection prj(map_ptr->srs()); mapnik::projection prj(map_ptr->srs());
prj.forward(x0,y0); prj.forward(x0, y0);
prj.forward(x1,y1); prj.forward(x1, y1);
default_extent_=mapnik::box2d<double>(x0,y0,x1,y1); default_extent_=mapnik::box2d<double>(x0, y0, x1, y1);
mapWidget_->zoomToBox(default_extent_); mapWidget_->zoomToBox(default_extent_);
std::cout << "SET DEFAULT EXT\n"; std::cout << "SET DEFAULT EXT:" << default_extent_ << std::endl;
} }
} }
catch (...) {} catch (...) {}

View file

@ -156,7 +156,7 @@ void MapWidget::mousePressEvent(QMouseEvent* e)
{ {
QVector<QPair<QString,QString> > info; QVector<QPair<QString,QString> > info;
projection map_proj(map_->srs()); // map projection projection map_proj(map_->srs(), true); // map projection
double scale_denom = scale_denominator(map_->scale(),map_proj.is_geographic()); double scale_denom = scale_denominator(map_->scale(),map_proj.is_geographic());
view_transform t(map_->width(),map_->height(),map_->get_current_extent()); view_transform t(map_->width(),map_->height(),map_->get_current_extent());
@ -170,7 +170,7 @@ void MapWidget::mousePressEvent(QMouseEvent* e)
double x = e->x(); double x = e->x();
double y = e->y(); double y = e->y();
std::cout << "query at " << x << "," << y << "\n"; std::cout << "query at " << x << "," << y << "\n";
projection layer_proj(layer.srs()); projection layer_proj(layer.srs(), true);
mapnik::proj_transform prj_trans(map_proj,layer_proj); mapnik::proj_transform prj_trans(map_proj,layer_proj);
//std::auto_ptr<mapnik::memory_datasource> data(new mapnik::memory_datasource); //std::auto_ptr<mapnik::memory_datasource> data(new mapnik::memory_datasource);
mapnik::featureset_ptr fs = map_->query_map_point(index,x,y); mapnik::featureset_ptr fs = map_->query_map_point(index,x,y);
@ -586,43 +586,43 @@ void MapWidget::updateMap()
try try
{ {
projection prj(map_->srs()); // map projection projection prj(map_->srs(), true); // map projection
box2d<double> ext = map_->get_current_extent(); box2d<double> ext = map_->get_current_extent();
double x0 = ext.minx(); double x0 = ext.minx();
double y0 = ext.miny(); double y0 = ext.miny();
double x1 = ext.maxx(); double x1 = ext.maxx();
double y1 = ext.maxy(); double y1 = ext.maxy();
double z = 0; double z = 0;
std::string dest_srs = {"epsg:4326"}; std::string dest_srs = {"epsg:4326"};
mapnik::proj_transform proj_tr(map_->srs(), dest_srs); mapnik::proj_transform proj_tr(map_->srs(), dest_srs);
proj_tr.forward(x0, y0, z); proj_tr.forward(x0, y0, z);
proj_tr.forward(x1, y1, z); proj_tr.forward(x1, y1, z);
std::cout << "MAP SIZE:" << map_->width() << "," << map_->height() << std::endl; std::cout << "MAP SIZE:" << map_->width() << "," << map_->height() << std::endl;
std::cout << "BBOX (WGS84): " << x0 << "," << y0 << "," << x1 << "," << y1 << "\n"; std::cout << "BBOX (WGS84): " << x0 << "," << y0 << "," << x1 << "," << y1 << "\n";
update(); update();
// emit signal to interested widgets // emit signal to interested widgets
emit mapViewChanged(); emit mapViewChanged();
} }
catch (...) catch (...)
{ {
std::cerr << "Unknown exception caught!\n"; std::cerr << "Unknown exception caught!\n";
} }
} }
} }
std::shared_ptr<Map> MapWidget::getMap() std::shared_ptr<Map> MapWidget::getMap()
{ {
return map_; return map_;
} }
void MapWidget::setMap(std::shared_ptr<Map> map) void MapWidget::setMap(std::shared_ptr<Map> map)
{ {
map_ = map; map_ = map;
} }
void MapWidget::layerSelected(int index) void MapWidget::layerSelected(int index)
{ {
selectedLayer_ = index; selectedLayer_ = index;
} }