root/trunk/include/mapnik/map.hpp @ 796

Revision 796, 9.6 kB (checked in by artem, 20 months ago)

+ (c++) renamed mapnik::Color to mapnik::color
+ (c++) added mapnik::color ctor from named colours (TODO: consider not to export color_factory)
+ (Python) fixed pickling
+ (Python) added to_hex_string method

Line 
1/*****************************************************************************
2 *
3 * This file is part of Mapnik (c++ mapping toolkit)
4 *
5 * Copyright (C) 2006 Artem Pavlenko
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
20 *
21 *****************************************************************************/
22//$Id: map.hpp 39 2005-04-10 20:39:53Z pavlenko $
23
24#ifndef MAP_HPP
25#define MAP_HPP
26
27#ifdef HAVE_CONFIG_H
28  #include <config.h>
29#endif
30
31#include <mapnik/feature_type_style.hpp>
32#include <mapnik/datasource.hpp>
33#include <mapnik/layer.hpp>
34#include <boost/optional/optional.hpp>
35
36namespace mapnik
37{
38    class MAPNIK_DECL Map
39    {   
40    public:
41
42        enum aspect_fix_mode
43        {
44           // grow the width or height of the specified geo bbox to fill the map size. default behaviour.
45           GROW_BBOX,
46           // grow the width or height of the map to accomodate the specified geo bbox.
47           GROW_CANVAS,
48           // shrink the width or height of the specified geo bbox to fill the map size.
49           SHRINK_BBOX,
50           // shrink the width or height of the map to accomodate the specified geo bbox.
51            SHRINK_CANVAS,
52           // adjust the width of the specified geo bbox, leave height and map size unchanged
53           ADJUST_BBOX_WIDTH,
54           // adjust the height of the specified geo bbox, leave width and map size unchanged
55            ADJUST_BBOX_HEIGHT,
56           // adjust the width of the map, leave height and geo bbox unchanged
57           ADJUST_CANVAS_WIDTH,
58           //adjust the height of the map, leave width and geo bbox unchanged
59           ADJUST_CANVAS_HEIGHT
60        };
61    private:
62        static const unsigned MIN_MAPSIZE=16;
63        static const unsigned MAX_MAPSIZE=MIN_MAPSIZE<<10;
64        unsigned width_;
65        unsigned height_;
66        std::string  srs_;
67        int buffer_size_;
68        boost::optional<color> background_;
69        std::map<std::string,feature_type_style> styles_;
70        std::map<std::string,FontSet> fontsets_;
71        std::vector<Layer> layers_;
72        aspect_fix_mode aspectFixMode_;
73        Envelope<double> currentExtent_;
74       
75    public:
76
77        typedef std::map<std::string,feature_type_style>::const_iterator const_style_iterator;
78        typedef std::map<std::string,feature_type_style>::iterator style_iterator;
79       
80        /*! \brief Default constructor.
81         *
82         *  Creates a map with these parameters:
83         *  - width = 400
84         *  - height = 400
85         *  - projection = "+proj=latlong +datum=WGS84"
86         */
87        Map();
88
89        /*! \brief Constructor
90         *  @param width Initial map width.
91         *  @param height Initial map height.
92         *  @param srs Initial map projection.
93         */
94        Map(int width, int height, std::string const& srs="+proj=latlong +datum=WGS84");
95
96        /*! \brief Copy Constructur.
97         *
98         *  @param rhs Map to copy from.
99         */
100        Map(const Map& rhs);
101
102        /*! \brief Assignment operator
103         *
104         *  TODO: to be documented
105         * 
106         */
107        Map& operator=(const Map& rhs);
108       
109        /*! \brief Get all styles
110         * @return Const reference to styles
111         */
112        std::map<std::string,feature_type_style> const& styles() const; 
113       
114        /*! \brief Get all styles
115         * @return Non-constant reference to styles
116         */
117        std::map<std::string,feature_type_style> & styles();
118       
119        /*! \brief Get first iterator in styles.
120         *  @return Constant style iterator.
121         */
122        const_style_iterator begin_styles() const;
123
124        /*! \brief Get last iterator in styles.
125         *  @return Constant style iterator.
126         */
127        const_style_iterator end_styles() const;
128
129        /*! \brief Get first iterator in styles.
130         *  @return Non-constant style iterator.
131         */
132        style_iterator begin_styles();
133
134        /*! \brief Get last iterator in styles.
135         *  @return Non-constant style iterator.
136         */
137        style_iterator end_styles();
138
139        /*! \brief Insert a style in the map.
140         *  @param name The name of the style.
141         *  @param style The style to insert.
142         *  @return true If success.
143         *  @return false If no success.
144         */
145        bool insert_style(std::string const& name,feature_type_style const& style);
146
147        /*! \brief Remove a style from the map.
148         *  @param name The name of the style.
149         */
150        void remove_style(const std::string& name);
151
152        /*! \brief Find a style.
153         *  @param name The name of the style.
154         *  @return The style if found. If not found return the default map style.
155         */
156        boost::optional<feature_type_style const&> find_style(std::string const& name) const;
157       
158        /*! \brief Insert a fontset into the map.
159         *  @param name The name of the fontset.
160         *  @param style The fontset to insert.
161         *  @return true If success.
162         *  @return false If failure.
163         */
164        bool insert_fontset(std::string const& name, FontSet const& fontset);
165       
166        /*! \brief Find a fontset.
167         *  @param name The name of the fontset.
168         *  @return The fontset if found. If not found return the default map fontset.
169         */
170        FontSet const& find_fontset(std::string const& name) const;
171
172        /*! \brief Get number of all layers.
173         */
174        size_t layerCount() const;
175
176        /*! \brief Add a layer to the map.
177         *  @param l The layer to add.
178         */
179        void addLayer(const Layer& l);
180
181        /*! \brief Get a layer.
182         *  @param index Layer number.
183         *  @return Constant layer.
184         */
185        const Layer& getLayer(size_t index) const;
186
187        /*! \brief Get a layer.
188         *  @param index Layer number.
189         *  @return Non-constant layer.
190         */
191        Layer& getLayer(size_t index);
192       
193        /*! \brief Remove a layer.
194         *  @param index Layer number.
195         */
196        void removeLayer(size_t index);
197
198        /*! \brief Get all layers.
199         *  @return Constant layers.
200         */
201        std::vector<Layer> const& layers() const;
202
203        /*! \brief Get all layers.
204         *  @return Non-constant layers.
205         */
206        std::vector<Layer> & layers();
207
208        /*! \brief Remove all layers and styles from the map.
209         */
210        void remove_all();
211
212        /*! \brief Get map width.
213         */
214        unsigned getWidth() const;
215
216        /*! \brief Get map height.
217         */
218        unsigned getHeight() const;
219
220        /*! \brief Set map width.
221         */
222        void setWidth(unsigned width);
223
224        /*! \brief Set map height.
225         */
226        void setHeight(unsigned height);
227
228        /*! \brief Resize the map.
229         */
230        void resize(unsigned width,unsigned height);
231
232        /*! \brief Get the map projection.
233         *  @return Map projection.
234         */
235        std::string const& srs() const;
236
237        /*! \brief Set the map projection.
238         *  @param srs Map projection.
239         */
240        void set_srs(std::string const& srs);
241
242        /*! \brief Set the map background color.
243         *  @param c Background color.
244         */
245        void set_background(const color& c);
246
247        /*! \brief Get the map background color
248         *  @return Background color as boost::optional
249         *  object
250         */
251        boost::optional<color> const& background() const;
252
253        /*! \brief Set buffer size
254         *  @param buffer_size Buffer size in pixels.
255         */
256       
257        void set_buffer_size(int buffer_size);
258       
259       /*! \brief Get the map buffer size
260         *  @return Buffer size as int
261         */
262        int buffer_size() const;
263       
264        /*! \brief Zoom the map at the current position.
265         *  @param factor The factor how much the map is zoomed in or out.
266         */
267        void zoom(double factor);
268
269        /*! \brief Zoom the map to a bounding box.
270         *
271         *  Aspect is handled automatic if not fitting to width/height.
272         *  @param box The bounding box where to zoom.
273         */
274        void zoomToBox(const Envelope<double>& box);
275
276        /*! \brief Zoom the map to show all data.
277         */
278        void zoom_all();
279
280        void pan(int x,int y);
281
282        void pan_and_zoom(int x,int y,double zoom);
283
284        /*! \brief Get current bounding box.
285         *  @return The current bounding box.
286         */
287        const Envelope<double>& getCurrentExtent() const;
288
289        double scale() const;
290       
291        double scale_denominator() const;
292
293        CoordTransform view_transform() const;
294
295        featureset_ptr query_point(unsigned index, double x, double y) const;
296
297        featureset_ptr query_map_point(unsigned index, double x, double y) const;
298        ~Map();
299
300        void setAspectFixMode(aspect_fix_mode afm) { aspectFixMode_ = afm; }
301        bool getAspectFixMode() { return aspectFixMode_; }
302
303    private:
304        void fixAspectRatio();
305    };
306}
307
308#endif //MAP_HPP
Note: See TracBrowser for help on using the browser.