正在显示
37 个修改的文件
包含
665 行增加
和
585 行删除
@@ -303,6 +303,18 @@ bool DmpProject::initVectorLayerVacuate(std::function<std::string(const std::str | @@ -303,6 +303,18 @@ bool DmpProject::initVectorLayerVacuate(std::function<std::string(const std::str | ||
303 | return false; | 303 | return false; |
304 | } | 304 | } |
305 | 305 | ||
306 | +std::shared_ptr<DmpRectangle> DmpProject::GetExtent() | ||
307 | +{ | ||
308 | + shared_ptr<DmpRectangle> rect(new DmpRectangle()); | ||
309 | + for (size_t i = 0; i < this->vectorLayers_.size(); i++) | ||
310 | + { | ||
311 | + DmpMapLayer* layer = this->vectorLayers_.at(i); | ||
312 | + DmpRectangle layerExtent = layer->extent(); | ||
313 | + rect->merge(layerExtent); | ||
314 | + } | ||
315 | + return rect; | ||
316 | +} | ||
317 | + | ||
306 | bool DmpProject::initVectorLayerVacuate(DmpProject* project) | 318 | bool DmpProject::initVectorLayerVacuate(DmpProject* project) |
307 | { | 319 | { |
308 | if(!project) return false; | 320 | if(!project) return false; |
@@ -16,6 +16,7 @@ | @@ -16,6 +16,7 @@ | ||
16 | #include <boost/filesystem.hpp> | 16 | #include <boost/filesystem.hpp> |
17 | #include "dmpcoordinatereferencesystem.h" | 17 | #include "dmpcoordinatereferencesystem.h" |
18 | #include "dmpmaplayer.h" | 18 | #include "dmpmaplayer.h" |
19 | +#include <memory> | ||
19 | 20 | ||
20 | //配图文件 | 21 | //配图文件 |
21 | class CORE_EXPORT DmpProject | 22 | class CORE_EXPORT DmpProject |
@@ -37,6 +38,7 @@ class CORE_EXPORT DmpProject | @@ -37,6 +38,7 @@ class CORE_EXPORT DmpProject | ||
37 | std::vector<DmpMapLayer*> vectorLayers() const; | 38 | std::vector<DmpMapLayer*> vectorLayers() const; |
38 | DmpMapLayer* getLayer(const std::string &layerName) const; | 39 | DmpMapLayer* getLayer(const std::string &layerName) const; |
39 | DmpMapLayer* getLayer()const; | 40 | DmpMapLayer* getLayer()const; |
41 | + std::shared_ptr<DmpRectangle> GetExtent(); | ||
40 | private: | 42 | private: |
41 | static DmpProject *project_; | 43 | static DmpProject *project_; |
42 | std::string projectName_; | 44 | std::string projectName_; |
@@ -215,8 +215,8 @@ void DmpVectorLayer::setDataSource(const std::string &dataSource, const std::str | @@ -215,8 +215,8 @@ void DmpVectorLayer::setDataSource(const std::string &dataSource, const std::str | ||
215 | } | 215 | } |
216 | 216 | ||
217 | DmpWkbTypes::GeometryType DmpVectorLayer::GeometryType() const | 217 | DmpWkbTypes::GeometryType DmpVectorLayer::GeometryType() const |
218 | -{ | ||
219 | - return DmpWkbTypes::GeometryType(wkbType_); | 218 | +{ |
219 | + return DmpWkbTypes::geometryType(wkbType_); | ||
220 | } | 220 | } |
221 | 221 | ||
222 | bool DmpVectorLayer::setDataProvider(const std::string &provider) | 222 | bool DmpVectorLayer::setDataProvider(const std::string &provider) |
@@ -50,6 +50,7 @@ class CORE_EXPORT DmpVectorLayer : public DmpMapLayer | @@ -50,6 +50,7 @@ class CORE_EXPORT DmpVectorLayer : public DmpMapLayer | ||
50 | void setRenderer(DmpFeatureRenderer *renderer); | 50 | void setRenderer(DmpFeatureRenderer *renderer); |
51 | void setDataSource(const std::string &dataSource, const std::string &baseName, const std::string &provider, bool loadDefaultStyleFlag); | 51 | void setDataSource(const std::string &dataSource, const std::string &baseName, const std::string &provider, bool loadDefaultStyleFlag); |
52 | DmpWkbTypes::GeometryType GeometryType() const; | 52 | DmpWkbTypes::GeometryType GeometryType() const; |
53 | + DmpWkbTypes::Type GeomWkbType() const{ return wkbType_;} | ||
53 | bool setDataProvider(std::string const &provider); | 54 | bool setDataProvider(std::string const &provider); |
54 | 55 | ||
55 | 56 | ||
@@ -65,6 +66,8 @@ class CORE_EXPORT DmpVectorLayer : public DmpMapLayer | @@ -65,6 +66,8 @@ class CORE_EXPORT DmpVectorLayer : public DmpMapLayer | ||
65 | std::string srid(){return srid_;} | 66 | std::string srid(){return srid_;} |
66 | size_t featurecount(){return featurecount_;} | 67 | size_t featurecount(){return featurecount_;} |
67 | bool IsInit(){return isinit_;} | 68 | bool IsInit(){return isinit_;} |
69 | + | ||
70 | + void setSrid(string srid){ srid_ = srid;} | ||
68 | private: | 71 | private: |
69 | bool readExtentFromXml_; | 72 | bool readExtentFromXml_; |
70 | DmpWkbTypes::Type wkbType_ = DmpWkbTypes::Unknown; | 73 | DmpWkbTypes::Type wkbType_ = DmpWkbTypes::Unknown; |
@@ -33,6 +33,24 @@ void DmpRectangle::normalize() | @@ -33,6 +33,24 @@ void DmpRectangle::normalize() | ||
33 | } | 33 | } |
34 | } | 34 | } |
35 | 35 | ||
36 | +void DmpRectangle::merge(DmpRectangle &rectangle) | ||
37 | +{ | ||
38 | + if(xmin_ == 0 && ymin_ ==0 && xmax_ ==0 && ymax_ ==0 ) | ||
39 | + { | ||
40 | + this->xmin_ = rectangle.xmin(); | ||
41 | + this->ymin_ = rectangle.ymin(); | ||
42 | + this->xmax_ = rectangle.xmax(); | ||
43 | + this->ymax_ = rectangle.ymax(); | ||
44 | + } | ||
45 | + else | ||
46 | + { | ||
47 | + if(rectangle.xmin() < this->xmin_ ) this->xmin_ = rectangle.xmin(); | ||
48 | + if(rectangle.ymin() < this->ymin_ ) this->ymin_ = rectangle.ymin(); | ||
49 | + if(rectangle.xmax() > this->xmax_ ) this->xmax_ = rectangle.xmax(); | ||
50 | + if(rectangle.ymax() < this->ymax_ ) this->ymax_ = rectangle.ymax(); | ||
51 | + } | ||
52 | +} | ||
53 | + | ||
36 | 54 | ||
37 | bool DmpRectangle::isNull() | 55 | bool DmpRectangle::isNull() |
38 | { | 56 | { |
@@ -38,6 +38,13 @@ class CORE_EXPORT DmpRectangle | @@ -38,6 +38,13 @@ class CORE_EXPORT DmpRectangle | ||
38 | double width() const { return xmax_ - xmin_; } | 38 | double width() const { return xmax_ - xmin_; } |
39 | double height() const { return ymax_ - ymin_; } | 39 | double height() const { return ymax_ - ymin_; } |
40 | 40 | ||
41 | + void setXmax(double xmax){xmax_ = xmax; } | ||
42 | + void setYmax(double ymax){ymax_ = ymax; } | ||
43 | + void setXmin(double xmin){xmin_ = xmin; } | ||
44 | + void setYmin(double ymin){ymin_ = ymin; } | ||
45 | + | ||
46 | + void merge(DmpRectangle &rectangle); | ||
47 | + | ||
41 | private: | 48 | private: |
42 | double xmin_ = 0.0; | 49 | double xmin_ = 0.0; |
43 | double ymin_ = 0.0; | 50 | double ymin_ = 0.0; |
@@ -12,7 +12,7 @@ namespace DmapCore_30 | @@ -12,7 +12,7 @@ namespace DmapCore_30 | ||
12 | 12 | ||
13 | SimpleLineSymbol::SimpleLineSymbol() | 13 | SimpleLineSymbol::SimpleLineSymbol() |
14 | { | 14 | { |
15 | - m_iAntialiasing = CAIRO_ANTIALIAS_DEFAULT; | 15 | + m_iAntialiasing = CAIRO_ANTIALIAS_BEST; |
16 | m_iColor = clsUtil::RandomColor(); | 16 | m_iColor = clsUtil::RandomColor(); |
17 | clsUtil::ToCairoColor(m_iColor, r, g, b, a); | 17 | clsUtil::ToCairoColor(m_iColor, r, g, b, a); |
18 | //m_pClsSurfBackup = NULL; | 18 | //m_pClsSurfBackup = NULL; |
@@ -12,7 +12,7 @@ namespace DmapCore_30 | @@ -12,7 +12,7 @@ namespace DmapCore_30 | ||
12 | { | 12 | { |
13 | SimpleMarkerSymbol::SimpleMarkerSymbol() | 13 | SimpleMarkerSymbol::SimpleMarkerSymbol() |
14 | { | 14 | { |
15 | - m_iAntialiasing = CAIRO_ANTIALIAS_DEFAULT; | 15 | + m_iAntialiasing = CAIRO_ANTIALIAS_BEST; |
16 | m_bBoundary = true; | 16 | m_bBoundary = true; |
17 | m_iColor = clsUtil::RandomColor(); | 17 | m_iColor = clsUtil::RandomColor(); |
18 | clsUtil::ToCairoColor(m_iColor, r, g, b, a); | 18 | clsUtil::ToCairoColor(m_iColor, r, g, b, a); |
@@ -12,7 +12,7 @@ namespace DmapCore_30 | @@ -12,7 +12,7 @@ namespace DmapCore_30 | ||
12 | { | 12 | { |
13 | SimplePolygonSymbol::SimplePolygonSymbol() | 13 | SimplePolygonSymbol::SimplePolygonSymbol() |
14 | { | 14 | { |
15 | - m_iAntialiasing = CAIRO_ANTIALIAS_DEFAULT; | 15 | + m_iAntialiasing = CAIRO_ANTIALIAS_BEST; |
16 | m_iBackgroundColor = clsUtil::RandomColor(); | 16 | m_iBackgroundColor = clsUtil::RandomColor(); |
17 | clsUtil::ToCairoColor(m_iBackgroundColor, r, g, b, a); | 17 | clsUtil::ToCairoColor(m_iBackgroundColor, r, g, b, a); |
18 | m_iLineType = 0; | 18 | m_iLineType = 0; |
@@ -316,16 +316,21 @@ namespace DmapCore_30 | @@ -316,16 +316,21 @@ namespace DmapCore_30 | ||
316 | x += m_dXdis; | 316 | x += m_dXdis; |
317 | y += m_dYdis; | 317 | y += m_dYdis; |
318 | cairo_t* cr = pClsCS->m_pCr; | 318 | cairo_t* cr = pClsCS->m_pCr; |
319 | - //cairo_font_options_set_antialias(cfo, CAIRO_ANTIALIAS_GRAY); | 319 | + //cairo_font_options_set_antialias(cr, CAIRO_ANTIALIAS_BEST); |
320 | cairo_text_extents(cr, sUTF8, m_pCrExtents); | 320 | cairo_text_extents(cr, sUTF8, m_pCrExtents); |
321 | int iX = (int)x; int iY = (int)y; | 321 | int iX = (int)x; int iY = (int)y; |
322 | int iTextW = (int)(m_pCrExtents->x_advance); int iTextH = (int)(m_pCrExtents->height); | 322 | int iTextW = (int)(m_pCrExtents->x_advance); int iTextH = (int)(m_pCrExtents->height); |
323 | //int surf_w = pClsCS->m_iW; int surf_h = pClsCS->m_iH; | 323 | //int surf_w = pClsCS->m_iW; int surf_h = pClsCS->m_iH; |
324 | + | ||
325 | + //文字被截取 | ||
326 | + if(iX < -30 || (iX + iTextW) > pClsCS->m_iW + 30 || (iY - iTextH ) < -15 || iY > pClsCS->m_iH + 15) | ||
327 | + { | ||
328 | + return false; | ||
329 | + } | ||
324 | 330 | ||
325 | /* | 331 | /* |
326 | 文字避让部分 | 332 | 文字避让部分 |
327 | */ | 333 | */ |
328 | - | ||
329 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | 334 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
330 | int xFrom = iX / gridsize; | 335 | int xFrom = iX / gridsize; |
331 | int xTo = (iX + iTextW) / gridsize; | 336 | int xTo = (iX + iTextW) / gridsize; |
@@ -371,6 +376,10 @@ namespace DmapCore_30 | @@ -371,6 +376,10 @@ namespace DmapCore_30 | ||
371 | //if (pFlag[iFlagW*i + j]) return false; | 376 | //if (pFlag[iFlagW*i + j]) return false; |
372 | } | 377 | } |
373 | } | 378 | } |
379 | + | ||
380 | + //文字截取部分 | ||
381 | + | ||
382 | + | ||
374 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | 383 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
375 | 384 | ||
376 | 385 |
@@ -8,7 +8,7 @@ namespace DmapCore_30 | @@ -8,7 +8,7 @@ namespace DmapCore_30 | ||
8 | { | 8 | { |
9 | m_pSurf = surface; | 9 | m_pSurf = surface; |
10 | m_pCr = cairo_create(m_pSurf); | 10 | m_pCr = cairo_create(m_pSurf); |
11 | - //cairo_set_antialias(m_pCr,cairo_antialias_t::CAIRO_ANTIALIAS_BEST); | 11 | + cairo_set_antialias(m_pCr,cairo_antialias_t::CAIRO_ANTIALIAS_BEST); |
12 | m_iN = 1; | 12 | m_iN = 1; |
13 | m_iW = cairo_image_surface_get_width(surface); | 13 | m_iW = cairo_image_surface_get_width(surface); |
14 | m_iH = cairo_image_surface_get_height(surface); | 14 | m_iH = cairo_image_surface_get_height(surface); |
@@ -287,7 +287,7 @@ namespace DmapCore_30 | @@ -287,7 +287,7 @@ namespace DmapCore_30 | ||
287 | //CAIRO_ANTIALIAS_FAST, | 287 | //CAIRO_ANTIALIAS_FAST, |
288 | // CAIRO_ANTIALIAS_GOOD, | 288 | // CAIRO_ANTIALIAS_GOOD, |
289 | // CAIRO_ANTIALIAS_BEST | 289 | // CAIRO_ANTIALIAS_BEST |
290 | - cairo_set_antialias(cr,CAIRO_ANTIALIAS_FAST); | 290 | + // cairo_set_antialias(cr,CAIRO_ANTIALIAS_FAST); |
291 | return true; | 291 | return true; |
292 | switch (iAntialias) | 292 | switch (iAntialias) |
293 | { | 293 | { |
@@ -30,7 +30,7 @@ namespace DmapCore_30 | @@ -30,7 +30,7 @@ namespace DmapCore_30 | ||
30 | 30 | ||
31 | bool legendParamater::next(char * title) | 31 | bool legendParamater::next(char * title) |
32 | { | 32 | { |
33 | - if(index/row_maxsize> current_Col_Index) | 33 | + if( row_maxsize >0 && index/row_maxsize > current_Col_Index) |
34 | { | 34 | { |
35 | current_Col_Index ++; | 35 | current_Col_Index ++; |
36 | pixXIndex = 10 + (current_Col_Index *100); | 36 | pixXIndex = 10 + (current_Col_Index *100); |
@@ -49,7 +49,7 @@ public: | @@ -49,7 +49,7 @@ public: | ||
49 | { | 49 | { |
50 | return; | 50 | return; |
51 | } | 51 | } |
52 | - | 52 | + // printf("%s\r\n", szRequest); |
53 | 53 | ||
54 | DmpSpServerRequest dmpRequest(request); | 54 | DmpSpServerRequest dmpRequest(request); |
55 | DmpSpServerResponse dmpResponse(response); | 55 | DmpSpServerResponse dmpResponse(response); |
@@ -44,19 +44,19 @@ DmpServerManager::~DmpServerManager() | @@ -44,19 +44,19 @@ DmpServerManager::~DmpServerManager() | ||
44 | delete mapProject; | 44 | delete mapProject; |
45 | mapProject = nullptr; | 45 | mapProject = nullptr; |
46 | } | 46 | } |
47 | - } | 47 | + } |
48 | projects_.clear(); | 48 | projects_.clear(); |
49 | } | 49 | } |
50 | 50 | ||
51 | void DmpServerManager::init(const boost::filesystem::path &modulePath) | 51 | void DmpServerManager::init(const boost::filesystem::path &modulePath) |
52 | { | 52 | { |
53 | serverRegistry_->init(modulePath); | 53 | serverRegistry_->init(modulePath); |
54 | - if(!loadServices()) | 54 | + if (!loadServices()) |
55 | { | 55 | { |
56 | std::cout << "加载服务失败!" << std::endl; | 56 | std::cout << "加载服务失败!" << std::endl; |
57 | LOGGER_ERROR("加载服务失败!"); | 57 | LOGGER_ERROR("加载服务失败!"); |
58 | } | 58 | } |
59 | - //LoadDmpServices(); | 59 | + // LoadDmpServices(); |
60 | } | 60 | } |
61 | 61 | ||
62 | std::string DmpServerManager::getCapabilities() | 62 | std::string DmpServerManager::getCapabilities() |
@@ -106,9 +106,9 @@ bool DmpServerManager::removeProject(const std::string &serviceName) | @@ -106,9 +106,9 @@ bool DmpServerManager::removeProject(const std::string &serviceName) | ||
106 | return true; | 106 | return true; |
107 | } | 107 | } |
108 | 108 | ||
109 | -bool DmpServerManager::publish(const std::string& serverName, const std::string& serviceName, const std::string& title, int capabilities, const std::string& projectData) | 109 | +bool DmpServerManager::publish(const std::string &serverName, const std::string &serviceName, const std::string &title, int capabilities, const std::string &projectData) |
110 | { | 110 | { |
111 | - //project | 111 | + // project |
112 | std::string projData; | 112 | std::string projData; |
113 | if (!DmpServerUtils::Base64Decode(projectData, &projData)) | 113 | if (!DmpServerUtils::Base64Decode(projectData, &projData)) |
114 | { | 114 | { |
@@ -122,9 +122,7 @@ bool DmpServerManager::publish(const std::string& serverName, const std::string& | @@ -122,9 +122,7 @@ bool DmpServerManager::publish(const std::string& serverName, const std::string& | ||
122 | } | 122 | } |
123 | 123 | ||
124 | project->initVectorLayerVacuate([](const std::string &tableguid) | 124 | project->initVectorLayerVacuate([](const std::string &tableguid) |
125 | - { | ||
126 | - return DmpHttp::get(DmpServerConfig::Instance()->getMetaUrl() + URL_VACUATE + tableguid); | ||
127 | - }); | 125 | + { return DmpHttp::get(DmpServerConfig::Instance()->getMetaUrl() + URL_VACUATE + tableguid); }); |
128 | 126 | ||
129 | if (!serverRegistry_->getServer(serverName)->publish(serviceName, title, capabilities, *project)) | 127 | if (!serverRegistry_->getServer(serverName)->publish(serviceName, title, capabilities, *project)) |
130 | { | 128 | { |
@@ -132,7 +130,7 @@ bool DmpServerManager::publish(const std::string& serverName, const std::string& | @@ -132,7 +130,7 @@ bool DmpServerManager::publish(const std::string& serverName, const std::string& | ||
132 | return false; | 130 | return false; |
133 | } | 131 | } |
134 | projects_[serviceName] = project; | 132 | projects_[serviceName] = project; |
135 | - | 133 | + |
136 | return true; | 134 | return true; |
137 | } | 135 | } |
138 | 136 | ||
@@ -159,34 +157,44 @@ bool DmpServerManager::stopService(const std::string &serverName, const std::str | @@ -159,34 +157,44 @@ bool DmpServerManager::stopService(const std::string &serverName, const std::str | ||
159 | } | 157 | } |
160 | bool DmpServerManager::loadServices() | 158 | bool DmpServerManager::loadServices() |
161 | { | 159 | { |
162 | - boost::property_tree::ptree pt,ptList; | ||
163 | - std::string conn = DmpServerConfig::Instance()->getMetaUrl(); | ||
164 | - const std::string url= conn + URI_RELOAD; | ||
165 | - std::string strContent=DmpHttp::get(url); | ||
166 | - if(strContent.length()==0) | ||
167 | - { | ||
168 | - return false; | ||
169 | - } | ||
170 | - std::stringstream ssData; | ||
171 | - ssData<<strContent.c_str(); | ||
172 | - boost::property_tree::read_json(ssData, pt); | ||
173 | - int iCount = std::atoi(pt.get<std::string>("data.count").c_str()); | ||
174 | - if(iCount>0) | 160 | + std::string strContent; |
161 | + try | ||
175 | { | 162 | { |
176 | - ptList=pt.get_child("data.list"); | ||
177 | - for (auto& e : ptList) | 163 | + boost::property_tree::ptree pt, ptList; |
164 | + std::string conn = DmpServerConfig::Instance()->getMetaUrl(); | ||
165 | + const std::string url = conn + URI_RELOAD; | ||
166 | + strContent = DmpHttp::get(url); | ||
167 | + if (strContent.length() == 0) | ||
178 | { | 168 | { |
179 | - std::string name = e.second.get<std::string>("name"); | ||
180 | - std::string title = e.second.get<std::string>("title"); | ||
181 | - std::string type = e.second.get<std::string>("type"); | ||
182 | - int capabilities =e.second.get<int>("capabilities"); | ||
183 | - std::string project = e.second.get<std::string>("project"); | ||
184 | - this->initServices(type,name,title,capabilities,project); | 169 | + return false; |
185 | } | 170 | } |
171 | + std::stringstream ssData; | ||
172 | + ssData << strContent.c_str(); | ||
173 | + boost::property_tree::read_json(ssData, pt); | ||
174 | + int iCount = std::atoi(pt.get<std::string>("data.count").c_str()); | ||
175 | + if (iCount > 0) | ||
176 | + { | ||
177 | + ptList = pt.get_child("data.list"); | ||
178 | + for (auto &e : ptList) | ||
179 | + { | ||
180 | + std::string name = e.second.get<std::string>("name"); | ||
181 | + std::string title = e.second.get<std::string>("title"); | ||
182 | + std::string type = e.second.get<std::string>("type"); | ||
183 | + int capabilities = e.second.get<int>("capabilities"); | ||
184 | + std::string project = e.second.get<std::string>("project"); | ||
185 | + this->initServices(type, name, title, capabilities, project); | ||
186 | + } | ||
187 | + } | ||
188 | + } | ||
189 | + catch(const std::exception& e) | ||
190 | + { | ||
191 | + std::cerr << e.what() << strContent.c_str() << '\n'; | ||
192 | + return false; | ||
186 | } | 193 | } |
194 | + | ||
187 | return true; | 195 | return true; |
188 | } | 196 | } |
189 | -bool DmpServerManager::initServices(const std::string& serverName, const std::string& serviceName, const std::string& title, int capabilities, const std::string& projectData) | 197 | +bool DmpServerManager::initServices(const std::string &serverName, const std::string &serviceName, const std::string &title, int capabilities, const std::string &projectData) |
190 | { | 198 | { |
191 | // project | 199 | // project |
192 | std::string projData; | 200 | std::string projData; |
@@ -202,9 +210,7 @@ bool DmpServerManager::initServices(const std::string& serverName, const std::st | @@ -202,9 +210,7 @@ bool DmpServerManager::initServices(const std::string& serverName, const std::st | ||
202 | } | 210 | } |
203 | 211 | ||
204 | project->initVectorLayerVacuate([](const std::string &tableguid) | 212 | project->initVectorLayerVacuate([](const std::string &tableguid) |
205 | - { | ||
206 | - return DmpHttp::get(DmpServerConfig::Instance()->getMetaUrl() + URL_VACUATE + tableguid); | ||
207 | - }); | 213 | + { return DmpHttp::get(DmpServerConfig::Instance()->getMetaUrl() + URL_VACUATE + tableguid); }); |
208 | 214 | ||
209 | if (!serverRegistry_->getServer(serverName)->publish(serviceName, title, capabilities, *project)) | 215 | if (!serverRegistry_->getServer(serverName)->publish(serviceName, title, capabilities, *project)) |
210 | { | 216 | { |
@@ -20,6 +20,7 @@ SET (MAPSERVER_SRCS | @@ -20,6 +20,7 @@ SET (MAPSERVER_SRCS | ||
20 | wms/dmpwmsparameters.cpp | 20 | wms/dmpwmsparameters.cpp |
21 | wms/dmpwmsgetcapabilities.cpp | 21 | wms/dmpwmsgetcapabilities.cpp |
22 | wms/dmpwmsgetmap.cpp | 22 | wms/dmpwmsgetmap.cpp |
23 | + wms/dmpwmsgetprint.cpp | ||
23 | wms/dmpwmsserviceinfo.cpp | 24 | wms/dmpwmsserviceinfo.cpp |
24 | wms/dmpwmsgetfeatureinfo.cpp | 25 | wms/dmpwmsgetfeatureinfo.cpp |
25 | wms/print/dmpmapprint.cpp | 26 | wms/print/dmpmapprint.cpp |
@@ -55,6 +56,7 @@ SET (MAPSERVER_HDRS | @@ -55,6 +56,7 @@ SET (MAPSERVER_HDRS | ||
55 | wms/dmpwmsparameters.h | 56 | wms/dmpwmsparameters.h |
56 | wms/dmpwmsgetcapabilities.h | 57 | wms/dmpwmsgetcapabilities.h |
57 | wms/dmpwmsgetmap.h | 58 | wms/dmpwmsgetmap.h |
59 | + wms/dmpwmsgetprint.h | ||
58 | wms/dmpwmsserviceinfo.h | 60 | wms/dmpwmsserviceinfo.h |
59 | wms/dmpwmsgetfeatureinfo.h | 61 | wms/dmpwmsgetfeatureinfo.h |
60 | wms/print/dmpmapprint.h | 62 | wms/print/dmpmapprint.h |
@@ -18,6 +18,23 @@ using boost::asio::ip::tcp; | @@ -18,6 +18,23 @@ using boost::asio::ip::tcp; | ||
18 | namespace mapserver | 18 | namespace mapserver |
19 | { | 19 | { |
20 | 20 | ||
21 | + void DmpMapServerUtil::initVectorLayerSrid(shared_ptr<DmpPgsql> pPgsqlConn,DmpVectorLayer* layer) | ||
22 | + { | ||
23 | + if(layer->srid().empty()) | ||
24 | + { | ||
25 | + string name = layer->name(); | ||
26 | + string sql = "select t.f_geometry_column shapeField, t.type ,f_table_schema,t.srid from public.geometry_columns t where lower( t.f_table_name) = lower('"+ name +"');"; | ||
27 | + if(pPgsqlConn->ExecWait(sql)) | ||
28 | + { | ||
29 | + string geom = pPgsqlConn->getString(0); | ||
30 | + string value = pPgsqlConn->getString( 1); | ||
31 | + string strSchema = pPgsqlConn->getString(2); | ||
32 | + string srid = pPgsqlConn->getString(3); | ||
33 | + layer->setSrid(srid); | ||
34 | + } | ||
35 | + } | ||
36 | + } | ||
37 | + | ||
21 | void DmpMapServerUtil::responseGml(shared_ptr<DmpPgsql> pPgsqlConn, std::string &responseData, const string &layerName, const std::string &srid) | 38 | void DmpMapServerUtil::responseGml(shared_ptr<DmpPgsql> pPgsqlConn, std::string &responseData, const string &layerName, const std::string &srid) |
22 | { | 39 | { |
23 | 40 |
@@ -13,13 +13,16 @@ | @@ -13,13 +13,16 @@ | ||
13 | #include <string> | 13 | #include <string> |
14 | #include <memory> | 14 | #include <memory> |
15 | #include "dmppgsqlsourcepools.h" | 15 | #include "dmppgsqlsourcepools.h" |
16 | - | 16 | +#include "dmpproject.h" |
17 | +#include "dmpvectorlayer.h" | ||
17 | 18 | ||
18 | namespace mapserver | 19 | namespace mapserver |
19 | { | 20 | { |
20 | class DmpMapServerUtil | 21 | class DmpMapServerUtil |
21 | { | 22 | { |
22 | public: | 23 | public: |
24 | + static void initVectorLayerSrid(shared_ptr<DmpPgsql> pPgsqlConn,DmpVectorLayer* layer); | ||
25 | + | ||
23 | static void responseGeojson(shared_ptr<DmpPgsql> pPgsqlConn, std::string &responseData,const string& layerName,const std::string &srid); | 26 | static void responseGeojson(shared_ptr<DmpPgsql> pPgsqlConn, std::string &responseData,const string& layerName,const std::string &srid); |
24 | static void responseGml(shared_ptr<DmpPgsql> pPgsqlConn, std::string &responseData,const string& layerName,const std::string &srid); | 27 | static void responseGml(shared_ptr<DmpPgsql> pPgsqlConn, std::string &responseData,const string& layerName,const std::string &srid); |
25 | static void toXmlString(std::string &s); | 28 | static void toXmlString(std::string &s); |
@@ -140,7 +140,7 @@ namespace DmpMapping | @@ -140,7 +140,7 @@ namespace DmpMapping | ||
140 | bool loadProjectService(const DmpServerContext &context,ProjectMap& vectorMappingProjects) | 140 | bool loadProjectService(const DmpServerContext &context,ProjectMap& vectorMappingProjects) |
141 | { | 141 | { |
142 | const char *data = (char *)(context.request()->GetData()); | 142 | const char *data = (char *)(context.request()->GetData()); |
143 | - if(data== nullptr || *data == '\0') | 143 | + if(data== nullptr || *data == '\0' || context.request()->method() != DmpServerRequest::Method::POST_METHOD) |
144 | { | 144 | { |
145 | LOGGER_ERROR("post 参数错误"); | 145 | LOGGER_ERROR("post 参数错误"); |
146 | context.response()->writeJson("{\"status\":\"false\",\"message\":\"post 参数错误!\"}"); | 146 | context.response()->writeJson("{\"status\":\"false\",\"message\":\"post 参数错误!\"}"); |
@@ -250,7 +250,7 @@ namespace DmpMapping | @@ -250,7 +250,7 @@ namespace DmpMapping | ||
250 | bool editService(const DmpServerContext &context,ProjectMap& vectorMappingProjects) | 250 | bool editService(const DmpServerContext &context,ProjectMap& vectorMappingProjects) |
251 | { | 251 | { |
252 | const char *data = (char *)(context.request()->GetData()); | 252 | const char *data = (char *)(context.request()->GetData()); |
253 | - if(data== nullptr || *data == '\0') | 253 | + if(data== nullptr || *data == '\0' || context.request()->method() != DmpServerRequest::Method::POST_METHOD) |
254 | { | 254 | { |
255 | LOGGER_ERROR("post 参数错误"); | 255 | LOGGER_ERROR("post 参数错误"); |
256 | context.response()->writeJson("{\"status\":\"false\",\"message\":\"post 参数错误!\"}"); | 256 | context.response()->writeJson("{\"status\":\"false\",\"message\":\"post 参数错误!\"}"); |
@@ -76,6 +76,11 @@ namespace DmpMapping | @@ -76,6 +76,11 @@ namespace DmpMapping | ||
76 | { | 76 | { |
77 | getmap(context,params); | 77 | getmap(context,params); |
78 | } | 78 | } |
79 | + else | ||
80 | + { | ||
81 | + std::string responseData = "{\"result\":\"false\",\"message\":\"配图服务未实现" + request + "接口\"}"; | ||
82 | + context.response()->writeJson(responseData); | ||
83 | + } | ||
79 | 84 | ||
80 | } | 85 | } |
81 | 86 |
@@ -56,6 +56,11 @@ namespace DmpWfs | @@ -56,6 +56,11 @@ namespace DmpWfs | ||
56 | { | 56 | { |
57 | writeGetFeature(context,params, project); | 57 | writeGetFeature(context,params, project); |
58 | } | 58 | } |
59 | + else | ||
60 | + { | ||
61 | + std::string responseData = "{\"result\":\"false\",\"message\":\"WFS 未实现" + request + "接口\"}"; | ||
62 | + context.response()->writeJson(responseData); | ||
63 | + } | ||
59 | } | 64 | } |
60 | } | 65 | } |
61 | 66 |
@@ -23,7 +23,31 @@ namespace DmpWfs | @@ -23,7 +23,31 @@ namespace DmpWfs | ||
23 | const DmpProject *project, | 23 | const DmpProject *project, |
24 | bool projectSettings) | 24 | bool projectSettings) |
25 | { | 25 | { |
26 | - WfsGetFeature(context, params, project, projectSettings); | 26 | + std::string errorinfo = WfsGetFeature(context, params, project, projectSettings); |
27 | + if(!errorinfo.empty()) | ||
28 | + { | ||
29 | + DmpWfsParameters::Format resultType = params.ResultType(); | ||
30 | + if (resultType == DmpWfsParameters::Format::GeoJson) | ||
31 | + { | ||
32 | + std::string responseData; | ||
33 | + responseData = "{\"result\":\"false\",\"message\":\"" + errorinfo + "\"}"; | ||
34 | + context.response()->writeJson(responseData); | ||
35 | + } | ||
36 | + else | ||
37 | + { | ||
38 | + boost::property_tree::ptree ptreeDoc; | ||
39 | + boost::property_tree::ptree ptreeRoot; | ||
40 | + ptreeRoot.add<bool>("result", false); | ||
41 | + ptreeRoot.add<std::string>("message", errorinfo); | ||
42 | + ptreeDoc.add_child("WfsGetfeatureResponse",ptreeRoot); | ||
43 | + std::stringstream stream; | ||
44 | + write_xml(stream, ptreeDoc); | ||
45 | + std::string responseData = stream.str(); | ||
46 | + context.response()->removeHeader("Content-Type"); | ||
47 | + context.response()->setHeader("Content-Type", "text/xml;charset=utf-8"); | ||
48 | + context.response()->write(responseData); | ||
49 | + } | ||
50 | + } | ||
27 | } | 51 | } |
28 | 52 | ||
29 | std::string WfsGetFeature(const DmpServerContext &context, const DmpWfsParameters ¶ms, | 53 | std::string WfsGetFeature(const DmpServerContext &context, const DmpWfsParameters ¶ms, |
@@ -21,6 +21,7 @@ | @@ -21,6 +21,7 @@ | ||
21 | #include "dmpwmsgetmap.h" | 21 | #include "dmpwmsgetmap.h" |
22 | #include "dmpwmsserviceinfo.h" | 22 | #include "dmpwmsserviceinfo.h" |
23 | #include "dmpwmsgetfeatureinfo.h" | 23 | #include "dmpwmsgetfeatureinfo.h" |
24 | +#include "dmpwmsgetprint.h" | ||
24 | using namespace std; | 25 | using namespace std; |
25 | 26 | ||
26 | namespace DmpWms | 27 | namespace DmpWms |
@@ -40,6 +41,7 @@ namespace DmpWms | @@ -40,6 +41,7 @@ namespace DmpWms | ||
40 | const DmpWmsParameters params(context.request()->serverParameters()); | 41 | const DmpWmsParameters params(context.request()->serverParameters()); |
41 | const DmpProject* project = context.serverProject()->project(); | 42 | const DmpProject* project = context.serverProject()->project(); |
42 | const std::string request = params.Request(); | 43 | const std::string request = params.Request(); |
44 | + // printf("%s\r\n", request.c_str()); | ||
43 | if (request.empty()) | 45 | if (request.empty()) |
44 | { | 46 | { |
45 | context.response()->writeHtml("wms,Operation is null"); | 47 | context.response()->writeHtml("wms,Operation is null"); |
@@ -66,12 +68,21 @@ namespace DmpWms | @@ -66,12 +68,21 @@ namespace DmpWms | ||
66 | } | 68 | } |
67 | else if(boost::iequals(request, "getserviceinfo")) | 69 | else if(boost::iequals(request, "getserviceinfo")) |
68 | { | 70 | { |
69 | - writeGetServiceInfo(context,params, project); | 71 | + writeGetServiceInfo(context,params, project); |
70 | } | 72 | } |
71 | - else if(request == "getlegendgraphic") | 73 | + else if(boost::iequals(request, "getlegendgraphic")) |
72 | { | 74 | { |
73 | 75 | ||
74 | } | 76 | } |
77 | + else if(boost::iequals(request, "getprint")) | ||
78 | + { | ||
79 | + writeGetPrint(context,params, project); | ||
80 | + } | ||
81 | + else | ||
82 | + { | ||
83 | + std::string responseData = "{\"result\":\"false\",\"message\":\"WMS 未实现" + request + "接口\"}"; | ||
84 | + context.response()->writeJson(responseData); | ||
85 | + } | ||
75 | } | 86 | } |
76 | } | 87 | } |
77 | 88 |
1 | +/************************************************************************** | ||
2 | +* file: dmpwmsgetprint.cpp | ||
3 | + | ||
4 | +* Author: qingxiongf | ||
5 | +* Date: 2022-02-10 14:18:07 | ||
6 | +* Email: qingxiongf@chinadci.com | ||
7 | +* copyright: 广州城市信息研究所有限公司 | ||
8 | +***************************************************************************/ | ||
9 | +#include "dmpwmsgetprint.h" | ||
10 | +#include "print/dmpmapprint.h" | ||
11 | +#include "dmpwmsrenderer.h" | ||
12 | +#include "dmpserverresponse.h" | ||
13 | +#include "dmpserverrequest.h" | ||
14 | +#include "dmpserverproject.h" | ||
15 | +#include <map> | ||
16 | +#include <memory> | ||
17 | +namespace DmpWms | ||
18 | +{ | ||
19 | + void writeGetPrint(const DmpServerContext &context,const DmpWmsParameters& params, | ||
20 | + const DmpProject* project, | ||
21 | + bool projectSettings ) | ||
22 | + { | ||
23 | + DmpWmsParameters::Format outformat = params.ResFormat(); | ||
24 | + DmpMapPrint mapPrint(outformat); | ||
25 | + | ||
26 | + std::string responseData; | ||
27 | + | ||
28 | + std::string name = context.serverProject()->name(); | ||
29 | + std::string title = context.serverProject()->title(); | ||
30 | + std::string boxx = params.BBox(); | ||
31 | + std::string printTemp = params.printTemp(); | ||
32 | + | ||
33 | + if(mapPrint.getPrintTempFile(responseData,project,printTemp.c_str(),boxx.c_str())) | ||
34 | + { | ||
35 | + if(outformat == DmpWmsParameters::Format::PDF) | ||
36 | + { | ||
37 | + context.response()->setHeader("Content-Type", "application/pdf"); | ||
38 | + } | ||
39 | + else if(outformat == DmpWmsParameters::Format::SVG) | ||
40 | + { | ||
41 | + context.response()->setHeader("Content-Type", "image/svg"); | ||
42 | + } | ||
43 | + else | ||
44 | + { | ||
45 | + context.response()->setHeader("Content-Type", "image/png"); | ||
46 | + } | ||
47 | + } | ||
48 | + else | ||
49 | + { | ||
50 | + context.response()->setHeader("Content-Type", "text/xml"); | ||
51 | + } | ||
52 | + | ||
53 | + context.response()->write(responseData); | ||
54 | + } | ||
55 | +} |
1 | +/************************************************************************** | ||
2 | +* file: dmpwmsgetprint.h | ||
3 | + | ||
4 | +* Author: qingxiongf | ||
5 | +* Date: 2022-02-10 14:17:58 | ||
6 | +* Email: qingxiongf@chinadci.com | ||
7 | +* copyright: 广州城市信息研究所有限公司 | ||
8 | +***************************************************************************/ | ||
9 | + | ||
10 | +#ifndef __dmpwmsgetprint_h__ | ||
11 | +#define __dmpwmsgetprint_h__ | ||
12 | + | ||
13 | + | ||
14 | +#include <boost/property_tree/ptree.hpp> | ||
15 | +#include <boost/property_tree/xml_parser.hpp> | ||
16 | +#include <boost/typeof/typeof.hpp> | ||
17 | +#include <memory> | ||
18 | +#include <vector> | ||
19 | +#include "dmpproject.h" | ||
20 | +#include "dmpwmsparameters.h" | ||
21 | +#include "dmpservercontext.h" | ||
22 | + | ||
23 | +namespace DmpWms | ||
24 | +{ | ||
25 | + void writeGetPrint(const DmpServerContext &context,const DmpWmsParameters& params, | ||
26 | + const DmpProject* project, | ||
27 | + bool projectSettings = false ); | ||
28 | +} | ||
29 | + | ||
30 | +#endif // __dmpwmsgetprint_h__ |
@@ -169,6 +169,13 @@ namespace DmpWms | @@ -169,6 +169,13 @@ namespace DmpWms | ||
169 | return value; | 169 | return value; |
170 | } | 170 | } |
171 | 171 | ||
172 | + std::string DmpWmsParameters::printTemp() const | ||
173 | + { | ||
174 | + std::string value = ""; | ||
175 | + GetStringParameter("PRINTTEMP",value); | ||
176 | + return value; | ||
177 | + } | ||
178 | + | ||
172 | DmpWmsParameters::Format DmpWmsParameters::InfoFormat() const | 179 | DmpWmsParameters::Format DmpWmsParameters::InfoFormat() const |
173 | { | 180 | { |
174 | std::string value = ""; | 181 | std::string value = ""; |
@@ -241,6 +248,16 @@ namespace DmpWms | @@ -241,6 +248,16 @@ namespace DmpWms | ||
241 | if (frm.compare("jpg") == 0 || frm.compare("jpeg") == 0 || frm.compare("image/jpeg") == 0 ) { | 248 | if (frm.compare("jpg") == 0 || frm.compare("jpeg") == 0 || frm.compare("image/jpeg") == 0 ) { |
242 | f = DmpWmsParameters::Format::JPG; | 249 | f = DmpWmsParameters::Format::JPG; |
243 | } | 250 | } |
251 | + else if(frm.compare("pdf") == 0){ | ||
252 | + f = DmpWmsParameters::Format::PDF; | ||
253 | + }else if(frm.compare("svg") == 0){ | ||
254 | + f = DmpWmsParameters::Format::SVG; | ||
255 | + }else if(frm.compare("xml") == 0 || frm.compare("gml") == 0){ | ||
256 | + f = DmpWmsParameters::Format::GML; | ||
257 | + }else if(frm.compare("json") == 0 || frm.compare("geojson") == 0){ | ||
258 | + f = DmpWmsParameters::Format::GeoJson; | ||
259 | + } | ||
260 | + | ||
244 | return f; | 261 | return f; |
245 | } | 262 | } |
246 | return DmpWmsParameters::Format::NONE; | 263 | return DmpWmsParameters::Format::NONE; |
@@ -61,6 +61,8 @@ namespace DmpWms | @@ -61,6 +61,8 @@ namespace DmpWms | ||
61 | int Y() const; //地图上查询点的Y坐标,以像素为单位。0是左侧。j是WMS 1.3.0中使用的参数键。 | 61 | int Y() const; //地图上查询点的Y坐标,以像素为单位。0是左侧。j是WMS 1.3.0中使用的参数键。 |
62 | 62 | ||
63 | DmpWmsParameters::Format ResFormat() const; //GetMap URL为Format GetFeatureInfo url为:info_format | 63 | DmpWmsParameters::Format ResFormat() const; //GetMap URL为Format GetFeatureInfo url为:info_format |
64 | + | ||
65 | + std::string printTemp() const; | ||
64 | private: | 66 | private: |
65 | bool GetStringParameter(const char* key, std::string &value) const; | 67 | bool GetStringParameter(const char* key, std::string &value) const; |
66 | bool GetIntParameter(const char* key, int& value) const; | 68 | bool GetIntParameter(const char* key, int& value) const; |
@@ -173,6 +173,25 @@ namespace DmpWms | @@ -173,6 +173,25 @@ namespace DmpWms | ||
173 | //ss += " limit 40000 "; | 173 | //ss += " limit 40000 "; |
174 | 174 | ||
175 | double t = pRect->m_dTop, r = pRect->m_dRight, b = pRect->m_dBottom, l = pRect->m_dLeft; | 175 | double t = pRect->m_dTop, r = pRect->m_dRight, b = pRect->m_dBottom, l = pRect->m_dLeft; |
176 | + //点 标注 避免被截取 | ||
177 | + if(layer->GeometryType() == DmpWkbTypes::GeometryType::PointGeometry) | ||
178 | + { | ||
179 | + double drh = (pRect->m_dTop - pRect->m_dBottom)/this->m_dHeight; | ||
180 | + double drw = (pRect->m_dRight - pRect->m_dLeft)/this->m_dWidth; | ||
181 | + t = t + drh * 15; | ||
182 | + b = b - drh * 15; | ||
183 | + if(length > 0) | ||
184 | + { | ||
185 | + l = l - drw * 30; | ||
186 | + r = r + drw * 20; | ||
187 | + } | ||
188 | + else | ||
189 | + { | ||
190 | + l = l - drw * 15; | ||
191 | + r = r + drw * 15; | ||
192 | + } | ||
193 | + } | ||
194 | + | ||
176 | std::string sql = format(ss.c_str(), shapeName.c_str(), layer->schema().c_str(), tableName.c_str(), shapeName.c_str(), l, b, r, t); | 195 | std::string sql = format(ss.c_str(), shapeName.c_str(), layer->schema().c_str(), tableName.c_str(), shapeName.c_str(), l, b, r, t); |
177 | //printf("%s\r\n",sql.c_str()); | 196 | //printf("%s\r\n",sql.c_str()); |
178 | return sql; | 197 | return sql; |
@@ -572,8 +591,8 @@ ST_GeometryFromText('POLYGON((%f %f, %f %f, %f %f, %f %f, %f %f))',%s),\ | @@ -572,8 +591,8 @@ ST_GeometryFromText('POLYGON((%f %f, %f %f, %f %f, %f %f, %f %f))',%s),\ | ||
572 | std::string sql = format(ss.c_str(), layer->schema().c_str(), tableName.c_str()); | 591 | std::string sql = format(ss.c_str(), layer->schema().c_str(), tableName.c_str()); |
573 | 592 | ||
574 | string shapeName = layer->geom(); | 593 | string shapeName = layer->geom(); |
575 | - sql += format(" ST_DWithin(\"%s\", ST_GeometryFromText('POINT(%f %f)',%s), %f) limit %d ", | ||
576 | - shapeName.c_str(), x, y, layer->srid().c_str(), dis, feature_count); | 594 | + sql += format(" ST_DWithin(\"%s\", ST_GeometryFromText('POINT(%f %f)',%s),%f) limit %d ", |
595 | + shapeName.c_str(), x, y,layer->srid().c_str(), dis, feature_count); | ||
577 | //cout<<sql.c_str() <<endl; | 596 | //cout<<sql.c_str() <<endl; |
578 | return sql; | 597 | return sql; |
579 | } | 598 | } |
@@ -596,16 +615,17 @@ ST_GeometryFromText('POLYGON((%f %f, %f %f, %f %f, %f %f, %f %f))',%s),\ | @@ -596,16 +615,17 @@ ST_GeometryFromText('POLYGON((%f %f, %f %f, %f %f, %f %f, %f %f))',%s),\ | ||
596 | double start = clock(); | 615 | double start = clock(); |
597 | double cost, cost2; | 616 | double cost, cost2; |
598 | 617 | ||
599 | - string sql = this->GetFeatureInfoSQL(layer, x0, y0, dis, feature_count); //sql语句中使用 ::box | ||
600 | - if (sql == "") | ||
601 | - continue; | ||
602 | - //printf("%s\r\n",sql.c_str()); | ||
603 | - string layerName = layer->name(); | 618 | + |
604 | try | 619 | try |
605 | { | 620 | { |
606 | shared_ptr<DmpPgsql> pPgsqlConn = DmpPgsqlSourcePools::get_instance()->GetPgsqlConn(layer->source()); | 621 | shared_ptr<DmpPgsql> pPgsqlConn = DmpPgsqlSourcePools::get_instance()->GetPgsqlConn(layer->source()); |
607 | if (pPgsqlConn == nullptr) | 622 | if (pPgsqlConn == nullptr) |
608 | break; | 623 | break; |
624 | + DmpMapServerUtil::initVectorLayerSrid(pPgsqlConn, layer); | ||
625 | + string sql = this->GetFeatureInfoSQL(layer, x0, y0, dis, feature_count); //sql语句中使用 ::box | ||
626 | + if (sql == "") continue; | ||
627 | + string layerName = layer->name(); | ||
628 | + //printf("%s\r\n",sql.c_str()); | ||
609 | if (pPgsqlConn->ExecWaitBinary(sql)) | 629 | if (pPgsqlConn->ExecWaitBinary(sql)) |
610 | { | 630 | { |
611 | if(pPgsqlConn->GetRowCount()>0 || i==0) | 631 | if(pPgsqlConn->GetRowCount()>0 || i==0) |
@@ -949,7 +969,8 @@ ST_GeometryFromText('POLYGON((%f %f, %f %f, %f %f, %f %f, %f %f))',%s),\ | @@ -949,7 +969,8 @@ ST_GeometryFromText('POLYGON((%f %f, %f %f, %f %f, %f %f, %f %f))',%s),\ | ||
949 | } | 969 | } |
950 | } | 970 | } |
951 | 971 | ||
952 | - for (int i = 0; i < (int)(m_vLayers.size()); i++) | 972 | + //for (int i = 0; i < (int)(m_vLayers.size()); i++) |
973 | + for (int i = (int)(m_vLayers.size()) -1; i > 0; i--) | ||
953 | { | 974 | { |
954 | DmpVectorLayer *layer = m_vLayers[i]; | 975 | DmpVectorLayer *layer = m_vLayers[i]; |
955 | sprintf(buff, "<log>draw layer %s</log>", layer->name().c_str()); | 976 | sprintf(buff, "<log>draw layer %s</log>", layer->name().c_str()); |
@@ -1206,7 +1227,9 @@ ST_GeometryFromText('POLYGON((%f %f, %f %f, %f %f, %f %f, %f %f))',%s),\ | @@ -1206,7 +1227,9 @@ ST_GeometryFromText('POLYGON((%f %f, %f %f, %f %f, %f %f, %f %f))',%s),\ | ||
1206 | 1227 | ||
1207 | map<DmpVectorLayer *, shared_ptr<DataCollection>> map_DataCollection; | 1228 | map<DmpVectorLayer *, shared_ptr<DataCollection>> map_DataCollection; |
1208 | 1229 | ||
1209 | - for (int i = 0; i < (int)(m_vLayers.size()); i++) | 1230 | + |
1231 | + //for (int i = 0; i < (int)(m_vLayers.size()); i++) | ||
1232 | + for (int i = (int)(m_vLayers.size()) -1; i > 0; i--) | ||
1210 | { | 1233 | { |
1211 | DmpVectorLayer *layer = m_vLayers[i]; | 1234 | DmpVectorLayer *layer = m_vLayers[i]; |
1212 | 1235 | ||
@@ -1292,7 +1315,7 @@ ST_GeometryFromText('POLYGON((%f %f, %f %f, %f %f, %f %f, %f %f))',%s),\ | @@ -1292,7 +1315,7 @@ ST_GeometryFromText('POLYGON((%f %f, %f %f, %f %f, %f %f, %f %f))',%s),\ | ||
1292 | if (PQntuples(res) == 0) | 1315 | if (PQntuples(res) == 0) |
1293 | continue; | 1316 | continue; |
1294 | 1317 | ||
1295 | - int shapeType = layer->GeometryType(); | 1318 | + int shapeType = layer->GeomWkbType(); |
1296 | shared_ptr<DataCollection> data(new DataCollection()); | 1319 | shared_ptr<DataCollection> data(new DataCollection()); |
1297 | data->InitDataCollection(res, shapeType, this->m_dWidth, this->m_dHeight, 0, m_dR, m_dScaleDenominator, x_dis, y_dis); | 1320 | data->InitDataCollection(res, shapeType, this->m_dWidth, this->m_dHeight, 0, m_dR, m_dScaleDenominator, x_dis, y_dis); |
1298 | 1321 | ||
@@ -1317,7 +1340,7 @@ ST_GeometryFromText('POLYGON((%f %f, %f %f, %f %f, %f %f, %f %f))',%s),\ | @@ -1317,7 +1340,7 @@ ST_GeometryFromText('POLYGON((%f %f, %f %f, %f %f, %f %f, %f %f))',%s),\ | ||
1317 | if (PQntuples(res) == 0) | 1340 | if (PQntuples(res) == 0) |
1318 | continue; | 1341 | continue; |
1319 | 1342 | ||
1320 | - int shapeType = layer->GeometryType(); | 1343 | + int shapeType = layer->GeomWkbType(); |
1321 | shared_ptr<DataCollection> data(new DataCollection()); | 1344 | shared_ptr<DataCollection> data(new DataCollection()); |
1322 | if (!renderHeat) | 1345 | if (!renderHeat) |
1323 | { | 1346 | { |
@@ -1361,6 +1384,76 @@ ST_GeometryFromText('POLYGON((%f %f, %f %f, %f %f, %f %f, %f %f))',%s),\ | @@ -1361,6 +1384,76 @@ ST_GeometryFromText('POLYGON((%f %f, %f %f, %f %f, %f %f, %f %f))',%s),\ | ||
1361 | return true; | 1384 | return true; |
1362 | } | 1385 | } |
1363 | 1386 | ||
1387 | + bool DmpWmsRenderer::GetMapLegend( std::stringstream& ab, shared_ptr<legendParamater> pLegendParamater) | ||
1388 | + { | ||
1389 | + clsCrSurf *pClsSurfThis; | ||
1390 | + | ||
1391 | + pClsSurfThis = m_pClsSurfBuff; //refresh画图在 buff 中 | ||
1392 | + this->DoSetBackGround(pClsSurfThis, m_iBackColor); | ||
1393 | + | ||
1394 | + for (int layerType = 0; layerType < 3; layerType++) | ||
1395 | + { | ||
1396 | + | ||
1397 | + for (int i = 0; i < (int)(m_vLayers.size()); i++) | ||
1398 | + { | ||
1399 | + DmpVectorLayer *layer = m_vLayers[i]; | ||
1400 | + | ||
1401 | + //if ((ml->m_bVisible) == false) | ||
1402 | + // continue; | ||
1403 | + | ||
1404 | + //if (ml->m_pDataset == nullptr) | ||
1405 | + // continue; | ||
1406 | + | ||
1407 | + //double r1 = ml->m_dUpperScale; // * | ||
1408 | + //double r2 = ml->m_dLowerScale; // * | ||
1409 | + std::shared_ptr<DmapCore_30::Renderer> renderer = layer->GetRenderer30(); | ||
1410 | + renderer->DrawLegend(pClsSurfThis, pLegendParamater, layerType, (char *)layer->name().c_str()); | ||
1411 | + } | ||
1412 | + } | ||
1413 | + | ||
1414 | + this->BufferCopy(m_pClsSurfBuff, m_pClsMaxSurfBuffer); | ||
1415 | + this->BufferCopy(m_pClsSurfBuff, m_pClsSurfDC); | ||
1416 | + | ||
1417 | + pLegendParamater->next(nullptr); | ||
1418 | + | ||
1419 | + cairo_surface_t *surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, (int)m_dWidth, pLegendParamater->pixYIndex + 10); //cairo_win32_surface_create(hdc); | ||
1420 | + clsCrSurf surfDC(surface); | ||
1421 | + this->BufferCopy(m_pClsSurfDC, &surfDC); | ||
1422 | + | ||
1423 | + cairo_surface_write_to_png_stream(surfDC.m_pSurf, cairo_write_func, &ab); | ||
1424 | + | ||
1425 | + return true; | ||
1426 | + } | ||
1427 | + | ||
1428 | + bool DmpWmsRenderer::GetMapLegend( shared_ptr<legendParamater> pLegendParamater, clsCrSurf* pClsSurf) | ||
1429 | + { | ||
1430 | + if(pClsSurf == nullptr) | ||
1431 | + { | ||
1432 | + pClsSurf = m_pClsSurfBuff; | ||
1433 | + } | ||
1434 | + | ||
1435 | + for (int layerType = 0; layerType < 3; layerType++) | ||
1436 | + { | ||
1437 | + for (int i = 0; i < (int)(m_vLayers.size()); i++) | ||
1438 | + { | ||
1439 | + DmpVectorLayer *layer = m_vLayers[i]; | ||
1440 | + | ||
1441 | + //if ((ml->m_bVisible) == false) | ||
1442 | + // continue; | ||
1443 | + | ||
1444 | + //if (ml->m_pDataset == nullptr) | ||
1445 | + // continue; | ||
1446 | + | ||
1447 | + //double r1 = ml->m_dUpperScale; // * | ||
1448 | + //double r2 = ml->m_dLowerScale; // * | ||
1449 | + std::shared_ptr<DmapCore_30::Renderer> renderer = layer->GetRenderer30(); | ||
1450 | + renderer->DrawLegend(pClsSurf, pLegendParamater, layerType, (char *)layer->name().c_str()); | ||
1451 | + } | ||
1452 | + | ||
1453 | + } | ||
1454 | + return true; | ||
1455 | + } | ||
1456 | + | ||
1364 | bool DmpWmsRenderer::ToStream(std::string &responseData) | 1457 | bool DmpWmsRenderer::ToStream(std::string &responseData) |
1365 | { | 1458 | { |
1366 | responseData.reserve(10240); | 1459 | responseData.reserve(10240); |
@@ -13,274 +13,191 @@ | @@ -13,274 +13,191 @@ | ||
13 | 13 | ||
14 | namespace DmpWms | 14 | namespace DmpWms |
15 | { | 15 | { |
16 | - static cairo_status_t cairo_write_func_print(void *pbuff, const unsigned char *data, unsigned int length) | 16 | + static cairo_status_t cairo_write_func_print(void *pbuff, const unsigned char *data, unsigned int length) |
17 | { | 17 | { |
18 | - //vector<unsigned char>& vecData = *((vector<unsigned char>*)closure); | 18 | + // vector<unsigned char>& vecData = *((vector<unsigned char>*)closure); |
19 | string *pResponseData = (string *)pbuff; | 19 | string *pResponseData = (string *)pbuff; |
20 | - pResponseData->append((char *)data,length); | 20 | + pResponseData->append((char *)data, length); |
21 | return CAIRO_STATUS_SUCCESS; | 21 | return CAIRO_STATUS_SUCCESS; |
22 | } | 22 | } |
23 | 23 | ||
24 | - DmpMapPrint::DmpMapPrint() | 24 | + DmpMapPrint::DmpMapPrint(DmpWmsParameters::Format outformat) |
25 | { | 25 | { |
26 | - | 26 | + this->format = outformat; |
27 | } | 27 | } |
28 | -/* | ||
29 | - bool DmpMapPrint::getPrint(std::string &responseData, DmpProject *project,const char* xml,string servername) | ||
30 | - { | ||
31 | - string result_msg; | ||
32 | - | ||
33 | - xml_document<> doc; // character type defaults to char | ||
34 | - try | ||
35 | - { | ||
36 | - doc.parse<0>((char *)xml); | ||
37 | - } | ||
38 | - catch (...) | ||
39 | - { | ||
40 | - result_msg = "error:Post参数是XML格式"; | ||
41 | - } | ||
42 | - | ||
43 | - xml_node<char> *node = doc.first_node(); | ||
44 | - if(!node) | ||
45 | - { | ||
46 | - return false; | ||
47 | - } | ||
48 | - | ||
49 | - m_height = 1122; | ||
50 | - m_width = 793; | ||
51 | - | ||
52 | - xml_node<char> *template_node = node->first_node("template"); | ||
53 | - if(template_node != nullptr) | ||
54 | - { | ||
55 | - InitTemplateValue(template_node->value()); | ||
56 | - } | ||
57 | - | ||
58 | - | ||
59 | - xml_node<char> *extent_node = node->first_node("extent"); | ||
60 | 28 | ||
61 | - if(extent_node) | ||
62 | - {// xmin="" ymin="" xmax="" ymax="" | ||
63 | - xml_attribute<char> *attr_xmin = node->first_attribute("xmin"); | ||
64 | - xml_attribute<char> *attr_ymin = node->first_attribute("ymin"); | ||
65 | - xml_attribute<char> *attr_xmax = node->first_attribute("xmax"); | ||
66 | - xml_attribute<char> *attr_ymax = node->first_attribute("ymax"); | ||
67 | - | ||
68 | - if(attr_xmin == nullptr || attr_ymin == nullptr || | ||
69 | - attr_xmax == nullptr || attr_ymax == nullptr) | ||
70 | - { | ||
71 | - return 0; | ||
72 | - } | 29 | + bool DmpMapPrint::getPrint(std::string &responseData,const DmpProject *project, const string &xml, const string& servername) |
30 | + { | ||
31 | + string result_msg; | ||
73 | 32 | ||
74 | - xmin = atof( attr_xmax->value()); | ||
75 | - ymin = atof( attr_ymin->value()); | ||
76 | - xmax = atof( attr_xmax->value()); | ||
77 | - ymax = atof( attr_ymax->value()); | ||
78 | - } | 33 | + try |
34 | + { | ||
35 | + std::stringstream stream(xml); | ||
36 | + boost::property_tree::ptree ptree; | ||
37 | + boost::property_tree::read_xml(stream, ptree); | ||
79 | 38 | ||
80 | - shared_ptr<MapParameter> pMapParameter(new MapParameter()); | 39 | + std::string templateStr = ptree.get<string>("template"); |
40 | + InitTemplateValue(templateStr); | ||
81 | 41 | ||
42 | + m_height = 1122; | ||
43 | + m_width = 793; | ||
82 | 44 | ||
83 | - shared_ptr<OperationalDmapLayer> dmapLayer(new OperationalDmapLayer()); | ||
84 | - dmapLayer->serviceName = servername; | 45 | + double xmin = ptree.get<double>("extent/xmin"); |
46 | + double ymin = ptree.get<double>("extent/ymin"); | ||
47 | + double xmax = ptree.get<double>("extent/xmax"); | ||
48 | + double ymax = ptree.get<double>("extent/ymax"); | ||
49 | + | ||
50 | + shared_ptr<DmpPrintParameter> pDmpPrintParameter(new DmpPrintParameter()); | ||
85 | 51 | ||
86 | - map<string, shared_ptr<WMSServer>>::iterator iter = mapWmsServer.find(dmapLayer->serviceName); | ||
87 | - if(iter !=mapWmsServer.end()) | ||
88 | - { | ||
89 | - dmapLayer->m_wmsServer = iter->second; | ||
90 | - Rect *rect = dmapLayer->m_wmsServer->GetExtent(); | ||
91 | - pMapParameter->InitParameter(xmin,xmax,ymax,ymin,m_width -100,m_height -120); | ||
92 | - //double scaleDenominator = this->RecalculateScale(rect->m_dRight,rect->m_dLeft,rect->m_dTop,rect->m_dBottom,1022,693); | ||
93 | - } | ||
94 | - else | ||
95 | - { | ||
96 | - return false; | ||
97 | - } | ||
98 | - | 52 | + shared_ptr<DmpPrintWMSService> dmapLayer(new DmpPrintWMSService()); |
53 | + dmapLayer->serviceName_ = servername; | ||
99 | 54 | ||
100 | - //dmapLayer->serviceName = "土地利用现状"; | ||
101 | - //dmapLayer->m_id = "土地利用现状"; | ||
102 | - //dmapLayer->boxX1 = 683497; | ||
103 | - //dmapLayer->boxX2 = 695357; | ||
104 | - //dmapLayer->boxY1 = 2534922; | ||
105 | - //dmapLayer->boxY2 = 2543053; | 55 | + dmapLayer->project_ = project; |
56 | + //shared_ptr<DmpRectangle> dmpRectangle | ||
57 | + //Rect *rect = dmapLayer->project_->GetExtent(); | ||
58 | + pDmpPrintParameter->InitParameter(xmin, xmax, ymax, ymin, m_width - 100, m_height - 120); | ||
106 | 59 | ||
107 | - Rect* rect = dmapLayer->m_wmsServer->GetExtent(); | 60 | + // dmapLayer->serviceName = "土地利用现状"; |
61 | + // dmapLayer->m_id = "土地利用现状"; | ||
62 | + // dmapLayer->boxX1 = 683497; | ||
63 | + // dmapLayer->boxX2 = 695357; | ||
64 | + // dmapLayer->boxY1 = 2534922; | ||
65 | + // dmapLayer->boxY2 = 2543053; | ||
108 | 66 | ||
109 | - dmapLayer->boxX1 = xmin; | ||
110 | - dmapLayer->boxX2 = xmax; | ||
111 | - dmapLayer->boxY1 = ymin; | ||
112 | - dmapLayer->boxY2 = ymax; | 67 | + //Rect *rect = dmapLayer->m_wmsServer->GetExtent(); |
113 | 68 | ||
114 | - shared_ptr<DmapPrintLayout> dmapLayout(new DmapPrintLayout()); | ||
115 | - this->vector_dmapPrintLayout.push_back(dmapLayout); | 69 | + dmapLayer->boxX1_ = xmin; |
70 | + dmapLayer->boxX2_ = xmax; | ||
71 | + dmapLayer->boxY1_ = ymin; | ||
72 | + dmapLayer->boxY2_ = ymax; | ||
116 | 73 | ||
74 | + shared_ptr<DmpPrintLayout> dmapLayout(new DmpPrintLayout()); | ||
75 | + this->vector_DmpPrintLayout.push_back(dmapLayout); | ||
117 | 76 | ||
118 | dmapLayout->data.push_back(dmapLayer); | 77 | dmapLayout->data.push_back(dmapLayer); |
119 | - dmapLayout->localtion_x = 50; | ||
120 | - dmapLayout->localtion_y = 70; | 78 | + dmapLayout->localtionX_ = 50; |
79 | + dmapLayout->localtionY_ = 70; | ||
121 | 80 | ||
122 | - dmapLayout->height = m_height -70; | ||
123 | - dmapLayout->width = m_width -50; | 81 | + dmapLayout->height_ = m_height - 70; |
82 | + dmapLayout->width_ = m_width - 50; | ||
124 | 83 | ||
125 | - this->m_height = m_height; | 84 | + this->m_height = m_height; |
126 | this->m_width = m_width; | 85 | this->m_width = m_width; |
127 | 86 | ||
128 | - | ||
129 | - shared_ptr<OperationalGeom> geomLayer_scale(new OperationalGeom()); | ||
130 | - geomLayer_scale->pMapParameter = pMapParameter; | ||
131 | - geomLayer_scale->type = "scale"; | ||
132 | - shared_ptr<DmapPrintLayout> dmapLayout_scale(new DmapPrintLayout()); | ||
133 | - this->vector_dmapPrintLayout.push_back(dmapLayout_scale); | ||
134 | - geomLayer_scale->localtion_x = 150; | ||
135 | - geomLayer_scale->localtion_y = m_height - 50; | 87 | + shared_ptr<DmpPrintScale> geomLayer_scale(new DmpPrintScale()); |
88 | + geomLayer_scale->pPrintParameter_ = pDmpPrintParameter; | ||
89 | + shared_ptr<DmpPrintLayout> dmapLayout_scale(new DmpPrintLayout()); | ||
90 | + this->vector_DmpPrintLayout.push_back(dmapLayout_scale); | ||
91 | + geomLayer_scale->localtionX_ = 150; | ||
92 | + geomLayer_scale->localtionY_ = m_height - 50; | ||
136 | dmapLayout_scale->data.push_back(geomLayer_scale); | 93 | dmapLayout_scale->data.push_back(geomLayer_scale); |
137 | 94 | ||
138 | - | ||
139 | - shared_ptr<OperationalGeom> geomLayer_compass(new OperationalGeom()); | ||
140 | - geomLayer_compass->pMapParameter = pMapParameter; | ||
141 | - geomLayer_compass->type = "compass"; | ||
142 | - shared_ptr<DmapPrintLayout> dmapLayout_compass(new DmapPrintLayout()); | ||
143 | - this->vector_dmapPrintLayout.push_back(dmapLayout_compass); | ||
144 | - geomLayer_compass->localtion_x = 80; | ||
145 | - geomLayer_compass->localtion_y = m_height - 80; | 95 | + shared_ptr<DmpPrintCompass> geomLayer_compass(new DmpPrintCompass()); |
96 | + geomLayer_compass->pPrintParameter_ = pDmpPrintParameter; | ||
97 | + shared_ptr<DmpPrintLayout> dmapLayout_compass(new DmpPrintLayout()); | ||
98 | + this->vector_DmpPrintLayout.push_back(dmapLayout_compass); | ||
99 | + geomLayer_compass->localtionX_ = 80; | ||
100 | + geomLayer_compass->localtionY_ = m_height - 80; | ||
146 | dmapLayout_compass->data.push_back(geomLayer_compass); | 101 | dmapLayout_compass->data.push_back(geomLayer_compass); |
147 | 102 | ||
148 | - | ||
149 | - ToPrint(ab); | ||
150 | - return true; | ||
151 | - } | ||
152 | - | ||
153 | - bool DmpMapPrint::getPrint( std::string &responseData, DmpProject* project, | ||
154 | - string servername,const char* printTemp,const char *bbox) | ||
155 | - { | ||
156 | - string result_msg; | ||
157 | - | ||
158 | - if(printTemp == nullptr || bbox == nullptr) | ||
159 | - return false; | ||
160 | - | ||
161 | - m_height = 1122; | ||
162 | - m_width = 793; | ||
163 | - | ||
164 | - | ||
165 | - double boxX1, boxY1, boxX2, boxY2; | ||
166 | - sscanf(bbox, "%lf,%lf,%lf,%lf", &boxY1, &boxX1, &boxY2, &boxX2); // &x1,&y1,&x2,&y2); | 103 | + ToPrint(responseData); |
104 | + return true; | ||
167 | 105 | ||
168 | - | ||
169 | - InitTemplateValue(printTemp); | ||
170 | - | 106 | + } |
107 | + catch (...) | ||
108 | + { | ||
171 | 109 | ||
172 | - shared_ptr<MapParameter> pMapParameter(new MapParameter()); | 110 | + } |
111 | + return false; | ||
112 | + } | ||
173 | 113 | ||
114 | + bool DmpMapPrint::getPrint(std::string &responseData,const DmpProject *project, const string& servername, | ||
115 | + const char *printTemp, const char *bbox) | ||
116 | + { | ||
117 | + string result_msg; | ||
174 | 118 | ||
175 | - shared_ptr<OperationalDmapLayer> dmapLayer(new OperationalDmapLayer()); | ||
176 | - dmapLayer->serviceName = servername; | 119 | + if (printTemp == nullptr || bbox == nullptr) |
120 | + return false; | ||
177 | 121 | ||
178 | - map<string, shared_ptr<WMSServer>>::iterator iter = mapWmsServer.find(dmapLayer->serviceName); | ||
179 | - if(iter !=mapWmsServer.end()) | ||
180 | - { | ||
181 | - | 122 | + m_height = 1122; |
123 | + m_width = 793; | ||
182 | 124 | ||
125 | + double boxX1, boxY1, boxX2, boxY2; | ||
126 | + sscanf(bbox, "%lf,%lf,%lf,%lf", &boxY1, &boxX1, &boxY2, &boxX2); // &x1,&y1,&x2,&y2); | ||
183 | 127 | ||
128 | + InitTemplateValue(printTemp); | ||
184 | 129 | ||
185 | - if (rect_service) | ||
186 | - { | ||
187 | - if (rect_service->m_dBottom > 0 && rect_service->m_dRight > 0 && rect_service->m_dLeft > 0 && rect_service->m_dTop > 0) | ||
188 | - { | ||
189 | - if (min(boxX1, boxX2) > rect_service->m_dRight || max(boxX1, boxX2) < rect_service->m_dLeft || | ||
190 | - min(boxY1, boxY2) > rect_service->m_dTop || max(boxY1, boxY2) < rect_service->m_dBottom) | ||
191 | - { | ||
192 | - if (!(min(boxY1, boxY2) > rect_service->m_dRight || max(boxY1, boxY2) < rect_service->m_dLeft || | ||
193 | - min(boxX1, boxX2) > rect_service->m_dTop || max(boxX1, boxX2) < rect_service->m_dBottom)) | ||
194 | - { | ||
195 | - double x1 = boxX1; | ||
196 | - boxX1 = boxY1; | ||
197 | - boxY1 = x1; | ||
198 | - double x2 = boxX2; | ||
199 | - boxX2 = boxY2; | ||
200 | - boxY2 = x2; | ||
201 | - } | ||
202 | - } | ||
203 | - } | ||
204 | - } | 130 | + shared_ptr<DmpPrintParameter> pDmpPrintParameter(new DmpPrintParameter()); |
131 | + | ||
132 | + shared_ptr<DmpPrintWMSService> dmapLayer(new DmpPrintWMSService()); | ||
133 | + dmapLayer->serviceName_ = servername; | ||
134 | + | ||
135 | + | ||
205 | xmin = min(boxX1, boxX2); | 136 | xmin = min(boxX1, boxX2); |
206 | ymin = min(boxY1, boxY2); | 137 | ymin = min(boxY1, boxY2); |
207 | xmax = max(boxX1, boxX2); | 138 | xmax = max(boxX1, boxX2); |
208 | ymax = max(boxY1, boxY2); | 139 | ymax = max(boxY1, boxY2); |
209 | - pMapParameter->InitParameter(xmin,xmax,ymax,ymin,m_width -100,m_height -120); | ||
210 | - //double scaleDenominator = this->RecalculateScale(rect->m_dRight,rect->m_dLeft,rect->m_dTop,rect->m_dBottom,1022,693); | ||
211 | - } | ||
212 | - else | ||
213 | - { | ||
214 | - return false; | ||
215 | - } | ||
216 | - | ||
217 | - | ||
218 | - //dmapLayer->serviceName = "土地利用现状"; | ||
219 | - //dmapLayer->m_id = "土地利用现状"; | ||
220 | - //dmapLayer->boxX1 = 683497; | ||
221 | - //dmapLayer->boxX2 = 695357; | ||
222 | - //dmapLayer->boxY1 = 2534922; | ||
223 | - //dmapLayer->boxY2 = 2543053; | 140 | + pDmpPrintParameter->InitParameter(xmin, xmax, ymax, ymin, m_width - 100, m_height - 120); |
141 | + // double scaleDenominator = this->RecalculateScale(rect->m_dRight,rect->m_dLeft,rect->m_dTop,rect->m_dBottom,1022,693); | ||
142 | + | ||
224 | 143 | ||
225 | - Rect* rect = dmapLayer->m_wmsServer->GetExtent(); | 144 | + // dmapLayer->serviceName = "土地利用现状"; |
145 | + // dmapLayer->m_id = "土地利用现状"; | ||
146 | + // dmapLayer->boxX1 = 683497; | ||
147 | + // dmapLayer->boxX2 = 695357; | ||
148 | + // dmapLayer->boxY1 = 2534922; | ||
149 | + // dmapLayer->boxY2 = 2543053; | ||
226 | 150 | ||
227 | - dmapLayer->boxX1 = xmin; | ||
228 | - dmapLayer->boxX2 = xmax; | ||
229 | - dmapLayer->boxY1 = ymin; | ||
230 | - dmapLayer->boxY2 = ymax; | 151 | + // Rect *rect = dmapLayer->m_wmsServer->GetExtent(); |
231 | 152 | ||
232 | - shared_ptr<DmapPrintLayout> dmapLayout(new DmapPrintLayout()); | ||
233 | - this->vector_dmapPrintLayout.push_back(dmapLayout); | 153 | + dmapLayer->boxX1_ = xmin; |
154 | + dmapLayer->boxX2_ = xmax; | ||
155 | + dmapLayer->boxY1_ = ymin; | ||
156 | + dmapLayer->boxY2_ = ymax; | ||
234 | 157 | ||
158 | + shared_ptr<DmpPrintLayout> dmapLayout(new DmpPrintLayout()); | ||
159 | + this->vector_DmpPrintLayout.push_back(dmapLayout); | ||
235 | 160 | ||
236 | dmapLayout->data.push_back(dmapLayer); | 161 | dmapLayout->data.push_back(dmapLayer); |
237 | - dmapLayout->localtion_x = 50; | ||
238 | - dmapLayout->localtion_y = 70; | 162 | + dmapLayout->localtionX_ = 50; |
163 | + dmapLayout->localtionY_ = 70; | ||
239 | 164 | ||
240 | - dmapLayout->height = m_height -120; | ||
241 | - dmapLayout->width = m_width -100; | 165 | + dmapLayout->height_ = m_height - 120; |
166 | + dmapLayout->width_ = m_width - 100; | ||
242 | 167 | ||
243 | - this->m_height = m_height; | 168 | + this->m_height = m_height; |
244 | this->m_width = m_width; | 169 | this->m_width = m_width; |
245 | 170 | ||
246 | - | ||
247 | - shared_ptr<OperationalGeom> geomLayer_scale(new OperationalGeom()); | ||
248 | - geomLayer_scale->pMapParameter = pMapParameter; | ||
249 | - geomLayer_scale->type = "scale"; | ||
250 | - shared_ptr<DmapPrintLayout> dmapLayout_scale(new DmapPrintLayout()); | ||
251 | - this->vector_dmapPrintLayout.push_back(dmapLayout_scale); | ||
252 | - geomLayer_scale->localtion_x = 150; | ||
253 | - geomLayer_scale->localtion_y = m_height - 110; | 171 | + shared_ptr<DmpPrintScale> geomLayer_scale(new DmpPrintScale()); |
172 | + geomLayer_scale->pPrintParameter_ = pDmpPrintParameter; | ||
173 | + shared_ptr<DmpPrintLayout> dmapLayout_scale(new DmpPrintLayout()); | ||
174 | + this->vector_DmpPrintLayout.push_back(dmapLayout_scale); | ||
175 | + geomLayer_scale->localtionX_ = 150; | ||
176 | + geomLayer_scale->localtionY_ = m_height - 110; | ||
254 | dmapLayout_scale->data.push_back(geomLayer_scale); | 177 | dmapLayout_scale->data.push_back(geomLayer_scale); |
255 | 178 | ||
256 | - | ||
257 | - shared_ptr<OperationalGeom> geomLayer_compass(new OperationalGeom()); | ||
258 | - geomLayer_compass->pMapParameter = pMapParameter; | ||
259 | - geomLayer_compass->type = "compass"; | ||
260 | - shared_ptr<DmapPrintLayout> dmapLayout_compass(new DmapPrintLayout()); | ||
261 | - this->vector_dmapPrintLayout.push_back(dmapLayout_compass); | ||
262 | - geomLayer_compass->localtion_x = 80; | ||
263 | - geomLayer_compass->localtion_y = m_height - 140; | 179 | + shared_ptr<DmpPrintCompass> geomLayer_compass(new DmpPrintCompass()); |
180 | + geomLayer_compass->pPrintParameter_ = pDmpPrintParameter; | ||
181 | + shared_ptr<DmpPrintLayout> dmapLayout_compass(new DmpPrintLayout()); | ||
182 | + this->vector_DmpPrintLayout.push_back(dmapLayout_compass); | ||
183 | + geomLayer_compass->localtionX_ = 80; | ||
184 | + geomLayer_compass->localtionY_ = m_height - 140; | ||
264 | dmapLayout_compass->data.push_back(geomLayer_compass); | 185 | dmapLayout_compass->data.push_back(geomLayer_compass); |
265 | 186 | ||
266 | - | ||
267 | - ToPrint(ab); | 187 | + ToPrint(responseData); |
268 | return true; | 188 | return true; |
269 | - | ||
270 | - } | ||
271 | - | 189 | + } |
272 | 190 | ||
273 | - bool DmpMapPrint::getPrintTempFile(string &responseData,,const char* tempName, const char* bbox) | 191 | + bool DmpMapPrint::getPrintTempFile(string &responseData,const DmpProject *project, const char *tempName, const char *bbox) |
274 | { | 192 | { |
275 | - string path = "./template/";path += tempName; path += ".xml"; | ||
276 | - | 193 | + string path = "../template/"; |
194 | + path += tempName; | ||
195 | + path += ".xml"; | ||
277 | 196 | ||
278 | ifstream fin(path.c_str(), ios::binary); | 197 | ifstream fin(path.c_str(), ios::binary); |
279 | - | ||
280 | if (!fin) | 198 | if (!fin) |
281 | { | 199 | { |
282 | - string result_msg = "<Error>打印模板未找到</Error>"; | ||
283 | - ab->AppendString(result_msg.c_str()); | 200 | + responseData = "<Error>打印模板未找到</Error>"; |
284 | return false; | 201 | return false; |
285 | } | 202 | } |
286 | 203 | ||
@@ -288,113 +205,100 @@ namespace DmpWms | @@ -288,113 +205,100 @@ namespace DmpWms | ||
288 | buffer << fin.rdbuf(); | 205 | buffer << fin.rdbuf(); |
289 | string content(buffer.str()); | 206 | string content(buffer.str()); |
290 | fin.close(); | 207 | fin.close(); |
291 | - return getPrintLayout(ab, pWmsServer,content.c_str(), bbox); | ||
292 | - //return true; | 208 | + return getPrintLayout(responseData, project, content.c_str(), bbox); |
209 | + // return true; | ||
293 | } | 210 | } |
294 | 211 | ||
295 | - | ||
296 | - bool DmpMapPrint::getPrintLayout(AppendBuffer *ab,shared_ptr<WMSServer> pWmsServer, | ||
297 | - const char* xml,const char *bbox) | ||
298 | - { | ||
299 | - string result_msg; | ||
300 | - if(xml == nullptr || bbox == nullptr) | ||
301 | - return false; | ||
302 | - | ||
303 | - m_height = 1122; | ||
304 | - m_width = 793; | ||
305 | - | ||
306 | - xml_document<> doc; // character type defaults to char | ||
307 | - try | ||
308 | - { | ||
309 | - doc.parse<0>((char *)xml); | ||
310 | - xml_node<char> *node = doc.first_node(); | ||
311 | - if (!node) | ||
312 | - { | ||
313 | - result_msg = "<Error>打印模板无法解析</Error>"; | ||
314 | - ab->AppendString(result_msg.c_str()); | ||
315 | - return false; | ||
316 | - } | 212 | + bool DmpMapPrint::getPrintLayout(string &responseData,const DmpProject *project, const char *xml, const char *bbox) |
213 | + { | ||
214 | + string result_msg; | ||
215 | + if (xml == nullptr || bbox == nullptr) | ||
216 | + return false; | ||
317 | 217 | ||
318 | - m_height = 1122; | ||
319 | - m_width = 793; | 218 | + m_height = 1122; |
219 | + m_width = 793; | ||
320 | 220 | ||
321 | - xml_node<char> *template_node = node->first_node("template"); | ||
322 | - if (template_node != nullptr) | ||
323 | - { | ||
324 | - InitTemplateValue(template_node->value()); | ||
325 | - } | 221 | + |
222 | + try | ||
223 | + { | ||
224 | + std::stringstream stream(xml); | ||
225 | + boost::property_tree::ptree ptree; | ||
226 | + boost::property_tree::read_xml(stream, ptree); | ||
227 | + | ||
228 | + std::string templateStr = ptree.get<string>("printlayout.template"); | ||
229 | + InitTemplateValue(templateStr); | ||
326 | 230 | ||
327 | double boxX1, boxY1, boxX2, boxY2; | 231 | double boxX1, boxY1, boxX2, boxY2; |
328 | sscanf(bbox, "%lf,%lf,%lf,%lf", &boxX1, &boxY1, &boxX2, &boxY2); // &x1,&y1,&x2,&y2); | 232 | sscanf(bbox, "%lf,%lf,%lf,%lf", &boxX1, &boxY1, &boxX2, &boxY2); // &x1,&y1,&x2,&y2); |
329 | - shared_ptr<MapParameter> pMapParameter(new MapParameter()); | ||
330 | - //Rect *rect_service = pWmsServer->GetExtent(); | ||
331 | - //if (rect_service) | 233 | + shared_ptr<DmpPrintParameter> pDmpPrintParameter(new DmpPrintParameter()); |
234 | + // Rect *rect_service = pWmsServer->GetExtent(); | ||
235 | + // if (rect_service) | ||
332 | //{ | 236 | //{ |
333 | // rect_service->GetExtent(boxX1, boxX2, boxY1, boxY2); | 237 | // rect_service->GetExtent(boxX1, boxX2, boxY1, boxY2); |
334 | - //} | ||
335 | - | 238 | + // } |
239 | + | ||
336 | xmin = min(boxX1, boxX2); | 240 | xmin = min(boxX1, boxX2); |
337 | ymin = min(boxY1, boxY2); | 241 | ymin = min(boxY1, boxY2); |
338 | xmax = max(boxX1, boxX2); | 242 | xmax = max(boxX1, boxX2); |
339 | ymax = max(boxY1, boxY2); | 243 | ymax = max(boxY1, boxY2); |
340 | - pMapParameter->pWmsService = pWmsServer; | ||
341 | - pMapParameter->InitParameter(xmin,xmax,ymax,ymin,m_width -100,m_height -120); | ||
342 | - | ||
343 | - shared_ptr<DmapPrintLayout> printLayout(new DmapPrintLayout()); | ||
344 | - | ||
345 | - if(printLayout->ReadXML(node,pMapParameter,result_msg)) | ||
346 | - { | ||
347 | - this->vector_dmapPrintLayout.push_back(printLayout); | ||
348 | - ToPrint(ab); | 244 | + pDmpPrintParameter->pWmsService = project; |
245 | + pDmpPrintParameter->InitParameter(xmin, xmax, ymax, ymin, m_width - 100, m_height - 120); | ||
246 | + | ||
247 | + shared_ptr<DmpPrintLayout> printLayout(new DmpPrintLayout()); | ||
248 | + boost::property_tree::ptree ptreelayout = ptree.get_child("printlayout"); | ||
249 | + if (printLayout->ReadXML(ptreelayout, pDmpPrintParameter, result_msg)) | ||
250 | + { | ||
251 | + this->vector_DmpPrintLayout.push_back(printLayout); | ||
252 | + ToPrint(responseData); | ||
349 | return true; | 253 | return true; |
350 | } | 254 | } |
351 | } | 255 | } |
352 | - catch (...) | ||
353 | - { | ||
354 | - result_msg = "<Error>error:Post参数是XML格式</Error>"; | ||
355 | - } | 256 | + catch (const std::exception& e) |
257 | + { | ||
258 | + std::cerr << e.what() << '\n'; | ||
259 | + result_msg = "<Error>error:Post参数是XML格式</Error>"; | ||
260 | + } | ||
356 | 261 | ||
357 | - ab->AppendString(result_msg.c_str()); | 262 | + responseData = result_msg; |
358 | return false; | 263 | return false; |
264 | + } | ||
359 | 265 | ||
360 | - } | ||
361 | - | ||
362 | - bool DmpMapPrint::ToPrint(AppendBuffer *ab) | 266 | + bool DmpMapPrint::ToPrint(string &responseData) |
363 | { | 267 | { |
364 | - if(isPicture == PrintOutputFormat::SVG) | 268 | + if (format == DmpWmsParameters::Format::SVG) |
365 | { | 269 | { |
366 | - //string path = this->GetFilePath("mapPrint.pdf"); | ||
367 | - cairo_surface_t *surface = cairo_svg_surface_create_for_stream(cairo_write_func_print,ab, | ||
368 | - (int)m_width, | ||
369 | - (int)m_height); | ||
370 | - | ||
371 | - //cairo_surface_set_fallback_resolution(surface,900,900); | ||
372 | - clsCrSurf mClsSurfDC(surface,(int)m_width,(int)m_height,false); | ||
373 | - cairo_set_antialias(mClsSurfDC.m_pCr,cairo_antialias_t::CAIRO_ANTIALIAS_BEST); | 270 | + // string path = this->GetFilePath("mapPrint.pdf"); |
271 | + cairo_surface_t *surface = cairo_svg_surface_create_for_stream(cairo_write_func_print, &responseData, | ||
272 | + (int)m_width, | ||
273 | + (int)m_height); | ||
274 | + | ||
275 | + // cairo_surface_set_fallback_resolution(surface,900,900); | ||
276 | + clsCrSurf mClsSurfDC(surface, (int)m_width, (int)m_height, false); | ||
277 | + cairo_set_antialias(mClsSurfDC.m_pCr, cairo_antialias_t::CAIRO_ANTIALIAS_BEST); | ||
374 | DoSetBackGround(&mClsSurfDC, 0xffffffff); | 278 | DoSetBackGround(&mClsSurfDC, 0xffffffff); |
375 | 279 | ||
376 | - for (size_t i = 0; i < vector_dmapPrintLayout.size(); i++) | 280 | + for (size_t i = 0; i < vector_DmpPrintLayout.size(); i++) |
377 | { | 281 | { |
378 | - shared_ptr<DmapPrintLayout> layout = vector_dmapPrintLayout.at(i); | ||
379 | - layout->DrawData(&mClsSurfDC,PrintOutputFormat::SVG); | 282 | + shared_ptr<DmpPrintLayout> layout = vector_DmpPrintLayout.at(i); |
283 | + layout->DrawData(&mClsSurfDC, DmpWmsParameters::Format::SVG); | ||
380 | } | 284 | } |
381 | } | 285 | } |
382 | - else if(isPicture == PrintOutputFormat::PDF) | 286 | + else if (format == DmpWmsParameters::Format::PDF) |
383 | { | 287 | { |
384 | - //string path = this->GetFilePath("mapPrint.pdf"); | ||
385 | - cairo_surface_t *surface = cairo_pdf_surface_create_for_stream(cairo_write_func_print,ab, | ||
386 | - (int)m_width, | ||
387 | - (int)m_height); | ||
388 | - | ||
389 | - //cairo_surface_set_fallback_resolution(surface,900,900); | ||
390 | - clsCrSurf mClsSurfDC(surface,(int)m_width,(int)m_height,false); | ||
391 | - cairo_set_antialias(mClsSurfDC.m_pCr,cairo_antialias_t::CAIRO_ANTIALIAS_BEST); | 288 | + // string path = this->GetFilePath("mapPrint.pdf"); |
289 | + cairo_surface_t *surface = cairo_pdf_surface_create_for_stream(cairo_write_func_print, &responseData, | ||
290 | + (int)m_width, | ||
291 | + (int)m_height); | ||
292 | + | ||
293 | + // cairo_surface_set_fallback_resolution(surface,900,900); | ||
294 | + clsCrSurf mClsSurfDC(surface, (int)m_width, (int)m_height, false); | ||
295 | + cairo_set_antialias(mClsSurfDC.m_pCr, cairo_antialias_t::CAIRO_ANTIALIAS_BEST); | ||
392 | DoSetBackGround(&mClsSurfDC, 0xffffffff); | 296 | DoSetBackGround(&mClsSurfDC, 0xffffffff); |
393 | 297 | ||
394 | - for (size_t i = 0; i < vector_dmapPrintLayout.size(); i++) | 298 | + for (size_t i = 0; i < vector_DmpPrintLayout.size(); i++) |
395 | { | 299 | { |
396 | - shared_ptr<DmapPrintLayout> layout = vector_dmapPrintLayout.at(i); | ||
397 | - layout->DrawData(&mClsSurfDC,PrintOutputFormat::PDF); | 300 | + shared_ptr<DmpPrintLayout> layout = vector_DmpPrintLayout.at(i); |
301 | + layout->DrawData(&mClsSurfDC, DmpWmsParameters::Format::PDF); | ||
398 | } | 302 | } |
399 | } | 303 | } |
400 | else | 304 | else |
@@ -403,32 +307,28 @@ namespace DmpWms | @@ -403,32 +307,28 @@ namespace DmpWms | ||
403 | (int)m_width, | 307 | (int)m_width, |
404 | (int)m_height); | 308 | (int)m_height); |
405 | 309 | ||
406 | - | ||
407 | - | ||
408 | - //cairo_surface_set_fallback_resolution(surface); | ||
409 | - //double dpix, dpiy; | ||
410 | - //cairo_surface_get_fallback_resolution(surface,&dpix, &dpiy); | ||
411 | - //printf("%f,%f",dpix,dpiy); | 310 | + // cairo_surface_set_fallback_resolution(surface); |
311 | + // double dpix, dpiy; | ||
312 | + // cairo_surface_get_fallback_resolution(surface,&dpix, &dpiy); | ||
313 | + // printf("%f,%f",dpix,dpiy); | ||
412 | 314 | ||
413 | clsCrSurf mClsSurfDC(surface); | 315 | clsCrSurf mClsSurfDC(surface); |
414 | DoSetBackGround(&mClsSurfDC, 0xffffffff); | 316 | DoSetBackGround(&mClsSurfDC, 0xffffffff); |
415 | - | ||
416 | 317 | ||
417 | - for (size_t i = 0; i < vector_dmapPrintLayout.size(); i++) | 318 | + for (size_t i = 0; i < vector_DmpPrintLayout.size(); i++) |
418 | { | 319 | { |
419 | - shared_ptr<DmapPrintLayout> layout = vector_dmapPrintLayout.at(i); | ||
420 | - layout->DrawData(&mClsSurfDC,PrintOutputFormat::PNG); | 320 | + shared_ptr<DmpPrintLayout> layout = vector_DmpPrintLayout.at(i); |
321 | + layout->DrawData(&mClsSurfDC, DmpWmsParameters::Format::PNG); | ||
421 | } | 322 | } |
422 | 323 | ||
423 | - cairo_surface_write_to_png_stream(surface, cairo_write_func_print, ab); | 324 | + cairo_surface_write_to_png_stream(surface, cairo_write_func_print, &responseData); |
424 | } | 325 | } |
425 | return true; | 326 | return true; |
426 | } | 327 | } |
427 | 328 | ||
428 | - | ||
429 | bool DmpMapPrint::InitTemplateValue(string templateValue) | 329 | bool DmpMapPrint::InitTemplateValue(string templateValue) |
430 | { | 330 | { |
431 | - | 331 | + |
432 | if (templateValue == "A4竖" || templateValue == "A4-hoch") | 332 | if (templateValue == "A4竖" || templateValue == "A4-hoch") |
433 | { | 333 | { |
434 | m_height = 1122; | 334 | m_height = 1122; |
@@ -463,222 +363,81 @@ namespace DmpWms | @@ -463,222 +363,81 @@ namespace DmpWms | ||
463 | } | 363 | } |
464 | 364 | ||
465 | 365 | ||
466 | - bool DmpMapPrint::Test(AppendBuffer *ab,map<string, shared_ptr<WMSServer>> &mapWmsServer,string servername) | ||
467 | - { | ||
468 | - //double scaleDenominator = 0; | ||
469 | - | ||
470 | - shared_ptr<MapParameter> pMapParameter(new MapParameter()); | ||
471 | - | ||
472 | - | ||
473 | - shared_ptr<OperationalDmapLayer> dmapLayer(new OperationalDmapLayer()); | ||
474 | - dmapLayer->serviceName = servername; | ||
475 | 366 | ||
476 | - map<string, shared_ptr<WMSServer>>::iterator iter = mapWmsServer.find(dmapLayer->serviceName); | ||
477 | - if(iter !=mapWmsServer.end()) | ||
478 | - { | ||
479 | - dmapLayer->m_wmsServer = iter->second; | ||
480 | - Rect *rect = dmapLayer->m_wmsServer->GetExtent(); | ||
481 | - pMapParameter->InitParameter(rect->m_dLeft,rect->m_dRight,rect->m_dTop,rect->m_dBottom,693,1022); | ||
482 | - double scaleDenominator = this->RecalculateScale(rect->m_dRight,rect->m_dLeft,rect->m_dTop,rect->m_dBottom,1022,693); | ||
483 | - } | ||
484 | - else | ||
485 | - { | 367 | + double DmpMapPrint::RecalculateScale(double right, double left, double top, double bottom, double width, double height) |
368 | + { | ||
369 | + double w = right - left; | ||
370 | + double h = top - bottom; | ||
371 | + double oneInchInLayoutUnits = 0.0254; | ||
372 | + double resolution = 96; | ||
373 | + if ((w > std::pow(10, 12)) || (w < std::pow(10, -12))) | ||
374 | + return false; | ||
375 | + if ((h > std::pow(10, 12)) || (h < std::pow(10, -12))) | ||
486 | return false; | 376 | return false; |
487 | - } | ||
488 | - | ||
489 | - | ||
490 | - //dmapLayer->serviceName = "土地利用现状"; | ||
491 | - //dmapLayer->m_id = "土地利用现状"; | ||
492 | - //dmapLayer->boxX1 = 683497; | ||
493 | - //dmapLayer->boxX2 = 695357; | ||
494 | - //dmapLayer->boxY1 = 2534922; | ||
495 | - //dmapLayer->boxY2 = 2543053; | ||
496 | - | ||
497 | - Rect* rect = dmapLayer->m_wmsServer->GetExtent(); | ||
498 | - | ||
499 | - dmapLayer->boxX1 = rect->m_dLeft; | ||
500 | - dmapLayer->boxX2 = rect->m_dRight; | ||
501 | - dmapLayer->boxY1 = rect->m_dBottom; | ||
502 | - dmapLayer->boxY2 = rect->m_dTop; | ||
503 | - | ||
504 | - shared_ptr<DmapPrintLayout> dmapLayout(new DmapPrintLayout()); | ||
505 | - this->vector_dmapPrintLayout.push_back(dmapLayout); | ||
506 | - | ||
507 | - | ||
508 | - dmapLayout->data.push_back(dmapLayer); | ||
509 | - dmapLayout->localtion_x = 50; | ||
510 | - dmapLayout->localtion_y = 70; | ||
511 | - | ||
512 | - dmapLayout->height = 1022; | ||
513 | - dmapLayout->width = 693; | ||
514 | - | ||
515 | - this->m_height = 1122; | ||
516 | - this->m_width = 793; | ||
517 | - | ||
518 | 377 | ||
519 | - shared_ptr<OperationalGeom> geomLayer_scale(new OperationalGeom()); | ||
520 | - geomLayer_scale->pMapParameter = pMapParameter; | ||
521 | - geomLayer_scale->type = "scale"; | ||
522 | - shared_ptr<DmapPrintLayout> dmapLayout_scale(new DmapPrintLayout()); | ||
523 | - this->vector_dmapPrintLayout.push_back(dmapLayout_scale); | ||
524 | - dmapLayout_scale->localtion_x = 150; | ||
525 | - dmapLayout_scale->localtion_y = 1022+20; | ||
526 | - dmapLayout_scale->data.push_back(geomLayer_scale); | 378 | + long double R1 = width / w; |
379 | + long double R2 = height / h; | ||
380 | + double r = R1 < R2 ? R1 : R2; | ||
381 | + if ((r > std::pow(10, 12)) || (r < std::pow(10, -12))) | ||
382 | + return false; | ||
527 | 383 | ||
384 | + // m_dR = R1 < R2 ? R1 : R2; | ||
385 | + double m_dR = r; | ||
386 | + double m_dXdis = width / 2.0 - m_dR * (right + left) / 2.0; | ||
387 | + double m_dYdis = height / 2.0 + m_dR * (top + bottom) / 2.0; | ||
528 | 388 | ||
529 | - shared_ptr<OperationalGeom> geomLayer_compass(new OperationalGeom()); | ||
530 | - geomLayer_compass->pMapParameter = pMapParameter; | ||
531 | - geomLayer_compass->type = "compass"; | ||
532 | - shared_ptr<DmapPrintLayout> dmapLayout_compass(new DmapPrintLayout()); | ||
533 | - this->vector_dmapPrintLayout.push_back(dmapLayout_compass); | ||
534 | - dmapLayout_compass->localtion_x = 80; | ||
535 | - dmapLayout_compass->localtion_y = 1022-10; | ||
536 | - dmapLayout_compass->data.push_back(geomLayer_compass); | 389 | + bool isWGS84 = left <= 180 && right < 180 && |
390 | + left >= -180 && right >= -180 && | ||
391 | + top < 90 && bottom < 90; | ||
537 | 392 | ||
538 | - | ||
539 | - if(isPicture == DmpWmsParameters::Format::SVG) | 393 | + double scaleDenominator = 0; |
394 | + if (isWGS84) | ||
540 | { | 395 | { |
541 | - //string path = this->GetFilePath("mapPrint.pdf"); | ||
542 | - cairo_surface_t *surface = cairo_svg_surface_create_for_stream(cairo_write_func_print,ab, | ||
543 | - (int)m_width, | ||
544 | - (int)m_height); | ||
545 | - | ||
546 | - //cairo_surface_set_fallback_resolution(surface,900,900); | ||
547 | - clsCrSurf mClsSurfDC(surface,(int)m_width,(int)m_height,false); | ||
548 | - cairo_set_antialias(mClsSurfDC.m_pCr,cairo_antialias_t::CAIRO_ANTIALIAS_BEST); | ||
549 | - DoSetBackGround(&mClsSurfDC, 0xffffffff); | ||
550 | - | ||
551 | - for (size_t i = 0; i < vector_dmapPrintLayout.size(); i++) | ||
552 | - { | ||
553 | - shared_ptr<DmapPrintLayout> layout = vector_dmapPrintLayout.at(i); | ||
554 | - layout->DrawData(&mClsSurfDC,DmpWmsParameters::Format::SVG); | ||
555 | - } | ||
556 | - } | ||
557 | - else if(isPicture == DmpWmsParameters::Format::PDF) | ||
558 | - { | ||
559 | - //string path = this->GetFilePath("mapPrint.pdf"); | ||
560 | - cairo_surface_t *surface = cairo_pdf_surface_create_for_stream(cairo_write_func_print,ab, | ||
561 | - (int)m_width, | ||
562 | - (int)m_height); | ||
563 | - | ||
564 | - //cairo_surface_set_fallback_resolution(surface,900,900); | ||
565 | - clsCrSurf mClsSurfDC(surface,(int)m_width,(int)m_height,false); | ||
566 | - cairo_set_antialias(mClsSurfDC.m_pCr,cairo_antialias_t::CAIRO_ANTIALIAS_BEST); | ||
567 | - DoSetBackGround(&mClsSurfDC, 0xffffffff); | ||
568 | - | ||
569 | - for (size_t i = 0; i < vector_dmapPrintLayout.size(); i++) | ||
570 | - { | ||
571 | - shared_ptr<DmapPrintLayout> layout = vector_dmapPrintLayout.at(i); | ||
572 | - layout->DrawData(&mClsSurfDC,DmpWmsParameters::Format::PDF); | ||
573 | - } | 396 | + scaleDenominator = (resolution / oneInchInLayoutUnits) * (1 / r) * 111000; |
397 | + // m_dR = r *(96 / 0.0254) *111000 ;//111000 为赤道1经度等于 111000米 | ||
574 | } | 398 | } |
575 | else | 399 | else |
576 | { | 400 | { |
577 | - cairo_surface_t *surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, | ||
578 | - (int)m_width, | ||
579 | - (int)m_height); | ||
580 | - | ||
581 | - | ||
582 | - | ||
583 | - //cairo_surface_set_fallback_resolution(surface); | ||
584 | - //double dpix, dpiy; | ||
585 | - //cairo_surface_get_fallback_resolution(surface,&dpix, &dpiy); | ||
586 | - //printf("%f,%f",dpix,dpiy); | ||
587 | - | ||
588 | - clsCrSurf mClsSurfDC(surface); | ||
589 | - DoSetBackGround(&mClsSurfDC, 0xffffffff); | ||
590 | - | ||
591 | - | ||
592 | - for (size_t i = 0; i < vector_dmapPrintLayout.size(); i++) | ||
593 | - { | ||
594 | - shared_ptr<DmapPrintLayout> layout = vector_dmapPrintLayout.at(i); | ||
595 | - layout->DrawData(&mClsSurfDC, DmpWmsParameters::Format::PNG); | ||
596 | - } | ||
597 | - | ||
598 | - cairo_surface_write_to_png_stream(surface, cairo_write_func_print, ab); | 401 | + scaleDenominator = (resolution / oneInchInLayoutUnits) * 1 / r; |
599 | } | 402 | } |
600 | 403 | ||
601 | - | 404 | + return scaleDenominator; |
602 | } | 405 | } |
603 | 406 | ||
604 | - | ||
605 | -double DmpMapPrint::RecalculateScale(double right, double left, double top, double bottom, double width, double height ) | ||
606 | -{ | ||
607 | - double w = right - left; | ||
608 | - double h = top - bottom; | ||
609 | - double oneInchInLayoutUnits = 0.0254; | ||
610 | - double resolution = 96; | ||
611 | - if ((w > std::pow(10, 12)) || (w < std::pow(10, -12))) | ||
612 | - return false; | ||
613 | - if ((h > std::pow(10, 12)) || (h < std::pow(10, -12))) | ||
614 | - return false; | ||
615 | - | ||
616 | - long double R1 = width / w; | ||
617 | - long double R2 = height / h; | ||
618 | - double r = R1 < R2 ? R1 : R2; | ||
619 | - if ((r > std::pow(10, 12)) || (r < std::pow(10, -12))) | ||
620 | - return false; | ||
621 | - | ||
622 | - //m_dR = R1 < R2 ? R1 : R2; | ||
623 | - double m_dR = r; | ||
624 | - double m_dXdis = width / 2.0 - m_dR * (right + left) / 2.0; | ||
625 | - double m_dYdis = height / 2.0 + m_dR * (top + bottom) / 2.0; | ||
626 | - | ||
627 | - | ||
628 | - | ||
629 | - | ||
630 | - bool isWGS84 = left <=180 && right <180 && | ||
631 | - left >= -180 && right >=-180 && | ||
632 | - top < 90 && bottom <90; | ||
633 | - | ||
634 | - double scaleDenominator = 0; | ||
635 | - if(isWGS84) | ||
636 | - { | ||
637 | - scaleDenominator = (resolution / oneInchInLayoutUnits)*(1/r)*111000; | ||
638 | - //m_dR = r *(96 / 0.0254) *111000 ;//111000 为赤道1经度等于 111000米 | ||
639 | - } | ||
640 | - else | ||
641 | - { | ||
642 | - scaleDenominator= (resolution / oneInchInLayoutUnits) * 1/r; | ||
643 | - } | ||
644 | - | ||
645 | - return scaleDenominator; | ||
646 | -} | ||
647 | - | ||
648 | string DmpMapPrint::GetFilePath(string path) | 407 | string DmpMapPrint::GetFilePath(string path) |
649 | { | 408 | { |
650 | char sz[200] = {0}; | 409 | char sz[200] = {0}; |
651 | - if(GetCurrentFolderPath(sz, sizeof(sz)) > 0) | 410 | + if (GetCurrentFolderPath(sz, sizeof(sz)) > 0) |
652 | { | 411 | { |
653 | std::string s; | 412 | std::string s; |
654 | s = sz; | 413 | s = sz; |
655 | size_t t = s.rfind('/'); | 414 | size_t t = s.rfind('/'); |
656 | sz[t] = 0; | 415 | sz[t] = 0; |
657 | - if(path[0]=='/') | 416 | + if (path[0] == '/') |
658 | { | 417 | { |
659 | return path; | 418 | return path; |
660 | } | 419 | } |
661 | - int i=0; | ||
662 | - if(path[0]=='.') | 420 | + int i = 0; |
421 | + if (path[0] == '.') | ||
663 | { | 422 | { |
664 | - if(path[1]=='.') | 423 | + if (path[1] == '.') |
665 | { | 424 | { |
666 | i++; | 425 | i++; |
667 | - s= sz; | 426 | + s = sz; |
668 | t = s.rfind('/'); | 427 | t = s.rfind('/'); |
669 | sz[t] = 0; | 428 | sz[t] = 0; |
670 | } | 429 | } |
671 | i++; | 430 | i++; |
672 | } | 431 | } |
673 | - if((sz[t]=='/' || sz[t]=='\\')&& (path[i]=='/' || path[i]=='\\')) | 432 | + if ((sz[t] == '/' || sz[t] == '\\') && (path[i] == '/' || path[i] == '\\')) |
674 | { | 433 | { |
675 | i++; | 434 | i++; |
676 | } | 435 | } |
677 | 436 | ||
678 | - int j= t; | ||
679 | - for(j=t;i<path.length(); i++,j++) | 437 | + int j = t; |
438 | + for (j = t; i < path.length(); i++, j++) | ||
680 | { | 439 | { |
681 | - if(path[i]=='\\') | 440 | + if (path[i] == '\\') |
682 | { | 441 | { |
683 | sz[j] = '/'; | 442 | sz[j] = '/'; |
684 | } | 443 | } |
@@ -686,32 +445,29 @@ double DmpMapPrint::RecalculateScale(double right, double left, double top, doub | @@ -686,32 +445,29 @@ double DmpMapPrint::RecalculateScale(double right, double left, double top, doub | ||
686 | { | 445 | { |
687 | sz[j] = path[i]; | 446 | sz[j] = path[i]; |
688 | } | 447 | } |
689 | - | ||
690 | } | 448 | } |
691 | - sz[j] =0; | ||
692 | - //strcat(sz, path.c_str()); | 449 | + sz[j] = 0; |
450 | + // strcat(sz, path.c_str()); | ||
693 | return sz; | 451 | return sz; |
694 | } | 452 | } |
695 | - else return 0; | ||
696 | - | 453 | + else |
454 | + return 0; | ||
697 | } | 455 | } |
698 | 456 | ||
699 | - int DmpMapPrint::GetCurrentFolderPath(char* processdir, size_t len) | 457 | + int DmpMapPrint::GetCurrentFolderPath(char *processdir, size_t len) |
700 | { | 458 | { |
701 | - char* path_end; | ||
702 | - if (readlink("/proc/self/exe", processdir, len) <= 0) | ||
703 | - return -1; | ||
704 | - path_end = strrchr(processdir, '/'); | ||
705 | - if (path_end == NULL) | ||
706 | - return -1; | ||
707 | - ++path_end; | ||
708 | - //strcpy(processname, path_end); | ||
709 | - *path_end = '\0'; | ||
710 | - return (size_t)(path_end - processdir); | 459 | + char *path_end; |
460 | + if (readlink("/proc/self/exe", processdir, len) <= 0) | ||
461 | + return -1; | ||
462 | + path_end = strrchr(processdir, '/'); | ||
463 | + if (path_end == NULL) | ||
464 | + return -1; | ||
465 | + ++path_end; | ||
466 | + // strcpy(processname, path_end); | ||
467 | + *path_end = '\0'; | ||
468 | + return (size_t)(path_end - processdir); | ||
711 | } | 469 | } |
712 | 470 | ||
713 | - | ||
714 | - | ||
715 | bool DmpMapPrint::DoSetBackGround(clsCrSurf *pClsCS, int iColor) | 471 | bool DmpMapPrint::DoSetBackGround(clsCrSurf *pClsCS, int iColor) |
716 | { | 472 | { |
717 | cairo_surface_t *surface = pClsCS->m_pSurf; | 473 | cairo_surface_t *surface = pClsCS->m_pSurf; |
@@ -721,9 +477,9 @@ double DmpMapPrint::RecalculateScale(double right, double left, double top, doub | @@ -721,9 +477,9 @@ double DmpMapPrint::RecalculateScale(double right, double left, double top, doub | ||
721 | //画一个矩形背景 | 477 | //画一个矩形背景 |
722 | cairo_rectangle(cr, 0, 0, surf_w, surf_h); | 478 | cairo_rectangle(cr, 0, 0, surf_w, surf_h); |
723 | double r, g, b, a; | 479 | double r, g, b, a; |
724 | - MyUtil::ToCairoColor(iColor, r, g, b, a); | ||
725 | - cairo_set_source_rgb(cr, r, g, b); | 480 | + //MyUtil::ToCairoColor(iColor, r, g, b, a); |
481 | + cairo_set_source_rgb(cr, 255, 255, 255); | ||
726 | cairo_fill(cr); | 482 | cairo_fill(cr); |
727 | return true; | 483 | return true; |
728 | - }*/ | 484 | + } |
729 | } | 485 | } |
@@ -7,8 +7,8 @@ | @@ -7,8 +7,8 @@ | ||
7 | * copyright: 广州城市信息研究所有限公司 | 7 | * copyright: 广州城市信息研究所有限公司 |
8 | ***************************************************************************/ | 8 | ***************************************************************************/ |
9 | 9 | ||
10 | -#ifndef __dmpprint_h__ | ||
11 | -#define __dmpprint_h__ | 10 | +#ifndef __dmpmapprint_h__ |
11 | +#define __dmpmapprint_h__ | ||
12 | 12 | ||
13 | #include <string> | 13 | #include <string> |
14 | #include <string.h> | 14 | #include <string.h> |
@@ -16,14 +16,18 @@ | @@ -16,14 +16,18 @@ | ||
16 | #include <map> | 16 | #include <map> |
17 | #include <math.h> | 17 | #include <math.h> |
18 | #include "dmpproject.h" | 18 | #include "dmpproject.h" |
19 | -#include "../dmpwmsrenderer.h" | ||
20 | - | ||
21 | #include "clsCrSurf.h" | 19 | #include "clsCrSurf.h" |
22 | #include "clsRect.h" | 20 | #include "clsRect.h" |
23 | #include "clsUtil.h" | 21 | #include "clsUtil.h" |
22 | +#include <boost/property_tree/ptree.hpp> | ||
23 | +#include <boost/property_tree/xml_parser.hpp> | ||
24 | +#include <boost/typeof/typeof.hpp> | ||
25 | +#include "dmpprintlayout.h" | ||
26 | +#include "dmpprintparameter.h" | ||
27 | +#include "../dmpwmsrenderer.h" | ||
28 | +#include "../dmpwmsparameters.h" | ||
24 | using namespace std; | 29 | using namespace std; |
25 | using namespace DmapCore_30; | 30 | using namespace DmapCore_30; |
26 | - | ||
27 | namespace DmpWms | 31 | namespace DmpWms |
28 | { | 32 | { |
29 | class DmpMapPrint | 33 | class DmpMapPrint |
@@ -41,7 +45,7 @@ namespace DmpWms | @@ -41,7 +45,7 @@ namespace DmpWms | ||
41 | int m_wkid; | 45 | int m_wkid; |
42 | int m_dpi; | 46 | int m_dpi; |
43 | double m_scale; | 47 | double m_scale; |
44 | - int isPicture; | 48 | + DmpWmsParameters::Format format; |
45 | 49 | ||
46 | private: | 50 | private: |
47 | bool DoSetBackGround(clsCrSurf *pClsCS, int iColor); | 51 | bool DoSetBackGround(clsCrSurf *pClsCS, int iColor); |
@@ -50,29 +54,28 @@ namespace DmpWms | @@ -50,29 +54,28 @@ namespace DmpWms | ||
50 | int GetCurrentFolderPath(char *processdir, size_t len); | 54 | int GetCurrentFolderPath(char *processdir, size_t len); |
51 | bool InitTemplateValue(string templateValue); | 55 | bool InitTemplateValue(string templateValue); |
52 | bool ToPrint(std::string &responseData); | 56 | bool ToPrint(std::string &responseData); |
53 | - | ||
54 | public: | 57 | public: |
55 | - DmpMapPrint(); | 58 | + DmpMapPrint(DmpWmsParameters::Format outformat); |
56 | 59 | ||
57 | - bool getPrint(std::string &responseData, DmpProject* project, const char *xml, string servername); | ||
58 | - bool getPrint(std::string &responseData, DmpProject* project, const char *printTemp, const char *bbox); | 60 | + bool getPrint(std::string &responseData,const DmpProject* project,const string & xml, const string& servername); |
61 | + bool getPrint(std::string &responseData,const DmpProject* project, const string& servername, const char *printTemp, const char *bbox); | ||
59 | 62 | ||
60 | bool getPrintLayout(std::string &responseData, | 63 | bool getPrintLayout(std::string &responseData, |
61 | - DmpProject* project, | 64 | + const DmpProject* project, |
62 | const char *xml, | 65 | const char *xml, |
63 | const char *bbox); | 66 | const char *bbox); |
64 | 67 | ||
65 | bool getPrintTempFile(std::string &responseData, | 68 | bool getPrintTempFile(std::string &responseData, |
66 | - DmpProject* project, | 69 | + const DmpProject* project, |
67 | const char *tempName, | 70 | const char *tempName, |
68 | const char *bbox); | 71 | const char *bbox); |
69 | 72 | ||
70 | - bool Test(std::string &responseData, DmpProject* project, string servername); | 73 | + // bool Test(std::string &responseData, DmpProject* project, string servername); |
71 | 74 | ||
72 | - // vector<shared_ptr<DmapPrintLayout>> vector_dmapPrintLayout; | 75 | + vector<shared_ptr<DmpPrintLayout>> vector_DmpPrintLayout; |
73 | // vector<shared_ptr<OperationalLayer>> vector_operationalLayer; | 76 | // vector<shared_ptr<OperationalLayer>> vector_operationalLayer; |
74 | 77 | ||
75 | }; | 78 | }; |
76 | } | 79 | } |
77 | 80 | ||
78 | -#endif // __dmpprint_h__ | 81 | +#endif // __dmpmapprint_h__ |
@@ -14,7 +14,7 @@ namespace DmpWms | @@ -14,7 +14,7 @@ namespace DmpWms | ||
14 | { | 14 | { |
15 | class DmpPrintCompass :public DmpPrintLayer | 15 | class DmpPrintCompass :public DmpPrintLayer |
16 | { | 16 | { |
17 | - private: | 17 | + public: |
18 | string serviceName; | 18 | string serviceName; |
19 | 19 | ||
20 | shared_ptr<DmpPrintParameter> pPrintParameter_ = nullptr; | 20 | shared_ptr<DmpPrintParameter> pPrintParameter_ = nullptr; |
@@ -7,11 +7,6 @@ | @@ -7,11 +7,6 @@ | ||
7 | * copyright: 广州城市信息研究所有限公司 | 7 | * copyright: 广州城市信息研究所有限公司 |
8 | ***************************************************************************/ | 8 | ***************************************************************************/ |
9 | #include "dmpprintlayout.h" | 9 | #include "dmpprintlayout.h" |
10 | -#include "dmpprintrect.h" | ||
11 | -#include "dmpprintscale.h" | ||
12 | -#include "dmpprinttext.h" | ||
13 | -#include "dmpprintcompass.h" | ||
14 | -#include "dmpprintwmsservice.h" | ||
15 | namespace DmpWms | 10 | namespace DmpWms |
16 | { | 11 | { |
17 | bool DmpPrintLayout::DrawData(clsCrSurf* pClsCS,DmpWmsParameters::Format format) | 12 | bool DmpPrintLayout::DrawData(clsCrSurf* pClsCS,DmpWmsParameters::Format format) |
@@ -28,7 +23,7 @@ namespace DmpWms | @@ -28,7 +23,7 @@ namespace DmpWms | ||
28 | 23 | ||
29 | bool DmpPrintLayout::ReadXML(boost::property_tree::ptree &pt, shared_ptr<DmpPrintParameter> pPrintParameter,string& errorstr) | 24 | bool DmpPrintLayout::ReadXML(boost::property_tree::ptree &pt, shared_ptr<DmpPrintParameter> pPrintParameter,string& errorstr) |
30 | { | 25 | { |
31 | - try | 26 | + /* try |
32 | { | 27 | { |
33 | boost::property_tree::ptree ptbound = pt.get_child("bound"); | 28 | boost::property_tree::ptree ptbound = pt.get_child("bound"); |
34 | this->ReadXmlAttribute(ptbound, showbound_, "show"); | 29 | this->ReadXmlAttribute(ptbound, showbound_, "show"); |
@@ -43,7 +38,7 @@ namespace DmpWms | @@ -43,7 +38,7 @@ namespace DmpWms | ||
43 | catch(const std::exception& e) | 38 | catch(const std::exception& e) |
44 | { | 39 | { |
45 | 40 | ||
46 | - } | 41 | + }*/ |
47 | 42 | ||
48 | try | 43 | try |
49 | { | 44 | { |
@@ -10,6 +10,11 @@ | @@ -10,6 +10,11 @@ | ||
10 | #ifndef __dmpprintlayout_h__ | 10 | #ifndef __dmpprintlayout_h__ |
11 | #define __dmpprintlayout_h__ | 11 | #define __dmpprintlayout_h__ |
12 | #include "dmpprintlayer.h" | 12 | #include "dmpprintlayer.h" |
13 | +#include "dmpprintrect.h" | ||
14 | +#include "dmpprintscale.h" | ||
15 | +#include "dmpprinttext.h" | ||
16 | +#include "dmpprintcompass.h" | ||
17 | +#include "dmpprintwmsservice.h" | ||
13 | #include <vector> | 18 | #include <vector> |
14 | namespace DmpWms | 19 | namespace DmpWms |
15 | { | 20 | { |
@@ -18,7 +18,7 @@ namespace DmpWms | @@ -18,7 +18,7 @@ namespace DmpWms | ||
18 | class DmpPrintParameter | 18 | class DmpPrintParameter |
19 | { | 19 | { |
20 | public: | 20 | public: |
21 | - DmpProject* pWmsService = nullptr; | 21 | + const DmpProject* pWmsService = nullptr; |
22 | 22 | ||
23 | bool isWGS84 = false; | 23 | bool isWGS84 = false; |
24 | double dWgs = 111000; | 24 | double dWgs = 111000; |
@@ -15,7 +15,7 @@ namespace DmpWms | @@ -15,7 +15,7 @@ namespace DmpWms | ||
15 | { | 15 | { |
16 | class DmpPrintScale :public DmpPrintLayer | 16 | class DmpPrintScale :public DmpPrintLayer |
17 | { | 17 | { |
18 | - private: | 18 | + public: |
19 | string serviceName; | 19 | string serviceName; |
20 | shared_ptr<DmpPrintParameter> pPrintParameter_ = nullptr; | 20 | shared_ptr<DmpPrintParameter> pPrintParameter_ = nullptr; |
21 | public: | 21 | public: |
请
注册
或
登录
后发表评论