提交 93c4271e4e636e2ca05189f8f26c33138c97b7fe
Merge branch 'master' of http://gitlab.ctune.cn/DMapServer/DMapServer4.1
正在显示
5 个修改的文件
包含
109 行增加
和
29 行删除
... | ... | @@ -19,7 +19,7 @@ namespace tileserver |
19 | 19 | DmpEsriBundleV1Provider:: DmpEsriBundleV1Provider(const std::string& rootPath) |
20 | 20 | : DmpAbstractEsriBundleProvider(rootPath) |
21 | 21 | { |
22 | - // _rootPath ="/mnt/d/Data/tile/GDMap/_alllayers"; | |
22 | + //rootPath_ ="/mnt/d/Code/tiles/GDMap/_alllayers"; | |
23 | 23 | } |
24 | 24 | void DmpEsriBundleV1Provider::WriteTile(const int row, const int col, const int level, const std::string& format, DmpServerResponse& response) |
25 | 25 | { |
... | ... | @@ -91,14 +91,14 @@ namespace tileserver |
91 | 91 | std::string format=dmpTileLayer->getFormat(); |
92 | 92 | // std::string lowerPoint=std::to_string(rectangle.xmin())+" "+std::to_string(rectangle.ymin()); |
93 | 93 | // std::string upperPoint=std::to_string(rectangle.xmax())+" "+std::to_string(rectangle.ymax()); |
94 | - DmpPoint min=DmpPoint(rectangle.xmin(),rectangle.ymin()); | |
95 | - DmpPoint max=DmpPoint(rectangle.xmax(),rectangle.ymax()); | |
94 | + DmpPoint min=DmpPoint(rectangle.xmin(),rectangle.ymax()); | |
95 | + DmpPoint max=DmpPoint(rectangle.xmax(),rectangle.ymin()); | |
96 | 96 | std::vector<DmpTileMatrixSet*> tileMatrixSets; |
97 | 97 | dmpTileLayer->getTileMatrixSets(tileMatrixSets); |
98 | 98 | double resolution; |
99 | 99 | DmpPoint origin; |
100 | 100 | int iLevel,xMinTile,yMinTile, xMaxTile, yMaxTile,buffLen; |
101 | - if(!TileProviderFactory::GetTileScale(dmpTileLayer,iLevel,xMinTile,yMinTile, xMaxTile, yMaxTile)) | |
101 | + if(!TileProviderFactory::GetTileScale(dmpTileLayer,iLevel,xMinTile,yMinTile, xMaxTile, yMaxTile,origin,resolution)) | |
102 | 102 | { |
103 | 103 | response.sendError(500, "缩略图范围错误:("); |
104 | 104 | return; |
... | ... | @@ -122,13 +122,45 @@ namespace tileserver |
122 | 122 | //cairo_surface_write_to_png (surface, "./wmts.png"); |
123 | 123 | } |
124 | 124 | } |
125 | + | |
126 | + cairo_surface_t* newimage=surface; | |
127 | + | |
128 | + int w,h; | |
129 | + w = cairo_image_surface_get_width (newimage); | |
130 | + h = cairo_image_surface_get_height (newimage); | |
131 | + DmpPoint topLeft; | |
132 | + // yMinTile=190; | |
133 | + // xMinTile=143; | |
134 | + TileProviderFactory::RowColToPoint(origin,xMinTile,yMaxTile,resolution,topLeft); | |
135 | + DmpPoint botRight; | |
136 | + // yMaxTile=191; | |
137 | + // xMaxTile=144; | |
138 | + //TileProviderFactory::RowColToPoint(origin,xMaxTile+1,yMinTile+1,resolution,botRight); | |
139 | + | |
140 | + DmpPoint clipPoint; | |
141 | + int wClip,hClip; | |
142 | + TileProviderFactory::GetClipBox(topLeft,min,max,resolution,clipPoint,wClip,hClip); | |
143 | + | |
144 | + cairo_surface_t *surface0 = cairo_image_surface_create (CAIRO_FORMAT_ARGB32,wClip, hClip); | |
145 | + cairo_t *cr0 =cairo_create (surface0); | |
146 | + | |
147 | + //cairo_rectangle(cr0,clipPoint.x(),clipPoint.y(),wClip,hClip); | |
148 | + cairo_rectangle(cr0,0,0,wClip,hClip); | |
149 | + cairo_set_source_surface (cr0, surface,-clipPoint.x(), -clipPoint.y()); | |
150 | + cairo_clip(cr0); | |
151 | + cairo_paint(cr0); | |
152 | + | |
153 | + //cairo_surface_write_to_png (surface0, "./wmtsbbox.png"); | |
154 | + | |
125 | 155 | std::string responseData; |
126 | - cairo_surface_write_to_png_stream(surface, TileProviderFactory::cairo_write_func, &responseData); | |
156 | + cairo_surface_write_to_png_stream(surface0, TileProviderFactory::cairo_write_func, &responseData); | |
127 | 157 | |
128 | 158 | response.removeHeader("Content-Type"); |
129 | 159 | std::string f = (format == "jpg") ? "image/jpg" : "image/png"; |
130 | 160 | response.setHeader("Content-Type", f); |
131 | - response.write(responseData); | |
161 | + response.write(responseData); | |
162 | + cairo_destroy (cr0); | |
163 | + cairo_surface_destroy (surface0); | |
132 | 164 | cairo_destroy (cr); |
133 | 165 | cairo_surface_destroy (surface); |
134 | 166 | } | ... | ... |
... | ... | @@ -81,14 +81,15 @@ namespace tileserver |
81 | 81 | std::string format=dmpTileLayer->getFormat(); |
82 | 82 | // std::string lowerPoint=std::to_string(rectangle.xmin())+" "+std::to_string(rectangle.ymin()); |
83 | 83 | // std::string upperPoint=std::to_string(rectangle.xmax())+" "+std::to_string(rectangle.ymax()); |
84 | - DmpPoint min=DmpPoint(rectangle.xmin(),rectangle.ymin()); | |
85 | - DmpPoint max=DmpPoint(rectangle.xmax(),rectangle.ymax()); | |
84 | + DmpPoint min=DmpPoint(rectangle.xmin(),rectangle.ymax()); | |
85 | + DmpPoint max=DmpPoint(rectangle.xmax(),rectangle.ymin()); | |
86 | 86 | std::vector<DmpTileMatrixSet*> tileMatrixSets; |
87 | 87 | dmpTileLayer->getTileMatrixSets(tileMatrixSets); |
88 | - double resolution; | |
89 | 88 | DmpPoint origin; |
89 | + double resolution; | |
90 | + | |
90 | 91 | int iLevel,xMinTile,yMinTile, xMaxTile, yMaxTile,buffLen; |
91 | - if(!TileProviderFactory::GetTileScale(dmpTileLayer,iLevel,xMinTile,yMinTile, xMaxTile, yMaxTile)) | |
92 | + if(!TileProviderFactory::GetTileScale(dmpTileLayer,iLevel,xMinTile,yMinTile, xMaxTile, yMaxTile,origin,resolution)) | |
92 | 93 | { |
93 | 94 | response.sendError(500, "缩略图范围错误:("); |
94 | 95 | return; |
... | ... | @@ -116,27 +117,40 @@ namespace tileserver |
116 | 117 | |
117 | 118 | } |
118 | 119 | |
119 | - cairo_surface_t *newimage=cairo_image_surface_create_from_png ("/mnt/d/56.png"); | |
120 | + //cairo_surface_t *newimage=cairo_image_surface_create_from_png ("/mnt/d/56.png"); | |
121 | + cairo_surface_t* newimage=surface; | |
120 | 122 | |
121 | - //cairo_arc (newcr, 128.0, 128.0, 76.8, 0, 2*3.14); | |
122 | 123 | int w,h; |
123 | 124 | w = cairo_image_surface_get_width (newimage); |
124 | 125 | h = cairo_image_surface_get_height (newimage); |
126 | + DmpPoint topLeft; | |
127 | + // yMinTile=190; | |
128 | + // xMinTile=143; | |
129 | + TileProviderFactory::RowColToPoint(origin,xMinTile,yMaxTile,resolution,topLeft); | |
130 | + //DmpPoint botRight=DmpPoint((xMaxTile-xMinTile+1)*resolution,(yMaxTile-xMinTile+1)*resolution); | |
131 | + // yMaxTile=191; | |
132 | + // xMaxTile=144; | |
133 | + //TileProviderFactory::RowColToPoint(origin,xMaxTile+1,yMinTile+1,resolution,botRight); | |
134 | + DmpPoint clipPoint; | |
135 | + int wClip,hClip; | |
125 | 136 | |
126 | - cairo_surface_t *surface0 = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, w/2, h/2); | |
137 | + TileProviderFactory::GetClipBox(topLeft,min,max,resolution,clipPoint,wClip,hClip); | |
138 | + | |
139 | + cairo_surface_t *surface0 = cairo_image_surface_create (CAIRO_FORMAT_ARGB32,wClip, hClip); | |
127 | 140 | cairo_t *cr0 =cairo_create (surface0); |
141 | + cairo_rectangle(cr0,0,0,wClip,hClip); | |
142 | + //cairo_rectangle(cr0,w/4,h/4,w/2,h/4); | |
128 | 143 | cairo_clip(cr0); |
129 | - //cairo_scale (cr0, w/2, h/2); | |
130 | - cairo_set_source_surface (cr0, newimage, 0, 0); | |
131 | - | |
132 | 144 | |
145 | + cairo_set_source_surface (cr0, newimage,-clipPoint.x(), -clipPoint.y()); | |
146 | + | |
133 | 147 | cairo_paint(cr0); |
134 | 148 | //cairo_surface_write_to_png (surface0, "./wmts.png"); |
135 | - cairo_surface_destroy (surface0); | |
136 | - | |
149 | + // cairo_surface_destroy (surface0); | |
150 | + | |
137 | 151 | |
138 | 152 | std::string responseData; |
139 | - cairo_surface_write_to_png_stream(surface, TileProviderFactory::cairo_write_func, &responseData); | |
153 | + cairo_surface_write_to_png_stream(surface0, TileProviderFactory::cairo_write_func, &responseData); | |
140 | 154 | //cairo_surface_write_to_png_stream(newimage, TileProviderFactory::cairo_write_func, &responseData); |
141 | 155 | |
142 | 156 | response.removeHeader("Content-Type"); |
... | ... | @@ -144,8 +158,8 @@ namespace tileserver |
144 | 158 | response.setHeader("Content-Type", f); |
145 | 159 | response.write(responseData); |
146 | 160 | //response.writeContent(&responseData,imageLen); |
147 | - | |
148 | - | |
161 | + cairo_destroy (cr0); | |
162 | + cairo_surface_destroy (surface0); | |
149 | 163 | cairo_destroy (cr); |
150 | 164 | cairo_surface_destroy (surface); |
151 | 165 | } | ... | ... |
... | ... | @@ -77,7 +77,7 @@ namespace tileserver |
77 | 77 | double resolution; |
78 | 78 | DmpPoint origin; |
79 | 79 | int iLevel,xMinTile,yMinTile, xMaxTile, yMaxTile; |
80 | - if(!TileProviderFactory::GetTileScale(dmpTileLayer,iLevel,xMinTile,yMinTile, xMaxTile, yMaxTile)) | |
80 | + if(!TileProviderFactory::GetTileScale(dmpTileLayer,iLevel,xMinTile,yMinTile, xMaxTile, yMaxTile,origin,resolution)) | |
81 | 81 | { |
82 | 82 | response.sendError(500, "缩略图范围错误:("); |
83 | 83 | return; | ... | ... |
... | ... | @@ -135,7 +135,7 @@ namespace tileserver |
135 | 135 | xTile=floor(abs(origin.x()-point.x())/resolution); |
136 | 136 | yTile=floor(abs(origin.y()-point.y())/resolution); |
137 | 137 | } |
138 | - bool TileProviderFactory::GetTileScale(DmpTileLayer* dmpTileLayer,int& iLevel,int& xMinTile,int& yMinTile,int& xMaxTile,int& yMaxTile) | |
138 | + bool TileProviderFactory::GetTileScale(DmpTileLayer* dmpTileLayer,int& iLevel,int& xMinTile,int& yMinTile,int& xMaxTile,int& yMaxTile,DmpPoint& origin,double& resolution) | |
139 | 139 | { |
140 | 140 | std::string tilePath=dmpTileLayer->getDataSource(); |
141 | 141 | DmpRectangle rectangle=dmpTileLayer->extent(); |
... | ... | @@ -143,8 +143,8 @@ namespace tileserver |
143 | 143 | DmpPoint max=DmpPoint(rectangle.xmax(),rectangle.ymax()); |
144 | 144 | std::vector<DmpTileMatrixSet*> tileMatrixSets; |
145 | 145 | dmpTileLayer->getTileMatrixSets(tileMatrixSets); |
146 | - DmpPoint origin; | |
147 | - double resolution; | |
146 | + // DmpPoint origin; | |
147 | + // double resolution; | |
148 | 148 | //筛选合适的切片层级 |
149 | 149 | iLevel=TileProviderFactory::screenTileMatrix(min,max,tileMatrixSets,resolution,origin); |
150 | 150 | if(iLevel==-1) |
... | ... | @@ -157,6 +157,13 @@ namespace tileserver |
157 | 157 | TileProviderFactory::PointToRowCol(max,origin,resolution,xMaxTile,yMaxTile); |
158 | 158 | return true; |
159 | 159 | } |
160 | + void TileProviderFactory::RowColToPoint(DmpPoint& origin,int xTile,int yTile,double resolution,DmpPoint& tileTopleft) | |
161 | + { | |
162 | + double xTileP=origin.x()+(xTile)*resolution; | |
163 | + double yTileP=origin.y()-(yTile)*resolution; | |
164 | + | |
165 | + tileTopleft=DmpPoint(xTileP,yTileP); | |
166 | + } | |
160 | 167 | bool TileProviderFactory::BufferCopy(cairo_surface_t *pClsCSFrom, cairo_surface_t *pClsCSTo, cairo_t *cr,int x,int y) |
161 | 168 | { |
162 | 169 | if (pClsCSFrom == NULL||pClsCSTo == NULL) |
... | ... | @@ -178,4 +185,30 @@ namespace tileserver |
178 | 185 | return CAIRO_STATUS_SUCCESS; |
179 | 186 | } |
180 | 187 | |
188 | + void TileProviderFactory::GetClipBox(DmpPoint& point0,DmpPoint& bboxPoint0,DmpPoint& bboxPoint1,const double& resolution,DmpPoint & topLeftP,int& wBbox,int &hBbox) | |
189 | + { | |
190 | + //默认切片256*256 | |
191 | + double xTile,yTile,xBox,yBox,xTop,yTop,xTopleft,yTopleft; | |
192 | + // //大图坐标距离 | |
193 | + // xTile=abs(point0.x()-point1.x()); | |
194 | + // yTile=abs(point0.y()-point1.y()); | |
195 | + // //bbox坐标距离 distance pixel | |
196 | + xBox=abs(bboxPoint1.x()-bboxPoint0.x()); | |
197 | + yBox=abs(bboxPoint1.y()-bboxPoint0.y()); | |
198 | + //bbox左上与大图距离 | |
199 | + xTopleft=abs(bboxPoint0.x()-point0.x()); | |
200 | + yTopleft=abs(bboxPoint0.y()-point0.y()); | |
201 | + // //获取bbox在合成大图种的范围及左上角坐标,默认大图左上角坐标为(0,0)像素坐标 | |
202 | + // int xTopLeftDistance=wImage*xTopleft/xTile; | |
203 | + // int yTopLeftDistance=hImage*yTopleft/yTile; | |
204 | + | |
205 | + // int wBboxDistance=wImage*xBox/xTile; | |
206 | + // int hBboxDistance=hImage*yBox/yTile; | |
207 | + DmpPoint BboxP=DmpPoint(xTopleft*256/resolution,yTopleft*256/resolution); | |
208 | + topLeftP=BboxP; | |
209 | + wBbox=xBox*256/resolution; | |
210 | + hBbox=yBox*256/resolution; | |
211 | + | |
212 | + | |
213 | + } | |
181 | 214 | } |
\ No newline at end of file | ... | ... |
... | ... | @@ -42,13 +42,14 @@ namespace tileserver |
42 | 42 | static int screenTileMatrix(DmpPoint& min,DmpPoint& max,std::vector<DmpTileMatrixSet*>& tileMatrixSets,double& resolution,DmpPoint& origin); |
43 | 43 | static int screenTileMatrix2(DmpPoint& min,DmpPoint& max,std::vector<DmpTileMatrixSet*>& tileMatrixSets,double& resolution,DmpPoint& origin); |
44 | 44 | static void PointToRowCol(DmpPoint& point,DmpPoint& origin,double resolution,int& xTile,int& yTile); |
45 | - static bool GetTileScale(DmpTileLayer* dmpTileLayer,int& iLevel,int& xMinTile,int& yMinTile,int& xMaxTile,int& yMaxTile); | |
45 | + static bool GetTileScale(DmpTileLayer* dmpTileLayer,int& iLevel,int& xMinTile,int& yMinTile,int& xMaxTile,int& yMaxTile,DmpPoint& origin,double& resolution); | |
46 | 46 | static cairo_status_t cairo_write_func(void *pbuff, const unsigned char *data, unsigned int length); |
47 | - | |
47 | + static void RowColToPoint(DmpPoint& origin,int xTile,int yTile,double resolution,DmpPoint& point0); | |
48 | + static void GetClipBox(DmpPoint& point0,DmpPoint& bboxPoint0,DmpPoint& bboxPoint1,const double& resolution ,DmpPoint & topLeftP,int& wBbox,int &hBbox); | |
48 | 49 | private: |
49 | 50 | TileProviderFactory(); |
51 | + | |
50 | 52 | }; |
51 | - | |
52 | - | |
53 | + | |
53 | 54 | } |
54 | 55 | #endif //__dmptileproviderfactory_h__ | ... | ... |
请
注册
或
登录
后发表评论