27 #include "../../../common/STLUtils.h"
28 #include "../../../geometry/Coord2D.h"
29 #include "../../../geometry/Envelope.h"
30 #include "../../../maptools/AbstractLayer.h"
31 #include "../../../maptools/Utils.h"
32 #include "../../../qt/widgets/layer/explorer/AbstractTreeItem.h"
33 #include "../utils/ScopedCursor.h"
39 #include <QPaintDevice>
40 #include <QResizeEvent>
42 #include <QGraphicsView>
47 m_displayPixmap(new QPixmap(size)),
48 m_draftPixmap(new QPixmap(size)),
49 m_backgroundColor(Qt::white),
50 m_resizePolicy(te::qt::widgets::
MapDisplay::Fixed),
51 m_timer(new QTimer(this)),
68 m_displayPixmap(new QPixmap(size())),
69 m_draftPixmap(new QPixmap(size())),
70 m_backgroundColor(Qt::white),
71 m_resizePolicy(te::qt::widgets::
MapDisplay::Fixed),
72 m_timer(new QTimer(this)),
87 delete m_displayPixmap;
90 std::map<te::map::AbstractLayer*, te::qt::widgets::Canvas*>::iterator it;
91 for(it = m_layerCanvasMap.begin(); it != m_layerCanvasMap.end(); ++it)
94 m_layerCanvasMap.clear();
100 std::map<te::map::AbstractLayer*, te::qt::widgets::Canvas*>::iterator it;
101 for(it = m_layerCanvasMap.begin(); it != m_layerCanvasMap.end(); ++it)
106 m_layerCanvasMap.
clear();
112 std::list<te::map::AbstractLayerPtr> vis, visibleLayers;
115 std::list<te::map::AbstractLayerPtr>::iterator vit;
116 for(vit = vis.begin(); vit != vis.end(); ++vit)
118 if((*vit)->getType() ==
"DATASETLAYER" ||
119 (*vit)->getType() ==
"QUERYLAYER" ||
120 (*vit)->getType() ==
"RASTERLAYER")
122 visibleLayers.push_front(*vit);
126 setLayerList(visibleLayers);
133 std::list<te::map::AbstractLayerPtr>::iterator lit;
134 for(lit = visibleLayers.begin(); lit != visibleLayers.end(); ++lit)
138 int srid = (*lit)->getSRID();
154 std::map<te::map::AbstractLayer*, te::qt::widgets::Canvas*>::iterator it;
155 for(it = m_layerCanvasMap.begin(); it != m_layerCanvasMap.end(); ++it)
158 canvas->
calcAspectRatio(m_extent.m_llx, m_extent.m_lly, m_extent.m_urx, m_extent.m_ury, m_hAlign, m_vAlign);
159 canvas->
setWindow(m_extent.m_llx, m_extent.m_lly, m_extent.m_urx, m_extent.m_ury);
167 emit extentChanged();
177 m_displayPixmap->fill(m_backgroundColor);
179 QPainter painter(m_displayPixmap);
181 std::list<te::map::AbstractLayerPtr>::iterator it;
183 for(it = m_layerList.begin(); it != m_layerList.end(); ++it)
184 draw(it->get(), painter);
193 return static_cast<unsigned int>(width());
198 return static_cast<unsigned int>(height());
203 return static_cast<double>(widthMM());
208 return static_cast<double>(heightMM());
214 emit displaySridChanged();
219 return m_displayPixmap;
224 return m_draftPixmap;
229 m_resizePolicy = policy;
245 draw(boost::dynamic_pointer_cast<te::map::AbstractLayer>(layer->
getChild(i)).
get(), painter);
253 layer->
draw(canvas, m_extent, m_srid);
261 QPaintDevice* device = canvas->
getDevice();
263 if(device->devType() == QInternal::Pixmap)
264 painter.drawPixmap(0, 0, *static_cast<QPixmap*>(device));
265 else if(device->devType() == QInternal::Image)
266 painter.drawImage(0, 0, *static_cast<QImage*>(device));
272 std::map<te::map::AbstractLayer*, te::qt::widgets::Canvas*>::iterator it = m_layerCanvasMap.find(layer);
273 if(it != m_layerCanvasMap.end())
278 canvas->
calcAspectRatio(m_extent.m_llx, m_extent.m_lly, m_extent.m_urx, m_extent.m_ury, m_hAlign, m_vAlign);
279 canvas->setWindow(m_extent.m_llx, m_extent.m_lly, m_extent.m_urx, m_extent.m_ury);
282 m_layerCanvasMap[layer] = canvas;
289 std::map<te::map::AbstractLayer*, te::qt::widgets::Canvas*>::iterator it;
290 for(it = m_layerCanvasMap.begin(); it != m_layerCanvasMap.end(); ++it)
291 it->second->resize(m_displayPixmap->width(), m_displayPixmap->height());
296 QPainter painter(
this);
297 painter.drawPixmap(0, 0, *m_displayPixmap);
299 emit displayPaintEvent(&painter);
301 painter.drawPixmap(0, 0, *m_draftPixmap);
306 QWidget::resizeEvent(e);
313 if(!m_oldSize.isValid())
314 e->oldSize().isValid() ? m_oldSize = e->oldSize() : m_oldSize = e->size();
317 m_timer->start(m_interval);
323 if(m_layerCanvasMap.empty())
330 return canvas->
getMatrix().inverted().map(p);
335 return m_backgroundColor;
340 m_backgroundColor = color;
351 delete m_displayPixmap;
352 m_displayPixmap =
new QPixmap(size());
353 m_displayPixmap->fill(m_backgroundColor);
355 delete m_draftPixmap;
356 m_draftPixmap =
new QPixmap(size());
357 m_draftPixmap->fill(Qt::transparent);
363 adjustExtent(m_oldSize, size());
371 if(!m_extent.isValid())
389 double newWidthW = (size.width() * widthW) / oldSize.width();
390 double newHeightW = (size.height() * heightW) / oldSize.height();
392 switch(m_resizePolicy)
404 e.
m_llx = center.
x - (newWidthW * 0.5);
405 e.
m_urx = center.
x + (newWidthW * 0.5);
406 e.
m_lly = center.
y - (newHeightW * 0.5);
407 e.
m_ury = center.
y + (newHeightW * 0.5);
const TreeItemPtr & getChild(std::size_t i) const
It returns the n-th child.
std::size_t getChildrenCount() const
It returns the number of children of this node.
This is the base class for layers.
double m_urx
Upper right corner x-coordinate.
virtual void clear()=0
It clears the canvas content and fills with the background color.
virtual Visibility getVisibility() const
It returns the layer visibility.
An utility struct for representing 2D coordinates.
virtual void draw(Canvas *canvas, const te::gm::Envelope &bbox, int srid)=0
It draws the layer geographic objects in the given canvas using the informed SRS. ...
void Union(const Envelope &rhs)
It updates the envelop with coordinates of another envelope.
virtual void setExtent(te::gm::Envelope &e, bool doRefresh=true)
It sets the world visible area and refreshes the contents in the map display.
Coord2D getCenter() const
It returns the rectangle's center coordinate.
MapDisplay()
It initializes a new MapDisplay.
double m_llx
Lower left corner x-coordinate.
An Envelope defines a 2D rectangular region.
#define TE_UNKNOWN_SRS
A numeric value to represent a unknown SRS identification in TerraLib.
virtual void setSRID(const int &srid, bool doRefresh=true)
It sets a new Spatial Reference System to be used by the Map Display.
double m_lly
Lower left corner y-coordinate.
A canvas is an abstraction of a drawing area.
double m_ury
Upper right corner y-coordinate.
boost::intrusive_ptr< AbstractLayer > AbstractLayerPtr
void transform(int oldsrid, int newsrid)
It will transform the coordinates of the Envelope from the old SRS to the new one.
TEMAPEXPORT void GetVisibleLayers(const std::list< te::map::AbstractLayerPtr > &layers, std::list< te::map::AbstractLayerPtr > &visibleLayers)
It gets the visible layers of the given layer list.