- Timestamp:
- 06/29/08 06:59:28 (5 months ago)
- Location:
- trunk
- Files:
-
- 2 modified
-
include/mapnik/map.hpp (modified) (3 diffs)
-
src/map.cpp (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/mapnik/map.hpp
r704 r705 38 38 class MAPNIK_DECL Map 39 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: 40 62 static const unsigned MIN_MAPSIZE=16; 41 63 static const unsigned MAX_MAPSIZE=MIN_MAPSIZE<<10; … … 48 70 std::vector<Layer> layers_; 49 71 Envelope<double> currentExtent_; 72 aspect_fix_mode aspectFixMode_; 50 73 51 74 public: 75 52 76 typedef std::map<std::string,feature_type_style>::const_iterator const_style_iterator; 53 77 typedef std::map<std::string,feature_type_style>::iterator style_iterator; … … 259 283 featureset_ptr query_map_point(unsigned index, double x, double y) const; 260 284 ~Map(); 285 286 void setAspectFixMode(aspect_fix_mode afm) { aspectFixMode_ = afm; } 287 bool getAspectFixMode() { return aspectFixMode_; } 288 261 289 private: 262 290 void fixAspectRatio(); -
trunk/src/map.cpp
r704 r705 35 35 : width_(400), 36 36 height_(400), 37 srs_("+proj=latlong +datum=WGS84") {} 37 srs_("+proj=latlong +datum=WGS84"), 38 aspectFixMode_(GROW_BBOX) {} 38 39 39 40 Map::Map(int width,int height, std::string const& srs) 40 41 : width_(width), 41 42 height_(height), 42 srs_(srs) {} 43 srs_(srs), 44 aspectFixMode_(GROW_BBOX) {} 43 45 44 46 Map::Map(const Map& rhs) … … 49 51 styles_(rhs.styles_), 50 52 layers_(rhs.layers_), 53 aspectFixMode_(rhs.aspectFixMode_), 51 54 currentExtent_(rhs.currentExtent_) {} 52 55 … … 60 63 styles_=rhs.styles_; 61 64 layers_=rhs.layers_; 65 aspectFixMode_=rhs.aspectFixMode_; 62 66 return *this; 63 67 } … … 296 300 double ratio1 = (double) width_ / (double) height_; 297 301 double ratio2 = currentExtent_.width() / currentExtent_.height(); 298 299 if (ratio2 > ratio1) 300 { 301 currentExtent_.height(currentExtent_.width() / ratio1); 302 } 303 else if (ratio2 < ratio1) 304 { 305 currentExtent_.width(currentExtent_.height() * ratio1); 306 } 302 if (ratio1 == ratio2) return; 303 304 switch(aspectFixMode_) 305 { 306 case ADJUST_BBOX_HEIGHT: 307 currentExtent_.height(currentExtent_.width() / ratio1); 308 break; 309 case ADJUST_BBOX_WIDTH: 310 currentExtent_.width(currentExtent_.height() * ratio1); 311 break; 312 case ADJUST_CANVAS_HEIGHT: 313 height_ = int (width_ / ratio2 + 0.5); 314 break; 315 case ADJUST_CANVAS_WIDTH: 316 width_ = int (height_ * ratio2 + 0.5); 317 break; 318 case GROW_BBOX: 319 if (ratio2 > ratio1) 320 currentExtent_.height(currentExtent_.width() / ratio1); 321 else 322 currentExtent_.width(currentExtent_.height() * ratio1); 323 break; 324 case SHRINK_BBOX: 325 if (ratio2 < ratio1) 326 currentExtent_.height(currentExtent_.width() / ratio1); 327 else 328 currentExtent_.width(currentExtent_.height() * ratio1); 329 break; 330 case GROW_CANVAS: 331 if (ratio2 > ratio1) 332 width_ = (int) (height_ * ratio2 + 0.5); 333 else 334 height_ = int (width_ / ratio2 + 0.5); 335 break; 336 case SHRINK_CANVAS: 337 if (ratio2 > ratio1) 338 height_ = int (width_ / ratio2 + 0.5); 339 else 340 width_ = (int) (height_ * ratio2 + 0.5); 341 break; 342 } 307 343 } 308 344
