mapnik/include/mapnik/map.hpp

469 lines
14 KiB
C++
Raw Normal View History

2006-03-31 12:32:02 +02:00
/*****************************************************************************
2012-02-02 02:53:35 +01:00
*
2006-03-31 12:32:02 +02:00
* This file is part of Mapnik (c++ mapping toolkit)
2005-06-14 17:06:59 +02:00
*
* Copyright (C) 2011 Artem Pavlenko
2005-06-14 17:06:59 +02:00
*
2006-03-31 12:32:02 +02:00
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
2005-06-14 17:06:59 +02:00
* but WITHOUT ANY WARRANTY; without even the implied warranty of
2006-03-31 12:32:02 +02:00
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
2005-06-14 17:06:59 +02:00
*
2006-03-31 12:32:02 +02:00
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
*****************************************************************************/
2005-06-14 17:06:59 +02:00
#ifndef MAPNIK_MAP_HPP
#define MAPNIK_MAP_HPP
2005-06-14 17:06:59 +02:00
// mapnik
#include <mapnik/enumeration.hpp>
#include <mapnik/feature_type_style.hpp>
#include <mapnik/datasource.hpp>
#include <mapnik/layer.hpp>
#include <mapnik/metawriter.hpp>
#include <mapnik/params.hpp>
// boost
#include <boost/optional/optional.hpp>
2005-06-14 17:06:59 +02:00
namespace mapnik
{
2010-06-02 13:03:30 +02:00
class MAPNIK_DECL Map
2012-02-02 02:53:35 +01:00
{
2010-06-02 13:03:30 +02:00
public:
2012-02-02 02:53:35 +01:00
enum aspect_fix_mode
2010-06-02 13:03:30 +02:00
{
// grow the width or height of the specified geo bbox to fill the map size. default behaviour.
GROW_BBOX,
// grow the width or height of the map to accomodate the specified geo bbox.
GROW_CANVAS,
2012-02-02 02:53:35 +01:00
// shrink the width or height of the specified geo bbox to fill the map size.
2010-06-02 13:03:30 +02:00
SHRINK_BBOX,
// shrink the width or height of the map to accomodate the specified geo bbox.
SHRINK_CANVAS,
// adjust the width of the specified geo bbox, leave height and map size unchanged
ADJUST_BBOX_WIDTH,
// adjust the height of the specified geo bbox, leave width and map size unchanged
ADJUST_BBOX_HEIGHT,
// adjust the width of the map, leave height and geo bbox unchanged
ADJUST_CANVAS_WIDTH,
2012-02-02 02:53:35 +01:00
//adjust the height of the map, leave width and geo bbox unchanged
2010-06-02 13:03:30 +02:00
ADJUST_CANVAS_HEIGHT,
2012-02-02 02:53:35 +01:00
//
2010-06-02 13:03:30 +02:00
aspect_fix_mode_MAX
};
2012-02-02 02:53:35 +01:00
2010-06-02 13:03:30 +02:00
private:
static const unsigned MIN_MAPSIZE=16;
static const unsigned MAX_MAPSIZE=MIN_MAPSIZE<<10;
unsigned width_;
unsigned height_;
std::string srs_;
2010-06-02 13:03:30 +02:00
int buffer_size_;
boost::optional<color> background_;
boost::optional<std::string> background_image_;
2010-06-02 13:03:30 +02:00
std::map<std::string,feature_type_style> styles_;
std::map<std::string,metawriter_ptr> metawriters_;
2010-06-02 13:03:30 +02:00
std::map<std::string,font_set> fontsets_;
std::vector<layer> layers_;
aspect_fix_mode aspectFixMode_;
box2d<double> current_extent_;
boost::optional<box2d<double> > maximum_extent_;
std::string base_path_;
parameters extra_params_;
2012-02-02 02:53:35 +01:00
2010-06-02 13:03:30 +02:00
public:
2010-06-02 13:03:30 +02:00
typedef std::map<std::string,feature_type_style>::const_iterator const_style_iterator;
typedef std::map<std::string,feature_type_style>::iterator style_iterator;
typedef std::map<std::string,font_set>::const_iterator const_fontset_iterator;
typedef std::map<std::string,font_set>::iterator fontset_iterator;
typedef std::map<std::string,metawriter_ptr>::const_iterator const_metawriter_iterator;
2012-02-02 02:53:35 +01:00
2010-06-02 13:03:30 +02:00
/*! \brief Default constructor.
*
* Creates a map with these parameters:
* - width = 400
* - height = 400
* - projection = "+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs"
2010-06-02 13:03:30 +02:00
*/
Map();
/*! \brief Constructor
* @param width Initial map width.
* @param height Initial map height.
* @param srs Initial map projection.
*/
Map(int width, int height, std::string const& srs="+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs");
2010-06-02 13:03:30 +02:00
/*! \brief Copy Constructur.
*
* @param rhs Map to copy from.
*/
Map(const Map& rhs);
/*! \brief Assignment operator
*
* TODO: to be documented
2012-02-02 02:53:35 +01:00
*
2010-06-02 13:03:30 +02:00
*/
Map& operator=(const Map& rhs);
2012-02-02 02:53:35 +01:00
2010-06-02 13:03:30 +02:00
/*! \brief Get all styles
* @return Const reference to styles
*/
2012-02-02 02:53:35 +01:00
std::map<std::string,feature_type_style> const& styles() const;
/*! \brief Get all styles
2010-06-02 13:03:30 +02:00
* @return Non-constant reference to styles
*/
std::map<std::string,feature_type_style> & styles();
2012-02-02 02:53:35 +01:00
2010-06-02 13:03:30 +02:00
/*! \brief Get first iterator in styles.
* @return Constant style iterator.
*/
const_style_iterator begin_styles() const;
/*! \brief Get last iterator in styles.
* @return Constant style iterator.
*/
const_style_iterator end_styles() const;
/*! \brief Get first iterator in styles.
* @return Non-constant style iterator.
*/
style_iterator begin_styles();
/*! \brief Get last iterator in styles.
* @return Non-constant style iterator.
*/
style_iterator end_styles();
/*! \brief Insert a style in the map.
* @param name The name of the style.
* @param style The style to insert.
* @return true If success.
* @return false If no success.
*/
bool insert_style(std::string const& name,feature_type_style const& style);
/*! \brief Remove a style from the map.
* @param name The name of the style.
*/
void remove_style(const std::string& name);
/*! \brief Find a style.
* @param name The name of the style.
* @return The style if found. If not found return the default map style.
*/
boost::optional<feature_type_style const&> find_style(std::string const& name) const;
/*! \brief Insert a metawriter in the map.
* @param name The name of the writer.
* @param style A pointer to the writer to insert.
* @return true If success.
* @return false If no success.
*/
bool insert_metawriter(std::string const& name, metawriter_ptr const& writer);
/*! \brief Remove a metawriter from the map.
* @param name The name of the writer.
*/
void remove_metawriter(const std::string& name);
/*! \brief Find a metawriter.
* @param name The name of the writer.
* @return The writer if found. If not found return 0.
*/
metawriter_ptr find_metawriter(std::string const& name) const;
/*! \brief Get all metawriters.
* @return Const reference to metawriters.
*/
std::map<std::string,metawriter_ptr> const& metawriters() const;
/*! \brief Get first iterator in metawriters.
* @return Constant metawriter iterator.
*/
const_metawriter_iterator begin_metawriters() const;
/*! \brief Get last iterator in metawriters.
* @return Constant metawriter iterator.
*/
const_metawriter_iterator end_metawriters() const;
2012-02-02 02:53:35 +01:00
2010-06-02 13:03:30 +02:00
/*! \brief Insert a fontset into the map.
* @param name The name of the fontset.
* @param style The fontset to insert.
* @return true If success.
* @return false If failure.
*/
bool insert_fontset(std::string const& name, font_set const& fontset);
2012-02-02 02:53:35 +01:00
2010-06-02 13:03:30 +02:00
/*! \brief Find a fontset.
* @param name The name of the fontset.
* @return The fontset if found. If not found return the default map fontset.
*/
boost::optional<font_set const&> find_fontset(std::string const& name) const;
2010-06-02 13:03:30 +02:00
/*! \brief Get all fontsets
* @return Const reference to fontsets
*/
std::map<std::string,font_set> const& fontsets() const;
/*! \brief Get all fontsets
* @return Non-constant reference to fontsets
*/
std::map<std::string,font_set> & fontsets();
/*! \brief Get number of all layers.
*/
2010-06-25 17:23:35 +02:00
size_t layer_count() const;
2010-06-02 13:03:30 +02:00
/*! \brief Add a layer to the map.
* @param l The layer to add.
*/
void addLayer(const layer& l);
/*! \brief Get a layer.
* @param index layer number.
* @return Constant layer.
*/
const layer& getLayer(size_t index) const;
/*! \brief Get a layer.
* @param index layer number.
* @return Non-constant layer.
*/
layer& getLayer(size_t index);
2012-02-02 02:53:35 +01:00
2010-06-02 13:03:30 +02:00
/*! \brief Remove a layer.
* @param index layer number.
*/
void removeLayer(size_t index);
/*! \brief Get all layers.
* @return Constant layers.
*/
std::vector<layer> const& layers() const;
/*! \brief Get all layers.
* @return Non-constant layers.
*/
std::vector<layer> & layers();
/*! \brief Remove all layers and styles from the map.
*/
void remove_all();
/*! \brief Get map width.
*/
2010-06-25 17:23:35 +02:00
unsigned width() const;
2010-06-02 13:03:30 +02:00
/*! \brief Get map height.
*/
2010-06-25 17:23:35 +02:00
unsigned height() const;
2010-06-02 13:03:30 +02:00
/*! \brief Set map width.
*/
2010-06-25 17:23:35 +02:00
void set_width(unsigned width);
2010-06-02 13:03:30 +02:00
/*! \brief Set map height.
*/
2010-06-25 17:23:35 +02:00
void set_height(unsigned height);
2010-06-02 13:03:30 +02:00
/*! \brief Resize the map.
*/
void resize(unsigned width,unsigned height);
/*! \brief Get the map projection.
* @return Map projection.
*/
std::string const& srs() const;
/*! \brief Set the map projection.
* @param srs Map projection.
*/
void set_srs(std::string const& srs);
/*! \brief Set the map background color.
* @param c Background color.
*/
void set_background(const color& c);
2012-02-02 02:53:35 +01:00
/*! \brief Get the map background color
2010-06-02 13:03:30 +02:00
* @return Background color as boost::optional
* object
*/
boost::optional<color> const& background() const;
2012-02-02 02:53:35 +01:00
/*! \brief Set the map background image filename.
* @param c Background image filename.
*/
void set_background_image(std::string const& image_filename);
2012-02-02 02:53:35 +01:00
/*! \brief Get the map background image
* @return Background image path as std::string
* object
*/
boost::optional<std::string> const& background_image() const;
2012-02-02 02:53:35 +01:00
/*! \brief Set buffer size
2010-06-02 13:03:30 +02:00
* @param buffer_size Buffer size in pixels.
*/
2012-02-02 02:53:35 +01:00
2010-06-02 13:03:30 +02:00
void set_buffer_size(int buffer_size);
2012-02-02 02:53:35 +01:00
/*! \brief Get the map buffer size
2010-06-02 13:03:30 +02:00
* @return Buffer size as int
*/
int buffer_size() const;
/*! \brief Set the map maximum extent.
* @param box The bounding box for the maximum extent.
*/
void set_maximum_extent(box2d<double>const& box);
2012-02-02 02:53:35 +01:00
/*! \brief Get the map maximum extent as box2d<double>
2012-02-02 02:53:35 +01:00
*/
boost::optional<box2d<double> > const& maximum_extent() const;
/*! \brief Get the non-const map maximum extent as box2d<double>
*/
boost::optional<box2d<double> > & maximum_extent();
/*! \brief Get the map base path where paths should be relative to.
*/
std::string const& base_path() const;
/*! \brief Set the map base path where paths should be releative to.
* @param srs Map base_path.
*/
void set_base_path(std::string const& base);
2010-06-02 13:03:30 +02:00
/*! \brief Zoom the map at the current position.
* @param factor The factor how much the map is zoomed in or out.
*/
void zoom(double factor);
2012-02-02 02:53:35 +01:00
/*! \brief Zoom the map to a bounding box.
2010-06-02 13:03:30 +02:00
*
* Aspect is handled automatic if not fitting to width/height.
* @param box The bounding box where to zoom.
*/
2010-06-25 17:23:35 +02:00
void zoom_to_box(const box2d<double>& box);
2010-06-02 13:03:30 +02:00
/*! \brief Zoom the map to show all data.
*/
void zoom_all();
void pan(int x,int y);
void pan_and_zoom(int x,int y,double zoom);
/*! \brief Get current bounding box.
* @return The current bounding box.
*/
2010-06-25 17:23:35 +02:00
const box2d<double>& get_current_extent() const;
2010-06-02 13:03:30 +02:00
/*! \brief Get current buffered bounding box.
* @return The current buffered bounding box.
*/
box2d<double> get_buffered_extent() const;
2012-02-02 02:53:35 +01:00
2010-06-02 13:03:30 +02:00
/*!
* @return The Map Scale.
*/
double scale() const;
2012-02-02 02:53:35 +01:00
2010-06-02 13:03:30 +02:00
double scale_denominator() const;
2010-06-02 13:03:30 +02:00
CoordTransform view_transform() const;
2012-02-02 02:53:35 +01:00
2010-06-02 13:03:30 +02:00
/*!
* @brief Query a Map layer (by layer index) for features
*
* Intersecting the given x,y location in the coordinates
* of map projection.
*
* @param index The index of the layer to query from.
* @param x The x coordinate where to query.
* @param y The y coordinate where to query.
* @return A Mapnik Featureset if successful otherwise will return NULL.
*/
featureset_ptr query_point(unsigned index, double x, double y) const;
/*!
* @brief Query a Map layer (by layer index) for features
*
* Intersecting the given x,y location in the coordinates
* of the pixmap or map surface.
*
* @param index The index of the layer to query from.
* @param x The x coordinate where to query.
* @param y The y coordinate where to query.
* @return A Mapnik Featureset if successful otherwise will return NULL.
*/
featureset_ptr query_map_point(unsigned index, double x, double y) const;
/*!
* @brief Resolve names to object references for metawriters.
*/
void init_metawriters();
2012-02-02 02:53:35 +01:00
2010-06-02 13:03:30 +02:00
~Map();
2010-06-25 17:23:35 +02:00
inline void set_aspect_fix_mode(aspect_fix_mode afm) { aspectFixMode_ = afm; }
inline aspect_fix_mode get_aspect_fix_mode() const { return aspectFixMode_; }
/*!
* @brief Metawriter properties.
*
* These properties are defined by the user and are substituted in filenames,
* sepcial columns in tables, etc.
*/
metawriter_property_map metawriter_output_properties;
/*!
* @brief Set a metawriter property.
*/
void set_metawriter_property(std::string name, std::string value);
/*!
* @brief Get a metawriter property.
*/
std::string get_metawriter_property(std::string name) const;
/*!
* @brief Get extra, arbitrary Parameters attached to the Map
*/
parameters const& get_extra_parameters() const;
/*!
* @brief Get non-const extra, arbitrary Parameters attached to the Map
*/
parameters& get_extra_parameters();
/*!
* @brief Set extra, arbitary Parameters of the Map
*/
void set_extra_parameters(parameters& params);
2010-06-02 13:03:30 +02:00
private:
void fixAspectRatio();
};
2012-02-02 02:53:35 +01:00
2010-06-02 13:03:30 +02:00
DEFINE_ENUM(aspect_fix_mode_e,Map::aspect_fix_mode);
2005-06-14 17:06:59 +02:00
}
#endif // MAPNIK_MAP_HPP