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
|
|
|
*
|
2006-03-31 12:32:02 +02:00
|
|
|
* Copyright (C) 2006 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.
|
|
|
|
*
|
|
|
|
* 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
|
|
|
*
|
2006-03-31 12:32:02 +02:00
|
|
|
*****************************************************************************/
|
2005-06-14 17:06:59 +02:00
|
|
|
|
2006-10-04 13:22:18 +02:00
|
|
|
//$Id: map.cpp 17 2005-03-08 23:58:43Z pavlenko $,
|
2007-10-08 19:42:41 +02:00
|
|
|
#include <mapnik/map.hpp>
|
2005-06-14 17:06:59 +02:00
|
|
|
|
2006-10-04 13:22:18 +02:00
|
|
|
#include <mapnik/style.hpp>
|
|
|
|
#include <mapnik/datasource.hpp>
|
2006-10-16 15:44:52 +02:00
|
|
|
#include <mapnik/projection.hpp>
|
2006-12-06 21:26:59 +01:00
|
|
|
#include <mapnik/filter_featureset.hpp>
|
|
|
|
#include <mapnik/hit_test_filter.hpp>
|
2009-01-14 07:12:55 +01:00
|
|
|
#include <mapnik/scale_denominator.hpp>
|
2005-06-14 17:06:59 +02:00
|
|
|
|
|
|
|
namespace mapnik
|
|
|
|
{
|
2005-12-14 18:01:09 +01:00
|
|
|
Map::Map()
|
2006-05-23 18:52:10 +02:00
|
|
|
: width_(400),
|
|
|
|
height_(400),
|
2008-06-29 12:59:28 +02:00
|
|
|
srs_("+proj=latlong +datum=WGS84"),
|
2008-09-21 12:14:38 +02:00
|
|
|
buffer_size_(0),
|
2008-06-29 12:59:28 +02:00
|
|
|
aspectFixMode_(GROW_BBOX) {}
|
2006-10-16 15:44:52 +02:00
|
|
|
|
|
|
|
Map::Map(int width,int height, std::string const& srs)
|
2005-06-14 17:06:59 +02:00
|
|
|
: width_(width),
|
2006-05-23 18:52:10 +02:00
|
|
|
height_(height),
|
2008-06-29 12:59:28 +02:00
|
|
|
srs_(srs),
|
2008-09-21 12:14:38 +02:00
|
|
|
buffer_size_(0),
|
2008-06-29 12:59:28 +02:00
|
|
|
aspectFixMode_(GROW_BBOX) {}
|
2007-08-01 11:59:23 +02:00
|
|
|
|
2005-06-14 17:06:59 +02:00
|
|
|
Map::Map(const Map& rhs)
|
|
|
|
: width_(rhs.width_),
|
2006-05-23 18:52:10 +02:00
|
|
|
height_(rhs.height_),
|
2006-10-16 15:44:52 +02:00
|
|
|
srs_(rhs.srs_),
|
2008-09-21 12:14:38 +02:00
|
|
|
buffer_size_(rhs.buffer_size_),
|
2006-05-23 18:52:10 +02:00
|
|
|
background_(rhs.background_),
|
|
|
|
styles_(rhs.styles_),
|
|
|
|
layers_(rhs.layers_),
|
2008-06-29 12:59:28 +02:00
|
|
|
aspectFixMode_(rhs.aspectFixMode_),
|
2006-05-23 18:52:10 +02:00
|
|
|
currentExtent_(rhs.currentExtent_) {}
|
2006-02-05 10:45:51 +01:00
|
|
|
|
2005-06-14 17:06:59 +02:00
|
|
|
Map& Map::operator=(const Map& rhs)
|
|
|
|
{
|
|
|
|
if (this==&rhs) return *this;
|
|
|
|
width_=rhs.width_;
|
|
|
|
height_=rhs.height_;
|
2006-10-16 15:44:52 +02:00
|
|
|
srs_=rhs.srs_;
|
2008-09-21 12:14:38 +02:00
|
|
|
buffer_size_ = rhs.buffer_size_;
|
2005-06-14 17:06:59 +02:00
|
|
|
background_=rhs.background_;
|
2006-05-23 18:52:10 +02:00
|
|
|
styles_=rhs.styles_;
|
2005-06-14 17:06:59 +02:00
|
|
|
layers_=rhs.layers_;
|
2008-06-29 12:59:28 +02:00
|
|
|
aspectFixMode_=rhs.aspectFixMode_;
|
2005-06-14 17:06:59 +02:00
|
|
|
return *this;
|
|
|
|
}
|
2007-08-07 14:02:24 +02:00
|
|
|
|
|
|
|
std::map<std::string,feature_type_style> const& Map::styles() const
|
|
|
|
{
|
|
|
|
return styles_;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::map<std::string,feature_type_style> & Map::styles()
|
|
|
|
{
|
|
|
|
return styles_;
|
|
|
|
}
|
|
|
|
|
2006-12-20 01:22:45 +01:00
|
|
|
Map::style_iterator Map::begin_styles()
|
2006-05-23 19:23:20 +02:00
|
|
|
{
|
|
|
|
return styles_.begin();
|
|
|
|
}
|
2006-12-20 01:22:45 +01:00
|
|
|
|
|
|
|
Map::style_iterator Map::end_styles()
|
|
|
|
{
|
|
|
|
return styles_.end();
|
|
|
|
}
|
|
|
|
|
|
|
|
Map::const_style_iterator Map::begin_styles() const
|
|
|
|
{
|
|
|
|
return styles_.begin();
|
|
|
|
}
|
|
|
|
|
|
|
|
Map::const_style_iterator Map::end_styles() const
|
2006-05-23 19:23:20 +02:00
|
|
|
{
|
|
|
|
return styles_.end();
|
|
|
|
}
|
|
|
|
|
2006-02-05 10:45:51 +01:00
|
|
|
bool Map::insert_style(std::string const& name,feature_type_style const& style)
|
|
|
|
{
|
2006-05-23 18:52:10 +02:00
|
|
|
return styles_.insert(make_pair(name,style)).second;
|
2006-02-05 10:45:51 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void Map::remove_style(std::string const& name)
|
|
|
|
{
|
2006-05-23 18:52:10 +02:00
|
|
|
styles_.erase(name);
|
2006-02-05 10:45:51 +01:00
|
|
|
}
|
2008-06-29 12:58:48 +02:00
|
|
|
|
|
|
|
bool Map::insert_fontset(std::string const& name, FontSet const& fontset)
|
|
|
|
{
|
|
|
|
return fontsets_.insert(make_pair(name, fontset)).second;
|
|
|
|
}
|
|
|
|
|
|
|
|
FontSet const& Map::find_fontset(std::string const& name) const
|
|
|
|
{
|
|
|
|
std::map<std::string,FontSet>::const_iterator itr = fontsets_.find(name);
|
|
|
|
if (itr!=fontsets_.end())
|
|
|
|
return itr->second;
|
|
|
|
static FontSet default_fontset;
|
|
|
|
return default_fontset;
|
|
|
|
}
|
|
|
|
|
2008-11-18 22:15:46 +01:00
|
|
|
boost::optional<feature_type_style const&> Map::find_style(std::string const& name) const
|
|
|
|
{
|
|
|
|
std::map<std::string,feature_type_style>::const_iterator itr = styles_.find(name);
|
|
|
|
if (itr!=styles_.end())
|
|
|
|
return boost::optional<feature_type_style const&>(itr->second);
|
|
|
|
else
|
|
|
|
return boost::optional<feature_type_style const&>() ;
|
2006-02-05 10:45:51 +01:00
|
|
|
}
|
|
|
|
|
2005-06-14 17:06:59 +02:00
|
|
|
size_t Map::layerCount() const
|
|
|
|
{
|
|
|
|
return layers_.size();
|
|
|
|
}
|
2006-02-05 10:45:51 +01:00
|
|
|
|
2005-06-14 17:06:59 +02:00
|
|
|
void Map::addLayer(const Layer& l)
|
|
|
|
{
|
|
|
|
layers_.push_back(l);
|
|
|
|
}
|
|
|
|
void Map::removeLayer(size_t index)
|
|
|
|
{
|
|
|
|
layers_.erase(layers_.begin()+index);
|
|
|
|
}
|
2006-10-09 11:43:09 +02:00
|
|
|
|
|
|
|
void Map::remove_all()
|
|
|
|
{
|
|
|
|
layers_.clear();
|
2006-10-09 12:29:57 +02:00
|
|
|
styles_.clear();
|
2006-10-09 11:43:09 +02:00
|
|
|
}
|
|
|
|
|
2005-06-14 17:06:59 +02:00
|
|
|
const Layer& Map::getLayer(size_t index) const
|
|
|
|
{
|
|
|
|
return layers_[index];
|
|
|
|
}
|
2006-03-28 17:39:38 +02:00
|
|
|
|
|
|
|
Layer& Map::getLayer(size_t index)
|
|
|
|
{
|
|
|
|
return layers_[index];
|
|
|
|
}
|
|
|
|
|
2005-09-08 15:20:37 +02:00
|
|
|
std::vector<Layer> const& Map::layers() const
|
|
|
|
{
|
2006-05-23 18:52:10 +02:00
|
|
|
return layers_;
|
2005-09-08 15:20:37 +02:00
|
|
|
}
|
1. hit_test implementation for geometry objects:
bool hit_test(double x, double y, double tol);
2. added image_view(unsigned x, unsigned y, unsigned width, unsigned height)
allowing to select region from image data e.g (in Python):
im = Image(2048,2048)
view = im.view(0,0,256,256)
save_to_file(filename,type, view)
3. changed envelope method to return vy value in datasource classes
4. features_at_point impl for shape and postgis plug-ins
2006-11-25 12:02:59 +01:00
|
|
|
|
|
|
|
std::vector<Layer> & Map::layers()
|
|
|
|
{
|
|
|
|
return layers_;
|
|
|
|
}
|
|
|
|
|
2005-11-24 16:51:29 +01:00
|
|
|
unsigned Map::getWidth() const
|
2005-06-14 17:06:59 +02:00
|
|
|
{
|
|
|
|
return width_;
|
|
|
|
}
|
|
|
|
|
2005-11-24 16:51:29 +01:00
|
|
|
unsigned Map::getHeight() const
|
2005-06-14 17:06:59 +02:00
|
|
|
{
|
|
|
|
return height_;
|
|
|
|
}
|
2005-11-24 16:51:29 +01:00
|
|
|
|
|
|
|
void Map::setWidth(unsigned width)
|
|
|
|
{
|
2006-05-23 18:52:10 +02:00
|
|
|
if (width >= MIN_MAPSIZE && width <= MAX_MAPSIZE)
|
|
|
|
{
|
|
|
|
width_=width;
|
|
|
|
fixAspectRatio();
|
|
|
|
}
|
2005-11-24 16:51:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void Map::setHeight(unsigned height)
|
|
|
|
{
|
2006-05-23 18:52:10 +02:00
|
|
|
if (height >= MIN_MAPSIZE && height <= MAX_MAPSIZE)
|
|
|
|
{
|
|
|
|
height_=height;
|
|
|
|
fixAspectRatio();
|
|
|
|
}
|
2005-11-24 16:51:29 +01:00
|
|
|
}
|
2006-10-16 15:44:52 +02:00
|
|
|
|
2005-11-24 16:51:29 +01:00
|
|
|
void Map::resize(unsigned width,unsigned height)
|
|
|
|
{
|
2006-05-23 18:52:10 +02:00
|
|
|
if (width >= MIN_MAPSIZE && width <= MAX_MAPSIZE &&
|
|
|
|
height >= MIN_MAPSIZE && height <= MAX_MAPSIZE)
|
|
|
|
{
|
|
|
|
width_=width;
|
|
|
|
height_=height;
|
|
|
|
fixAspectRatio();
|
|
|
|
}
|
2005-11-24 16:51:29 +01:00
|
|
|
}
|
2005-06-14 17:06:59 +02:00
|
|
|
|
2006-10-16 15:44:52 +02:00
|
|
|
std::string const& Map::srs() const
|
2005-06-14 17:06:59 +02:00
|
|
|
{
|
2006-10-16 15:44:52 +02:00
|
|
|
return srs_;
|
2005-06-14 17:06:59 +02:00
|
|
|
}
|
2006-10-16 15:44:52 +02:00
|
|
|
|
2008-09-21 12:14:38 +02:00
|
|
|
void Map::set_srs(std::string const& srs)
|
|
|
|
{
|
|
|
|
srs_ = srs;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Map::set_buffer_size( int buffer_size)
|
|
|
|
{
|
|
|
|
buffer_size_ = buffer_size;
|
|
|
|
}
|
|
|
|
|
|
|
|
int Map::buffer_size() const
|
|
|
|
{
|
|
|
|
return buffer_size_;
|
|
|
|
}
|
|
|
|
|
2007-08-01 11:59:23 +02:00
|
|
|
boost::optional<Color> const& Map::background() const
|
|
|
|
{
|
|
|
|
return background_;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Map::set_background(const Color& c)
|
|
|
|
{
|
|
|
|
background_ = c;
|
|
|
|
}
|
|
|
|
|
2005-06-14 17:06:59 +02:00
|
|
|
void Map::zoom(double factor)
|
|
|
|
{
|
|
|
|
coord2d center = currentExtent_.center();
|
|
|
|
double w = factor * currentExtent_.width();
|
|
|
|
double h = factor * currentExtent_.height();
|
2006-10-09 12:29:57 +02:00
|
|
|
currentExtent_ = Envelope<double>(center.x - 0.5 * w,
|
|
|
|
center.y - 0.5 * h,
|
|
|
|
center.x + 0.5 * w,
|
|
|
|
center.y + 0.5 * h);
|
2006-05-23 18:52:10 +02:00
|
|
|
fixAspectRatio();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Map::zoom_all()
|
|
|
|
{
|
2006-10-16 15:44:52 +02:00
|
|
|
try
|
2006-05-23 18:52:10 +02:00
|
|
|
{
|
2006-10-16 15:44:52 +02:00
|
|
|
projection proj0(srs_);
|
|
|
|
Envelope<double> ext;
|
|
|
|
bool first = true;
|
|
|
|
std::vector<Layer>::const_iterator itr = layers_.begin();
|
|
|
|
std::vector<Layer>::const_iterator end = layers_.end();
|
|
|
|
while (itr != end)
|
2006-05-23 18:52:10 +02:00
|
|
|
{
|
2006-10-16 15:44:52 +02:00
|
|
|
std::string const& layer_srs = itr->srs();
|
|
|
|
projection proj1(layer_srs);
|
|
|
|
proj_transform prj_trans(proj0,proj1);
|
|
|
|
|
|
|
|
Envelope<double> layerExt = itr->envelope();
|
|
|
|
double x0 = layerExt.minx();
|
|
|
|
double y0 = layerExt.miny();
|
|
|
|
double z0 = 0.0;
|
|
|
|
double x1 = layerExt.maxx();
|
|
|
|
double y1 = layerExt.maxy();
|
|
|
|
double z1 = 0.0;
|
|
|
|
prj_trans.backward(x0,y0,z0);
|
|
|
|
prj_trans.backward(x1,y1,z1);
|
|
|
|
|
|
|
|
Envelope<double> layerExt2(x0,y0,x1,y1);
|
2006-11-19 18:13:33 +01:00
|
|
|
#ifdef MAPNIK_DEBUG
|
2006-10-16 15:44:52 +02:00
|
|
|
std::clog << " layer1 - > " << layerExt << "\n";
|
|
|
|
std::clog << " layer2 - > " << layerExt2 << "\n";
|
2006-11-19 18:13:33 +01:00
|
|
|
#endif
|
2006-10-16 15:44:52 +02:00
|
|
|
if (first)
|
|
|
|
{
|
|
|
|
ext = layerExt2;
|
|
|
|
first = false;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ext.expand_to_include(layerExt2);
|
|
|
|
}
|
|
|
|
++itr;
|
2006-05-23 18:52:10 +02:00
|
|
|
}
|
2006-10-16 15:44:52 +02:00
|
|
|
zoomToBox(ext);
|
|
|
|
}
|
|
|
|
catch (proj_init_error & ex)
|
|
|
|
{
|
2007-09-16 13:23:51 +02:00
|
|
|
std::clog << "proj_init_error:" << ex.what() << '\n';
|
2006-05-23 18:52:10 +02:00
|
|
|
}
|
2005-06-14 17:06:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void Map::zoomToBox(const Envelope<double> &box)
|
|
|
|
{
|
|
|
|
currentExtent_=box;
|
|
|
|
fixAspectRatio();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Map::fixAspectRatio()
|
|
|
|
{
|
|
|
|
double ratio1 = (double) width_ / (double) height_;
|
|
|
|
double ratio2 = currentExtent_.width() / currentExtent_.height();
|
2008-06-29 12:59:28 +02:00
|
|
|
if (ratio1 == ratio2) return;
|
|
|
|
|
|
|
|
switch(aspectFixMode_)
|
2006-05-23 18:52:10 +02:00
|
|
|
{
|
2008-06-29 12:59:28 +02:00
|
|
|
case ADJUST_BBOX_HEIGHT:
|
|
|
|
currentExtent_.height(currentExtent_.width() / ratio1);
|
|
|
|
break;
|
|
|
|
case ADJUST_BBOX_WIDTH:
|
|
|
|
currentExtent_.width(currentExtent_.height() * ratio1);
|
|
|
|
break;
|
|
|
|
case ADJUST_CANVAS_HEIGHT:
|
|
|
|
height_ = int (width_ / ratio2 + 0.5);
|
|
|
|
break;
|
|
|
|
case ADJUST_CANVAS_WIDTH:
|
|
|
|
width_ = int (height_ * ratio2 + 0.5);
|
|
|
|
break;
|
|
|
|
case GROW_BBOX:
|
|
|
|
if (ratio2 > ratio1)
|
|
|
|
currentExtent_.height(currentExtent_.width() / ratio1);
|
|
|
|
else
|
|
|
|
currentExtent_.width(currentExtent_.height() * ratio1);
|
|
|
|
break;
|
|
|
|
case SHRINK_BBOX:
|
|
|
|
if (ratio2 < ratio1)
|
|
|
|
currentExtent_.height(currentExtent_.width() / ratio1);
|
|
|
|
else
|
|
|
|
currentExtent_.width(currentExtent_.height() * ratio1);
|
|
|
|
break;
|
|
|
|
case GROW_CANVAS:
|
|
|
|
if (ratio2 > ratio1)
|
|
|
|
width_ = (int) (height_ * ratio2 + 0.5);
|
|
|
|
else
|
|
|
|
height_ = int (width_ / ratio2 + 0.5);
|
|
|
|
break;
|
|
|
|
case SHRINK_CANVAS:
|
|
|
|
if (ratio2 > ratio1)
|
|
|
|
height_ = int (width_ / ratio2 + 0.5);
|
|
|
|
else
|
|
|
|
width_ = (int) (height_ * ratio2 + 0.5);
|
|
|
|
break;
|
2006-05-23 18:52:10 +02:00
|
|
|
}
|
2005-06-14 17:06:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
const Envelope<double>& Map::getCurrentExtent() const
|
|
|
|
{
|
|
|
|
return currentExtent_;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Map::pan(int x,int y)
|
|
|
|
{
|
2005-12-23 13:31:54 +01:00
|
|
|
int dx = x - int(0.5 * width_);
|
2006-05-23 18:52:10 +02:00
|
|
|
int dy = int(0.5 * height_) - y;
|
|
|
|
double s = width_/currentExtent_.width();
|
|
|
|
double minx = currentExtent_.minx() + dx/s;
|
|
|
|
double maxx = currentExtent_.maxx() + dx/s;
|
|
|
|
double miny = currentExtent_.miny() + dy/s;
|
|
|
|
double maxy = currentExtent_.maxy() + dy/s;
|
|
|
|
currentExtent_.init(minx,miny,maxx,maxy);
|
2005-06-14 17:06:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void Map::pan_and_zoom(int x,int y,double factor)
|
|
|
|
{
|
|
|
|
pan(x,y);
|
|
|
|
zoom(factor);
|
|
|
|
}
|
|
|
|
|
|
|
|
double Map::scale() const
|
|
|
|
{
|
|
|
|
if (width_>0)
|
|
|
|
return currentExtent_.width()/width_;
|
|
|
|
return currentExtent_.width();
|
|
|
|
}
|
1. hit_test implementation for geometry objects:
bool hit_test(double x, double y, double tol);
2. added image_view(unsigned x, unsigned y, unsigned width, unsigned height)
allowing to select region from image data e.g (in Python):
im = Image(2048,2048)
view = im.view(0,0,256,256)
save_to_file(filename,type, view)
3. changed envelope method to return vy value in datasource classes
4. features_at_point impl for shape and postgis plug-ins
2006-11-25 12:02:59 +01:00
|
|
|
|
2009-01-14 07:12:55 +01:00
|
|
|
double Map::scale_denominator() const
|
|
|
|
{
|
|
|
|
projection map_proj(srs_);
|
|
|
|
return mapnik::scale_denominator( *this, map_proj.is_geographic());
|
|
|
|
}
|
|
|
|
|
1. hit_test implementation for geometry objects:
bool hit_test(double x, double y, double tol);
2. added image_view(unsigned x, unsigned y, unsigned width, unsigned height)
allowing to select region from image data e.g (in Python):
im = Image(2048,2048)
view = im.view(0,0,256,256)
save_to_file(filename,type, view)
3. changed envelope method to return vy value in datasource classes
4. features_at_point impl for shape and postgis plug-ins
2006-11-25 12:02:59 +01:00
|
|
|
CoordTransform Map::view_transform() const
|
|
|
|
{
|
|
|
|
return CoordTransform(width_,height_,currentExtent_);
|
|
|
|
}
|
2006-12-06 22:21:17 +01:00
|
|
|
|
2007-01-16 16:18:25 +01:00
|
|
|
featureset_ptr Map::query_point(unsigned index, double x, double y) const
|
2006-12-06 22:21:17 +01:00
|
|
|
{
|
|
|
|
if ( index< layers_.size())
|
|
|
|
{
|
|
|
|
mapnik::Layer const& layer = layers_[index];
|
|
|
|
try
|
|
|
|
{
|
|
|
|
double z = 0;
|
2006-12-31 12:42:57 +01:00
|
|
|
mapnik::projection dest(srs_);
|
2006-12-06 22:21:17 +01:00
|
|
|
mapnik::projection source(layer.srs());
|
|
|
|
proj_transform prj_trans(source,dest);
|
|
|
|
prj_trans.backward(x,y,z);
|
|
|
|
|
|
|
|
double minx = currentExtent_.minx();
|
|
|
|
double miny = currentExtent_.miny();
|
|
|
|
double maxx = currentExtent_.maxx();
|
|
|
|
double maxy = currentExtent_.maxy();
|
|
|
|
|
|
|
|
prj_trans.backward(minx,miny,z);
|
|
|
|
prj_trans.backward(maxx,maxy,z);
|
|
|
|
double tol = (maxx - minx) / width_ * 3;
|
|
|
|
mapnik::datasource_ptr ds = layer.datasource();
|
|
|
|
if (ds)
|
|
|
|
{
|
|
|
|
#ifdef MAPNIK_DEBUG
|
|
|
|
std::clog << " query at point tol = " << tol << " (" << x << "," << y << ")\n";
|
|
|
|
#endif
|
2006-12-07 16:02:08 +01:00
|
|
|
featureset_ptr fs = ds->features_at_point(mapnik::coord2d(x,y));
|
|
|
|
if (fs)
|
|
|
|
return featureset_ptr(new filter_featureset<hit_test_filter>(fs,hit_test_filter(x,y,tol)));
|
2006-12-06 22:21:17 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (...)
|
|
|
|
{
|
|
|
|
#ifdef MAPNIK_DEBUG
|
|
|
|
std::clog << "exception caught in \"query_map_point\"\n";
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return featureset_ptr();
|
|
|
|
}
|
|
|
|
|
2006-12-06 21:26:59 +01:00
|
|
|
featureset_ptr Map::query_map_point(unsigned index, double x, double y) const
|
|
|
|
{
|
|
|
|
if ( index< layers_.size())
|
|
|
|
{
|
|
|
|
mapnik::Layer const& layer = layers_[index];
|
|
|
|
CoordTransform tr = view_transform();
|
|
|
|
tr.backward(&x,&y);
|
2006-12-31 12:42:57 +01:00
|
|
|
|
2006-12-06 21:26:59 +01:00
|
|
|
try
|
|
|
|
{
|
|
|
|
mapnik::projection dest(srs_);
|
|
|
|
mapnik::projection source(layer.srs());
|
|
|
|
proj_transform prj_trans(source,dest);
|
2006-12-06 22:21:17 +01:00
|
|
|
double z = 0;
|
2006-12-06 21:26:59 +01:00
|
|
|
prj_trans.backward(x,y,z);
|
|
|
|
|
|
|
|
double minx = currentExtent_.minx();
|
|
|
|
double miny = currentExtent_.miny();
|
|
|
|
double maxx = currentExtent_.maxx();
|
|
|
|
double maxy = currentExtent_.maxy();
|
|
|
|
|
|
|
|
prj_trans.backward(minx,miny,z);
|
|
|
|
prj_trans.backward(maxx,maxy,z);
|
|
|
|
double tol = (maxx - minx) / width_ * 3;
|
|
|
|
mapnik::datasource_ptr ds = layer.datasource();
|
|
|
|
if (ds)
|
|
|
|
{
|
|
|
|
#ifdef MAPNIK_DEBUG
|
|
|
|
std::clog << " query at point tol = " << tol << " (" << x << "," << y << ")\n";
|
|
|
|
#endif
|
2006-12-07 16:02:08 +01:00
|
|
|
featureset_ptr fs = ds->features_at_point(mapnik::coord2d(x,y));
|
|
|
|
if (fs)
|
|
|
|
return featureset_ptr(new filter_featureset<hit_test_filter>(fs,hit_test_filter(x,y,tol)));
|
2006-12-06 21:26:59 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (...)
|
|
|
|
{
|
|
|
|
#ifdef MAPNIK_DEBUG
|
|
|
|
std::clog << "exception caught in \"query_map_point\"\n";
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return featureset_ptr();
|
|
|
|
}
|
|
|
|
|
2005-06-14 17:06:59 +02:00
|
|
|
Map::~Map() {}
|
|
|
|
}
|