2007-08-07 17:09:41 +02:00
|
|
|
/* This file is part of Mapnik (c++ mapping toolkit)
|
2011-10-23 16:09:12 +02:00
|
|
|
*
|
2021-01-05 15:39:07 +01:00
|
|
|
* Copyright (C) 2021 Artem Pavlenko
|
2007-08-07 17:09:41 +02:00
|
|
|
*
|
|
|
|
* Mapnik is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
2016-01-26 10:54:42 +01:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2007-08-07 17:09:41 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#include <QtGui>
|
|
|
|
|
|
|
|
#include <boost/bind.hpp>
|
|
|
|
#include <mapnik/agg_renderer.hpp>
|
|
|
|
#include <mapnik/layer.hpp>
|
2021-03-09 16:02:11 +01:00
|
|
|
#include <mapnik/proj_transform.hpp>
|
2011-09-08 10:21:41 +02:00
|
|
|
#include <mapnik/scale_denominator.hpp>
|
2014-08-28 11:29:04 +02:00
|
|
|
#include <mapnik/view_transform.hpp>
|
2014-08-28 11:59:08 +02:00
|
|
|
#include <mapnik/transform_path_adapter.hpp>
|
2007-08-07 17:09:41 +02:00
|
|
|
#include <mapnik/memory_datasource.hpp>
|
2012-01-13 18:19:03 +01:00
|
|
|
#include <mapnik/feature_kv_iterator.hpp>
|
2012-05-03 16:21:17 +02:00
|
|
|
#include <mapnik/image_util.hpp>
|
2013-12-02 11:14:11 +01:00
|
|
|
#include <mapnik/util/timer.hpp>
|
2012-05-03 16:21:17 +02:00
|
|
|
|
|
|
|
#ifdef HAVE_CAIRO
|
|
|
|
// cairo
|
2015-09-30 16:28:59 +02:00
|
|
|
#include <mapnik/cairo/cairo_image_util.hpp>
|
2014-06-06 14:38:00 +02:00
|
|
|
#include <mapnik/cairo/cairo_renderer.hpp>
|
2012-05-03 16:21:17 +02:00
|
|
|
#endif
|
|
|
|
|
2007-08-07 17:09:41 +02:00
|
|
|
#include "mapwidget.hpp"
|
|
|
|
#include "info_dialog.hpp"
|
|
|
|
|
2015-01-22 03:31:02 +01:00
|
|
|
using mapnik::image_rgba8;
|
2007-08-07 17:09:41 +02:00
|
|
|
using mapnik::Map;
|
2009-12-16 21:02:06 +01:00
|
|
|
using mapnik::layer;
|
|
|
|
using mapnik::box2d;
|
2007-08-07 17:09:41 +02:00
|
|
|
using mapnik::coord2d;
|
|
|
|
using mapnik::feature_ptr;
|
2014-08-28 11:17:15 +02:00
|
|
|
using mapnik::view_transform;
|
2007-08-07 17:09:41 +02:00
|
|
|
using mapnik::projection;
|
2011-09-08 10:21:41 +02:00
|
|
|
using mapnik::scale_denominator;
|
2012-01-13 18:19:03 +01:00
|
|
|
using mapnik::feature_kv_iterator;
|
2007-08-07 17:09:41 +02:00
|
|
|
|
|
|
|
double scales [] = {279541132.014,
|
|
|
|
139770566.007,
|
|
|
|
69885283.0036,
|
|
|
|
34942641.5018,
|
|
|
|
17471320.7509,
|
|
|
|
8735660.37545,
|
|
|
|
4367830.18772,
|
|
|
|
2183915.09386,
|
|
|
|
1091957.54693,
|
|
|
|
545978.773466,
|
|
|
|
272989.386733,
|
|
|
|
136494.693366,
|
|
|
|
68247.3466832,
|
|
|
|
34123.6733416,
|
|
|
|
17061.8366708,
|
|
|
|
8530.9183354,
|
|
|
|
4265.4591677,
|
|
|
|
2132.72958385,
|
|
|
|
1066.36479192,
|
|
|
|
533.182395962};
|
|
|
|
|
2011-10-23 16:09:12 +02:00
|
|
|
MapWidget::MapWidget(QWidget *parent)
|
2007-10-05 13:27:00 +02:00
|
|
|
: QWidget(parent),
|
|
|
|
map_(),
|
|
|
|
selected_(1),
|
|
|
|
extent_(),
|
|
|
|
cur_tool_(ZoomToBox),
|
|
|
|
start_x_(0),
|
|
|
|
start_y_(0),
|
|
|
|
end_x_(0),
|
|
|
|
end_y_(0),
|
|
|
|
drag_(false),
|
|
|
|
first_(true),
|
|
|
|
pen_(QColor(0,0,255,96)),
|
2010-06-17 10:26:08 +02:00
|
|
|
selectedLayer_(-1),
|
2012-05-03 16:21:17 +02:00
|
|
|
scaling_factor_(1.0),
|
|
|
|
cur_renderer_(AGG)
|
2007-08-07 17:09:41 +02:00
|
|
|
{
|
|
|
|
pen_.setWidth(3);
|
|
|
|
pen_.setCapStyle(Qt::RoundCap);
|
|
|
|
pen_.setJoinStyle(Qt::RoundJoin);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MapWidget::setTool(eTool tool)
|
|
|
|
{
|
|
|
|
cur_tool_=tool;
|
|
|
|
}
|
|
|
|
|
|
|
|
void MapWidget::paintEvent(QPaintEvent*)
|
2011-10-23 16:09:12 +02:00
|
|
|
{
|
2007-08-07 17:09:41 +02:00
|
|
|
QPainter painter(this);
|
2011-10-23 16:09:12 +02:00
|
|
|
|
2007-08-07 17:09:41 +02:00
|
|
|
if (drag_)
|
|
|
|
{
|
|
|
|
if (cur_tool_ == ZoomToBox)
|
|
|
|
{
|
|
|
|
unsigned width = end_x_-start_x_;
|
|
|
|
unsigned height = end_y_-start_y_;
|
|
|
|
painter.drawPixmap(QPoint(0, 0),pix_);
|
|
|
|
painter.setPen(pen_);
|
2010-06-03 14:34:37 +02:00
|
|
|
painter.setBrush(QColor(200,200,255,128));
|
2007-08-07 17:09:41 +02:00
|
|
|
painter.drawRect(start_x_,start_y_,width,height);
|
|
|
|
}
|
|
|
|
else if (cur_tool_ == Pan)
|
|
|
|
{
|
|
|
|
int dx = end_x_-start_x_;
|
|
|
|
int dy = end_y_-start_y_;
|
2010-06-01 15:30:53 +02:00
|
|
|
painter.setBrush(QColor(200,200,200,128));
|
2007-08-07 17:09:41 +02:00
|
|
|
painter.drawRect(0,0,width(),height());
|
|
|
|
painter.drawPixmap(QPoint(dx,dy),pix_);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
painter.drawPixmap(QPoint(0, 0),pix_);
|
|
|
|
}
|
|
|
|
painter.end();
|
|
|
|
}
|
2011-10-23 16:09:12 +02:00
|
|
|
|
2007-08-07 17:09:41 +02:00
|
|
|
void MapWidget::resizeEvent(QResizeEvent * ev)
|
|
|
|
{
|
|
|
|
if (map_)
|
|
|
|
{
|
|
|
|
map_->resize(ev->size().width(),ev->size().height());
|
2008-06-29 12:58:29 +02:00
|
|
|
updateMap();
|
2007-08-07 17:09:41 +02:00
|
|
|
}
|
|
|
|
}
|
2011-10-23 16:09:12 +02:00
|
|
|
|
2007-08-07 17:09:41 +02:00
|
|
|
void MapWidget::mousePressEvent(QMouseEvent* e)
|
|
|
|
{
|
2011-10-23 16:09:12 +02:00
|
|
|
if (e->button()==Qt::LeftButton)
|
2007-08-07 17:09:41 +02:00
|
|
|
{
|
|
|
|
if (cur_tool_ == ZoomToBox || cur_tool_==Pan)
|
|
|
|
{
|
|
|
|
start_x_ = e->x();
|
|
|
|
start_y_ = e->y();
|
|
|
|
drag_=true;
|
|
|
|
}
|
|
|
|
else if (cur_tool_==Info)
|
|
|
|
{
|
|
|
|
if (map_)
|
2011-10-23 16:09:12 +02:00
|
|
|
{
|
2007-08-07 17:09:41 +02:00
|
|
|
QVector<QPair<QString,QString> > info;
|
2011-10-23 16:09:12 +02:00
|
|
|
|
2021-03-15 19:09:21 +01:00
|
|
|
projection map_proj(map_->srs(), true); // map projection
|
2013-02-21 11:39:02 +01:00
|
|
|
double scale_denom = scale_denominator(map_->scale(),map_proj.is_geographic());
|
2014-08-28 11:17:15 +02:00
|
|
|
view_transform t(map_->width(),map_->height(),map_->get_current_extent());
|
2011-10-23 16:09:12 +02:00
|
|
|
|
2010-06-25 17:23:35 +02:00
|
|
|
for (unsigned index = 0; index < map_->layer_count();++index)
|
2007-08-07 17:09:41 +02:00
|
|
|
{
|
2007-10-05 13:27:00 +02:00
|
|
|
if (int(index) != selectedLayer_) continue;
|
2011-10-23 16:09:12 +02:00
|
|
|
|
2009-12-16 21:02:06 +01:00
|
|
|
layer & layer = map_->layers()[index];
|
2012-03-12 16:39:59 +01:00
|
|
|
if (!layer.visible(scale_denom)) continue;
|
2007-08-07 17:09:41 +02:00
|
|
|
std::string name = layer.name();
|
|
|
|
double x = e->x();
|
|
|
|
double y = e->y();
|
|
|
|
std::cout << "query at " << x << "," << y << "\n";
|
2021-03-15 19:09:21 +01:00
|
|
|
projection layer_proj(layer.srs(), true);
|
2007-10-05 13:27:00 +02:00
|
|
|
mapnik::proj_transform prj_trans(map_proj,layer_proj);
|
|
|
|
//std::auto_ptr<mapnik::memory_datasource> data(new mapnik::memory_datasource);
|
2007-08-07 17:09:41 +02:00
|
|
|
mapnik::featureset_ptr fs = map_->query_map_point(index,x,y);
|
2011-10-23 16:09:12 +02:00
|
|
|
|
2007-08-07 17:09:41 +02:00
|
|
|
if (fs)
|
|
|
|
{
|
2015-02-18 13:21:16 +01:00
|
|
|
feature_ptr feat = fs->next();
|
|
|
|
if (feat)
|
|
|
|
{
|
|
|
|
feature_kv_iterator itr(*feat,true);
|
|
|
|
feature_kv_iterator end(*feat);
|
|
|
|
|
|
|
|
for ( ;itr!=end; ++itr)
|
|
|
|
{
|
|
|
|
info.push_back(QPair<QString,QString>(QString(std::get<0>(*itr).c_str()),
|
|
|
|
std::get<1>(*itr).to_string().c_str()));
|
|
|
|
}
|
|
|
|
|
2015-10-08 15:52:41 +02:00
|
|
|
#if 0 //
|
2015-02-18 13:21:16 +01:00
|
|
|
using path_type = mapnik::transform_path_adapter<mapnik::view_transform,mapnik::vertex_adapter>;
|
|
|
|
|
2015-10-08 15:52:41 +02:00
|
|
|
for (unsigned i=0; i < feat->num_geometries();++i)
|
2015-02-18 13:21:16 +01:00
|
|
|
{
|
|
|
|
mapnik::geometry_type const& geom = feat->get_geometry(i);
|
|
|
|
mapnik::vertex_adapter va(geom);
|
|
|
|
path_type path(t,va,prj_trans);
|
|
|
|
if (va.size() > 0)
|
2007-10-05 13:27:00 +02:00
|
|
|
{
|
2015-02-18 13:21:16 +01:00
|
|
|
QPainterPath qpath;
|
|
|
|
double x,y;
|
|
|
|
va.vertex(&x,&y);
|
|
|
|
qpath.moveTo(x,y);
|
|
|
|
for (unsigned j = 1; j < geom.size(); ++j)
|
|
|
|
{
|
|
|
|
va.vertex(&x,&y);
|
|
|
|
qpath.lineTo(x,y);
|
|
|
|
}
|
|
|
|
QPainter painter(&pix_);
|
|
|
|
QPen pen(QColor(255,0,0,96));
|
|
|
|
pen.setWidth(3);
|
|
|
|
pen.setCapStyle(Qt::RoundCap);
|
|
|
|
pen.setJoinStyle(Qt::RoundJoin);
|
|
|
|
painter.setPen(pen);
|
|
|
|
painter.drawPath(qpath);
|
|
|
|
update();
|
2007-10-05 13:27:00 +02:00
|
|
|
}
|
2015-10-08 15:52:41 +02:00
|
|
|
}
|
2015-02-18 13:21:16 +01:00
|
|
|
#endif
|
2015-10-08 15:52:41 +02:00
|
|
|
}
|
2007-08-07 17:09:41 +02:00
|
|
|
}
|
2011-10-23 16:09:12 +02:00
|
|
|
|
2007-10-05 13:27:00 +02:00
|
|
|
if (info.size() > 0)
|
2007-08-07 17:09:41 +02:00
|
|
|
{
|
|
|
|
info_dialog info_dlg(info,this);
|
|
|
|
info_dlg.exec();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2011-10-23 16:09:12 +02:00
|
|
|
|
2007-08-07 17:09:41 +02:00
|
|
|
// remove annotation layer
|
|
|
|
map_->layers().erase(remove_if(map_->layers().begin(),
|
|
|
|
map_->layers().end(),
|
2009-12-16 21:02:06 +01:00
|
|
|
bind(&layer::name,_1) == "*annotations*")
|
2007-08-07 17:09:41 +02:00
|
|
|
, map_->layers().end());
|
|
|
|
}
|
2011-10-23 16:09:12 +02:00
|
|
|
}
|
2007-08-07 17:09:41 +02:00
|
|
|
}
|
2011-10-23 16:09:12 +02:00
|
|
|
else if (e->button()==Qt::RightButton)
|
|
|
|
{
|
2008-06-29 12:58:29 +02:00
|
|
|
//updateMap();
|
2007-08-07 17:09:41 +02:00
|
|
|
}
|
|
|
|
}
|
2011-10-23 16:09:12 +02:00
|
|
|
|
2007-08-07 17:09:41 +02:00
|
|
|
void MapWidget::mouseMoveEvent(QMouseEvent* e)
|
2011-10-23 16:09:12 +02:00
|
|
|
{
|
2007-08-07 17:09:41 +02:00
|
|
|
if (cur_tool_ == ZoomToBox || cur_tool_==Pan)
|
|
|
|
{
|
|
|
|
end_x_ = e->x();
|
|
|
|
end_y_ = e->y();
|
|
|
|
update();
|
2011-10-23 16:09:12 +02:00
|
|
|
}
|
2007-08-07 17:09:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void MapWidget::mouseReleaseEvent(QMouseEvent* e)
|
|
|
|
{
|
2011-10-23 16:09:12 +02:00
|
|
|
if (e->button()==Qt::LeftButton)
|
2007-08-07 17:09:41 +02:00
|
|
|
{
|
|
|
|
end_x_ = e->x();
|
|
|
|
end_y_ = e->y();
|
|
|
|
if (cur_tool_ == ZoomToBox)
|
|
|
|
{
|
|
|
|
drag_=false;
|
|
|
|
if (map_)
|
|
|
|
{
|
2014-08-28 11:17:15 +02:00
|
|
|
view_transform t(map_->width(),map_->height(),map_->get_current_extent());
|
2009-12-16 21:02:06 +01:00
|
|
|
box2d<double> box = t.backward(box2d<double>(start_x_,start_y_,end_x_,end_y_));
|
2010-06-25 17:23:35 +02:00
|
|
|
map_->zoom_to_box(box);
|
2008-06-29 12:58:29 +02:00
|
|
|
updateMap();
|
2007-08-07 17:09:41 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (cur_tool_==Pan)
|
|
|
|
{
|
|
|
|
drag_=false;
|
|
|
|
if (map_)
|
|
|
|
{
|
2010-06-25 17:23:35 +02:00
|
|
|
int cx = int(0.5 * map_->width());
|
|
|
|
int cy = int(0.5 * map_->height());
|
2007-08-07 17:09:41 +02:00
|
|
|
int dx = end_x_ - start_x_;
|
|
|
|
int dy = end_y_ - start_y_;
|
2011-10-23 16:09:12 +02:00
|
|
|
map_->pan(cx - dx ,cy - dy);
|
2008-06-29 12:58:29 +02:00
|
|
|
updateMap();
|
2007-08-07 17:09:41 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-01 01:16:19 +02:00
|
|
|
void MapWidget::wheelEvent(QWheelEvent* e)
|
|
|
|
{
|
|
|
|
if (!map_)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2021-10-07 20:05:11 +02:00
|
|
|
#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
|
|
|
|
QPointF corner(map_->width(), map_->height());
|
|
|
|
QPointF zoomCoords;
|
|
|
|
double zoom;
|
|
|
|
if (e->angleDelta().y() > 0)
|
|
|
|
{
|
|
|
|
zoom = 0.5;
|
|
|
|
QPointF center = corner / 2;
|
|
|
|
QPointF delta = e->position() - center;
|
|
|
|
zoomCoords = zoom * delta + center;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
zoom = 2.0;
|
|
|
|
zoomCoords = corner - e->position();
|
|
|
|
}
|
|
|
|
#else
|
2012-06-01 01:16:19 +02:00
|
|
|
QPoint corner(map_->width(), map_->height());
|
|
|
|
QPoint zoomCoords;
|
|
|
|
double zoom;
|
|
|
|
if (e->delta() > 0)
|
|
|
|
{
|
|
|
|
zoom = 0.5;
|
|
|
|
QPoint center = corner / 2;
|
|
|
|
QPoint delta = e->pos() - center;
|
|
|
|
zoomCoords = zoom * delta + center;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
zoom = 2.0;
|
|
|
|
zoomCoords = corner - e->pos();
|
|
|
|
}
|
2021-10-07 20:05:11 +02:00
|
|
|
#endif
|
2012-06-01 01:16:19 +02:00
|
|
|
|
|
|
|
map_->pan_and_zoom(zoomCoords.x(), zoomCoords.y(), zoom);
|
|
|
|
updateMap();
|
|
|
|
}
|
2007-08-07 17:09:41 +02:00
|
|
|
|
2011-10-23 16:09:12 +02:00
|
|
|
void MapWidget::keyPressEvent(QKeyEvent *e)
|
2007-08-07 17:09:41 +02:00
|
|
|
{
|
2009-12-16 21:02:06 +01:00
|
|
|
std::cout << "key pressed:"<< e->key()<<"\n";
|
2011-10-23 16:09:12 +02:00
|
|
|
switch (e->key()) {
|
2007-08-07 17:09:41 +02:00
|
|
|
case Qt::Key_Minus:
|
|
|
|
zoomOut();
|
|
|
|
break;
|
|
|
|
case Qt::Key_Plus:
|
|
|
|
case 61:
|
|
|
|
zoomIn();
|
|
|
|
break;
|
|
|
|
case 65:
|
|
|
|
defaultView();
|
|
|
|
break;
|
|
|
|
case Qt::Key_Up:
|
|
|
|
panUp();
|
|
|
|
break;
|
|
|
|
case Qt::Key_Down:
|
|
|
|
panDown();
|
2011-10-23 16:09:12 +02:00
|
|
|
break;
|
2007-08-07 17:09:41 +02:00
|
|
|
case Qt::Key_Left:
|
|
|
|
panLeft();
|
2011-10-23 16:09:12 +02:00
|
|
|
break;
|
2007-08-07 17:09:41 +02:00
|
|
|
case Qt::Key_Right:
|
|
|
|
panRight();
|
|
|
|
break;
|
|
|
|
case 49:
|
|
|
|
zoomToLevel(10);
|
|
|
|
break;
|
|
|
|
case 50:
|
|
|
|
zoomToLevel(11);
|
|
|
|
break;
|
|
|
|
case 51:
|
|
|
|
zoomToLevel(12);
|
2011-10-23 16:09:12 +02:00
|
|
|
break;
|
2007-08-07 17:09:41 +02:00
|
|
|
case 52:
|
|
|
|
zoomToLevel(13);
|
|
|
|
break;
|
|
|
|
case 53:
|
|
|
|
zoomToLevel(14);
|
|
|
|
break;
|
|
|
|
case 54:
|
|
|
|
zoomToLevel(15);
|
2011-10-23 16:09:12 +02:00
|
|
|
break;
|
2007-08-07 17:09:41 +02:00
|
|
|
case 55:
|
|
|
|
zoomToLevel(16);
|
|
|
|
break;
|
|
|
|
case 56:
|
|
|
|
zoomToLevel(17);
|
|
|
|
break;
|
|
|
|
case 57:
|
|
|
|
zoomToLevel(18);
|
2011-10-23 16:09:12 +02:00
|
|
|
break;
|
2009-12-16 21:02:06 +01:00
|
|
|
default:
|
|
|
|
QWidget::keyPressEvent(e);
|
2007-08-07 17:09:41 +02:00
|
|
|
}
|
2011-10-23 16:09:12 +02:00
|
|
|
|
|
|
|
|
2007-08-07 17:09:41 +02:00
|
|
|
}
|
|
|
|
|
2009-12-16 21:02:06 +01:00
|
|
|
void MapWidget::zoomToBox(mapnik::box2d<double> const& bbox)
|
2007-08-07 17:09:41 +02:00
|
|
|
{
|
|
|
|
if (map_)
|
|
|
|
{
|
2010-06-25 17:23:35 +02:00
|
|
|
map_->zoom_to_box(bbox);
|
2008-06-29 12:58:29 +02:00
|
|
|
updateMap();
|
2007-08-07 17:09:41 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-10-23 16:09:12 +02:00
|
|
|
void MapWidget::defaultView()
|
2007-08-07 17:09:41 +02:00
|
|
|
{
|
|
|
|
if (map_)
|
|
|
|
{
|
|
|
|
map_->resize(width(),height());
|
|
|
|
map_->zoom_all();
|
2008-06-29 12:58:29 +02:00
|
|
|
updateMap();
|
2007-08-07 17:09:41 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-10-23 16:09:12 +02:00
|
|
|
void MapWidget::zoomIn()
|
2007-08-07 17:09:41 +02:00
|
|
|
{
|
|
|
|
if (map_)
|
|
|
|
{
|
|
|
|
map_->zoom(0.5);
|
2008-06-29 12:58:29 +02:00
|
|
|
updateMap();
|
2007-08-07 17:09:41 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-10-23 16:09:12 +02:00
|
|
|
void MapWidget::zoomOut()
|
2007-08-07 17:09:41 +02:00
|
|
|
{
|
|
|
|
if (map_)
|
|
|
|
{
|
|
|
|
map_->zoom(2.0);
|
2008-06-29 12:58:29 +02:00
|
|
|
updateMap();
|
2007-08-07 17:09:41 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void MapWidget::panUp()
|
|
|
|
{
|
|
|
|
if (map_)
|
|
|
|
{
|
2010-06-25 17:23:35 +02:00
|
|
|
double cx = 0.5*map_->width();
|
|
|
|
double cy = 0.5*map_->height();
|
2007-08-07 17:09:41 +02:00
|
|
|
map_->pan(int(cx),int(cy - cy*0.25));
|
2008-06-29 12:58:29 +02:00
|
|
|
updateMap();
|
2007-08-07 17:09:41 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void MapWidget::panDown()
|
|
|
|
{
|
|
|
|
if (map_)
|
|
|
|
{
|
2010-06-25 17:23:35 +02:00
|
|
|
double cx = 0.5*map_->width();
|
|
|
|
double cy = 0.5*map_->height();
|
2007-08-07 17:09:41 +02:00
|
|
|
map_->pan(int(cx),int(cy + cy*0.25));
|
2008-06-29 12:58:29 +02:00
|
|
|
updateMap();
|
2007-08-07 17:09:41 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void MapWidget::panLeft()
|
|
|
|
{
|
|
|
|
if (map_)
|
|
|
|
{
|
2010-06-25 17:23:35 +02:00
|
|
|
double cx = 0.5*map_->width();
|
|
|
|
double cy = 0.5*map_->height();
|
2007-08-07 17:09:41 +02:00
|
|
|
map_->pan(int(cx - cx * 0.25),int(cy));
|
2008-06-29 12:58:29 +02:00
|
|
|
updateMap();
|
2007-08-07 17:09:41 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void MapWidget::panRight()
|
2011-10-23 16:09:12 +02:00
|
|
|
{
|
2007-08-07 17:09:41 +02:00
|
|
|
if (map_)
|
|
|
|
{
|
2010-06-25 17:23:35 +02:00
|
|
|
double cx = 0.5*map_->width();
|
|
|
|
double cy = 0.5*map_->height();
|
2011-10-23 16:09:12 +02:00
|
|
|
map_->pan(int(cx + cx * 0.25),int(cy));
|
2008-06-29 12:58:29 +02:00
|
|
|
updateMap();
|
2007-08-07 17:09:41 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void MapWidget::zoomToLevel(int level)
|
|
|
|
{
|
|
|
|
if ( map_ && level >= 0 && level < 19 )
|
|
|
|
{
|
|
|
|
double scale_denom = scales[level];
|
|
|
|
std::cerr << "scale denominator = " << scale_denom << "\n";
|
2010-06-25 17:23:35 +02:00
|
|
|
mapnik::box2d<double> ext = map_->get_current_extent();
|
|
|
|
double width = static_cast<double>(map_->width());
|
2011-10-23 16:09:12 +02:00
|
|
|
double height= static_cast<double>(map_->height());
|
2007-08-07 17:09:41 +02:00
|
|
|
mapnik::coord2d pt = ext.center();
|
|
|
|
|
|
|
|
double res = scale_denom * 0.00028;
|
2011-10-23 16:09:12 +02:00
|
|
|
|
2009-12-16 21:02:06 +01:00
|
|
|
mapnik::box2d<double> box(pt.x - 0.5 * width * res,
|
2007-08-07 17:09:41 +02:00
|
|
|
pt.y - 0.5 * height*res,
|
|
|
|
pt.x + 0.5 * width * res,
|
|
|
|
pt.y + 0.5 * height*res);
|
2010-06-25 17:23:35 +02:00
|
|
|
map_->zoom_to_box(box);
|
2008-06-29 12:58:29 +02:00
|
|
|
updateMap();
|
2007-08-07 17:09:41 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-10-23 16:09:12 +02:00
|
|
|
void MapWidget::export_to_file(unsigned ,unsigned ,std::string const&,std::string const&)
|
2007-08-07 17:09:41 +02:00
|
|
|
{
|
2015-01-22 03:31:02 +01:00
|
|
|
//image_rgba8 image(width,height);
|
2007-08-07 17:09:41 +02:00
|
|
|
//agg_renderer renderer(map,image);
|
|
|
|
//renderer.apply();
|
|
|
|
//image.saveToFile(filename,type);
|
2012-05-03 18:18:02 +02:00
|
|
|
std::cout << "Export to file .." << std::endl;
|
2007-08-07 17:09:41 +02:00
|
|
|
}
|
2011-10-23 16:09:12 +02:00
|
|
|
|
2010-06-17 10:26:08 +02:00
|
|
|
void MapWidget::set_scaling_factor(double scaling_factor)
|
|
|
|
{
|
|
|
|
scaling_factor_ = scaling_factor;
|
|
|
|
}
|
2007-10-05 13:27:00 +02:00
|
|
|
|
2012-05-03 16:21:17 +02:00
|
|
|
void render_agg(mapnik::Map const& map, double scaling_factor, QPixmap & pix)
|
2011-10-23 16:09:12 +02:00
|
|
|
{
|
2012-05-03 16:21:17 +02:00
|
|
|
unsigned width=map.width();
|
|
|
|
unsigned height=map.height();
|
2012-07-10 17:58:43 +02:00
|
|
|
|
2015-01-22 03:31:02 +01:00
|
|
|
image_rgba8 buf(width,height);
|
|
|
|
mapnik::agg_renderer<image_rgba8> ren(map,buf,scaling_factor);
|
2012-07-10 17:58:43 +02:00
|
|
|
|
2012-05-03 16:21:17 +02:00
|
|
|
try
|
2012-07-10 17:58:43 +02:00
|
|
|
{
|
2013-12-02 11:14:11 +01:00
|
|
|
mapnik::auto_cpu_timer t(std::clog, "rendering took: ");
|
2013-12-02 10:52:08 +01:00
|
|
|
ren.apply();
|
2015-05-04 12:49:11 +02:00
|
|
|
QImage image((uchar*)buf.data(),width,height,QImage::Format_ARGB32);
|
2012-05-03 16:21:17 +02:00
|
|
|
pix = QPixmap::fromImage(image.rgbSwapped());
|
|
|
|
}
|
2014-08-21 12:14:33 +02:00
|
|
|
//catch (mapnik::config_error & ex)
|
|
|
|
//{
|
|
|
|
// std::cerr << ex.what() << std::endl;
|
|
|
|
//}
|
2015-10-16 03:06:33 +02:00
|
|
|
catch (std::exception const& ex)
|
2012-06-01 01:09:12 +02:00
|
|
|
{
|
|
|
|
std::cerr << "exception: " << ex.what() << std::endl;
|
|
|
|
}
|
2012-05-03 16:21:17 +02:00
|
|
|
catch (...)
|
|
|
|
{
|
|
|
|
std::cerr << "Unknown exception caught!\n";
|
|
|
|
}
|
|
|
|
}
|
2011-10-23 16:09:12 +02:00
|
|
|
|
2009-12-21 14:45:07 +01:00
|
|
|
|
2012-05-03 18:18:02 +02:00
|
|
|
void render_grid(mapnik::Map const& map, double scaling_factor, QPixmap & pix)
|
|
|
|
{
|
2013-05-16 17:24:18 +02:00
|
|
|
std::cerr << "Not supported" << std::endl;
|
2012-05-03 18:18:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-05-03 16:21:17 +02:00
|
|
|
void render_cairo(mapnik::Map const& map, double scaling_factor, QPixmap & pix)
|
|
|
|
{
|
2015-02-18 13:21:16 +01:00
|
|
|
// FIXME
|
2015-02-19 12:03:15 +01:00
|
|
|
#ifdef HAVE_CAIRO
|
2013-01-09 18:00:30 +01:00
|
|
|
mapnik::cairo_surface_ptr image_surface(cairo_image_surface_create(CAIRO_FORMAT_ARGB32,map.width(),map.height()),
|
|
|
|
mapnik::cairo_surface_closer());
|
2014-08-11 14:40:12 +02:00
|
|
|
mapnik::cairo_ptr cairo = mapnik::create_context(image_surface);
|
|
|
|
if (cairo)
|
2013-12-02 11:14:11 +01:00
|
|
|
{
|
|
|
|
mapnik::auto_cpu_timer t(std::clog, "rendering took: ");
|
2014-08-11 14:40:12 +02:00
|
|
|
mapnik::cairo_renderer<mapnik::cairo_ptr> renderer(map, cairo, scaling_factor);
|
2013-12-02 11:14:11 +01:00
|
|
|
renderer.apply();
|
|
|
|
}
|
2015-01-22 03:31:02 +01:00
|
|
|
mapnik::image_rgba8 data(map.width(), map.height());
|
2015-01-13 11:46:20 +01:00
|
|
|
mapnik::cairo_image_to_rgba8(data, image_surface);
|
2015-05-04 12:49:11 +02:00
|
|
|
QImage image((uchar*)data.bytes(),data.width(),data.height(),QImage::Format_ARGB32);
|
2012-05-03 16:21:17 +02:00
|
|
|
pix = QPixmap::fromImage(image.rgbSwapped());
|
|
|
|
#endif
|
|
|
|
}
|
2011-10-23 16:09:12 +02:00
|
|
|
|
2012-05-03 16:21:17 +02:00
|
|
|
void MapWidget::updateRenderer(QString const& txt)
|
|
|
|
{
|
|
|
|
if (txt == "AGG") cur_renderer_ = AGG;
|
|
|
|
else if (txt == "Cairo") cur_renderer_ = Cairo;
|
2012-05-03 18:18:02 +02:00
|
|
|
else if (txt == "Grid") cur_renderer_ = Grid;
|
2012-05-03 16:21:17 +02:00
|
|
|
std::cerr << "Update renderer called" << std::endl;
|
|
|
|
updateMap();
|
|
|
|
}
|
|
|
|
|
2012-07-10 17:58:43 +02:00
|
|
|
void MapWidget::updateScaleFactor(double scale_factor)
|
|
|
|
{
|
|
|
|
set_scaling_factor(scale_factor);
|
|
|
|
updateMap();
|
|
|
|
}
|
|
|
|
|
2012-05-03 16:21:17 +02:00
|
|
|
void MapWidget::updateMap()
|
|
|
|
{
|
|
|
|
if (map_)
|
|
|
|
{
|
|
|
|
if (cur_renderer_== AGG)
|
|
|
|
{
|
|
|
|
render_agg(*map_, scaling_factor_, pix_);
|
|
|
|
}
|
|
|
|
else if (cur_renderer_ == Cairo)
|
|
|
|
{
|
|
|
|
render_cairo(*map_, scaling_factor_, pix_);
|
|
|
|
}
|
2012-05-03 18:18:02 +02:00
|
|
|
else if (cur_renderer_ == Grid)
|
|
|
|
{
|
|
|
|
render_grid(*map_, scaling_factor_, pix_);
|
|
|
|
}
|
2012-05-03 16:21:17 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
std::cerr << "Unknown renderer..." << std::endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
2021-03-15 19:09:21 +01:00
|
|
|
projection prj(map_->srs(), true); // map projection
|
|
|
|
box2d<double> ext = map_->get_current_extent();
|
|
|
|
double x0 = ext.minx();
|
|
|
|
double y0 = ext.miny();
|
|
|
|
double x1 = ext.maxx();
|
|
|
|
double y1 = ext.maxy();
|
|
|
|
double z = 0;
|
|
|
|
std::string dest_srs = {"epsg:4326"};
|
|
|
|
mapnik::proj_transform proj_tr(map_->srs(), dest_srs);
|
|
|
|
|
|
|
|
proj_tr.forward(x0, y0, z);
|
|
|
|
proj_tr.forward(x1, y1, z);
|
|
|
|
std::cout << "MAP SIZE:" << map_->width() << "," << map_->height() << std::endl;
|
|
|
|
std::cout << "BBOX (WGS84): " << x0 << "," << y0 << "," << x1 << "," << y1 << "\n";
|
|
|
|
update();
|
|
|
|
// emit signal to interested widgets
|
|
|
|
emit mapViewChanged();
|
|
|
|
}
|
|
|
|
catch (...)
|
|
|
|
{
|
|
|
|
std::cerr << "Unknown exception caught!\n";
|
|
|
|
}
|
2008-06-29 12:58:29 +02:00
|
|
|
}
|
2007-08-07 17:09:41 +02:00
|
|
|
}
|
|
|
|
|
2013-09-20 15:00:11 +02:00
|
|
|
std::shared_ptr<Map> MapWidget::getMap()
|
2007-08-07 17:09:41 +02:00
|
|
|
{
|
2021-03-15 19:09:21 +01:00
|
|
|
return map_;
|
2007-08-07 17:09:41 +02:00
|
|
|
}
|
|
|
|
|
2013-09-20 15:00:11 +02:00
|
|
|
void MapWidget::setMap(std::shared_ptr<Map> map)
|
2007-08-07 17:09:41 +02:00
|
|
|
{
|
2021-03-15 19:09:21 +01:00
|
|
|
map_ = map;
|
2007-08-07 17:09:41 +02:00
|
|
|
}
|
2007-10-05 13:27:00 +02:00
|
|
|
|
|
|
|
|
|
|
|
void MapWidget::layerSelected(int index)
|
|
|
|
{
|
2021-03-15 19:09:21 +01:00
|
|
|
selectedLayer_ = index;
|
2007-10-05 13:27:00 +02:00
|
|
|
}
|