examples/maptools/MapDisplay.cpp
Go to the documentation of this file.
1 #include "MapToolsExamples.h"
2 
3 // TerraLib
4 #include <terralib/common.h>
5 #include <terralib/geometry.h>
6 #include <terralib/dataaccess.h>
7 #include <terralib/maptools.h>
10 
11 // STL
12 #include <cassert>
13 #include <iostream>
14 #include <list>
15 #include <memory>
16 
17 // Qt
18 #include <QApplication>
19 
20 void MapDisplay()
21 {
22 // If you want to use any Qt resource you must initialize a QApplication in some place!
23  int argc = 0;
24  QApplication app(argc, 0);
25 
26  try
27  {
28  std::string connInfo ("file://");
29  connInfo += TERRALIB_DATA_DIR "/shape/munic_2001.shp";
30 
31  // Creates and connects data source
33 
34  // Get the number of data set types that belongs to the data source
35  std::vector<std::string> datasets = datasource->getDataSetNames();
36 
37  // Creates the MapDisplay
38  std::unique_ptr<te::qt::widgets::MapDisplay> mapDisplay(new te::qt::widgets::MultiThreadMapDisplay(QSize(700, 500)));
39 
40  // MapDisplay box
41  te::gm::Envelope env;
42 
43  // A map of GeomType -> Style
44  std::map<te::gm::GeomType, te::se::Style*> styles;
47  styles[te::gm::PointType] = MarkPointStyle("circle");
48 
49  // Creates the Layer list
50  int id = 0;
51  std::list<te::map::AbstractLayerPtr> layerList;
52  for(unsigned int i = 0; i < datasets.size(); ++i)
53  {
54  std::unique_ptr<te::da::DataSetType> dt(datasource->getDataSetType(datasets[i]));
55 
56  if(!dt->hasGeom())
57  continue;
58 
60  assert(geomProperty);
61 
62  // To MapDisplay extent
63  std::unique_ptr<te::gm::Envelope> e(datasource->getExtent(datasets[i], geomProperty->getName()));
64  env.Union(*e);
65 
66  // Creates a Layer
68  layer->setDataSourceId(datasource->getId());
69  layer->setDataSetName(datasets[i]);
71  layer->setExtent(*e);
72  layer->setStyle(styles[geomProperty->getGeometryType()]);
73  layer->setRendererType("ABSTRACT_LAYER_RENDERER");
74 
75  layerList.push_back(layer);
76  }
77 
78  mapDisplay->setMinimumSize(QSize(60, 60));
79  mapDisplay->setResizePolicy(te::qt::widgets::MapDisplay::Center);
80  mapDisplay->setLayerList(layerList);
81  mapDisplay->show();
82  mapDisplay->setExtent(env);
83 
84  app.exec();
85 
86  layerList.clear();
87  }
88  catch(const std::exception& e)
89  {
90  std::cout << std::endl << "An exception has occurred in DrawLayer example: " << e.what() << std::endl;
91  }
92  catch(...)
93  {
94  std::cout << std::endl << "An unexpected exception has occurred in DrawLayer example!" << std::endl;
95  }
96 }
Geometric property.
virtual void setDataSourceId(const std::string &id)
te::se::Style * MarkPointStyle(const std::string &markName)
Definition: Styling.cpp:244
boost::shared_ptr< DataSource > DataSourcePtr
void MapDisplay()
It retrieves data from a data source, create a set of layer and show map display. ...
void setDataSetName(const std::string &name)
A Qt4 widget to control the display of a set of layers.
A multi thread Qt4 widget to control the display of a set of layers.
void Union(const Envelope &rhs)
It updates the envelop with coordinates of another envelope.
te::se::Style * SimpleLineStyle()
Definition: Styling.cpp:150
void setRendererType(const std::string &t)
static DataSourceManager & getInstance()
It returns a reference to the singleton instance.
An Envelope defines a 2D rectangular region.
GeomType getGeometryType() const
It returns the geometry subtype allowed for the property.
static te::dt::TimeDuration dt(20, 30, 50, 11)
virtual void setVisibility(Visibility v)
It sets the layer visibility.
virtual void setExtent(const te::gm::Envelope &mbr)
It sets the Layer extent (or minimum bounding box).
virtual void setStyle(te::se::Style *style)
It sets the Style associated to the layer.
This file contains include headers for the TerraLib Common Runtime module.
A layer with reference to a dataset.
Definition: DataSetLayer.h:47
unsigned int G_ID
std::string Convert2String(boost::int16_t value)
It converts a short integer value to a string.
Definition: StringUtils.h:56
This file contains include headers for the Vector Geometry model of TerraLib.
te::se::Style * SimplePolygonStyle()
Definition: Styling.cpp:24
TEDATAACCESSEXPORT te::gm::GeometryProperty * GetFirstGeomProperty(const DataSetType *dt)
This file contains include headers for the Data Access module of TerraLib.
This file contains include headers for the Map Tools module of TerraLib.
A multi thread Qt4 widget to control the display of a set of layers.
const std::string & getName() const
It returns the property name.
Definition: Property.h:127