All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Zoom.cpp
Go to the documentation of this file.
1 /* Copyright (C) 2008 National Institute For Space Research (INPE) - Brazil.
2 
3  This file is part of the TerraLib - a Framework for building GIS enabled applications.
4 
5  TerraLib is free software: you can redistribute it and/or modify
6  it under the terms of the GNU Lesser General Public License as published by
7  the Free Software Foundation, either version 3 of the License,
8  or (at your option) any later version.
9 
10  TerraLib is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU Lesser General Public License for more details.
14 
15  You should have received a copy of the GNU Lesser General Public License
16  along with TerraLib. See COPYING. If not, write to
17  TerraLib Team at <terralib-team@terralib.org>.
18  */
19 
20 /*!
21  \file terralib/qt/widgets/tools/Zoom.cpp
22 
23  \brief This is a utility class to geographic zoom operation.
24 */
25 
26 // TerraLib
27 #include "../../../geometry/Coord2D.h"
28 #include "../../../geometry/Envelope.h"
29 #include "../canvas/MapDisplay.h"
30 #include "Zoom.h"
31 
32 te::qt::widgets::Zoom::Zoom(te::qt::widgets::MapDisplay* display, const double& zoomFactor, const ZoomType& type, QObject* parent)
33  : AbstractTool(display, parent),
34  m_zoomFactor(zoomFactor),
35  m_zoomType(type)
36 {
37 }
38 
40 {
41 }
42 
44 {
45  m_zoomType = type;
46 }
47 
48 void te::qt::widgets::Zoom::applyZoom(const QPointF& point)
49 {
50  // Gets the current display extent
51  const te::gm::Envelope& currentExtent = m_display->getExtent();
52  if(!currentExtent.isValid())
53  return;
54 
55  // Adjusting zoom factor based on zoomType
56  double factor = m_zoomFactor;
57  if(m_zoomType == In)
58  factor = 1 / factor;
59 
60  // If point is not null, the zoom extent will be centered on this point. Otherwise, keep the current center.
61  te::gm::Coord2D center;
62  point.isNull() ? center = currentExtent.getCenter() : center = te::gm::Coord2D(point.x(), point.y());
63 
64  // Bulding the zoom extent based on zoom factor value and the given point
65  double w = currentExtent.getWidth() * factor * 0.5;
66  double h = currentExtent.getHeight() * factor * 0.5;
67 
68  te::gm::Envelope e(center.x - w, center.y - h, center.x + w, center.y + h);
69 
70  // Updates the map display with the new extent
71  m_display->setExtent(e);
72 }
double y
y-coordinate.
Definition: Coord2D.h:114
double x
x-coordinate.
Definition: Coord2D.h:113
This is a utility class to geographic zoom operation.
virtual ~Zoom()
Destructor.
Definition: Zoom.cpp:39
void setZoomType(const ZoomType &type)
Sets the zoom operation type.
Definition: Zoom.cpp:43
double getWidth() const
It returns the envelope width.
Definition: Envelope.h:443
A widget to control the display of a set of layers.
Definition: MapDisplay.h:66
An utility struct for representing 2D coordinates.
Definition: Coord2D.h:40
This class defines an interface for objects that can receive application events and respond to them...
Definition: AbstractTool.h:62
ZoomType
Defines the zoom type.
Definition: Zoom.h:58
Coord2D getCenter() const
It returns the rectangle's center coordinate.
Definition: Envelope.cpp:51
An Envelope defines a 2D rectangular region.
Definition: Envelope.h:51
void applyZoom(const QPointF &point=QPointF())
Performs the zoom operation on map display, considering the zoom factor, zoom type and the given poin...
Definition: Zoom.cpp:48
Zoom(MapDisplay *display, const double &zoomFactor=2.0, const ZoomType &type=In, QObject *parent=0)
It constructs a zoom associated with the given map display.
Definition: Zoom.cpp:32
double getHeight() const
It returns the envelope height.
Definition: Envelope.h:448
bool isValid() const
It tells if the rectangle is valid or not.
Definition: Envelope.h:438