提交 04ba64955b532dc050a80909ac0ab0fdc09798be

作者 WZP 万忠平
2 个父辈 00c3feaa 36db4485
正在显示 79 个修改的文件 包含 20047 行增加407 行删除
1   -dmap server 4.0
\ No newline at end of file
  1 +dmap server 4.0
  2 +
... ...
... ... @@ -47,11 +47,12 @@ bool DmpVectorLayer::writeXml(boost::property_tree::ptree &layerNode)
47 47
48 48 void DmpVectorLayer::setRenderer(DmpFeatureRenderer *renderer)
49 49 {
50   -
  50 +
51 51 }
52 52
53 53 void DmpVectorLayer::setDataSource(const std::string &dataSource, const std::string &baseName, const std::string &provider, bool loadDefaultStyleFlag)
54 54 {
  55 +
55 56 DmpWkbTypes::GeometryType geomType = GeometryType();
56 57 }
57 58
... ...
1   -[Core]
2   -Filter="%Severity% >= debug"
3   -
4   -[Sinks.TextFileSettings]
5   -Destination=TextFile
6   -FileName="dmap_%Y%m%d.log"
7   -AutoFlush=true
8   -Format="[%TimeStamp%] [%Uptime%] [%Scope%] <%Severity%> %Message%"
9   -Asynchronous=false
10   -Append=true
  1 +[Core]
  2 +Filter="%Severity% >= debug"
  3 +
  4 +[Sinks.TextFileSettings]
  5 +Destination=TextFile
  6 +FileName="dmap_%Y%m%d.log"
  7 +AutoFlush=true
  8 +Format="[%TimeStamp%] [%Uptime%] [%Scope%] <%Severity%> %Message%"
  9 +Asynchronous=false
  10 +Append=true
... ...
  1 +
  2 +
  3 +#include "AppendBuffer.h"
  4 +#include "stdlib.h"
  5 +#include <string.h>
  6 +//
  7 +
  8 +namespace DmapCore_30
  9 +{
  10 +
  11 +AppendBuffer::AppendBuffer(void)
  12 +{
  13 + allSize=0;
  14 + head=0;
  15 + now=0;
  16 +}
  17 +
  18 + AppendBuffer::AppendBuffer(const char *fileName)
  19 + {
  20 + allSize = 0;
  21 + head = 0;
  22 + now = 0;
  23 + if (fileName)
  24 + {
  25 + f = fopen(fileName, "wb");
  26 + }
  27 + }
  28 +
  29 +AppendBuffer::~AppendBuffer(void)
  30 +{
  31 + Reset();
  32 +}
  33 +
  34 +//分配一个新的BUFFER
  35 +AppendBuffer::Buffer *AppendBuffer::NewABuffer(void)
  36 +{
  37 + Buffer *buf=new Buffer;
  38 + buf->buffer=(char *)malloc(APPEND_BUFFER_SIZE); //每个BUFFER都留这么大的空间?
  39 + if(buf->buffer==0)
  40 + {
  41 + delete buf;
  42 + return 0;
  43 + }
  44 + buf->next=0;
  45 + buf->bufferNowCount=0;
  46 +
  47 + return buf;
  48 +}
  49 +char *AppendBuffer::GetString()
  50 + {
  51 + char *s = (char *)malloc(this->allSize + 1);
  52 + if (s == 0)return 0;
  53 + char *ss = s; int cc = 0;
  54 + for (Buffer *h = head; h;)
  55 + {
  56 + memcpy(ss, h->buffer, h->bufferNowCount);
  57 + ss += h->bufferNowCount;
  58 + // cc += h->bufferNowCount;
  59 + h = h->next;
  60 + }
  61 + s[this->allSize] = 0;
  62 + return s;
  63 + }
  64 +void AppendBuffer::AppendString(const char * str, int len)
  65 +{
  66 +
  67 + if(now==0)AddABuffer(); //当前的指针为0
  68 +
  69 + int remain;
  70 + for(;;)
  71 + {
  72 + remain=APPEND_BUFFER_SIZE-now->bufferNowCount;
  73 + if(remain==0)
  74 + {
  75 + AddABuffer();
  76 + remain=APPEND_BUFFER_SIZE-now->bufferNowCount;
  77 + }
  78 + if(remain>=len)//放得下
  79 + {
  80 + memcpy(now->buffer+now->bufferNowCount,str,len);
  81 + //len-=len;
  82 + now->bufferNowCount+=len;
  83 + this->allSize+=len;
  84 + break;
  85 + }
  86 + else //放不下
  87 + {
  88 + memcpy(now->buffer+now->bufferNowCount,str,remain);
  89 + len-=remain;
  90 + now->bufferNowCount=APPEND_BUFFER_SIZE;
  91 + str+=remain;
  92 + this->allSize+=remain;
  93 + AddABuffer();
  94 + }
  95 + }
  96 +}
  97 +
  98 +//int AppendBuffer::GetSize()
  99 +//{
  100 +// int size = 0;
  101 +// for (AppendBuffer::Buffer *pb = this->head; pb; pb = pb->next)
  102 +// {
  103 +// size = size + sizeof(pb->buffer);
  104 +// }
  105 +// return size;
  106 +//}
  107 +
  108 +
  109 +void AppendBuffer::SetBuffer(AppendBuffer::Buffer *buf,const char * str, int len)
  110 +{
  111 + memcpy(buf->buffer,str,len);
  112 + this->allSize+=len;
  113 + buf->bufferNowCount=len;
  114 +}
  115 +
  116 +int AppendBuffer::AppendString(const char * str)
  117 +{
  118 + AppendString(str,(int)(strlen(str)));
  119 + return 0;
  120 +}
  121 +
  122 +
  123 +int AppendBuffer::AddABuffer(void)
  124 +{
  125 + if(head==0)
  126 + {
  127 + head=NewABuffer();
  128 + now=head; //now是当前的指针
  129 + }
  130 + else
  131 + {
  132 + now->next=NewABuffer();
  133 + now=now->next;
  134 + }
  135 + if(now==0)return 1;//stbstb
  136 + return 0;
  137 +}
  138 +
  139 +int AppendBuffer::AppendOtherOne(AppendBuffer * other)
  140 +{
  141 + this->now->next=other->head;
  142 + this->now=other->now;
  143 + this->allSize+=other->allSize;
  144 + other->head=0;
  145 + //other->allSize=0; //stbstb
  146 + //other->now=0;
  147 + return 0;
  148 +}
  149 +
  150 +void AppendBuffer::Reset(void)
  151 +{
  152 + for(;head;)
  153 + {
  154 + now=head;
  155 + head=now->next;
  156 + free(now->buffer);
  157 + delete now;
  158 + }
  159 + head=0;
  160 + now=0;
  161 + allSize=0;
  162 +}
  163 +
  164 +}
\ No newline at end of file
... ...
  1 +/**************************************************************************
  2 +* file: AppendBuffer.h
  3 +
  4 +* Author: qingxiongf
  5 +* Date: 2021-12-12 23:00:46
  6 +* Email: qingxiongf@chinadci.com
  7 +* copyright: 广州城市信息研究所有限公司
  8 +***************************************************************************/
  9 +
  10 +#ifndef __AppendBuffer_h__
  11 +#define __AppendBuffer_h__
  12 +
  13 +#include "dmap_core.h"
  14 +#include "stdio.h"
  15 +#include <string>
  16 +
  17 +#define APPEND_BUFFER_SIZE 200000
  18 +
  19 +namespace DmapCore_30
  20 +{
  21 +
  22 + class CORE_EXPORT AppendBuffer
  23 + {
  24 + public:
  25 + struct Buffer
  26 + {
  27 + Buffer *next;
  28 + char *buffer;
  29 + int bufferNowCount;
  30 + };
  31 +
  32 + private:
  33 + FILE *f;
  34 +
  35 +
  36 + public:
  37 + int allSize;
  38 + AppendBuffer(void);
  39 + char *GetString();
  40 +
  41 + std::string content_type;
  42 +
  43 + public:
  44 + ~AppendBuffer(void);
  45 + AppendBuffer(const char *fileName);
  46 + Buffer *head;
  47 + Buffer *now;
  48 + // char *bufferNow;
  49 + // char *bufferNowCount;
  50 + AppendBuffer::Buffer *NewABuffer(void);
  51 +
  52 + public:
  53 + void SetBuffer(AppendBuffer::Buffer *buf, const char *str, int len);
  54 + void AppendString(const char *str, int len);
  55 + /* int GetSize();*/
  56 + public:
  57 + int AppendString(const char *str);
  58 + int AddABuffer(void);
  59 +
  60 + //int AppendString(const char * str);
  61 + //int AppendString(const char * str);
  62 + public:
  63 + int AppendOtherOne(AppendBuffer *other);
  64 +
  65 + public:
  66 + void Reset(void);
  67 + };
  68 +
  69 +} // namespace DmapCore_30
  70 +
  71 +#endif // __AppendBuffer_h__
  72 +
... ...
  1 +#include "DataCollection.h"
  2 +#include "clsStruct.h"
  3 +//#include "Geometry.h"
  4 +#include "clsUtil.h"
  5 +#include <stdlib.h>
  6 +
  7 +namespace DmapCore_30
  8 +{
  9 +
  10 + DataCollection::DataCollection()
  11 + {
  12 + m_iPartCount = 0;
  13 + m_iStructType = 0;
  14 + m_pData = 0; //此指针只能够是自定义的6种结构体类型
  15 +
  16 + m_dR = 1;
  17 + m_dScaleDenominator = 1;
  18 + m_dXdis = 1;
  19 + m_dYdis = 1;
  20 +
  21 + m_subset = 0;
  22 +
  23 + m_iN = 0;
  24 + }
  25 +
  26 +
  27 + void DataCollection::InitDataCollection(PGresult *res, int shapeType, int imageWidth, int imageHeight,
  28 + int subset, double r,
  29 + double dScaleDenominator, double x_dis, double y_dis)
  30 + {
  31 + //InitDataCollection();
  32 + m_iN = 1;
  33 + //其他所有变量初始化
  34 + m_iPartCount = PQntuples(res);
  35 + m_dR = r;
  36 + m_dScaleDenominator = dScaleDenominator;
  37 + m_dXdis = x_dis;
  38 + m_dYdis = y_dis;
  39 + m_imageWidth = imageWidth;
  40 + m_imageHeight = imageHeight;
  41 +
  42 + if (subset < 0)
  43 + {
  44 + m_subset = 2;
  45 + }
  46 + else
  47 + {
  48 + m_subset = subset + 2;
  49 + }
  50 +
  51 + this->CollectFieldName(res);
  52 +
  53 + switch (shapeType)
  54 + {
  55 + case GeometryType_Point:
  56 + MallocForPoint(res);
  57 + break;
  58 + case GeometryType_MultiPoint:
  59 + break;
  60 + case GeometryType_LineString:
  61 + MallocForLineStringGeom(res);
  62 + break;
  63 + case GeometryType_MultiLineString:
  64 + MallocForLineStringGeom(res);
  65 + break;
  66 + case GeometryType_Polygon:
  67 + MallocForPolygonForGeom(res);
  68 + break;
  69 + case GeometryType_MultiPolygon:
  70 + MallocForPolygonForGeom(res);
  71 + break;
  72 + default:
  73 +
  74 + break;
  75 + }
  76 + //CollectAllField(res);
  77 + }
  78 +
  79 +
  80 +/*
  81 + void DataCollection::InitDataCollection(Geometry *geom, double r, double dScaleDenominator,
  82 + double x_dis, double y_dis)
  83 + {
  84 + //InitDataCollection();
  85 + m_iN = 1;
  86 + m_iPartCount = 1;
  87 + m_dR = r;
  88 + m_dScaleDenominator = dScaleDenominator;
  89 + m_dXdis = x_dis;
  90 + m_dYdis = y_dis;
  91 +
  92 + int geomType = geom->GeometryType();
  93 + switch (geomType)
  94 + {
  95 + case dmapGeometryPoint:
  96 + {
  97 + Point *p = (Point *)geom;
  98 + this->MallocForPoint(p);
  99 + break;
  100 + }
  101 + case dmapGeometryMultiPoint:
  102 + {
  103 + MultiPoint *mp = (MultiPoint *)geom;
  104 + this->MallocForMultiPoint(mp);
  105 + break;
  106 + }
  107 + case dmapGeometryPath:
  108 + {
  109 + Path *path = (Path *)geom;
  110 + this->MallocForPath(path);
  111 + break;
  112 + }
  113 + case dmapGeometryMultiLineString:
  114 + {
  115 + MultiLineString *ml = (MultiLineString *)geom;
  116 + this->MallocForMultiLineString(ml);
  117 + break;
  118 + }
  119 + case dmapGeometryRing:
  120 + {
  121 + Ring *ring = (Ring *)geom;
  122 + this->MallocForRing(ring);
  123 + break;
  124 + }
  125 + case dmapGeometryPolygon:
  126 + {
  127 + Polygon *pPolygon = (Polygon *)geom;
  128 + this->MallocForPolygon(pPolygon);
  129 + break;
  130 + }
  131 + case dmapGeometryMultiPolygon:
  132 + {
  133 + MultiPolygon *mp = (MultiPolygon *)geom;
  134 + this->MallocForMultiPolygon(mp);
  135 + break;
  136 + }
  137 + default:
  138 + break;
  139 + }
  140 + }*/
  141 +
  142 +
  143 + DataCollection::~DataCollection()
  144 + {
  145 + //cout<<"free begin;" <<endl;
  146 + if (m_pData)
  147 + {
  148 + switch (m_iStructType)
  149 + {
  150 + case clsStruct::Struct_Point:
  151 + {
  152 + this->FreeForPOINT();
  153 + break;
  154 + }
  155 + case clsStruct::Struct_Line:
  156 + {
  157 + this->FreeForLINE();
  158 + break;
  159 + }
  160 + case clsStruct::Struct_MLine:
  161 + {
  162 + this->FreeForMLINE();
  163 + break;
  164 + }
  165 + case clsStruct::Struct_Polygon:
  166 + {
  167 + this->FreeForPOLYGON();
  168 + break;
  169 + }
  170 + case clsStruct::Struct_MPolygon:
  171 + {
  172 + this->FreeForMPOLYGON();
  173 + break;
  174 + }
  175 + default:
  176 + break;
  177 + }
  178 + }
  179 + //cout<<"free end;" <<endl;
  180 + }
  181 +
  182 +
  183 +
  184 + /*
  185 + Malloc PGresult
  186 + */
  187 + bool DataCollection::MallocForPoint(PGresult *res)
  188 + {
  189 + m_iStructType = clsStruct::Struct_Point;
  190 +
  191 + int n_fields = PQnfields(res);
  192 + map<int, PointClass *> map_Point;
  193 +
  194 + for (size_t i = 0; i < m_iPartCount; i++)
  195 + {
  196 + unsigned char *here = (unsigned char *)PQgetvalue(res, i, 0);
  197 + unsigned char hasZorSrsid = ((unsigned char *)(here + 4))[0] / 16;
  198 + unsigned char hasZ = hasZorSrsid / 8;
  199 + unsigned char hasSrsid = hasZorSrsid % 8;
  200 +
  201 + int not_big = here[0];
  202 + here++;
  203 + int shapetype = ((int *)here)[0];
  204 + here += 4;
  205 + if (hasSrsid)
  206 + here += 4;
  207 +
  208 + double x = ((double *)here)[0];
  209 + here += 8; // clsUtil::ReadDouble(here, not_big);
  210 + double y = ((double *)here)[0];
  211 + here += 8; // clsUtil::ReadDouble(here, not_big);
  212 + double x0 = 0, y0 = 0;
  213 + this->ToScale(x, y, x0, y0);
  214 +
  215 + int key = ((int)(x0 / m_subset)) * 10000 + ((int)(y0 / m_subset));
  216 + if (map_Point.find(key) == map_Point.end())
  217 + {
  218 + PointClass *pointClass = new PointClass();
  219 + pointClass->x = x0;
  220 + pointClass->y = y0;
  221 + /*clsStruct::POINT* pp0 = new clsStruct::POINT();
  222 + pp0->x = x0;
  223 + pp0->y = y0;*/
  224 + map_Point[key] = pointClass;
  225 + for (int i0 = 1; i0 < n_fields; i0++)
  226 + {
  227 + char *vc = PQgetvalue(res, i, i0);
  228 + pointClass->m_pdata.push_back(vc);
  229 + }
  230 + }
  231 + }
  232 +
  233 + clsStruct::POINT *pp = (clsStruct::POINT *)malloc(sizeof(clsStruct::POINT) * map_Point.size());
  234 + if (pp == NULL)
  235 + return false;
  236 + int index = 0;
  237 +
  238 + //创建预留空间
  239 + m_vAllField.resize(map_Point.size());
  240 + for (int i = 0; i < map_Point.size(); i++)
  241 + m_vAllField[i].resize(n_fields - 1); //这里是不包含shape 数据的
  242 + //开辟预留空间后, 可以直接赋值,不需要 pushback
  243 +
  244 + for (map<int, PointClass *>::iterator iter = map_Point.begin(); iter != map_Point.end(); iter++)
  245 + {
  246 + PointClass *p = iter->second;
  247 + pp[index].x = p->x;
  248 + pp[index].y = p->y;
  249 + for (int j = 0; j < n_fields - 1; j++) //这里从第二列开始
  250 + {
  251 + m_vAllField[index][j] = p->m_pdata.at(j);
  252 + }
  253 + p->m_pdata.clear();
  254 + delete p;
  255 + iter->second = NULL;
  256 + index++;
  257 + }
  258 +
  259 + this->m_iPartCount = map_Point.size();
  260 +
  261 + map_Point.clear();
  262 +
  263 + m_pData = pp;
  264 + return true;
  265 + }
  266 +
  267 + bool DataCollection::MallocForLineStringGeom(PGresult *res)
  268 + {
  269 + m_iStructType = clsStruct::Struct_MLine;
  270 + // bool isLineZ = false;
  271 + int n_fields = PQnfields(res);
  272 + clsStruct::MLINE *pp = (clsStruct::MLINE *)malloc(sizeof(clsStruct::MLINE) * m_iPartCount);
  273 + if (pp == NULL)
  274 + return false;
  275 + m_vAllField.resize(m_iPartCount);
  276 + for (int i = 0; i < m_iPartCount; i++)
  277 + m_vAllField[i].resize(n_fields - 1); //这里是不包含shape 数据的
  278 +
  279 + for (int i = 0; i < m_iPartCount; i++)
  280 + {
  281 +
  282 + //clsStruct::MLINE ml;
  283 +
  284 + unsigned char *here = (unsigned char *)PQgetvalue(res, i, 0);
  285 + unsigned char geom_type = (here)[1];
  286 + unsigned char hasZorSrsid = ((unsigned char *)(here + 4))[0] / 16;
  287 + unsigned char hasZ = hasZorSrsid / 8;
  288 + unsigned char hasSrsid = hasZorSrsid % 8;
  289 + int not_big = clsUtil::ReadByte(here);
  290 + int shapetype = clsUtil::ReadInt(here, not_big);
  291 + if (hasSrsid)
  292 + here += 4;
  293 + //if (shapetype < 0) isLineZ = true;
  294 + if (geom_type == DCGeometryType::GeometryType_LineString)
  295 + {
  296 + int nLine = 1;//clsUtil::ReadInt(here, not_big);
  297 + clsStruct::LINE *pPath = (clsStruct::LINE *)malloc(sizeof(clsStruct::LINE) * nLine);
  298 + if (pPath == 0)
  299 + continue;
  300 + pp[i].nLine = nLine;
  301 + pp[i].p = pPath;
  302 +
  303 + for (int j = 0; j < nLine; j++)
  304 + {
  305 + //clsStruct::LINE path;
  306 +
  307 + //int not_big2 = clsUtil::ReadByte(here);
  308 + //here += 4; //跳过 shapetype 读取
  309 +
  310 + int nPoint = clsUtil::ReadInt(here, not_big);
  311 + clsStruct::POINT *pPoint = (clsStruct::POINT *)malloc(sizeof(clsStruct::POINT) * nPoint);
  312 + if (pPoint == 0)
  313 + continue;
  314 + pPath[j].nPoint = nPoint;
  315 + pPath[j].p = pPoint;
  316 +
  317 + for (int k = 0; k < nPoint; k++)
  318 + {
  319 + //clsStruct::POINT point;
  320 +
  321 + double x = clsUtil::ReadDouble(here, not_big);
  322 + double y = clsUtil::ReadDouble(here, not_big);
  323 + if (hasZ)
  324 + {
  325 + //Z 值跳过
  326 + here += 8;
  327 + }
  328 + double x0 = 0, y0 = 0;
  329 + this->ToScale(x, y, x0, y0);
  330 +
  331 + pPoint[k].x = x0;
  332 + pPoint[k].y = y0;
  333 + }
  334 + }
  335 + }
  336 + else if (geom_type == DCGeometryType::GeometryType_MultiLineString)
  337 + {
  338 + int nLine = clsUtil::ReadInt(here, not_big);
  339 + clsStruct::LINE *pPath = (clsStruct::LINE *)malloc(sizeof(clsStruct::LINE) * nLine);
  340 + if (pPath == 0)
  341 + continue;
  342 + pp[i].nLine = nLine;
  343 + pp[i].p = pPath;
  344 +
  345 + for (int j = 0; j < nLine; j++)
  346 + {
  347 + //clsStruct::LINE path;
  348 +
  349 + int not_big2 = clsUtil::ReadByte(here);
  350 + here += 4; //跳过 shapetype 读取
  351 +
  352 + int nPoint = clsUtil::ReadInt(here, not_big2);
  353 + clsStruct::POINT *pPoint = (clsStruct::POINT *)malloc(sizeof(clsStruct::POINT) * nPoint);
  354 + if (pPoint == 0)
  355 + continue;
  356 + pPath[j].nPoint = nPoint;
  357 + pPath[j].p = pPoint;
  358 +
  359 + for (int k = 0; k < nPoint; k++)
  360 + {
  361 + //clsStruct::POINT point;
  362 +
  363 + double x = clsUtil::ReadDouble(here, not_big2);
  364 + double y = clsUtil::ReadDouble(here, not_big2);
  365 + if (hasZ)
  366 + {
  367 + //Z 值跳过
  368 + here += 8;
  369 + }
  370 + double x0 = 0, y0 = 0;
  371 + this->ToScale(x, y, x0, y0);
  372 +
  373 + pPoint[k].x = x0;
  374 + pPoint[k].y = y0;
  375 + }
  376 + }
  377 + }
  378 +
  379 + for (int j = 0; j < n_fields - 1; j++) //这里从第二列开始
  380 + {
  381 + m_vAllField[i][j] = (char *)PQgetvalue(res, i, j + 1);
  382 + }
  383 + /*ml.nLine = nLine;
  384 + ml.p = pPath;
  385 + pp[i] = ml;*/
  386 + }
  387 +
  388 + m_pData = pp;
  389 + return true;
  390 + }
  391 +
  392 + bool DataCollection::MallocForMultiLineString(PGresult *res)
  393 + {
  394 + m_iStructType = clsStruct::Struct_MLine;
  395 + // bool isLineZ = false;
  396 + int n_fields = PQnfields(res);
  397 + clsStruct::MLINE *pp = (clsStruct::MLINE *)malloc(sizeof(clsStruct::MLINE) * m_iPartCount);
  398 + if (pp == NULL)
  399 + return false;
  400 + m_vAllField.resize(m_iPartCount);
  401 + for (int i = 0; i < m_iPartCount; i++)
  402 + m_vAllField[i].resize(n_fields - 1); //这里是不包含shape 数据的
  403 +
  404 + for (int i = 0; i < m_iPartCount; i++)
  405 + {
  406 +
  407 + //clsStruct::MLINE ml;
  408 +
  409 + unsigned char *here = (unsigned char *)PQgetvalue(res, i, 0);
  410 + unsigned char hasZorSrsid = ((unsigned char *)(here + 4))[0] / 16;
  411 + unsigned char hasZ = hasZorSrsid / 8;
  412 + unsigned char hasSrsid = hasZorSrsid % 8;
  413 + int not_big = clsUtil::ReadByte(here);
  414 + int shapetype = clsUtil::ReadInt(here, not_big);
  415 + if (hasSrsid)
  416 + here += 4;
  417 + //if (shapetype < 0) isLineZ = true;
  418 +
  419 + int nLine = clsUtil::ReadInt(here, not_big);
  420 + clsStruct::LINE *pPath = (clsStruct::LINE *)malloc(sizeof(clsStruct::LINE) * nLine);
  421 + if (pPath == 0)
  422 + continue;
  423 + pp[i].nLine = nLine;
  424 + pp[i].p = pPath;
  425 +
  426 + for (int j = 0; j < nLine; j++)
  427 + {
  428 + //clsStruct::LINE path;
  429 +
  430 + int not_big2 = clsUtil::ReadByte(here);
  431 + here += 4; //跳过 shapetype 读取
  432 +
  433 + int nPoint = clsUtil::ReadInt(here, not_big2);
  434 + clsStruct::POINT *pPoint = (clsStruct::POINT *)malloc(sizeof(clsStruct::POINT) * nPoint);
  435 + if (pPoint == 0)
  436 + continue;
  437 + pPath[j].nPoint = nPoint;
  438 + pPath[j].p = pPoint;
  439 +
  440 + for (int k = 0; k < nPoint; k++)
  441 + {
  442 + //clsStruct::POINT point;
  443 +
  444 + double x = clsUtil::ReadDouble(here, not_big2);
  445 + double y = clsUtil::ReadDouble(here, not_big2);
  446 + if (hasZ)
  447 + {
  448 + //Z 值跳过
  449 + here += 8;
  450 + }
  451 + double x0 = 0, y0 = 0;
  452 + this->ToScale(x, y, x0, y0);
  453 +
  454 + pPoint[k].x = x0;
  455 + pPoint[k].y = y0;
  456 + }
  457 +
  458 + /*path.nPoint = nPoint;
  459 + path.p = pPoint;
  460 + pPath[j] = path;*/
  461 + }
  462 + for (int j = 0; j < n_fields - 1; j++) //这里从第二列开始
  463 + {
  464 + m_vAllField[i][j] = (char *)PQgetvalue(res, i, j + 1);
  465 + }
  466 + /*ml.nLine = nLine;
  467 + ml.p = pPath;
  468 + pp[i] = ml;*/
  469 + }
  470 +
  471 + m_pData = pp;
  472 + return true;
  473 + }
  474 +
  475 +
  476 +
  477 + bool DataCollection::PolygonIsLessThanOnePixel(unsigned char *here, int not_big1)
  478 + {
  479 + double dpix = 1 / this->m_dR;
  480 + here += 9;
  481 + int npolygonCount = clsUtil::ReadInt(here, not_big1);
  482 +
  483 + double x0 = clsUtil::ReadDouble(here, not_big1);
  484 + double y0 = clsUtil::ReadDouble(here, not_big1);
  485 +
  486 + if (npolygonCount < 6)
  487 + {
  488 + int step = (npolygonCount / 2);
  489 + here += step * 16;
  490 + double x = clsUtil::ReadDouble(here, not_big1);
  491 + double y = clsUtil::ReadDouble(here, not_big1);
  492 + if (abs(x - x0) < dpix && abs(y - y0) < dpix)
  493 + {
  494 + return true;
  495 + }
  496 + }
  497 + else if (npolygonCount < 35)
  498 + {
  499 + int step = (npolygonCount / 3);
  500 + here += step * 16;
  501 + double x1 = clsUtil::ReadDouble(here, not_big1);
  502 + double y1 = clsUtil::ReadDouble(here, not_big1);
  503 +
  504 + here += step * 16;
  505 + double x2 = clsUtil::ReadDouble(here, not_big1);
  506 + double y2 = clsUtil::ReadDouble(here, not_big1);
  507 + if (abs(x1 - x0) < dpix && abs(y1 - y0) < dpix &&
  508 + abs(x2 - x0) < dpix && abs(y2 - y0) < dpix)
  509 + {
  510 + return true;
  511 + }
  512 + }
  513 + else
  514 + {
  515 + for (int step = 10; step < npolygonCount; step += 11)
  516 + {
  517 + here += 10 * 16;
  518 + double x1 = clsUtil::ReadDouble(here, not_big1);
  519 + double y1 = clsUtil::ReadDouble(here, not_big1);
  520 + if (abs(x1 - x0) > dpix || abs(y1 - y0) > dpix)
  521 + {
  522 + return false;
  523 + }
  524 + }
  525 +
  526 + return true;
  527 + }
  528 + return false;
  529 + }
  530 +
  531 + bool DataCollection::MallocForPolygonForGeom(PGresult *res)
  532 + {
  533 + bool allPolygonToPoint = false;
  534 +
  535 + if (m_imageWidth > 0 && m_imageHeight > 0)
  536 + {
  537 + allPolygonToPoint = m_iPartCount > (m_imageWidth * m_imageHeight / 8);
  538 + }
  539 +
  540 + //double maxcount = (d1* d2)/1.5;
  541 + //bool isPolygonZ = false;
  542 + m_iStructType = clsStruct::Struct_MPolygon;
  543 + int n_fields = PQnfields(res);
  544 +
  545 + clsStruct::MPOLYGON *pp = (clsStruct::MPOLYGON *)malloc(sizeof(clsStruct::MPOLYGON) * m_iPartCount);
  546 + if (pp == NULL)
  547 + return false;
  548 + m_vAllField.resize(m_iPartCount);
  549 + for (int i = 0; i < m_iPartCount; i++)
  550 + m_vAllField[i].resize(n_fields - 1); //这里是不包含shape 数据的
  551 +
  552 + for (int i = 0; i < m_iPartCount; i++)
  553 + {
  554 +
  555 + int not_big1, not_big2, shapetype1, nring, npoint, srid;
  556 + unsigned char *here = (unsigned char *)PQgetvalue(res, i, 0);
  557 +
  558 + unsigned char geom_type = (here)[1];
  559 + unsigned char hasZorSrsid = ((unsigned char *)(here + 4))[0] / 16;
  560 + unsigned char hasZ = hasZorSrsid / 8;
  561 + unsigned char hasSrsid = hasZorSrsid % 8;
  562 + // printf("%d %d \r\n",i,geom_type );
  563 + not_big1 = clsUtil::ReadByte(here);
  564 + shapetype1 = clsUtil::ReadInt(here, not_big1);
  565 + if (hasSrsid)
  566 + srid = clsUtil::ReadInt(here, not_big1); //跳过srid
  567 + //if (shapetype1 < 0) isPolygonZ = true;
  568 + if (geom_type == DCGeometryType::GeometryType_Point)
  569 + {
  570 + double x = clsUtil::ReadDouble(here, not_big1);
  571 + double y = clsUtil::ReadDouble(here, not_big1);
  572 + clsStruct::POLYGON *pPgon = (clsStruct::POLYGON *)malloc(sizeof(clsStruct::POLYGON));
  573 + if (pPgon == NULL)
  574 + {
  575 + free(pp);
  576 + pp = 0;
  577 + break;
  578 + }
  579 +
  580 + clsStruct::LINE *pRing = (clsStruct::LINE *)malloc(sizeof(clsStruct::LINE));
  581 + if (pRing == NULL)
  582 + {
  583 + free(pp);
  584 + pp = 0;
  585 + free(pPgon);
  586 + pPgon = 0;
  587 + break;
  588 + }
  589 +
  590 + pPgon[0].nRing = 1;
  591 + pPgon[0].p = pRing;
  592 +
  593 + clsStruct::POINT *pPoint = (clsStruct::POINT *)malloc(sizeof(clsStruct::POINT));
  594 +
  595 + pRing[0].nPoint = 1;
  596 + pRing[0].p = pPoint;
  597 +
  598 + double x0 = 0, y0 = 0;
  599 + this->ToScale(x, y, x0, y0);
  600 + pPoint[0].x = x0;
  601 + pPoint[0].y = y0;
  602 +
  603 + pp[i].nPolygon = 1;
  604 + pp[i].p = pPgon;
  605 + }
  606 + else if (geom_type == DCGeometryType::GeometryType_Polygon)
  607 + {
  608 + clsStruct::POLYGON *pPgon = (clsStruct::POLYGON *)malloc(sizeof(clsStruct::POLYGON) * 1);
  609 + //clsStruct::MPOLYGON mpgon;
  610 + if (pPgon == NULL)
  611 + continue;
  612 + pp[i].nPolygon = 1;
  613 + pp[i].p = pPgon;
  614 +
  615 + //for (int j = 0; j < npolygon; j++)
  616 + {
  617 + //not_big2 = clsUtil::ReadByte(here);
  618 + //here += 4; //跳过 shapetype, 没意义, 必然是polygon
  619 +
  620 + nring = clsUtil::ReadInt(here, not_big1);
  621 + clsStruct::LINE *pRing = (clsStruct::LINE *)malloc(sizeof(clsStruct::LINE) * nring);
  622 + if (pRing == NULL)
  623 + break;
  624 + pPgon[0].nRing = nring;
  625 + pPgon[0].p = pRing;
  626 +
  627 + for (int k = 0; k < nring; k++)
  628 + {
  629 + npoint = clsUtil::ReadInt(here, not_big1);
  630 + clsStruct::POINT *pPoint = (clsStruct::POINT *)malloc(sizeof(clsStruct::POINT) * npoint);
  631 + if (pPoint == NULL)
  632 + break;
  633 + pRing[k].nPoint = npoint;
  634 + pRing[k].p = pPoint;
  635 + //clsStruct::LINE ring;
  636 +
  637 + for (int m = 0; m < npoint; m++)
  638 + {
  639 + double x = clsUtil::ReadDouble(here, not_big1);
  640 + double y = clsUtil::ReadDouble(here, not_big1);
  641 + if (hasZ)
  642 + {
  643 + //Z 值跳过
  644 + here += 8;
  645 + }
  646 + double x0 = 0, y0 = 0;
  647 + this->ToScale(x, y, x0, y0);
  648 +
  649 + pPoint[m].x = x0;
  650 + pPoint[m].y = y0;
  651 + }
  652 + }
  653 + }
  654 + }
  655 + else if (geom_type == DCGeometryType::GeometryType_MultiPolygon)
  656 + {
  657 + int npolygon = clsUtil::ReadInt(here, not_big1);
  658 +
  659 + if (PolygonIsLessThanOnePixel(here, not_big1))
  660 + {
  661 + //here += 4;
  662 + //npolygon = clsUtil::ReadInt(here, not_big1)
  663 + not_big2 = clsUtil::ReadByte(here);
  664 + here += 12;
  665 + double x = clsUtil::ReadDouble(here, not_big2);
  666 + double y = clsUtil::ReadDouble(here, not_big2);
  667 + clsStruct::POLYGON *pPgon = (clsStruct::POLYGON *)malloc(sizeof(clsStruct::POLYGON));
  668 + if (pPgon == NULL)
  669 + {
  670 + free(pp);
  671 + pp = 0;
  672 + break;
  673 + }
  674 +
  675 + clsStruct::LINE *pRing = (clsStruct::LINE *)malloc(sizeof(clsStruct::LINE));
  676 + if (pRing == NULL)
  677 + {
  678 + free(pp);
  679 + pp = 0;
  680 + free(pPgon);
  681 + pPgon = 0;
  682 + break;
  683 + }
  684 +
  685 + pPgon[0].nRing = 1;
  686 + pPgon[0].p = pRing;
  687 +
  688 + clsStruct::POINT *pPoint = (clsStruct::POINT *)malloc(sizeof(clsStruct::POINT));
  689 +
  690 + pRing[0].nPoint = 1;
  691 + pRing[0].p = pPoint;
  692 +
  693 + double x0 = 0, y0 = 0;
  694 + this->ToScale(x, y, x0, y0);
  695 + pPoint[0].x = x0;
  696 + pPoint[0].y = y0;
  697 +
  698 + pp[i].nPolygon = 1;
  699 + pp[i].p = pPgon;
  700 + }
  701 + else
  702 + {
  703 +
  704 + clsStruct::POLYGON *pPgon = (clsStruct::POLYGON *)malloc(sizeof(clsStruct::POLYGON) * npolygon);
  705 + //clsStruct::MPOLYGON mpgon;
  706 + if (pPgon == NULL)
  707 + continue;
  708 + pp[i].nPolygon = npolygon;
  709 + pp[i].p = pPgon;
  710 +
  711 + for (int j = 0; j < npolygon; j++)
  712 + {
  713 + not_big2 = clsUtil::ReadByte(here);
  714 + here += 4; //跳过 shapetype, 没意义, 必然是polygon
  715 +
  716 + nring = clsUtil::ReadInt(here, not_big2);
  717 + clsStruct::LINE *pRing = (clsStruct::LINE *)malloc(sizeof(clsStruct::LINE) * nring);
  718 + if (pRing == NULL)
  719 + break;
  720 + pPgon[j].nRing = nring;
  721 + pPgon[j].p = pRing;
  722 + //clsStruct::POLYGON pgon;
  723 +
  724 + for (int k = 0; k < nring; k++)
  725 + {
  726 + npoint = clsUtil::ReadInt(here, not_big2);
  727 + clsStruct::POINT *pPoint = (clsStruct::POINT *)malloc(sizeof(clsStruct::POINT) * npoint);
  728 + if (pPoint == NULL)
  729 + break;
  730 + pRing[k].nPoint = npoint;
  731 + pRing[k].p = pPoint;
  732 + //clsStruct::LINE ring;
  733 +
  734 + for (int m = 0; m < npoint; m++)
  735 + {
  736 + double x = clsUtil::ReadDouble(here, not_big2);
  737 + double y = clsUtil::ReadDouble(here, not_big2);
  738 + if (hasZ)
  739 + {
  740 + //Z 值跳过
  741 + here += 8;
  742 + }
  743 + double x0 = 0, y0 = 0;
  744 + this->ToScale(x, y, x0, y0);
  745 +
  746 + pPoint[m].x = x0;
  747 + pPoint[m].y = y0;
  748 + }
  749 + }
  750 + }
  751 + }
  752 + }
  753 +
  754 + for (int j = 0; j < n_fields - 1; j++) //这里从第二列开始
  755 + {
  756 + m_vAllField[i][j] = (char *)PQgetvalue(res, i, j + 1);
  757 + }
  758 + }
  759 +
  760 + m_pData = pp;
  761 + return true;
  762 + }
  763 +
  764 + bool DataCollection::MallocForPolygon(PGresult *res)
  765 + {
  766 +
  767 + //double d1 = (queryX2 - queryX1)*m_dR;
  768 + //double d2 = (queryY2 - queryY1)*m_dR;
  769 +
  770 + bool allPolygonToPoint = false;
  771 +
  772 + if (m_imageWidth > 0 && m_imageHeight > 0)
  773 + {
  774 + allPolygonToPoint = m_iPartCount > (m_imageWidth * m_imageHeight / 8);
  775 + }
  776 +
  777 + //double maxcount = (d1* d2)/1.5;
  778 + //bool isPolygonZ = false;
  779 + m_iStructType = clsStruct::Struct_MPolygon;
  780 + int n_fields = PQnfields(res);
  781 +
  782 + clsStruct::MPOLYGON *pp = (clsStruct::MPOLYGON *)malloc(sizeof(clsStruct::MPOLYGON) * m_iPartCount);
  783 + if (pp == NULL)
  784 + return false;
  785 + m_vAllField.resize(m_iPartCount);
  786 + for (int i = 0; i < m_iPartCount; i++)
  787 + m_vAllField[i].resize(n_fields - 1); //这里是不包含shape 数据的
  788 +
  789 + for (int i = 0; i < m_iPartCount; i++)
  790 + {
  791 +
  792 + int not_big1, not_big2, shapetype1, nring, npoint;
  793 + // unsigned char *here1 = (unsigned char *)PQgetvalue(res, i, 0);
  794 + // shared_ptr<PolygonClass> dd = GetDataPolygon(here1);
  795 + // continue;
  796 + unsigned char *here = (unsigned char *)PQgetvalue(res, i, 0);
  797 +
  798 + unsigned char geom_type = (here)[1];
  799 + unsigned char hasZorSrsid = ((unsigned char *)(here + 4))[0] / 16;
  800 + unsigned char hasZ = hasZorSrsid / 8;
  801 + unsigned char hasSrsid = hasZorSrsid % 8;
  802 +
  803 + not_big1 = clsUtil::ReadByte(here);
  804 + shapetype1 = clsUtil::ReadInt(here, not_big1);
  805 + if (hasSrsid)
  806 + shapetype1 = clsUtil::ReadInt(here, not_big1); //跳过srid
  807 + //if (shapetype1 < 0) isPolygonZ = true;
  808 + if (geom_type == DCGeometryType::GeometryType_Point)
  809 + {
  810 + double x = clsUtil::ReadDouble(here, not_big1);
  811 + double y = clsUtil::ReadDouble(here, not_big1);
  812 + clsStruct::POLYGON *pPgon = (clsStruct::POLYGON *)malloc(sizeof(clsStruct::POLYGON));
  813 + if (pPgon == NULL)
  814 + {
  815 + free(pp);
  816 + pp = 0;
  817 + break;
  818 + }
  819 +
  820 + clsStruct::LINE *pRing = (clsStruct::LINE *)malloc(sizeof(clsStruct::LINE));
  821 + if (pRing == NULL)
  822 + {
  823 + free(pp);
  824 + pp = 0;
  825 + free(pPgon);
  826 + pPgon = 0;
  827 + break;
  828 + }
  829 +
  830 + pPgon[0].nRing = 1;
  831 + pPgon[0].p = pRing;
  832 +
  833 + clsStruct::POINT *pPoint = (clsStruct::POINT *)malloc(sizeof(clsStruct::POINT));
  834 +
  835 + pRing[0].nPoint = 1;
  836 + pRing[0].p = pPoint;
  837 +
  838 + double x0 = 0, y0 = 0;
  839 + this->ToScale(x, y, x0, y0);
  840 + pPoint[0].x = x0;
  841 + pPoint[0].y = y0;
  842 +
  843 + pp[i].nPolygon = 1;
  844 + pp[i].p = pPgon;
  845 + }
  846 + else
  847 + {
  848 + //nring = clsUtil::ReadInt(here, not_big1);
  849 + //npolygon = clsUtil::ReadInt(here, not_big1);
  850 +
  851 + if (false)
  852 + {
  853 + //here += 4;
  854 + //npolygon = clsUtil::ReadInt(here, not_big1)
  855 + not_big2 = clsUtil::ReadByte(here);
  856 + here += 12;
  857 + double x = clsUtil::ReadDouble(here, not_big2);
  858 + double y = clsUtil::ReadDouble(here, not_big2);
  859 + clsStruct::POLYGON *pPgon = (clsStruct::POLYGON *)malloc(sizeof(clsStruct::POLYGON));
  860 + if (pPgon == NULL)
  861 + {
  862 + free(pp);
  863 + pp = 0;
  864 + break;
  865 + }
  866 +
  867 + clsStruct::LINE *pRing = (clsStruct::LINE *)malloc(sizeof(clsStruct::LINE));
  868 + if (pRing == NULL)
  869 + {
  870 + free(pp);
  871 + pp = 0;
  872 + free(pPgon);
  873 + pPgon = 0;
  874 + break;
  875 + }
  876 +
  877 + pPgon[0].nRing = 1;
  878 + pPgon[0].p = pRing;
  879 +
  880 + clsStruct::POINT *pPoint = (clsStruct::POINT *)malloc(sizeof(clsStruct::POINT));
  881 +
  882 + pRing[0].nPoint = 1;
  883 + pRing[0].p = pPoint;
  884 +
  885 + double x0 = 0, y0 = 0;
  886 + this->ToScale(x, y, x0, y0);
  887 + pPoint[0].x = x0;
  888 + pPoint[0].y = y0;
  889 +
  890 + pp[i].nPolygon = 1;
  891 + pp[i].p = pPgon;
  892 + }
  893 + else
  894 + {
  895 +
  896 + clsStruct::POLYGON *pPgon = (clsStruct::POLYGON *)malloc(sizeof(clsStruct::POLYGON) * 1);
  897 + //clsStruct::MPOLYGON mpgon;
  898 + if (pPgon == NULL)
  899 + continue;
  900 + pp[i].nPolygon = 1;
  901 + pp[i].p = pPgon;
  902 +
  903 + //for (int j = 0; j < npolygon; j++)
  904 + {
  905 + //not_big2 = clsUtil::ReadByte(here);
  906 + //here += 4; //跳过 shapetype, 没意义, 必然是polygon
  907 +
  908 + nring = clsUtil::ReadInt(here, not_big2);
  909 + clsStruct::LINE *pRing = (clsStruct::LINE *)malloc(sizeof(clsStruct::LINE) * nring);
  910 + if (pRing == NULL)
  911 + break;
  912 + pPgon[0].nRing = nring;
  913 + pPgon[0].p = pRing;
  914 +
  915 + for (int k = 0; k < nring; k++)
  916 + {
  917 + npoint = clsUtil::ReadInt(here, not_big2);
  918 + clsStruct::POINT *pPoint = (clsStruct::POINT *)malloc(sizeof(clsStruct::POINT) * npoint);
  919 + if (pPoint == NULL)
  920 + break;
  921 + pRing[k].nPoint = npoint;
  922 + pRing[k].p = pPoint;
  923 + //clsStruct::LINE ring;
  924 +
  925 + for (int m = 0; m < npoint; m++)
  926 + {
  927 + double x = clsUtil::ReadDouble(here, not_big2);
  928 + double y = clsUtil::ReadDouble(here, not_big2);
  929 + if (hasZ)
  930 + {
  931 + //Z 值跳过
  932 + here += 8;
  933 + }
  934 + double x0 = 0, y0 = 0;
  935 + this->ToScale(x, y, x0, y0);
  936 +
  937 + pPoint[m].x = x0;
  938 + pPoint[m].y = y0;
  939 + }
  940 + }
  941 + }
  942 + }
  943 + }
  944 +
  945 + for (int j = 0; j < n_fields - 1; j++) //这里从第二列开始
  946 + {
  947 + m_vAllField[i][j] = (char *)PQgetvalue(res, i, j + 1);
  948 + }
  949 + }
  950 +
  951 + m_pData = pp;
  952 + return true;
  953 + }
  954 +
  955 + bool DataCollection::MallocForMultiPolygon(PGresult *res)
  956 + {
  957 +
  958 + //double d1 = (queryX2 - queryX1)*m_dR;
  959 + //double d2 = (queryY2 - queryY1)*m_dR;
  960 +
  961 + bool allPolygonToPoint = false;
  962 +
  963 + if (m_imageWidth > 0 && m_imageHeight > 0)
  964 + {
  965 + allPolygonToPoint = m_iPartCount > (m_imageWidth * m_imageHeight / 8);
  966 + }
  967 +
  968 + //double maxcount = (d1* d2)/1.5;
  969 + //bool isPolygonZ = false;
  970 + m_iStructType = clsStruct::Struct_MPolygon;
  971 + int n_fields = PQnfields(res);
  972 +
  973 + clsStruct::MPOLYGON *pp = (clsStruct::MPOLYGON *)malloc(sizeof(clsStruct::MPOLYGON) * m_iPartCount);
  974 + if (pp == NULL)
  975 + return false;
  976 + m_vAllField.resize(m_iPartCount);
  977 + for (int i = 0; i < m_iPartCount; i++)
  978 + m_vAllField[i].resize(n_fields - 1); //这里是不包含shape 数据的
  979 +
  980 + for (int i = 0; i < m_iPartCount; i++)
  981 + {
  982 +
  983 + int not_big1, not_big2, shapetype1, npolygon, nring, npoint;
  984 + unsigned char *here = (unsigned char *)PQgetvalue(res, i, 0);
  985 + unsigned char geom_type = (here)[1];
  986 + unsigned char hasZorSrsid = ((unsigned char *)(here + 4))[0] / 16;
  987 + unsigned char hasZ = hasZorSrsid / 8;
  988 + unsigned char hasSrsid = hasZorSrsid % 8;
  989 + not_big1 = clsUtil::ReadByte(here);
  990 + shapetype1 = clsUtil::ReadInt(here, not_big1);
  991 + if (hasSrsid)
  992 + here += 4; //跳过srid
  993 + //if (shapetype1 < 0) isPolygonZ = true;
  994 + if (geom_type == DCGeometryType::GeometryType_Point)
  995 + {
  996 + double x = clsUtil::ReadDouble(here, not_big1);
  997 + double y = clsUtil::ReadDouble(here, not_big1);
  998 + clsStruct::POLYGON *pPgon = (clsStruct::POLYGON *)malloc(sizeof(clsStruct::POLYGON));
  999 + if (pPgon == NULL)
  1000 + {
  1001 + free(pp);
  1002 + pp = 0;
  1003 + break;
  1004 + }
  1005 +
  1006 + clsStruct::LINE *pRing = (clsStruct::LINE *)malloc(sizeof(clsStruct::LINE));
  1007 + if (pRing == NULL)
  1008 + {
  1009 + free(pp);
  1010 + pp = 0;
  1011 + free(pPgon);
  1012 + pPgon = 0;
  1013 + break;
  1014 + }
  1015 +
  1016 + pPgon[0].nRing = 1;
  1017 + pPgon[0].p = pRing;
  1018 +
  1019 + clsStruct::POINT *pPoint = (clsStruct::POINT *)malloc(sizeof(clsStruct::POINT));
  1020 +
  1021 + pRing[0].nPoint = 1;
  1022 + pRing[0].p = pPoint;
  1023 +
  1024 + double x0 = 0, y0 = 0;
  1025 + this->ToScale(x, y, x0, y0);
  1026 + pPoint[0].x = x0;
  1027 + pPoint[0].y = y0;
  1028 +
  1029 + pp[i].nPolygon = 1;
  1030 + pp[i].p = pPgon;
  1031 + }
  1032 + else
  1033 + {
  1034 + npolygon = clsUtil::ReadInt(here, not_big1);
  1035 +
  1036 + if (PolygonIsLessThanOnePixel(here, not_big1))
  1037 + {
  1038 + //here += 4;
  1039 + //npolygon = clsUtil::ReadInt(here, not_big1)
  1040 + not_big2 = clsUtil::ReadByte(here);
  1041 + here += 12;
  1042 + double x = clsUtil::ReadDouble(here, not_big2);
  1043 + double y = clsUtil::ReadDouble(here, not_big2);
  1044 + clsStruct::POLYGON *pPgon = (clsStruct::POLYGON *)malloc(sizeof(clsStruct::POLYGON));
  1045 + if (pPgon == NULL)
  1046 + {
  1047 + free(pp);
  1048 + pp = 0;
  1049 + break;
  1050 + }
  1051 +
  1052 + clsStruct::LINE *pRing = (clsStruct::LINE *)malloc(sizeof(clsStruct::LINE));
  1053 + if (pRing == NULL)
  1054 + {
  1055 + free(pp);
  1056 + pp = 0;
  1057 + free(pPgon);
  1058 + pPgon = 0;
  1059 + break;
  1060 + }
  1061 +
  1062 + pPgon[0].nRing = 1;
  1063 + pPgon[0].p = pRing;
  1064 +
  1065 + clsStruct::POINT *pPoint = (clsStruct::POINT *)malloc(sizeof(clsStruct::POINT));
  1066 +
  1067 + pRing[0].nPoint = 1;
  1068 + pRing[0].p = pPoint;
  1069 +
  1070 + double x0 = 0, y0 = 0;
  1071 + this->ToScale(x, y, x0, y0);
  1072 + pPoint[0].x = x0;
  1073 + pPoint[0].y = y0;
  1074 +
  1075 + pp[i].nPolygon = 1;
  1076 + pp[i].p = pPgon;
  1077 + }
  1078 + else
  1079 + {
  1080 +
  1081 + clsStruct::POLYGON *pPgon = (clsStruct::POLYGON *)malloc(sizeof(clsStruct::POLYGON) * npolygon);
  1082 + //clsStruct::MPOLYGON mpgon;
  1083 + if (pPgon == NULL)
  1084 + continue;
  1085 + pp[i].nPolygon = npolygon;
  1086 + pp[i].p = pPgon;
  1087 +
  1088 + for (int j = 0; j < npolygon; j++)
  1089 + {
  1090 + not_big2 = clsUtil::ReadByte(here);
  1091 + here += 4; //跳过 shapetype, 没意义, 必然是polygon
  1092 +
  1093 + nring = clsUtil::ReadInt(here, not_big2);
  1094 + clsStruct::LINE *pRing = (clsStruct::LINE *)malloc(sizeof(clsStruct::LINE) * nring);
  1095 + if (pRing == NULL)
  1096 + break;
  1097 + pPgon[j].nRing = nring;
  1098 + pPgon[j].p = pRing;
  1099 + //clsStruct::POLYGON pgon;
  1100 +
  1101 + for (int k = 0; k < nring; k++)
  1102 + {
  1103 + npoint = clsUtil::ReadInt(here, not_big2);
  1104 + clsStruct::POINT *pPoint = (clsStruct::POINT *)malloc(sizeof(clsStruct::POINT) * npoint);
  1105 + if (pPoint == NULL)
  1106 + break;
  1107 + pRing[k].nPoint = npoint;
  1108 + pRing[k].p = pPoint;
  1109 + //clsStruct::LINE ring;
  1110 +
  1111 + for (int m = 0; m < npoint; m++)
  1112 + {
  1113 + double x = clsUtil::ReadDouble(here, not_big2);
  1114 + double y = clsUtil::ReadDouble(here, not_big2);
  1115 + if (hasZ)
  1116 + {
  1117 + //Z 值跳过
  1118 + here += 8;
  1119 + }
  1120 + double x0 = 0, y0 = 0;
  1121 + this->ToScale(x, y, x0, y0);
  1122 +
  1123 + pPoint[m].x = x0;
  1124 + pPoint[m].y = y0;
  1125 + }
  1126 + }
  1127 + }
  1128 + }
  1129 + }
  1130 +
  1131 + for (int j = 0; j < n_fields - 1; j++) //这里从第二列开始
  1132 + {
  1133 + m_vAllField[i][j] = (char *)PQgetvalue(res, i, j + 1);
  1134 + }
  1135 + }
  1136 +
  1137 + m_pData = pp;
  1138 + return true;
  1139 + }
  1140 +
  1141 +/*
  1142 + bool DataCollection::MallocForPoint(Point *p)
  1143 + {
  1144 + m_iStructType = clsStruct::Struct_Point;
  1145 +
  1146 + clsStruct::POINT *pp = (clsStruct::POINT *)malloc(sizeof(clsStruct::POINT));
  1147 + if (pp == NULL)
  1148 + return false;
  1149 + double x = p->m_dX;
  1150 + double y = p->m_dY;
  1151 + double x0 = 0, y0 = 0;
  1152 + this->ToScale(x, y, x0, y0);
  1153 +
  1154 + pp[0].x = x0;
  1155 + pp[0].y = y0;
  1156 +
  1157 + m_pData = pp;
  1158 + return true;
  1159 + }
  1160 + bool DataCollection::MallocForMultiPoint(MultiPoint *mp)
  1161 + {
  1162 + m_iStructType = clsStruct::Struct_Line;
  1163 +
  1164 + clsStruct::LINE *pp = (clsStruct::LINE *)malloc(sizeof(clsStruct::LINE));
  1165 + if (pp == NULL)
  1166 + return false;
  1167 + int npoint = (int)(mp->m_vX.size());
  1168 + clsStruct::POINT *pPoint = (clsStruct::POINT *)malloc(sizeof(clsStruct::POINT) * npoint);
  1169 + if (pPoint == NULL)
  1170 + return false;
  1171 + pp->nPoint = npoint;
  1172 + pp->p = pPoint;
  1173 +
  1174 + for (int i = 0; i < npoint; i++)
  1175 + {
  1176 + double x = mp->m_vX[i];
  1177 + double y = mp->m_vY[i];
  1178 + double x0 = 0, y0 = 0;
  1179 + this->ToScale(x, y, x0, y0);
  1180 +
  1181 + pPoint[i].x = x0;
  1182 + pPoint[i].y = y0;
  1183 + }
  1184 +
  1185 + m_pData = pp;
  1186 + return true;
  1187 + }
  1188 + bool DataCollection::MallocForPath(Path *path)
  1189 + {
  1190 + m_iStructType = clsStruct::Struct_Line;
  1191 +
  1192 + clsStruct::LINE *pp = (clsStruct::LINE *)malloc(sizeof(clsStruct::LINE));
  1193 + if (pp == NULL)
  1194 + return false;
  1195 + int npoint = (int)(path->m_vX.size());
  1196 + clsStruct::POINT *pPoint = (clsStruct::POINT *)malloc(sizeof(clsStruct::POINT) * npoint);
  1197 + if (pPoint == NULL)
  1198 + return false;
  1199 + pp->nPoint = npoint;
  1200 + pp->p = pPoint;
  1201 +
  1202 + for (int i = 0; i < npoint; i++)
  1203 + {
  1204 + double x = path->m_vX[i];
  1205 + double y = path->m_vY[i];
  1206 + double x0 = 0, y0 = 0;
  1207 + this->ToScale(x, y, x0, y0);
  1208 +
  1209 + pPoint[i].x = x0;
  1210 + pPoint[i].y = y0;
  1211 + }
  1212 +
  1213 + m_pData = pp;
  1214 + return true;
  1215 + }
  1216 + bool DataCollection::MallocForMultiLineString(MultiLineString *ml)
  1217 + {
  1218 + m_iStructType = clsStruct::Struct_MLine;
  1219 +
  1220 + clsStruct::MLINE *pp = (clsStruct::MLINE *)malloc(sizeof(clsStruct::MLINE));
  1221 + if (pp == NULL)
  1222 + return false;
  1223 + int nLine = (int)(ml->m_vLineX.size());
  1224 + clsStruct::LINE *pPath = (clsStruct::LINE *)(malloc(sizeof(clsStruct::LINE) * nLine));
  1225 + if (pPath == NULL)
  1226 + {
  1227 + free(pp);
  1228 + pp = 0;
  1229 + return false;
  1230 + }
  1231 + pp->nLine = nLine;
  1232 + pp->p = pPath;
  1233 +
  1234 + for (int i = 0; i < nLine; i++)
  1235 + {
  1236 + int nPoint = (int)(ml->m_vLineX[i].size());
  1237 + clsStruct::POINT *pPoint = (clsStruct::POINT *)malloc(sizeof(clsStruct::POINT) * nPoint);
  1238 + if (pPoint == NULL)
  1239 + {
  1240 + pPath[i].nPoint = 0;
  1241 + pPath[i].p = 0;
  1242 + continue;
  1243 + }
  1244 + pPath[i].nPoint = nPoint;
  1245 + pPath[i].p = pPoint;
  1246 +
  1247 + for (int j = 0; j < nPoint; j++)
  1248 + {
  1249 + double x = ml->m_vLineX[i][j];
  1250 + double y = ml->m_vLineY[i][j];
  1251 + double x0 = 0, y0 = 0;
  1252 + this->ToScale(x, y, x0, y0);
  1253 +
  1254 + pPoint[j].x = x0;
  1255 + pPoint[j].y = y0;
  1256 + }
  1257 + }
  1258 +
  1259 + m_pData = pp;
  1260 +
  1261 + return true;
  1262 + }
  1263 + bool DataCollection::MallocForRing(Ring *ring)
  1264 + {
  1265 + m_iStructType = clsStruct::Struct_Line;
  1266 + m_iPartCount = 1;
  1267 + clsStruct::LINE *pp = (clsStruct::LINE *)malloc(sizeof(clsStruct::LINE));
  1268 + if (pp == NULL)
  1269 + return false;
  1270 + int npoint = (int)(ring->m_vX.size());
  1271 + clsStruct::POINT *pPoint = (clsStruct::POINT *)malloc(sizeof(clsStruct::POINT) * npoint);
  1272 + if (pPoint == NULL)
  1273 + {
  1274 + free(pp);
  1275 + pp = 0;
  1276 + return false;
  1277 + }
  1278 + pp->nPoint = npoint;
  1279 + pp->p = pPoint;
  1280 +
  1281 + for (int i = 0; i < npoint; i++)
  1282 + {
  1283 + double x = ring->m_vX[i];
  1284 + double y = ring->m_vY[i];
  1285 + double x0 = 0, y0 = 0;
  1286 + this->ToScale(x, y, x0, y0);
  1287 +
  1288 + pPoint[i].x = x0;
  1289 + pPoint[i].y = y0;
  1290 + }
  1291 + m_pData = pp;
  1292 + return true;
  1293 + }
  1294 +
  1295 + bool DataCollection::MallocForPolygon(Polygon *pPolygon)
  1296 + {
  1297 + m_iStructType = clsStruct::Struct_Polygon;
  1298 + m_iPartCount = 1;
  1299 +
  1300 + clsStruct::POLYGON *pp = (clsStruct::POLYGON *)malloc(sizeof(clsStruct::POLYGON));
  1301 + if (pp == NULL)
  1302 + return false;
  1303 + int nRing = (int)(pPolygon->m_vR.size());
  1304 + clsStruct::LINE *pStRing = (clsStruct::LINE *)malloc(sizeof(clsStruct::LINE) * nRing);
  1305 + if (pStRing == NULL)
  1306 + {
  1307 + free(pp);
  1308 + pp = 0;
  1309 + return false;
  1310 + }
  1311 + pp->nRing = nRing;
  1312 + pp->p = pStRing;
  1313 +
  1314 + for (int i = 0; i < nRing; i++)
  1315 + {
  1316 + Ring *ring = pPolygon->m_vR[i];
  1317 +
  1318 + int nPoint = (int)(ring->m_vX.size());
  1319 + clsStruct::POINT *pStPoint = (clsStruct::POINT *)malloc(sizeof(clsStruct::POINT) * nPoint);
  1320 + if (pStPoint == NULL)
  1321 + {
  1322 + pStRing[i].nPoint = 0;
  1323 + pStRing[i].p = 0;
  1324 + continue;
  1325 + }
  1326 +
  1327 + pStRing[i].nPoint = nPoint;
  1328 + pStRing[i].p = pStPoint;
  1329 + for (int j = 0; j < nPoint; j++)
  1330 + {
  1331 + double x = ring->m_vX[j];
  1332 + double y = ring->m_vY[j];
  1333 + double x0 = 0, y0 = 0;
  1334 + this->ToScale(x, y, x0, y0);
  1335 + pStPoint[j].x = x0;
  1336 + pStPoint[j].y = y0;
  1337 + }
  1338 + }
  1339 + m_pData = pp;
  1340 + return true;
  1341 + }
  1342 +
  1343 + bool DataCollection::MallocForMultiPolygon(MultiPolygon *mp)
  1344 + {
  1345 + m_iPartCount = 1;
  1346 + m_iStructType = clsStruct::Struct_MPolygon;
  1347 + clsStruct::MPOLYGON *pp = (clsStruct::MPOLYGON *)malloc(sizeof(clsStruct::MPOLYGON));
  1348 + if (pp == NULL)
  1349 + return false;
  1350 + int nPolygon = (int)(mp->m_vpPolygon.size());
  1351 + clsStruct::POLYGON *pStPolygon = (clsStruct::POLYGON *)malloc(sizeof(clsStruct::POLYGON) * nPolygon);
  1352 + if (pStPolygon == NULL)
  1353 + {
  1354 + free(pp);
  1355 + pp = 0;
  1356 + return false;
  1357 + }
  1358 + pp->nPolygon = nPolygon;
  1359 + pp->p = pStPolygon;
  1360 +
  1361 + for (int i = 0; i < nPolygon; i++)
  1362 + {
  1363 + Polygon *pPolygon = mp->m_vpPolygon[i];
  1364 +
  1365 + int nRing = (int)(pPolygon->m_vR.size());
  1366 + clsStruct::LINE *pStRing = (clsStruct::LINE *)malloc(sizeof(clsStruct::LINE) * nRing);
  1367 + if (pStRing == NULL)
  1368 + {
  1369 + pStPolygon[i].nRing = 0;
  1370 + pStPolygon[i].p = 0;
  1371 + continue;
  1372 + }
  1373 +
  1374 + pStPolygon[i].nRing = nRing;
  1375 + pStPolygon[i].p = pStRing;
  1376 + for (int j = 0; j < nRing; j++)
  1377 + {
  1378 + Ring *pRing = pPolygon->m_vR[j];
  1379 +
  1380 + int nPoint = (int)(pRing->m_vX.size());
  1381 + clsStruct::POINT *pStPoint = (clsStruct::POINT *)malloc(sizeof(clsStruct::POINT) * nPoint);
  1382 + if (pStPoint == NULL)
  1383 + {
  1384 + pStRing[j].nPoint = 0;
  1385 + pStRing[j].p = 0;
  1386 + continue;
  1387 + }
  1388 + pStRing[j].nPoint = nPoint;
  1389 + pStRing[j].p = pStPoint;
  1390 +
  1391 + for (int k = 0; k < nPoint; k++)
  1392 + {
  1393 + double x = pRing->m_vX[k];
  1394 + double y = pRing->m_vY[k];
  1395 + double x0 = 0, y0 = 0;
  1396 + this->ToScale(x, y, x0, y0);
  1397 + pStPoint[k].x = x0;
  1398 + pStPoint[k].y = y0;
  1399 + }
  1400 + }
  1401 + }
  1402 + m_pData = pp;
  1403 + return true;
  1404 + }*/
  1405 +
  1406 + /*
  1407 + Free
  1408 + */
  1409 + bool DataCollection::FreeForPOINT()
  1410 + {
  1411 + free(m_pData);
  1412 + m_pData = NULL;
  1413 + return true;
  1414 + }
  1415 +
  1416 + bool DataCollection::FreeForLINE()
  1417 + {
  1418 + clsStruct::LINE *pp = (clsStruct::LINE *)m_pData;
  1419 + for (int i = 0; i < m_iPartCount; i++)
  1420 + {
  1421 + free(pp[i].p);
  1422 + }
  1423 + free(m_pData);
  1424 + m_pData = NULL;
  1425 + return true;
  1426 + }
  1427 +
  1428 + bool DataCollection::FreeForMLINE()
  1429 + {
  1430 + clsStruct::MLINE *pp = (clsStruct::MLINE *)m_pData;
  1431 +
  1432 + for (int i = 0; i < m_iPartCount; i++)
  1433 + {
  1434 + int nLine = pp[i].nLine;
  1435 + clsStruct::LINE *pLine = pp[i].p;
  1436 + for (int j = 0; j < nLine; j++)
  1437 + free(pLine[j].p);
  1438 + free(pLine);
  1439 + }
  1440 + free(m_pData);
  1441 + m_pData = NULL;
  1442 + return true;
  1443 + }
  1444 +
  1445 + bool DataCollection::FreeForPOLYGON()
  1446 + {
  1447 + clsStruct::POLYGON *pp = (clsStruct::POLYGON *)m_pData;
  1448 +
  1449 + for (int i = 0; i < m_iPartCount; i++)
  1450 + {
  1451 + int nRing = pp[i].nRing;
  1452 + clsStruct::LINE *pRing = pp[i].p;
  1453 + for (int j = 0; j < nRing; j++)
  1454 + free(pRing[j].p);
  1455 + free(pRing);
  1456 + }
  1457 + free(m_pData);
  1458 + m_pData = NULL;
  1459 + return true;
  1460 + }
  1461 + bool DataCollection::FreeForMPOLYGON()
  1462 + {
  1463 + clsStruct::MPOLYGON *pp = (clsStruct::MPOLYGON *)m_pData;
  1464 +
  1465 + for (int i = 0; i < m_iPartCount; i++)
  1466 + {
  1467 + clsStruct::POLYGON *pPolygon = pp[i].p;
  1468 + int nPolygon = pp[i].nPolygon;
  1469 +
  1470 + for (int j = 0; j < nPolygon; j++)
  1471 + {
  1472 + int nRing = pPolygon[j].nRing;
  1473 + clsStruct::LINE *pRing = pPolygon[j].p;
  1474 +
  1475 + for (int k = 0; k < nRing; k++)
  1476 + free(pRing[k].p);
  1477 +
  1478 + free(pRing);
  1479 + }
  1480 + free(pPolygon);
  1481 + }
  1482 + free(m_pData);
  1483 + m_pData = NULL;
  1484 + return true;
  1485 + }
  1486 +
  1487 + void DataCollection::ToScale(double x, double y, double &x0, double &y0)
  1488 + {
  1489 + x0 = m_dR * x + m_dXdis;
  1490 + y0 = -m_dR * y + m_dYdis;
  1491 + //return true;
  1492 + }
  1493 +
  1494 + bool DataCollection::CollectAllField(PGresult *res)
  1495 + {
  1496 + //直接认为第一列是shape元素,跳过
  1497 + int n_tuples = PQntuples(res);
  1498 + int n_fields = PQnfields(res);
  1499 +
  1500 + //创建预留空间
  1501 + m_vAllField.resize(n_tuples);
  1502 + for (int i = 0; i < n_tuples; i++)
  1503 + m_vAllField[i].resize(n_fields - 1); //这里是不包含shape 数据的
  1504 + //开辟预留空间后, 可以直接赋值,不需要 pushback
  1505 + for (int i = 0; i < n_tuples; i++)
  1506 + {
  1507 + for (int j = 0; j < n_fields - 1; j++) //这里从第二列开始
  1508 + {
  1509 + const char *ss = PQgetvalue(res, i, j + 1);
  1510 + m_vAllField[i][j] = PQgetvalue(res, i, j + 1);
  1511 + }
  1512 + }
  1513 +
  1514 + m_vFieldName.resize(n_fields - 1);
  1515 + for (int i = 0; i < n_fields - 1; i++) //从第二列开始
  1516 + {
  1517 + m_vFieldName[i] = PQfname(res, i + 1);
  1518 + }
  1519 + return true;
  1520 + }
  1521 +
  1522 + bool DataCollection::CollectFieldName(PGresult *res)
  1523 + {
  1524 + //直接认为第一列是shape元素,跳过
  1525 + int n_fields = PQnfields(res);
  1526 + if (n_fields < 2)
  1527 + return false;
  1528 +
  1529 + for (int i = 0; i < n_fields - 1; i++) //从第二列开始
  1530 + {
  1531 + string fieldname = PQfname(res, i + 1);
  1532 + if (fieldname == "geodmap_area")
  1533 + {
  1534 + m_dmapAreaIndex = i;
  1535 + n_fields--;
  1536 + break;
  1537 + }
  1538 + }
  1539 +
  1540 + m_vFieldName.resize(n_fields - 1);
  1541 + for (int i = 0; i < n_fields - 1; i++) //从第二列开始
  1542 + {
  1543 + m_vFieldName[i] = PQfname(res, i + 1);
  1544 + }
  1545 + return true;
  1546 + }
  1547 +
  1548 + shared_ptr<PointClass> DataCollection::GetDataPoint(unsigned char *vc)
  1549 + {
  1550 + unsigned char hasZorSrsid = ((unsigned char *)(vc + 4))[0] / 16;
  1551 + unsigned char hasZ = hasZorSrsid / 8;
  1552 + unsigned char hasSrsid = hasZorSrsid % 8;
  1553 +
  1554 + int not_big = clsUtil::ReadByte(vc);
  1555 + int shapetype = clsUtil::ReadInt(vc, not_big);
  1556 + if (hasSrsid)
  1557 + vc += 4;
  1558 +
  1559 + double x = clsUtil::ReadDouble(vc, not_big);
  1560 + double y = clsUtil::ReadDouble(vc, not_big);
  1561 +
  1562 + shared_ptr<PointClass> point(new PointClass());
  1563 + point->x = x;
  1564 + point->y = y;
  1565 + return point;
  1566 + }
  1567 +
  1568 + shared_ptr<PointClass> DataCollection::GetMDataPoint(unsigned char *vc)
  1569 + {
  1570 + unsigned char hasZorSrsid = ((unsigned char *)(vc + 4))[0] / 16;
  1571 + unsigned char hasZ = hasZorSrsid / 8;
  1572 + unsigned char hasSrsid = hasZorSrsid % 8;
  1573 +
  1574 + int not_big = clsUtil::ReadByte(vc);
  1575 + int shapetype = clsUtil::ReadInt(vc, not_big);
  1576 +
  1577 + if (hasSrsid)
  1578 + {
  1579 + int srsid = clsUtil::ReadInt(vc, not_big);
  1580 + }
  1581 +
  1582 + unsigned char *here = vc;
  1583 +
  1584 + int nPointCount = clsUtil::ReadInt(vc, not_big);
  1585 +
  1586 + for (int j = 0; j < nPointCount; j++)
  1587 + {
  1588 + //clsStruct::LINE path;
  1589 +
  1590 + int not_big2 = clsUtil::ReadByte(vc);
  1591 + vc += 4; //跳过 shapetype 读取
  1592 + double x = clsUtil::ReadDouble(vc, not_big);
  1593 + double y = clsUtil::ReadDouble(vc, not_big);
  1594 +
  1595 + shared_ptr<PointClass> point(new PointClass());
  1596 + point->x = x;
  1597 + point->y = y;
  1598 + return point;
  1599 + }
  1600 + shared_ptr<PointClass> point(new PointClass());
  1601 + return point;
  1602 + }
  1603 +
  1604 + shared_ptr<PolygonClass> DataCollection::GetDataLine(unsigned char *vc)
  1605 + {
  1606 + unsigned char hasZorSrsid = ((unsigned char *)(vc + 4))[0] / 16;
  1607 + unsigned char hasZ = hasZorSrsid / 8;
  1608 + unsigned char hasSrsid = hasZorSrsid % 8;
  1609 +
  1610 + int not_big = clsUtil::ReadByte(vc);
  1611 + int shapetype = clsUtil::ReadInt(vc, not_big);
  1612 + if (hasSrsid)
  1613 + {
  1614 + int srsid = clsUtil::ReadInt(vc, not_big);
  1615 + }
  1616 +
  1617 + shared_ptr<PolygonClass> p_polygon(new PolygonClass());
  1618 + p_polygon->polygonCount = 1;
  1619 + double pol_minx = 1000000000;
  1620 + double pol_miny = 1000000000;
  1621 + double pol_maxx = -100000000;
  1622 + double pol_maxy = -100000000;
  1623 + //pp[i].nLine = nLine;
  1624 + //pp[i].p = pPath;
  1625 +
  1626 + //for (int j = 0; j < nLine; j++)
  1627 + {
  1628 + //clsStruct::LINE path;
  1629 +
  1630 + //int not_big2 = clsUtil::ReadByte(vc);
  1631 + //vc += 4; //跳过 shapetype 读取
  1632 +
  1633 + int nPoint = clsUtil::ReadInt(vc, not_big);
  1634 + p_polygon->vecParts.push_back(nPoint);
  1635 + for (int k = 0; k < nPoint; k++)
  1636 + {
  1637 + //clsStruct::POINT point;
  1638 +
  1639 + double x = clsUtil::ReadDouble(vc, not_big);
  1640 + double y = clsUtil::ReadDouble(vc, not_big);
  1641 + p_polygon->vec_X.push_back(x);
  1642 + p_polygon->vec_Y.push_back(y);
  1643 + if (hasZ)
  1644 + vc += 8;
  1645 + if (pol_minx > x)
  1646 + pol_minx = x;
  1647 + if (pol_miny > y)
  1648 + pol_miny = y;
  1649 + if (pol_maxx < x)
  1650 + pol_maxx = x;
  1651 + if (pol_maxy < y)
  1652 + pol_maxy = y;
  1653 + }
  1654 + }
  1655 + p_polygon->minx = pol_minx;
  1656 + p_polygon->miny = pol_miny;
  1657 + p_polygon->maxx = pol_maxx;
  1658 + p_polygon->maxy = pol_maxy;
  1659 + return p_polygon;
  1660 + }
  1661 +
  1662 + shared_ptr<PolygonClass> DataCollection::GetDataMLine(unsigned char *vc)
  1663 + {
  1664 + unsigned char hasZorSrsid = ((unsigned char *)(vc + 4))[0] / 16;
  1665 + unsigned char hasZ = hasZorSrsid / 8;
  1666 + unsigned char hasSrsid = hasZorSrsid % 8;
  1667 +
  1668 + int not_big = clsUtil::ReadByte(vc);
  1669 + int shapetype = clsUtil::ReadInt(vc, not_big);
  1670 +
  1671 + if (hasSrsid)
  1672 + {
  1673 + int srsid = clsUtil::ReadInt(vc, not_big);
  1674 + }
  1675 +
  1676 + int nLine = clsUtil::ReadInt(vc, not_big);
  1677 + shared_ptr<PolygonClass> p_polygon(new PolygonClass());
  1678 + p_polygon->polygonCount = nLine;
  1679 + double pol_minx = 1000000000;
  1680 + double pol_miny = 1000000000;
  1681 + double pol_maxx = -100000000;
  1682 + double pol_maxy = -100000000;
  1683 + //pp[i].nLine = nLine;
  1684 + //pp[i].p = pPath;
  1685 +
  1686 + for (int j = 0; j < nLine; j++)
  1687 + {
  1688 + //clsStruct::LINE path;
  1689 +
  1690 + int not_big2 = clsUtil::ReadByte(vc);
  1691 + vc += 4; //跳过 shapetype 读取
  1692 +
  1693 + int nPoint = clsUtil::ReadInt(vc, not_big2);
  1694 + p_polygon->vecParts.push_back(nPoint);
  1695 + for (int k = 0; k < nPoint; k++)
  1696 + {
  1697 + //clsStruct::POINT point;
  1698 +
  1699 + double x = clsUtil::ReadDouble(vc, not_big2);
  1700 + double y = clsUtil::ReadDouble(vc, not_big2);
  1701 + p_polygon->vec_X.push_back(x);
  1702 + p_polygon->vec_Y.push_back(y);
  1703 + if (hasZ)
  1704 + vc += 8;
  1705 + if (pol_minx > x)
  1706 + pol_minx = x;
  1707 + if (pol_miny > y)
  1708 + pol_miny = y;
  1709 + if (pol_maxx < x)
  1710 + pol_maxx = x;
  1711 + if (pol_maxy < y)
  1712 + pol_maxy = y;
  1713 + }
  1714 + }
  1715 + p_polygon->minx = pol_minx;
  1716 + p_polygon->miny = pol_miny;
  1717 + p_polygon->maxx = pol_maxx;
  1718 + p_polygon->maxy = pol_maxy;
  1719 + return p_polygon;
  1720 + }
  1721 +
  1722 + shared_ptr<PolygonClass> DataCollection::GetDataPolygon(unsigned char *here)
  1723 + {
  1724 + shared_ptr<PolygonClass> p_polygon(new PolygonClass());
  1725 + try
  1726 + {
  1727 + unsigned char hasZorSrsid = ((unsigned char *)(here + 4))[0] / 16;
  1728 + unsigned char hasZ = hasZorSrsid / 8;
  1729 + unsigned char hasSrsid = hasZorSrsid % 8;
  1730 + //bool hasZ = false;
  1731 + int not_big1, not_big2, shapetype1, nring, npoint;
  1732 + not_big1 = clsUtil::ReadByte(here);
  1733 + shapetype1 = clsUtil::ReadInt(here, not_big1);
  1734 + if (hasSrsid)
  1735 + {
  1736 + int srsid = clsUtil::ReadInt(here, not_big1);
  1737 + }
  1738 +
  1739 + double pol_minx = 1000000000;
  1740 + double pol_miny = 1000000000;
  1741 + double pol_maxx = -100000000;
  1742 + double pol_maxy = -100000000;
  1743 +
  1744 + p_polygon->polygonCount = 1;
  1745 +
  1746 + //for (int j = 0; j < 1; j++)
  1747 + //{
  1748 + //not_big2 = clsUtil::ReadByte(here);
  1749 + //here += 4; //跳过 shapetype, 没意义, 必然是polygon
  1750 +
  1751 + nring = clsUtil::ReadInt(here, not_big1);
  1752 + p_polygon->vecParts.push_back(nring);
  1753 +
  1754 + for (int k = 0; k < nring; k++)
  1755 + {
  1756 + npoint = clsUtil::ReadInt(here, not_big1);
  1757 + p_polygon->vecParts.push_back(npoint);
  1758 +
  1759 + for (int m = 0; m < npoint; m++)
  1760 + {
  1761 + double x = clsUtil::ReadDouble(here, not_big1);
  1762 + double y = clsUtil::ReadDouble(here, not_big1);
  1763 + if (hasZ)
  1764 + here += 8;
  1765 + p_polygon->vec_X.push_back(x);
  1766 + p_polygon->vec_Y.push_back(y);
  1767 +
  1768 + if (pol_minx > x)
  1769 + pol_minx = x;
  1770 + if (pol_miny > y)
  1771 + pol_miny = y;
  1772 + if (pol_maxx < x)
  1773 + pol_maxx = x;
  1774 + if (pol_maxy < y)
  1775 + pol_maxy = y;
  1776 + }
  1777 + }
  1778 + //}
  1779 +
  1780 + p_polygon->minx = pol_minx;
  1781 + p_polygon->miny = pol_miny;
  1782 + p_polygon->maxx = pol_maxx;
  1783 + p_polygon->maxy = pol_maxy;
  1784 +
  1785 + if (p_polygon->vec_X.size() == 0)
  1786 + {
  1787 + //delete p_polygon;
  1788 + return NULL;
  1789 + }
  1790 + }
  1791 + catch (const std::exception &e)
  1792 + {
  1793 + //std::cerr << e.what() << '\n';
  1794 + //delete p_polygon;
  1795 + return NULL;
  1796 + }
  1797 +
  1798 + return p_polygon;
  1799 + }
  1800 +
  1801 + shared_ptr<PolygonClass> DataCollection::GetDataMPolygon(unsigned char *here)
  1802 + {
  1803 + shared_ptr<PolygonClass> p_polygon(new PolygonClass());
  1804 + try
  1805 + {
  1806 + unsigned char hasZorSrsid = ((unsigned char *)(here + 4))[0] / 16;
  1807 + unsigned char hasZ = hasZorSrsid / 8;
  1808 + unsigned char hasSrsid = hasZorSrsid % 8;
  1809 +
  1810 + unsigned char geom_type = (here)[1];
  1811 +
  1812 + if (geom_type == DCGeometryType::GeometryType_Point)
  1813 + {
  1814 + int not_big1 = clsUtil::ReadByte(here);
  1815 + int shapetype1 = clsUtil::ReadInt(here, not_big1);
  1816 + if (hasSrsid)
  1817 + here += 4;
  1818 + p_polygon->polygonCount = 1;
  1819 + double x = clsUtil::ReadDouble(here, not_big1);
  1820 + double y = clsUtil::ReadDouble(here, not_big1);
  1821 +
  1822 + p_polygon->minx = x;
  1823 + p_polygon->miny = y;
  1824 + p_polygon->maxx = x;
  1825 + p_polygon->maxy = y;
  1826 +
  1827 + p_polygon->vec_X.push_back(x);
  1828 + p_polygon->vec_Y.push_back(y);
  1829 + }
  1830 + else
  1831 + {
  1832 + int not_big1, not_big2, shapetype1, npolygon, nring, npoint;
  1833 + not_big1 = clsUtil::ReadByte(here);
  1834 + shapetype1 = clsUtil::ReadInt(here, not_big1);
  1835 + if (hasSrsid)
  1836 + here += 4; //跳过srid
  1837 + npolygon = clsUtil::ReadInt(here, not_big1);
  1838 + /*clsStruct::POLYGON* pPgon = (clsStruct::POLYGON*)malloc(sizeof(clsStruct::POLYGON)* npolygon);*/
  1839 + //clsStruct::MPOLYGON mpgon;
  1840 + if (npolygon == 0)
  1841 + {
  1842 + return NULL;
  1843 + }
  1844 + double pol_minx = 1000000000;
  1845 + double pol_miny = 1000000000;
  1846 + double pol_maxx = -100000000;
  1847 + double pol_maxy = -100000000;
  1848 +
  1849 + p_polygon->polygonCount = npolygon;
  1850 +
  1851 + for (int j = 0; j < npolygon; j++)
  1852 + {
  1853 + not_big2 = clsUtil::ReadByte(here);
  1854 + here += 4; //跳过 shapetype, 没意义, 必然是polygon
  1855 +
  1856 + nring = clsUtil::ReadInt(here, not_big2);
  1857 + p_polygon->vecParts.push_back(nring);
  1858 +
  1859 + for (int k = 0; k < nring; k++)
  1860 + {
  1861 + npoint = clsUtil::ReadInt(here, not_big2);
  1862 + p_polygon->vecParts.push_back(npoint);
  1863 +
  1864 + for (int m = 0; m < npoint; m++)
  1865 + {
  1866 + double x = clsUtil::ReadDouble(here, not_big2);
  1867 + double y = clsUtil::ReadDouble(here, not_big2);
  1868 + if (hasZ)
  1869 + here += 8;
  1870 + p_polygon->vec_X.push_back(x);
  1871 + p_polygon->vec_Y.push_back(y);
  1872 +
  1873 + if (pol_minx > x)
  1874 + pol_minx = x;
  1875 + if (pol_miny > y)
  1876 + pol_miny = y;
  1877 + if (pol_maxx < x)
  1878 + pol_maxx = x;
  1879 + if (pol_maxy < y)
  1880 + pol_maxy = y;
  1881 + }
  1882 + }
  1883 + }
  1884 +
  1885 + p_polygon->minx = pol_minx;
  1886 + p_polygon->miny = pol_miny;
  1887 + p_polygon->maxx = pol_maxx;
  1888 + p_polygon->maxy = pol_maxy;
  1889 +
  1890 + if (p_polygon->vec_X.size() == 0)
  1891 + {
  1892 + //delete p_polygon;
  1893 + return NULL;
  1894 + }
  1895 + }
  1896 + }
  1897 + catch (const std::exception &e)
  1898 + {
  1899 + //std::cerr << e.what() << '\n';
  1900 + //delete p_polygon;
  1901 + return NULL;
  1902 + }
  1903 +
  1904 + return p_polygon;
  1905 + }
  1906 +
  1907 +}
... ...
  1 +#pragma once
  2 +#ifndef _DataCollection_H_
  3 +#define _DataCollection_H_
  4 +
  5 +#include<vector>
  6 +#include<string>
  7 +#include "dmap_core.h"
  8 +#include<libpq-fe.h>
  9 +#include <map>
  10 +#include "memory"
  11 +using namespace std;
  12 +
  13 +namespace DmapCore_30
  14 +{
  15 +
  16 +
  17 + enum DMapFieldType
  18 +{
  19 + dmapShort = 0,
  20 + dmapInt = 1,
  21 + dmapLong = 2,
  22 + dmapDouble = 3,
  23 + dmapBoolean = 4,
  24 + dmapChar = 5,
  25 + dmapString = 6,
  26 + dmapGeography = 7,
  27 + dmapData = 8,
  28 + dmapGeometry = 9,
  29 + shapePoint = 10,
  30 + shapeLineString = 11,
  31 + shapePolygon = 12,
  32 + shapeMultiPoint = 13,
  33 + shapeMultiLineString = 14,
  34 + shapeMultiPolygon = 15
  35 +};
  36 +
  37 +
  38 +/*static enum ZoomFlag
  39 +{
  40 +dmapZoomReset = 0,
  41 +dmapZoomIn = 1,
  42 +dmapZoomOut = 2,
  43 +dmapZoomNoChange = 3
  44 +};*/
  45 +
  46 + enum PointType
  47 +{
  48 + dmapPointTypeCircle = 0, //圆
  49 + dmapPointTypeTriangle = 1, //三角形
  50 + dmapPointTypeSquare = 2, //正方形
  51 + dmapPointTypeCross = 3, //十字架
  52 + dmapPointTypeStar = 4, //五角星
  53 +};
  54 + enum LineType
  55 +{
  56 + dmapLineTypeSolid = 0,
  57 + dmapLineTypeDash = 1,
  58 + dmapLineTypeDot = 2,
  59 + dmapLineTypeDashDot = 3,
  60 + dmapLineTypeDashDotDot = 4,
  61 +};
  62 +
  63 +enum DCGeometryType
  64 + {
  65 + GeometryType_Point = 1,
  66 + GeometryType_LineString = 2,
  67 + GeometryType_Polygon = 3,
  68 + GeometryType_MultiPoint = 4,
  69 + GeometryType_MultiLineString = 5,
  70 + GeometryType_MultiPolygon = 6,
  71 + };
  72 +
  73 + enum GeometryType
  74 +{
  75 + dmapGeometryPoint = 0,
  76 + dmapGeometryMultiPoint = 1,
  77 + dmapGeometryPath = 2,
  78 + dmapGeometryMultiLineString = 3,
  79 + dmapGeometryRing = 4,
  80 + dmapGeometryPolygon = 5,
  81 + dmapGeometryMultiPolygon = 6
  82 +};
  83 +
  84 + enum ImageType
  85 +{
  86 + dmapImageTypePNG = 0,
  87 + dmapImageTypeJPG = 1
  88 +};
  89 + enum StorageType
  90 +{
  91 + dmapStorageTypeExploded = 0,
  92 + dmapStorageTypeCompact = 1
  93 +};
  94 +
  95 +/*
  96 +range的[lower,upper]区间两个端点是否使用
  97 +all表示两边使用
  98 +upper表示使用大端点,不使用小端点
  99 +*/
  100 + enum EqulityType
  101 +{
  102 + dmapEqualityAll = 0,
  103 + dmapEqualityUpper = 1,
  104 + dmapEqualityLower = 2,
  105 + dmapEqualityNone = 3
  106 +};
  107 +
  108 +
  109 + enum dmapAntialias
  110 +{
  111 + dmapAntialiasingDefault=0,
  112 + dmapAntialiasingNone = 1,
  113 + dmapAntialiasingGray = 2,
  114 + dmapAntialiasingSubpixel = 3,
  115 + dmapAntialiasingFast = 4,
  116 + dmapAntialiasingGood = 5,
  117 + dmapAntialiasingBest = 6,
  118 + dmapAntialiasingTrue = 7,
  119 + dmapAntialiasingFalse = 8
  120 +};
  121 +
  122 +
  123 + enum dmapLineLabelPositionDirection
  124 +{
  125 + dmapLineLabelPositionLevel = 0,
  126 + dmapLineLabelPositionParallel = 1,
  127 + dmapLineLabelPositionCurved = 2,
  128 + dmapLineLabelPositionVertical = 3,
  129 +};
  130 +
  131 + enum dmapLineLabelPositionPlace //在线上方或下方 或左边或右边 或者线上
  132 +{
  133 + dmapLineLabelPositionLeft = 0,
  134 + dmapLineLabelPositionRight = 1,
  135 + dmapLineLabelPositionOnTop = 2,
  136 + dmapLineLabelPositionAbove = 3,
  137 + dmapLineLabelPositionBelow = 4,
  138 +};
  139 +
  140 + enum dmapLineLabelPositionStartOrEnd
  141 +{
  142 + dmapLineLabelPositionStart = 0,
  143 + dmapLineLabelPositionEnd = 1,
  144 + dmapLineLabelPositionCenter = 2,
  145 +};
  146 +
  147 + enum dmapPolygonLabelPositionDirection
  148 +{
  149 + dmapPolygonLabelPositionParallel = 0,
  150 + dmapPolygonLabelPositionStraight = 1,
  151 + dmapPolygonLabelPositionParallelAndStraight = 2,
  152 +};
  153 +
  154 +
  155 + enum dmapRotateMethod
  156 +{
  157 + dmapRotate_geographic = 0,
  158 + dmapRotate_Arithmetic = 1,
  159 + dmapRotate_Mod_arithmetic = 2
  160 +};
  161 +
  162 + class PGeomClass
  163 + {
  164 + public:
  165 + vector<char *> m_pdata;
  166 + ~PGeomClass()
  167 + {
  168 + for (size_t i = 0; i < m_pdata.size(); i++)
  169 + {
  170 + char *data = m_pdata.at(i);
  171 + if (data != 0)
  172 + {
  173 + free(data);
  174 + m_pdata[i] = 0;
  175 + }
  176 + }
  177 + m_pdata.clear();
  178 + }
  179 + };
  180 +
  181 +
  182 + class PointClass :public PGeomClass
  183 + {
  184 + public:
  185 + float x;
  186 + float y;
  187 + };
  188 +
  189 +
  190 +
  191 + class PolygonClass :public PGeomClass
  192 + {
  193 + public:
  194 + unsigned int polygonCount;
  195 + vector<int> vecParts;
  196 + vector<float> vec_X;
  197 + vector<float> vec_Y;
  198 +
  199 + float minx;
  200 + float miny;
  201 + float maxx;
  202 + float maxy;
  203 + };
  204 +
  205 + //class Point;
  206 + //class MultiPoint;
  207 +// class Path;
  208 +// class MultiLineString;
  209 + //class Ring;
  210 + //class Polygon;
  211 +// class MultiPolygon;
  212 + //class Geometry;
  213 + class CORE_EXPORT DataCollection
  214 + {
  215 + public:
  216 +
  217 + void InitDataCollection(PGresult* res, int shapeType,int imageWidth, int imageHeight, int subset, double r = 1, double dScaleDenominator=1,double x_dis = 0, double y_dis = 0);
  218 + //DataCollection(Recordsets* recss, int shapeType, double r = 1, double x_dis = 0, double y_dis = 0);
  219 + //void InitDataCollection(Geometry* geom, double r = 1, double dScaleDenominator=1, double x_dis = 0, double y_dis = 0);
  220 +
  221 +
  222 + void InitHeatCollection(PGresult* res,int shapeType,int imageWidth, int imageHeight, double layer_minx, double layer_maxx, double layer_miny, double layer_maxy,
  223 + int subset, double r = 1, double dScaleDenominator=1,double x_dis = 0, double y_dis = 0);
  224 +
  225 +
  226 +
  227 +
  228 + ~DataCollection();
  229 +
  230 + DataCollection();
  231 +
  232 + // void InitDataCollection();
  233 + int m_iPartCount;
  234 + int m_iStructType;
  235 + void * m_pData; //此指针只能够是自定义的6种结构体类型
  236 +
  237 + vector<vector<string> > m_vAllField; //这是结果集的所有除 shape 外的field, 数组中每个元素表示一行数据
  238 + vector<string> m_vFieldName; // 这是所有字段的名字
  239 + double m_dR;
  240 + double m_dXdis;
  241 + double m_dYdis;
  242 + double m_dScaleDenominator;
  243 +
  244 + int m_imageWidth =0;
  245 + int m_imageHeight =0;
  246 +
  247 + int m_subset;
  248 +
  249 + bool m_dmapAreaIndex = -1;
  250 +
  251 + //shared_ptr<DataHeatCollection> pHeatData;
  252 +
  253 + private:
  254 + int m_iN;
  255 +
  256 +
  257 + bool MallocForPoint(PGresult* res);
  258 + bool MallocForMultiLineString(PGresult* res);
  259 + bool MallocForPolygon(PGresult *res);
  260 + bool MallocForMultiPolygon(PGresult* res);
  261 +
  262 + bool MallocForPolygonForGeom(PGresult *res);
  263 + bool MallocForLineStringGeom(PGresult *res);
  264 +
  265 + //bool MallocForHeatCollectionGeom(PGresult *res,int dcigridColIndex);
  266 +
  267 + //bool MallocForPoint(Point* p);
  268 + //bool MallocForMultiPoint(MultiPoint* mp);
  269 + //bool MallocForPath(Path* path);
  270 + //bool MallocForMultiLineString(MultiLineString* ml);
  271 + //bool MallocForRing(Ring* ring);
  272 + //bool MallocForPolygon(Polygon* pPolygon);
  273 + //bool MallocForMultiPolygon(MultiPolygon* mp);
  274 +
  275 + bool PolygonIsLessThanOnePixel(unsigned char* here,int not_big1);
  276 +
  277 + /*
  278 + Struct_Point = 0,
  279 + Struct_Line = 1,
  280 + Struct_MLine = 2,
  281 + Struct_Polygon = 3,
  282 + Struct_MPolygon = 4
  283 + */
  284 + bool FreeForPOINT();
  285 + bool FreeForLINE();
  286 + bool FreeForMLINE();
  287 + bool FreeForPOLYGON();
  288 + bool FreeForMPOLYGON();
  289 +
  290 + inline void ToScale(double x, double y, double&x0, double&y0);
  291 + bool CollectAllField(PGresult* res);
  292 + bool CollectFieldName(PGresult* res);
  293 +
  294 +
  295 + shared_ptr<PointClass> GetDataPoint(unsigned char *vc);
  296 + shared_ptr<PointClass> GetMDataPoint(unsigned char *vc);
  297 + shared_ptr<PolygonClass> GetDataLine(unsigned char *vc);
  298 + shared_ptr<PolygonClass> GetDataMLine(unsigned char *vc);
  299 + shared_ptr<PolygonClass> GetDataPolygon(unsigned char *vc);
  300 + shared_ptr<PolygonClass> GetDataMPolygon(unsigned char *vc);
  301 + };
  302 +
  303 +
  304 +
  305 +
  306 +}
  307 +#endif
\ No newline at end of file
... ...
  1 +
  2 +#ifndef _GroupRenderer_H_
  3 +#define _GroupRenderer_H_
  4 +
  5 +#include "GroupRenderer.h"
  6 +#include"SimpleMarkerSymbol.h"
  7 +#include"SimpleLabelRenderer.h"
  8 +#include"SimpleLineSymbol.h"
  9 +#include"SimplePolygonSymbol.h"
  10 +#include"ValueMapRenderer.h"
  11 +//#include"RangeMapRenderer.h"
  12 +#include"SimpleRenderer.h"
  13 +#include"TrueTypeMarkerSymbol.h"
  14 +#include "clsUtil.h"
  15 +#include "clsXML.h"
  16 +
  17 +namespace DmapCore_30
  18 +{
  19 + GroupRenderer::GroupRenderer()
  20 + {
  21 + m_vSymbols = {};
  22 + m_sTag = "";
  23 + m_sXML = "";
  24 + m_simpleRenderer = true;
  25 + }
  26 + GroupRenderer::~GroupRenderer()
  27 + {
  28 + this->Clear();
  29 + }
  30 + bool GroupRenderer::Parse(boost::property_tree::ptree &pt, AppendBuffer *f)
  31 + {
  32 +
  33 + //遍历所有节点
  34 + for (auto ptchild =pt.begin(); ptchild != pt.end(); ++ptchild)
  35 + {
  36 + //所有子节点都是样式
  37 + Renderer* renderer = NULL;
  38 + if (clsXML::XMLParse(ptchild->first, ptchild->second, &renderer))
  39 + {
  40 + if (renderer)m_vSymbols.push_back(renderer);
  41 + }
  42 + }
  43 + return true;
  44 +
  45 +
  46 + }
  47 +
  48 + void GroupRenderer::ToJson(AppendBuffer *ab)
  49 + {
  50 +
  51 + //strcat(resultbuff,R"("GROUPRENDERER":[)");
  52 + ab->AppendString(R"("GROUPRENDERER":[)");
  53 + int length = (int)m_vSymbols.size();
  54 + for (int i = 0; i < length; i++)
  55 + {
  56 + if(i>0){
  57 + ab->AppendString(",");
  58 + }
  59 + // strcat(resultbuff,",");
  60 + Renderer* renderer = m_vSymbols[i];
  61 + renderer->ToJson(ab);
  62 + }
  63 + ab->AppendString("]");
  64 + //strcat(resultbuff,"]");
  65 +
  66 +
  67 + }
  68 +
  69 +
  70 +
  71 + GroupRenderer* GroupRenderer::CreateNew()
  72 + {
  73 + GroupRenderer* dest = new GroupRenderer();
  74 + return dest;
  75 + }
  76 + int GroupRenderer::RendererType()
  77 + {
  78 + return dmapGroupRenderer;
  79 + }
  80 +
  81 + const char* GroupRenderer::GetTag()
  82 + {
  83 + return m_sTag.c_str();
  84 + }
  85 + bool GroupRenderer::SetTag(const char* sTag)
  86 + {
  87 + if (!sTag)
  88 + return false;
  89 + m_sTag = sTag;
  90 + return true;
  91 + }
  92 + bool GroupRenderer::AddSymbol(int index, Renderer* pRenderer)
  93 + {
  94 + int length__ = m_vSymbols.size();
  95 + if (index > length__)return false;
  96 + pRenderer->AddRef();
  97 + if (index < 0 || index == length__)
  98 + m_vSymbols.push_back(pRenderer);
  99 + else
  100 + m_vSymbols.insert(m_vSymbols.begin() + index, pRenderer);
  101 + return true;
  102 + }
  103 + bool GroupRenderer::Remove(int index)
  104 + {
  105 + RemoveIndexP(index, m_vSymbols);
  106 + }
  107 + Renderer* GroupRenderer::GetItem(int index)
  108 + {
  109 + GetIndexP(index, m_vSymbols);
  110 + }
  111 + bool GroupRenderer::SetItem(int index, Renderer* pRenderer)
  112 + {
  113 + SetIndexP(index, pRenderer, m_vSymbols);
  114 + }
  115 + int GroupRenderer::GetSymbolCount()
  116 + {
  117 + int length = (int)m_vSymbols.size();
  118 + return length;
  119 +
  120 + }
  121 + bool GroupRenderer::Clear()
  122 + {
  123 + ClearP(m_vSymbols);
  124 + }
  125 +
  126 + //bool GroupRenderer::DrawSimpleData(clsCrSurf* pClsCS, DataCollection* data, char* pFlag)
  127 + //{
  128 + // int length = (int)(m_vSymbols.size());
  129 +
  130 + // for (int i = 0; i < length; i++)
  131 + // {
  132 + // Renderer* renderer = m_vSymbols[i];
  133 + // if (renderer->m_simpleRenderer)
  134 + // {
  135 + // int renType = renderer->RendererType();
  136 + // renderer->DrawData(pClsCS, data, pFlag);
  137 + // }
  138 + // }
  139 + // return true;
  140 + //}
  141 +
  142 +
  143 + bool GroupRenderer::DrawData(clsCrSurf* pClsCS, DataCollection* data, bool drawSimpleData, char* pFlag)
  144 + {
  145 + int length = (int)(m_vSymbols.size());
  146 +
  147 + for (int i = 0; i < length; i++)
  148 + {
  149 + Renderer* renderer = m_vSymbols[i];
  150 + //if (renderer->m_simpleRenderer == drawSimpleData)
  151 + {
  152 + int renType = renderer->RendererType();
  153 + renderer->DrawData(pClsCS, data,true, pFlag);
  154 + }
  155 + }
  156 + return true;
  157 + }
  158 + bool GroupRenderer::DrawData(clsCrSurf* pClsCS, DataCollection* data, int dataIndex, char* pFlag)
  159 + {
  160 + int length = (int)(m_vSymbols.size());
  161 + for (int i = 0; i < length; i++)
  162 + {
  163 + Renderer* renderer = m_vSymbols[i];
  164 + int renType = renderer->RendererType();
  165 + renderer->DrawData(pClsCS, data, dataIndex, pFlag);
  166 + }
  167 + return true;
  168 + }
  169 +
  170 + bool GroupRenderer::DrawLegend(clsCrSurf* pClsCS, shared_ptr<legendParamater> pLegendParamater, int layerType,char* pFlag = NULL)
  171 + {
  172 + int length = (int)(m_vSymbols.size());
  173 + for (int i = 0; i < length; i++)
  174 + {
  175 + Renderer* renderer = m_vSymbols[i];
  176 + int renType = renderer->RendererType();
  177 + renderer->DrawLegend(pClsCS, pLegendParamater,layerType, pFlag);
  178 + }
  179 + return true;
  180 + }
  181 +
  182 +
  183 + void GroupRenderer::TryAddField(vector<string>&pvField)
  184 + {
  185 + int length = (int)(m_vSymbols.size());
  186 + for (int i = 0; i < length; i++)
  187 + {
  188 + if (m_vSymbols[i] == 0)continue;
  189 + m_vSymbols[i]->TryAddField(pvField);
  190 + }
  191 + }
  192 +
  193 + bool GroupRenderer::TryFindHeatRenderer()
  194 + {
  195 + int length = (int)(m_vSymbols.size());
  196 + for (int i = 0; i < length; i++)
  197 + {
  198 + Renderer* renderer = m_vSymbols[i];
  199 + if(renderer->TryFindHeatRenderer())
  200 + {
  201 + return true;
  202 + }
  203 + }
  204 + return false;
  205 + }
  206 +}
  207 +
  208 +#endif
\ No newline at end of file
... ...
  1 +#pragma once
  2 +#include<vector>
  3 +using namespace std;
  4 +#include"Renderer.h"
  5 +
  6 +namespace DmapCore_30
  7 +{
  8 + class clsCrSurf;
  9 + class DataCollection;
  10 + class GroupRenderer :public Renderer
  11 + {
  12 + public:
  13 + GroupRenderer();
  14 + ~GroupRenderer();
  15 + static GroupRenderer* CreateNew();
  16 + virtual int RendererType();
  17 + virtual bool Parse(boost::property_tree::ptree &pt, AppendBuffer *f);
  18 + virtual void ToJson(AppendBuffer *ab);
  19 + // virtual bool DrawSimpleData(clsCrSurf* pClsCS, DataCollection* data, char* pFlag);
  20 + virtual bool DrawData(clsCrSurf* pClsCS, DataCollection* data, bool drawSimpleData, char* pFlag);
  21 + virtual bool DrawData(clsCrSurf* pClsCS, DataCollection* data, int dataIndex, char* pFlag);
  22 + virtual bool DrawLegend(clsCrSurf* pClsCS, shared_ptr<legendParamater> pLegendParamater, int layerType, char* pFlag);
  23 + vector<Renderer*> m_vSymbols;
  24 + const char* GetTag();
  25 + bool SetTag(const char* sTag);
  26 + bool AddSymbol(int index, Renderer*);
  27 + bool Remove(int index);
  28 + Renderer* GetItem(int index);
  29 + bool SetItem(int index, Renderer* pRenderer);
  30 + int GetSymbolCount();
  31 + bool Clear();
  32 +
  33 + void TryAddField(vector<string>&pvField);
  34 + bool TryFindHeatRenderer();
  35 + private:
  36 +
  37 + string m_sTag;
  38 + };
  39 +
  40 +}
\ No newline at end of file
... ...
  1 +
  2 +
  3 +#include "Renderer.h"
  4 +#include"SimpleMarkerSymbol.h"
  5 +#include"SimplePolygonSymbol.h"
  6 +#include"ValueMapRenderer.h"
  7 +//#include"RangeMapRenderer.h"
  8 +#include"GroupRenderer.h"
  9 +#include"SimpleLineSymbol.h"
  10 +
  11 +#include"clsUtil.h"
  12 +#include"clsMalloc.h"
  13 +#include <unistd.h>
  14 +#include <algorithm>
  15 +namespace DmapCore_30
  16 +{
  17 + Renderer::Renderer()
  18 + {
  19 + m_iN = 1;
  20 + }
  21 +
  22 +
  23 + Renderer::~Renderer()
  24 + {
  25 + }
  26 +
  27 + bool Renderer::AddRef()
  28 + {
  29 + m_iN++;
  30 + return true;
  31 + }
  32 + bool Renderer::Release()
  33 + {
  34 + m_iN--;
  35 + if (m_iN < 0)
  36 + return false;
  37 + if (!m_iN)
  38 + {
  39 + switch (this->RendererType())
  40 + {
  41 + case dmapSimpleMarkerSymbol:delete (SimpleMarkerSymbol*)this; break;
  42 + case dmapSimpleLineSymbol:
  43 + delete ((SimpleLineSymbol*)this);
  44 + break;
  45 + case dmapSimplePolygonSymbol: delete (SimplePolygonSymbol*)this; break;
  46 + case dmapValueMapRenderer: delete (ValueMapRenderer*)this; break;
  47 + //case dmapRangeMapRenderer: delete (RangeMapRenderer*)this; break;
  48 + case dmapGroupRenderer: delete (GroupRenderer*)this; break;
  49 + default:
  50 + delete this;
  51 + break;
  52 + }
  53 + }
  54 + return true;
  55 + }
  56 +
  57 + int Renderer::GetN()
  58 + {
  59 + return m_iN;
  60 + }
  61 +/*
  62 + bool Renderer::RendererXmlParse(Renderer**ppRen, const char* fileName)
  63 + {
  64 + if (!(*ppRen))
  65 + {
  66 + rapidxml::xml_document<char> doc;
  67 + rapidxml::file<> fdoc(fileName);
  68 + try
  69 + {
  70 + doc.parse<0>(fdoc.data());
  71 + }
  72 + catch (...)
  73 + {
  74 + return false;
  75 + }
  76 +
  77 + rapidxml::xml_node<char>* root = doc.first_node();
  78 + bool flag = clsXML::XMLParse(root, NULL, ppRen);
  79 + return flag;
  80 + }
  81 + AppendBuffer ab(fileName);
  82 + clsXML::XMLHead(&ab);
  83 + clsXML::XMLParse(NULL, &ab, ppRen);
  84 +
  85 + return true;
  86 + }
  87 +*/
  88 + void Renderer::TryAddField2(vector<string>&pvField, std::string field)
  89 + {
  90 + if (field.size() == 0)return;
  91 + vector<string>::iterator it = find(pvField.begin(), pvField.end(), field);
  92 + if (it == pvField.end())
  93 + pvField.push_back(field);
  94 + };
  95 +
  96 + string Renderer::GetFilePath(string path)
  97 + {
  98 + char sz[200] = {0};
  99 + if(GetCurrentFolderPath(sz, sizeof(sz)) > 0)
  100 + {
  101 + std::string s;
  102 + s = sz;
  103 + size_t t = s.rfind('/');
  104 + sz[t] = 0;
  105 + if(path[0]=='/')
  106 + {
  107 + return path;
  108 + }
  109 + int i=0;
  110 + if(path[0]=='.')
  111 + {
  112 + if(path[1]=='.')
  113 + {
  114 + i++;
  115 + s= sz;
  116 + t = s.rfind('/');
  117 + sz[t] = 0;
  118 + }
  119 + i++;
  120 + }
  121 + if((sz[t]=='/' || sz[t]=='\\')&& (path[i]=='/' || path[i]=='\\'))
  122 + {
  123 + i++;
  124 + }
  125 +
  126 + int j= t;
  127 + for(j=t;i<path.length(); i++,j++)
  128 + {
  129 + if(path[i]=='\\')
  130 + {
  131 + sz[j] = '/';
  132 + }
  133 + else
  134 + {
  135 + sz[j] = path[i];
  136 + }
  137 +
  138 + }
  139 + sz[j] =0;
  140 + //strcat(sz, path.c_str());
  141 + return sz;
  142 + }
  143 + else return 0;
  144 +
  145 + }
  146 +
  147 +
  148 + int Renderer::GetCurrentFolderPath(char* processdir, size_t len)
  149 + {
  150 + char* path_end;
  151 + if (readlink("/proc/self/exe", processdir, len) <= 0)
  152 + return -1;
  153 + path_end = strrchr(processdir, '/');
  154 + if (path_end == NULL)
  155 + return -1;
  156 + ++path_end;
  157 + //strcpy(processname, path_end);
  158 + *path_end = '\0';
  159 + return (size_t)(path_end - processdir);
  160 + }
  161 +
  162 +
  163 + void Renderer::TryAddField(vector<string>&pvField)
  164 + {
  165 +
  166 + };
  167 +/*
  168 + bool Renderer::RenStr(Renderer** ppRen, const char** psXML)
  169 + {
  170 + using namespace rapidxml;
  171 + if (*ppRen == NULL)
  172 + {
  173 + if (psXML == 0 || *psXML == 0 || (*psXML)[0] == 0)return false;
  174 + char *xml = _strdup(*psXML); clsMalloc mcx(xml);
  175 + if (xml == 0 || xml[0] == 0)return false;
  176 + try{
  177 + xml_document<> doc; // character type defaults to char
  178 + doc.parse<0>(xml);
  179 + xml_node<char> *n = doc.first_node();
  180 + if (n == 0){ return false; }
  181 + bool flag = clsXML::XMLParse(n, NULL, ppRen);
  182 + return flag;
  183 + }
  184 + catch (parse_error e)
  185 + {
  186 +
  187 + return false;
  188 + }
  189 + catch (...)
  190 + {
  191 + return false;
  192 + }
  193 + }
  194 + AppendBuffer ab(0);
  195 + clsXML::XMLParse(NULL, &ab, ppRen);
  196 + clsMalloc clsM1(ab.GetString());
  197 + (*ppRen)->m_sXML = clsM1.mem;
  198 +
  199 + *psXML = (*ppRen)->m_sXML.c_str();
  200 + return true;
  201 +
  202 + }*/
  203 +}
  204 +
... ...
  1 +
  2 +#ifndef _Renderer_H_
  3 +#define _Renderer_H_
  4 +#pragma once
  5 +#include <boost/property_tree/ptree.hpp>
  6 +#include <boost/property_tree/xml_parser.hpp>
  7 +#include <boost/foreach.hpp>
  8 +#include <string>
  9 +#include "AppendBuffer.h"
  10 +#include "legendParamater.h"
  11 +#include <memory>
  12 +#include <cairo/cairo.h>
  13 +#include"clsXML.h"
  14 +#include "dmap_core.h"
  15 +using namespace std;
  16 +namespace DmapCore_30
  17 +{
  18 +
  19 + enum RendererType
  20 +{
  21 + dmapSimpleMarkerSymbol = 1,
  22 + dmapSimpleLineSymbol = 2,
  23 + dmapSimplePolygonSymbol = 3,
  24 + dmapValueMapRenderer = 4,
  25 + dmapRangeMapRenderer = 5,
  26 + dmapGroupRenderer = 6,
  27 + dmapScaleDependentRenderer = 7,
  28 + dmapSimpleLabelRenderer = 8,
  29 + dmapTrueTypeMarkerSymbol = 9,
  30 + dmapSimpleRenderer = 10,
  31 + dmapTextSymbol = 11,
  32 + dmapHeatMapRenderer = 12
  33 +};
  34 +
  35 + class clsCrSurf;
  36 + class DataCollection;
  37 + class CORE_EXPORT Renderer
  38 + {
  39 + public:
  40 + Renderer();
  41 + ~Renderer();
  42 + bool AddRef();
  43 + bool Release();
  44 + virtual int RendererType() = 0;
  45 + virtual void ToJson(AppendBuffer *ab)=0;
  46 +
  47 + virtual bool DrawData(clsCrSurf* pClsCS, DataCollection* data, bool drawSimpleData, char* pFlag = NULL) = 0;
  48 + virtual bool DrawData(clsCrSurf* pClsCS, DataCollection* data, int dataIndex, char* pFlag = NULL) =0;
  49 + virtual bool Parse( boost::property_tree::ptree &pt, AppendBuffer *f) = 0;
  50 + //static bool RendererXmlParse(Renderer**pRen, const char* fileName);
  51 + //static bool RenStr(Renderer** ppRen, const char** psXML); //纯粹作弊,什么都没干,直接调用现有接口
  52 +
  53 + virtual bool DrawLegend(clsCrSurf* pClsCS, shared_ptr<legendParamater> pLegendParamater, int layerType, char* pFlag = NULL) = 0;
  54 +
  55 + virtual void TryAddField(vector<string>&pvField);
  56 + virtual bool TryFindHeatRenderer()=0;
  57 + void TryAddField2(vector<string>&pvField, std::string field);
  58 +
  59 +
  60 + string GetFilePath(string path);
  61 + int GetCurrentFolderPath(char* processdir, size_t len);
  62 + int GetN();//仅作调试使用
  63 + string m_sXML;
  64 +
  65 + bool m_simpleRenderer;
  66 + private:
  67 + int m_iN;
  68 +
  69 +
  70 + };
  71 +
  72 +}
  73 +
  74 +#endif
\ No newline at end of file
... ...
  1 +
  2 +#include "ScaleDependentRenderer.h"
  3 +#include"clsXML.h"
  4 +#include"DataCollection.h"
  5 +#include"SimpleMarkerSymbol.h"
  6 +#include"SimpleLabelRenderer.h"
  7 +#include"SimpleLineSymbol.h"
  8 +#include"SimplePolygonSymbol.h"
  9 +#include"ValueMapRenderer.h"
  10 +#include"RangeMapRenderer.h"
  11 +#include"GroupRenderer.h"
  12 +namespace DmapCore_30
  13 +{
  14 + ScaleDependentRenderer::ScaleDependentRenderer()
  15 + {
  16 + m_dLower = 0.0;
  17 + m_dUpper = 1e308;
  18 + m_pRenderer = NULL;
  19 + m_simpleRenderer = false;
  20 + }
  21 +
  22 +
  23 + ScaleDependentRenderer::~ScaleDependentRenderer()
  24 + {
  25 + if (m_pRenderer)
  26 + {
  27 + m_pRenderer->Release();
  28 + m_pRenderer = NULL; //注意手工重置为 NULL
  29 + }
  30 + }
  31 + BOOL ScaleDependentRenderer::Parse(rapidxml::xml_node<char>* node, AppendBuffer *f)
  32 + {
  33 + if (!node&& !f)return false;
  34 + clsXML clsX(f, "SCALEDEPENDENTRENDERER");
  35 + clsXML::XMLAttrParse(node, f, &m_dLower, "lower");
  36 + clsXML::XMLAttrParse(node, f, &m_dUpper, "upper");
  37 + clsX.closeProperties();
  38 + if (node)
  39 + {
  40 + clsXML::XMLParse(node->first_node(), NULL, &m_pRenderer);
  41 + }
  42 + else
  43 + {
  44 + clsXML::XMLParse(NULL, f, &m_pRenderer);
  45 + }
  46 + return true;
  47 + }
  48 +
  49 + void ScaleDependentRenderer::ToJson(AppendBuffer *ab)
  50 + {
  51 +
  52 + }
  53 +
  54 + //BOOL ScaleDependentRenderer::RendererString(Renderer** ppRen, const char** psXML)
  55 + //{
  56 + // return true;
  57 + //}
  58 +
  59 + int ScaleDependentRenderer::RendererType()
  60 + {
  61 + return dmapScaleDependentRenderer;
  62 + }
  63 + ScaleDependentRenderer* ScaleDependentRenderer::CreateNew()
  64 + {
  65 + ScaleDependentRenderer* sdr = new ScaleDependentRenderer();
  66 + return sdr;
  67 + }
  68 +
  69 + double ScaleDependentRenderer::GetLower()
  70 + {
  71 + return m_dLower;
  72 + }
  73 + BOOL ScaleDependentRenderer::SetLower(double lower)
  74 + {
  75 + if (lower < 0)
  76 + return false;
  77 + m_dLower = lower;
  78 + return true;
  79 + }
  80 + double ScaleDependentRenderer::GetUpper()
  81 + {
  82 + return m_dUpper;
  83 + }
  84 + BOOL ScaleDependentRenderer::SetUpper(double upper)
  85 + {
  86 + if (upper < 0)
  87 + return false;
  88 + m_dUpper = upper;
  89 + return true;
  90 + }
  91 +
  92 + Renderer* ScaleDependentRenderer::GetRenderer()
  93 + {
  94 + if (m_pRenderer)
  95 + m_pRenderer->AddRef();
  96 + return m_pRenderer;
  97 + }
  98 + BOOL ScaleDependentRenderer::SetRenderer(Renderer* renderer)
  99 + {
  100 + if (!renderer)
  101 + return false;
  102 + renderer->AddRef();
  103 + if (m_pRenderer)
  104 + m_pRenderer->Release();
  105 + m_pRenderer = renderer;
  106 + return true;
  107 + }
  108 +
  109 + BOOL ScaleDependentRenderer::DrawData(clsCrSurf* pClsCS, DataCollection* data,
  110 + bool drawSimpleData, char* pFlag)
  111 + {
  112 + //DrawData是否要使用重载??现在弄进去有麻烦啊
  113 + double r__ = data->m_dR;
  114 + double r = r__ / (96/0.0254);
  115 + if (r <m_dLower || r > m_dUpper)
  116 + return false;
  117 + int renType = m_pRenderer->RendererType();
  118 + m_pRenderer->DrawData(pClsCS, data, pFlag);
  119 + /*switch (renType)
  120 + {
  121 + case dmapSimpleMarkerSymbol:((SimpleMarkerSymbol*)m_pRenderer)->DrawData(pClsCS, data); break;
  122 + case dmapSimpleLineSymbol:((SimpleLineSymbol*)m_pRenderer)->DrawData(pClsCS, data); break;
  123 + case dmapSimplePolygonSymbol:((SimplePolygonSymbol*)m_pRenderer)->DrawData(pClsCS, data); break;
  124 + case dmapValueMapRenderer:((ValueMapRenderer*)m_pRenderer)->DrawData(pClsCS, data); break;
  125 + case dmapRangeMapRenderer:((RangeMapRenderer*)m_pRenderer)->DrawData(pClsCS, data); break;
  126 + case dmapGroupRenderer:((GroupRenderer*)m_pRenderer)->DrawData(pClsCS, data, pFlag); break;
  127 + case dmapSimpleLabelRenderer:((SimpleLabelRenderer*)m_pRenderer)->DrawData(pClsCS, data, pFlag); break;
  128 + default:
  129 + break;
  130 + }*/
  131 + return true;
  132 + }
  133 +
  134 + BOOL ScaleDependentRenderer::DrawData(clsCrSurf* pClsCS,
  135 + DataCollection* data, int dataIndex, char* pFlag)
  136 + {
  137 + //DrawData是否要使用重载??现在弄进去有麻烦啊
  138 + double r__ = data->m_dR;
  139 + double r = r__ / (96/0.0254);
  140 + if (r <m_dLower || r > m_dUpper)
  141 + return false;
  142 + int renType = m_pRenderer->RendererType();
  143 + // data->m_pData
  144 + m_pRenderer->DrawData(pClsCS, data, dataIndex, pFlag);
  145 + /*switch (renType)
  146 + {
  147 + case dmapSimpleMarkerSymbol:((SimpleMarkerSymbol*)m_pRenderer)->DrawData(pClsCS, data); break;
  148 + case dmapSimpleLineSymbol:((SimpleLineSymbol*)m_pRenderer)->DrawData(pClsCS, data); break;
  149 + case dmapSimplePolygonSymbol:((SimplePolygonSymbol*)m_pRenderer)->DrawData(pClsCS, data); break;
  150 + case dmapValueMapRenderer:((ValueMapRenderer*)m_pRenderer)->DrawData(pClsCS, data); break;
  151 + case dmapRangeMapRenderer:((RangeMapRenderer*)m_pRenderer)->DrawData(pClsCS, data); break;
  152 + case dmapGroupRenderer:((GroupRenderer*)m_pRenderer)->DrawData(pClsCS, data, pFlag); break;
  153 + case dmapSimpleLabelRenderer:((SimpleLabelRenderer*)m_pRenderer)->DrawData(pClsCS, data, pFlag); break;
  154 + default:
  155 + break;
  156 + }*/
  157 + return true;
  158 + }
  159 +
  160 + BOOL ScaleDependentRenderer::DrawLegend(clsCrSurf* pClsCS, shared_ptr<legendParamater> pLegendParamater,int layerType, char* pFlag)
  161 + {
  162 +
  163 + return true;
  164 + }
  165 +
  166 +
  167 + void ScaleDependentRenderer::TryAddField(vector<string>&pvField)
  168 + {
  169 + if (m_pRenderer)m_pRenderer->TryAddField(pvField);
  170 + }
  171 +}
\ No newline at end of file
... ...
  1 +#ifndef _ScaleDependentRenderer_H_
  2 +#define _ScaleDependentRenderer_H_
  3 +#include <boost/property_tree/ptree.hpp>
  4 +#include <boost/property_tree/xml_parser.hpp>
  5 +#include <boost/foreach.hpp>
  6 +#include"Renderer.h"
  7 +#include<vector>
  8 +#include "dmap_core.h"
  9 +using namespace std;
  10 +namespace DmapCore_30
  11 +{
  12 + class clsCrSurf;
  13 + class DataCollection;
  14 + class CORE_EXPORT ScaleDependentRenderer :public Renderer
  15 + {
  16 + public:
  17 + //scale中只有一个样式,通常为group
  18 + ScaleDependentRenderer();
  19 + ~ScaleDependentRenderer();
  20 + virtual BOOL Parse(rapidxml::xml_node<char>* node, AppendBuffer *f);
  21 + virtual void ToJson(AppendBuffer *ab);
  22 + //virtual BOOL RendererString(Renderer** ppRen, const char** psXML);
  23 + virtual BOOL DrawData(clsCrSurf* pClsCS, DataCollection* data, bool drawSimpleData, char* pFlag);
  24 + virtual BOOL DrawData(clsCrSurf* pClsCS, DataCollection* data, int drawSimpleData, char* pFlag);
  25 + virtual BOOL DrawLegend(clsCrSurf* pClsCS, shared_ptr<legendParamater> pLegendParamater,int layerType, char* pFlag);
  26 + virtual int RendererType();
  27 + static ScaleDependentRenderer* CreateNew();
  28 +
  29 +
  30 + double GetLower();
  31 + BOOL SetLower(double lower);
  32 + double GetUpper();
  33 + BOOL SetUpper(double upper);
  34 + Renderer* GetRenderer();
  35 + BOOL SetRenderer(Renderer* renderer);
  36 +
  37 + virtual void TryAddField(vector<string>&pvField);
  38 + virtual bool TryFindHeatRenderer(){ return false; }
  39 +
  40 + double m_dLower;
  41 + double m_dUpper;
  42 + Renderer* m_pRenderer;
  43 + };
  44 +
  45 +}
  46 +#endif
\ No newline at end of file
... ...
  1 +
  2 +
  3 +#include "SimpleLabelRenderer.h"
  4 +#include"clsXML.h"
  5 +#include"DataCollection.h"
  6 +#include"clsCrSurf.h"
  7 +#define _USE_MATH_DEFINES
  8 +#include<math.h>
  9 +#include"clsMalloc.h"
  10 +#include"clsUtil.h"
  11 +//#include"StringHelp.h"
  12 +//#include"algorithm.h"
  13 +#include<iterator>
  14 +#include <stdlib.h>
  15 +#include <iostream>
  16 +#include "clsJson.h"
  17 +#include <string.h>
  18 +//#include <string.h>
  19 +#define dotX 5
  20 +#define dotY 5
  21 +#define WordIntervalLine 8.0 //文字与线条隔开两个像素
  22 +#define WordIntervalPoint 5.0 //文字与点隔开两个像素
  23 +namespace DmapCore_30
  24 +{
  25 +
  26 +SimpleLabelRenderer::SimpleLabelRenderer()
  27 +{
  28 + m_pTextSymbol = new TextSymbol();
  29 + m_sField = "";
  30 + m_sLabelPriorities = "0,0,0,0,0,0,0,0";
  31 + m_pTextSymbol = NULL;
  32 + /*m_iFeatureWeight = 0;
  33 + m_iLabelWeight = 0;
  34 + m_iHowmanyLabels = 0;
  35 + m_dLabelBufferRatio = 0;*/
  36 + m_sRotationAngles = "0";
  37 + //m_iRotateMethod = 0;
  38 + m_vdAngles.push_back(0);
  39 + m_sRotationAngleField = "";
  40 + m_bIsVerticalToAngle = false;
  41 + this->DoSetPointLabelPositionType();
  42 + m_iLineLabelPositionDirection = 0;
  43 + m_iLineLabelPositionStartOrEnd = 0;
  44 + m_sLineLabelPositionPlaces = "9,9,9";
  45 + this->DoSetLineLabelPositionPlaces();
  46 +
  47 + m_iPolygonLabelPositionDirection = 0;
  48 + m_bLabelInPolygon = false;
  49 + m_simpleRenderer = false;
  50 +}
  51 +
  52 +
  53 +SimpleLabelRenderer::~SimpleLabelRenderer()
  54 +{
  55 + if (m_pTextSymbol)
  56 + m_pTextSymbol->Release();
  57 +}
  58 +
  59 +int SimpleLabelRenderer::RendererType()
  60 +{
  61 + return dmapSimpleLabelRenderer;
  62 +}
  63 +bool SimpleLabelRenderer::Parse(boost::property_tree::ptree &pt, AppendBuffer *f)
  64 +{
  65 +
  66 + clsXML clsX(f, "SIMPLELABELRENDERER");
  67 + clsXML::XMLAttrParse(pt, f, &m_sField, "field");
  68 +
  69 +
  70 + clsXML::XMLAttrParse(pt, f, &m_sLabelPriorities, "labelpriorities");
  71 + clsXML::XMLAttrParse(pt, f, &m_sRotationAngles, "rotationangles");
  72 + //clsXML::ParseEnum("rotatemethod", pt, f, &m_iRotateMethod,"geograghic","arithmetic","mod_arithmetic");
  73 + clsXML::XMLAttrParse(pt, f, &m_sRotationAngleField, "rotationanglefield");
  74 + clsXML::XMLAttrParse(pt, f,&m_bIsVerticalToAngle,"isverticaltoangle" );
  75 + //if (pt)
  76 + this->DoSetPointLabelPositionType();
  77 +
  78 + clsXML::ParseEnum("linelabelpositiondirection", pt, f, &m_iLineLabelPositionDirection, "level", "parallel", "curved","vertical");
  79 + clsXML::ParseEnum("linelabelpositionstartorend",pt,f,&m_iLineLabelPositionStartOrEnd,"start","end","center");
  80 + clsXML::XMLAttrParse(pt, f, &m_sLineLabelPositionPlaces, "linelabelpositionplace");
  81 + if (m_sLineLabelPositionPlaces == "error")
  82 + {
  83 + m_sLineLabelPositionPlaces = "9,9,9";
  84 + }
  85 + //if (pt)
  86 + this->DoSetLineLabelPositionPlaces();
  87 +
  88 +
  89 + clsXML::ParseEnum("polygonlabelpositiondirection",pt,f,&m_iPolygonLabelPositionDirection,"parallel","straight","parallelandstraight");
  90 + clsXML::XMLAttrParse(pt, f, &m_bLabelInPolygon, "labelinpolygon");
  91 + clsX.closeProperties();
  92 + //if (pt)
  93 + //{
  94 + Renderer* ts = NULL;
  95 + boost::property_tree::ptree pt_textsymbol = pt.get_child("TEXTSYMBOL");
  96 + clsXML::XMLParse("TEXTSYMBOL",pt_textsymbol, &ts);
  97 + m_pTextSymbol = (TextSymbol*)ts;
  98 + //}
  99 + //else
  100 + //{
  101 + // Renderer* ren = (Renderer*)m_pTextSymbol;
  102 + // clsXML::XMLParse(NULL, f, &ren);
  103 + //}
  104 +
  105 + return true;
  106 +}
  107 +
  108 + void SimpleLabelRenderer::ToJson(AppendBuffer *ab)
  109 + {
  110 + char buff[300] = {0};
  111 + char resultbuff[5000] = {0};
  112 + strcat(resultbuff, R"("SIMPLELABELRENDERER":{)");
  113 + clsJson::JsonAttrParse("field", resultbuff, buff, this->m_sField);
  114 + clsJson::JsonAttrParse("labelpriorities", resultbuff, buff, this->m_sLabelPriorities);
  115 + clsJson::JsonAttrParse("rotationangles", resultbuff, buff, this->m_sRotationAngles);
  116 + clsJson::JsonAttrParse("rotationanglefield", resultbuff, buff, this->m_sRotationAngleField);
  117 + clsJson::JsonAttrParse("isverticaltoangle", resultbuff, buff, this->m_bIsVerticalToAngle);
  118 +
  119 + clsJson::ParseEnum("linelabelpositiondirection", resultbuff, buff, m_iLineLabelPositionDirection, "level", "parallel", "curved","vertical");
  120 + clsJson::ParseEnum("linelabelpositionstartorend", resultbuff, buff, m_iLineLabelPositionStartOrEnd, "start","end","center");
  121 + clsJson::JsonAttrParse("linelabelpositionplace", resultbuff, buff, m_sLineLabelPositionPlaces);
  122 + clsJson::ParseEnum("polygonlabelpositiondirection", resultbuff, buff, m_iPolygonLabelPositionDirection, "parallel","straight","parallelandstraight");
  123 +
  124 + clsJson::JsonAttrParse("labelinpolygon", resultbuff, buff, this->m_bLabelInPolygon);
  125 + ab->AppendString(resultbuff);
  126 + if(m_pTextSymbol)
  127 + {
  128 + m_pTextSymbol->ToJson(ab);
  129 + ab->AppendString("}");
  130 + }
  131 + else
  132 + {
  133 + ab->AppendString(R"("JsonEnd":"" })");
  134 + }
  135 +
  136 + //clsJson::JsonAttrEnd(resultbuff);
  137 + }
  138 +//bool SimpleLabelRenderer::RendererString(Renderer** ppRen, const char** psXML)
  139 +//{
  140 +// return true;
  141 +//}
  142 +
  143 +bool SimpleLabelRenderer::DrawData(clsCrSurf* pClsCS, DataCollection* data, bool drawSimpleData, char* pFlag)
  144 +{
  145 + int iPartCount = data->m_iPartCount;
  146 + if (m_pTextSymbol == 0)
  147 + {
  148 + return true;
  149 + }
  150 +
  151 + //m_lpt = this->DoSetLabelPositionType();
  152 + m_pTextSymbol->SetCairo(pClsCS);
  153 +
  154 + for (int i = 0; i < iPartCount; i++)
  155 + this->DrawStruct(pClsCS, data, i);
  156 + return true;
  157 +}
  158 +
  159 +
  160 +bool SimpleLabelRenderer::DrawData(clsCrSurf* pClsCS, DataCollection* data, int dataIndex, char* pFlag)
  161 +{
  162 + int iPartCount = data->m_iPartCount;
  163 + if (m_pTextSymbol == 0)
  164 + {
  165 + return true;
  166 + }
  167 + //m_lpt = this->DoSetLabelPositionType();
  168 + m_pTextSymbol->SetCairo(pClsCS);
  169 +
  170 + //for (int i = 0; i < iPartCount; i++)
  171 + this->DrawStruct(pClsCS, data, dataIndex);
  172 + return true;
  173 +}
  174 +
  175 +SimpleLabelRenderer* SimpleLabelRenderer::CreateNew()
  176 +{
  177 + SimpleLabelRenderer* dest = new SimpleLabelRenderer();
  178 + return dest;
  179 +}
  180 +const char* SimpleLabelRenderer::GetField()
  181 +{
  182 + return m_sField.c_str();
  183 +}
  184 +bool SimpleLabelRenderer::SetField(const char* sField)
  185 +{
  186 + m_sField = sField;
  187 + return true;
  188 +}
  189 +const char* SimpleLabelRenderer::GetLabelPriorities()
  190 +{
  191 + return m_sLabelPriorities.c_str();
  192 +}
  193 +bool SimpleLabelRenderer::SetLabelPriorities(const char* sLabelPriorities)
  194 +{
  195 + bool flag = this->TrackPriorityString(sLabelPriorities);
  196 + if (!flag)
  197 + return false;
  198 + m_sLabelPriorities = sLabelPriorities;
  199 +
  200 + this->DoSetPointLabelPositionType();
  201 + return true;
  202 +}
  203 +TextSymbol* SimpleLabelRenderer::GetTextSymbol()
  204 +{
  205 + if (m_pTextSymbol)
  206 + m_pTextSymbol->AddRef();
  207 + return m_pTextSymbol;
  208 +}
  209 +bool SimpleLabelRenderer::SetTextSymbol(TextSymbol* ts)
  210 +{
  211 + if (!ts)
  212 + return false;
  213 + ts->AddRef();
  214 + if (m_pTextSymbol)
  215 + m_pTextSymbol->Release();
  216 + m_pTextSymbol = ts;
  217 + return true;
  218 +}
  219 +const char*SimpleLabelRenderer::GetRotationAngleField()
  220 +{
  221 + return m_sRotationAngleField.c_str();
  222 +}
  223 +bool SimpleLabelRenderer::SetRotationAngleField(const char* sAngleField)
  224 +{
  225 + m_sRotationAngleField = sAngleField;
  226 + if (m_sRotationAngleField != "")
  227 + {
  228 + this->DoSetPointLabelPositionType();
  229 + }
  230 + return true;
  231 +}
  232 +const char* SimpleLabelRenderer::GetRotationAngles()
  233 +{
  234 + return m_sRotationAngles.c_str();
  235 +}
  236 +bool SimpleLabelRenderer::SetRotationAngles(const char* sRotationalAngles)
  237 +{
  238 + m_sRotationAngles = sRotationalAngles;
  239 + bool bIsNumber = this->TrackRotationAngles(sRotationalAngles);
  240 + if (bIsNumber)
  241 + {
  242 + this->CalculateAngles();
  243 + this->DoSetPointLabelPositionType();
  244 + }
  245 +
  246 + return true;
  247 +}
  248 +//int SimpleLabelRenderer::GetRotateMethod()
  249 +//{
  250 +// return m_iRotateMethod;
  251 +//}
  252 +//bool SimpleLabelRenderer::SetRotateMethod(int iRotateMethod)
  253 +//{
  254 +// m_iRotateMethod = iRotateMethod;
  255 +// return true;
  256 +//}
  257 +int SimpleLabelRenderer::GetLineLabelPositionDirection()
  258 +{
  259 + return m_iLineLabelPositionDirection;
  260 +}
  261 +bool SimpleLabelRenderer::SetLineLabelPositionDirection(int iLineLabelPositionDirection)
  262 +{
  263 + m_iLineLabelPositionDirection = iLineLabelPositionDirection;
  264 + return true;
  265 +}
  266 +const char*SimpleLabelRenderer::GetLineLabelPositionPlace()
  267 +{
  268 + return m_sLineLabelPositionPlaces.c_str();
  269 +}
  270 +bool SimpleLabelRenderer::SetLineLabelPositionPlace(const char*sLineLabelPositionPlace)
  271 +{
  272 + m_sLineLabelPositionPlaces = sLineLabelPositionPlace;
  273 + this->DoSetLineLabelPositionPlaces();
  274 + return true;
  275 +}
  276 +int SimpleLabelRenderer::GetLineLabelPositionStartOrEnd()
  277 +{
  278 + return m_iLineLabelPositionStartOrEnd;
  279 +}
  280 +bool SimpleLabelRenderer::SetLineLabelPositionStartOrEnd(int iLineLabelPositionStartOrEnd)
  281 +{
  282 + m_iLineLabelPositionStartOrEnd = iLineLabelPositionStartOrEnd;
  283 + return true;
  284 +}
  285 +
  286 +int SimpleLabelRenderer::GetPolygonLabelPositionDirection()
  287 +{
  288 + return m_iPolygonLabelPositionDirection;
  289 +}
  290 +bool SimpleLabelRenderer::SetPolygonLabelPositionDirection(int iPolygonLabelPositionDirection)
  291 +{
  292 + m_iPolygonLabelPositionDirection = iPolygonLabelPositionDirection;
  293 + return true;
  294 +}
  295 +bool SimpleLabelRenderer::GetLabelInPolygon()
  296 +{
  297 + return m_bLabelInPolygon;
  298 +}
  299 +bool SimpleLabelRenderer::SetLabelInPolygon(bool bLabelInPolygon)
  300 +{
  301 + m_bLabelInPolygon = bLabelInPolygon;
  302 + return true;
  303 +}
  304 +bool SimpleLabelRenderer::GetIsVerticalToAngle()
  305 +{
  306 + return m_bIsVerticalToAngle;
  307 +}
  308 +bool SimpleLabelRenderer::SetIsVerticalToAngle(bool bIsVerticalToAngle)
  309 +{
  310 + m_bIsVerticalToAngle = bIsVerticalToAngle;
  311 + return true;
  312 +}
  313 +
  314 +
  315 +
  316 +bool SimpleLabelRenderer::DoSetLineLabelPositionPlaces()
  317 +{
  318 + if (m_sLineLabelPositionPlaces == "")
  319 + return true;
  320 + const char* sLLPP = m_sLineLabelPositionPlaces.c_str();
  321 +
  322 + char str[1000];
  323 + strcpy(str, sLLPP);
  324 + int len = strlen(str);
  325 + char * p = str;
  326 + int k = 0;
  327 + for (int i = 0; i < len + 1; i++)
  328 + {
  329 + char c = str[i];
  330 + if (c == 0)
  331 + {
  332 + m_LineLabelPositionPlaces[k] = stoi(p, NULL);
  333 + break;
  334 + }
  335 + if (c == ',')
  336 + {
  337 + str[i] = 0;
  338 + m_LineLabelPositionPlaces[k++] = stoi(p, NULL);
  339 + p = str + i+1;
  340 + }
  341 + }
  342 + return true;
  343 +}
  344 +
  345 +
  346 +void SimpleLabelRenderer::TryAddField(vector<string>&pvField)
  347 +{
  348 + TryAddField2(pvField, m_sField);
  349 + if (m_plpt == SimpleLabelRenderer::dmapPointLabelPositionAngleField)
  350 + {
  351 + TryAddField2(pvField, m_sRotationAngleField);
  352 + }
  353 +
  354 +
  355 + /*
  356 + vector<string>::iterator it = find(pvField->begin(), pvField->end(), m_sField);
  357 + if (it == pvField->end())
  358 + pvField->push_back(m_sField);
  359 +
  360 + if (m_plpt == SimpleLabelRenderer::dmapPointLabelPositionAngleField)
  361 + {
  362 + vector<string>::iterator it = find(pvField->begin(), pvField->end(), m_sRotationAngles);
  363 + if (it == pvField->end())
  364 + pvField->push_back(m_sRotationAngleField);
  365 + }*/
  366 +}
  367 +
  368 +
  369 +
  370 +SimpleLabelRenderer::PointLabelPositionType SimpleLabelRenderer::DoSetPointLabelPositionType()
  371 +{
  372 + if (m_sLabelPriorities != "0,0,0,0,0,0,0,0")
  373 + {
  374 + if (m_sLabelPriorities == "DMap_PlaceOnTopHorizontal")
  375 + m_plpt = SimpleLabelRenderer::dmapPointLabelPositionOnTopHorizontal;
  376 + else
  377 + {
  378 + //判断是否是8个数字
  379 + const char* sLabelPriorities = m_sLabelPriorities.c_str();
  380 + bool isNumbers = this->TrackPriorityString(sLabelPriorities);
  381 + if (!isNumbers)
  382 + m_plpt = SimpleLabelRenderer::dmapPointLabelPositionError;
  383 + else
  384 + {
  385 + m_plpt = SimpleLabelRenderer::dmapPointLabelPositionPeriphery;
  386 + this->CalculatePrioritiesNumber();
  387 + }
  388 +
  389 + }
  390 + }
  391 + else
  392 + {
  393 + if (m_sRotationAngleField != "")
  394 + m_plpt = SimpleLabelRenderer::dmapPointLabelPositionAngleField;
  395 + else
  396 + m_plpt = SimpleLabelRenderer::dmapPointLabelPositionAngleNumber;
  397 + }
  398 +
  399 + return m_plpt;
  400 +}
  401 +
  402 +bool SimpleLabelRenderer::TrackPriorityString(const char* sPriority)
  403 +{
  404 + //判断 m_sLabelPriorities 是否是8个数字,是返回true
  405 + return true;
  406 +}
  407 +
  408 +bool SimpleLabelRenderer::TrackRotationAngles(const char* sRotationalAngles)
  409 +{
  410 + /*
  411 + 这里偷个懒,认为只有正负号,小数点,逗号,数字的字符串就是合法的
  412 + */
  413 + int len = strlen(sRotationalAngles);
  414 + bool bIsNumber = true;
  415 +
  416 + for (int i = 0; i < len; i++)
  417 + {
  418 + char c = sRotationalAngles[i];
  419 + switch (c)
  420 + {
  421 + case '+':
  422 + case '-':
  423 + case '.':
  424 + case ',':
  425 + case '0':
  426 + case '1':
  427 + case '2':
  428 + case '3':
  429 + case '4':
  430 + case '5':
  431 + case '6':
  432 + case '7':
  433 + case '8':
  434 + case '9':
  435 + break;
  436 + default:
  437 + bIsNumber = false;
  438 + break;
  439 + }
  440 + }
  441 +
  442 + return bIsNumber;
  443 +
  444 +}
  445 +
  446 +bool SimpleLabelRenderer::CalculatePrioritiesNumber()
  447 +{
  448 + const char* ss = m_sLabelPriorities.c_str();
  449 +
  450 + int num[8]; // 这是从字符串接收来的8个数字
  451 +
  452 + for (int i = 0; i < 8; i++)
  453 + {
  454 + num[i] = ss[2 * i] - '0';
  455 + if (num[i] == 0)
  456 + {
  457 + num[i] = 9; //将0 暂时作为9处理
  458 + m_i8[i] = 0;
  459 + }
  460 + else
  461 + m_i8[i] = i + 1;
  462 + }
  463 +
  464 + int temp;
  465 + for (int i = 0; i < 7; i++)
  466 + {
  467 + for (int j = 0; j < 7 - i; j++)
  468 + {
  469 + if (num[j] > num[j + 1])
  470 + {
  471 + temp = num[j]; num[j] = num[j + 1]; num[j + 1] = temp;
  472 + temp = m_i8[j]; m_i8[j] = m_i8[j + 1]; m_i8[j + 1] = temp;
  473 + }
  474 + }
  475 + }
  476 + return true;
  477 +}
  478 +bool SimpleLabelRenderer::CalculateAngles()
  479 +{
  480 + m_vdAngles.clear();
  481 + const char* sAngles = m_sRotationAngles.c_str();
  482 + int len = strlen(sAngles);
  483 + clsMalloc m(100);
  484 + char * sAngles_ = m.mem;
  485 + memcpy(sAngles_, sAngles, len);
  486 + char * p = sAngles_;
  487 + for (int i = 0; i <= len; i++)
  488 + {
  489 + char c = sAngles_[i];
  490 + if (!c)
  491 + {
  492 + double dAngle = stod(p, NULL);
  493 + dAngle = dAngle / 180 * M_PI;
  494 + m_vdAngles.push_back(dAngle);
  495 + break;
  496 + }
  497 +
  498 + if (c == ',')
  499 + {
  500 + sAngles_[i] = 0;
  501 + double dAngle = stod(p, NULL);
  502 + dAngle = dAngle / 180 * M_PI;
  503 + m_vdAngles.push_back(dAngle);
  504 + p = sAngles_ + i + 1;
  505 + }
  506 + }
  507 + return true;
  508 +}
  509 +
  510 +
  511 +bool SimpleLabelRenderer::DrawStruct(clsCrSurf* pClsCS, DataCollection* data, int index)
  512 +{
  513 + int iStructType = data->m_iStructType;
  514 +
  515 + /*
  516 + 获取到SimpleLabelRenderer的field
  517 + */
  518 + int iFieldCount = (int)(data->m_vFieldName.size());
  519 + int iFieldIndex = -1;
  520 + for (int i = 0; i < iFieldCount; i++)
  521 + {
  522 + if (strcmp(m_sField.c_str() , data->m_vFieldName[i].c_str()) ==0)
  523 + {
  524 + iFieldIndex = i;
  525 + break;
  526 + }
  527 + }
  528 +
  529 + if (iFieldIndex < 0)return false;
  530 + const char* sFieldValue_GBK = (data->m_vAllField[index][iFieldIndex]).c_str();
  531 + if (sFieldValue_GBK == NULL || sFieldValue_GBK[0] == 0 || (sFieldValue_GBK[1] == 0 && sFieldValue_GBK[0] == ' '))
  532 + {
  533 + return false;
  534 + }
  535 +
  536 + //if (index >= 2)
  537 + //{
  538 + // return false;
  539 + //}
  540 +
  541 +// printf(sFieldValue_GBK); printf(" %d \r\n", index);
  542 +
  543 + /*printf(" %d \r\n",index);
  544 + if ( index == 72)
  545 + {
  546 + printf(" %d \r\n", index);
  547 + }*/
  548 +
  549 + //clsMalloc clsM;
  550 + //bool flag = clsUtil::ConvertEncGB18030_UTF8(sFieldValue_GBK, clsM);
  551 + //if (!flag)
  552 + //return false;
  553 + //char* sUTF8 = (char *)sFieldValue_GBK;//clsM.mem;
  554 +
  555 +
  556 + switch (iStructType)
  557 + {
  558 + case clsStruct::Struct_Point:
  559 + {
  560 + /*clsStruct::POINT* pPoint = ((clsStruct::POINT*)(data->m_pData)) + index;
  561 + this->DrawPoint(pClsCS, pPoint, sUTF8);*/
  562 + this->DrawPoint(pClsCS, data, index, (char *)sFieldValue_GBK);
  563 + break;
  564 + }
  565 + case clsStruct::Struct_MLine:
  566 + {
  567 + clsStruct::MLINE* pMLine = ((clsStruct::MLINE*)(data->m_pData)) + index;
  568 + this->DrawMLine(pClsCS, pMLine, (char *)sFieldValue_GBK);
  569 + break;
  570 + }
  571 + case clsStruct::Struct_MPolygon:
  572 + {
  573 + clsStruct::MPOLYGON* pMPolygon = ((clsStruct::MPOLYGON*)(data->m_pData)) + index;
  574 + this->DrawMPolygon(pClsCS, pMPolygon, (char *)sFieldValue_GBK);
  575 + break;
  576 + }
  577 + default:
  578 + break;
  579 + }
  580 +
  581 + return true;
  582 +}
  583 +
  584 +
  585 +
  586 +bool SimpleLabelRenderer::DrawPoint(clsCrSurf* pClsCS, DataCollection* data, int index, char* sUTF8)
  587 +{
  588 + clsStruct::POINT* pStructPoint = ((clsStruct::POINT*)(data->m_pData)) + index;
  589 + double x = pStructPoint->x, y = pStructPoint->y;
  590 +
  591 + switch (m_plpt)
  592 + {
  593 + case SimpleLabelRenderer::dmapPointLabelPositionOnTopHorizontal:
  594 + {
  595 + cairo_text_extents_t extents;
  596 + cairo_text_extents(pClsCS->m_pCr, sUTF8, &extents);
  597 + x = x - extents.width / 2;
  598 + y = y + extents.height / 2;
  599 + m_pTextSymbol->DrawAText(pClsCS, x, y, sUTF8);
  600 + break;
  601 + }
  602 + case SimpleLabelRenderer::dmapPointLabelPositionAngleNumber:
  603 + {
  604 + int iAnglesCount = m_vdAngles.size();
  605 + for (int i = 0; i < iAnglesCount; i++)
  606 + {
  607 + double dAngle = m_vdAngles[i];
  608 +
  609 + dAngle = clsUtil::StandardizationAngle(dAngle);
  610 + double x_show, y_show;
  611 + cairo_text_extents_t extents;
  612 + cairo_text_extents(pClsCS->m_pCr, sUTF8, &extents);
  613 + double dTextW = extents.x_advance;
  614 + double dTextH = extents.height;
  615 + if (dAngle >= 0 && dAngle < M_PI / 2)
  616 + {
  617 + if (m_bIsVerticalToAngle)
  618 + {
  619 + dAngle = dAngle - M_PI / 2;
  620 + double dAngle__ = -dAngle;
  621 + double x_ = x - cos(dAngle__)*dTextW / 2;
  622 + double y_ = y + sin(dAngle__)*dTextW / 2;
  623 + x_show = x_ + sin(dAngle__)*(dTextH + WordIntervalPoint);
  624 + y_show = y_ + cos(dAngle__)*(dTextH + WordIntervalPoint);
  625 + }
  626 + else
  627 + {
  628 + double x_ = x - sin(dAngle)*dTextH / 2;
  629 + double y_ = y + cos(dAngle)*dTextH / 2;
  630 + x_show = x_ + cos(dAngle)*WordIntervalPoint;
  631 + y_show = y_ + sin(dAngle)*WordIntervalPoint;
  632 + }
  633 + }
  634 + else if ((dAngle > M_PI / 2) && (dAngle < M_PI))
  635 + {
  636 + if (m_bIsVerticalToAngle)
  637 + {
  638 + dAngle -= M_PI / 2;
  639 + double x_ = x - cos(dAngle)*dTextW / 2;
  640 + double y_ = y - sin(dAngle)*dTextW / 2;
  641 + x_show = x_ - sin(dAngle)*(dTextH + WordIntervalPoint);
  642 + y_show = y_ + cos(dAngle)*(dTextH + WordIntervalPoint);
  643 + }
  644 + else
  645 + {
  646 + double dAngle_ = dAngle - M_PI / 2;
  647 + double x_ = x - cos(dAngle_)*(dTextW + WordIntervalPoint);
  648 + double y_ = y + sin(dAngle_)*(dTextW + WordIntervalPoint);
  649 + x_show = x_ + sin(dAngle_)*dTextH / 2;
  650 + y_show = y_ + cos(dAngle_)*dTextH / 2;
  651 + dAngle = -dAngle_;
  652 + }
  653 + }
  654 + else if ((dAngle >= M_PI) && (dAngle <= 3 * M_PI / 2))
  655 + {
  656 + if (m_bIsVerticalToAngle)
  657 + {
  658 + double dAngle_ = dAngle - M_PI;
  659 + double x_ = x - sin(dAngle_)*dTextW / 2;
  660 + double y_ = y + cos(dAngle_)*dTextW / 2;
  661 + x_show = x_ - cos(dAngle_)*WordIntervalPoint;
  662 + y_show = y_ - sin(dAngle_)*WordIntervalPoint;
  663 +
  664 + dAngle = dAngle_ - M_PI / 2;
  665 + }
  666 + else
  667 + {
  668 + dAngle -= M_PI;
  669 + double x_ = x - sin(dAngle)*dTextH / 2;
  670 + double y_ = y + cos(dAngle)*dTextH / 2;
  671 + x_show = x_ - cos(dAngle)*(dTextW + WordIntervalPoint);
  672 + y_show = y_ - sin(dAngle)*(dTextW + WordIntervalPoint);
  673 + }
  674 + }
  675 + else
  676 + {
  677 + if (m_bIsVerticalToAngle)
  678 + {
  679 + dAngle -= 3 * M_PI / 2;
  680 + double x_ = x - cos(dAngle)* dTextW / 2;
  681 + double y_ = y - sin(dAngle)* dTextW / 2;
  682 + x_show = x_ + sin(dAngle)*WordIntervalPoint;
  683 + y_show = y_ - cos(dAngle)* WordIntervalPoint;
  684 + }
  685 + else
  686 + {
  687 + double dAngle_ = 2 * M_PI - dAngle;
  688 + double x_ = x + sin(dAngle_)*dTextH / 2;
  689 + double y_ = y + cos(dAngle_)*dTextH / 2;
  690 + x_show = x_ + cos(dAngle_)*WordIntervalPoint;
  691 + y_show = y_ - sin(dAngle_)*WordIntervalPoint;
  692 + dAngle = -dAngle_;
  693 +
  694 + }
  695 + }
  696 +
  697 + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  698 + if (m_pTextSymbol->DrawAText(pClsCS, x_show, y_show, sUTF8, dAngle))
  699 + break;
  700 + }
  701 + break;
  702 + }
  703 + case SimpleLabelRenderer::dmapPointLabelPositionAngleField:
  704 + {
  705 + /*
  706 + 获取 弧度
  707 + */
  708 + int iFieldCount = (int)(data->m_vFieldName.size());
  709 + int iFieldIndex = -1;
  710 + for (int i = 0; i < iFieldCount; i++)
  711 + {
  712 + if (m_sRotationAngleField == data->m_vFieldName[i])
  713 + {
  714 + iFieldIndex = i;
  715 + break;
  716 + }
  717 + }
  718 + if (iFieldIndex == -1)
  719 + break;
  720 + const char* sAngle = (data->m_vAllField[index][iFieldIndex]).c_str();
  721 + double dAngle = stod(sAngle, NULL);
  722 + dAngle = dAngle / 180 * M_PI;
  723 +
  724 +
  725 +
  726 + dAngle = clsUtil::StandardizationAngle(dAngle);
  727 + double x_show, y_show;
  728 + cairo_text_extents_t extents;
  729 + cairo_text_extents(pClsCS->m_pCr, sUTF8, &extents);
  730 + double dTextW = extents.x_advance;
  731 + double dTextH = extents.height;
  732 + if (dAngle >= 0 && dAngle < M_PI / 2)
  733 + {
  734 + if (m_bIsVerticalToAngle)
  735 + {
  736 + dAngle = dAngle - M_PI / 2;
  737 + double dAngle__ = -dAngle;
  738 + double x_ = x - cos(dAngle__)*dTextW / 2;
  739 + double y_ = y + sin(dAngle__)*dTextW / 2;
  740 + x_show = x_ + sin(dAngle__)*(dTextH + WordIntervalPoint);
  741 + y_show = y_ + cos(dAngle__)*(dTextH + WordIntervalPoint);
  742 + }
  743 + else
  744 + {
  745 + double x_ = x - sin(dAngle)*dTextH / 2;
  746 + double y_ = y + cos(dAngle)*dTextH / 2;
  747 + x_show = x_ + cos(dAngle)*WordIntervalPoint;
  748 + y_show = y_ + sin(dAngle)*WordIntervalPoint;
  749 + }
  750 + }
  751 + else if ((dAngle > M_PI / 2) && (dAngle < M_PI))
  752 + {
  753 + if (m_bIsVerticalToAngle)
  754 + {
  755 + dAngle -= M_PI / 2;
  756 + double x_ = x - cos(dAngle)*dTextW / 2;
  757 + double y_ = y - sin(dAngle)*dTextW / 2;
  758 + x_show = x_ - sin(dAngle)*(dTextH + WordIntervalPoint);
  759 + y_show = y_ + cos(dAngle)*(dTextH + WordIntervalPoint);
  760 + }
  761 + else
  762 + {
  763 + double dAngle_ = dAngle - M_PI / 2;
  764 + double x_ = x - cos(dAngle_)*(dTextW + WordIntervalPoint);
  765 + double y_ = y + sin(dAngle_)*(dTextW + WordIntervalPoint);
  766 + x_show = x_ + sin(dAngle_)*dTextH / 2;
  767 + y_show = y_ + cos(dAngle_)*dTextH / 2;
  768 + dAngle = -dAngle_;
  769 + }
  770 + }
  771 + else if ((dAngle >= M_PI) && (dAngle <= 3 * M_PI / 2))
  772 + {
  773 + if (m_bIsVerticalToAngle)
  774 + {
  775 + double dAngle_ = dAngle - M_PI;
  776 + double x_ = x - sin(dAngle_)*dTextW / 2;
  777 + double y_ = y + cos(dAngle_)*dTextW / 2;
  778 + x_show = x_ - cos(dAngle_)*WordIntervalPoint;
  779 + y_show = y_ - sin(dAngle_)*WordIntervalPoint;
  780 +
  781 + dAngle = dAngle_ - M_PI / 2;
  782 + }
  783 + else
  784 + {
  785 + dAngle -= M_PI;
  786 + double x_ = x - sin(dAngle)*dTextH / 2;
  787 + double y_ = y + cos(dAngle)*dTextH / 2;
  788 + x_show = x_ - cos(dAngle)*(dTextW + WordIntervalPoint);
  789 + y_show = y_ - sin(dAngle)*(dTextW + WordIntervalPoint);
  790 + }
  791 + }
  792 + else
  793 + {
  794 + if (m_bIsVerticalToAngle)
  795 + {
  796 + dAngle -= 3 * M_PI / 2;
  797 + double x_ = x - cos(dAngle)* dTextW / 2;
  798 + double y_ = y - sin(dAngle)* dTextW / 2;
  799 + x_show = x_ + sin(dAngle)*WordIntervalPoint;
  800 + y_show = y_ - cos(dAngle)* WordIntervalPoint;
  801 + }
  802 + else
  803 + {
  804 + double dAngle_ = 2 * M_PI - dAngle;
  805 + double x_ = x + sin(dAngle_)*dTextH / 2;
  806 + double y_ = y + cos(dAngle_)*dTextH / 2;
  807 + x_show = x_ + cos(dAngle_)*WordIntervalPoint;
  808 + y_show = y_ - sin(dAngle_)*WordIntervalPoint;
  809 + dAngle = -dAngle_;
  810 +
  811 + }
  812 + }
  813 +
  814 + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  815 +
  816 +
  817 +
  818 + m_pTextSymbol->DrawAText(pClsCS, x_show, y_show, sUTF8, dAngle);
  819 + break;
  820 + }
  821 + case SimpleLabelRenderer::dmapPointLabelPositionPeriphery:
  822 + {
  823 + cairo_text_extents_t extents;
  824 + cairo_text_extents(pClsCS->m_pCr, sUTF8, &extents);
  825 + double textW = extents.width, textH = extents.height;
  826 +
  827 + for (int i = 0; i < 8; i++)
  828 + {
  829 + bool flag = false;
  830 + switch (m_i8[i])
  831 + {
  832 + case 1:{if (m_pTextSymbol->DrawAText(pClsCS, x - dotX - textW, y - dotY, sUTF8,-1,-1)) flag = true; break; }
  833 + case 2:{if (m_pTextSymbol->DrawAText(pClsCS, x - textW / 2, y - dotY, sUTF8,0,-1)) flag = true; break; }
  834 + case 3:{if (m_pTextSymbol->DrawAText(pClsCS, x + dotX, y - dotY, sUTF8,1,-1)) flag = true; break; }
  835 + case 4:{if (m_pTextSymbol->DrawAText(pClsCS, x + dotX, y + textH / 2, sUTF8,1,0)) flag = true; break; }
  836 + case 5:{if (m_pTextSymbol->DrawAText(pClsCS, x + dotX, y + dotY + textH, sUTF8,1,1)) flag = true; break; }
  837 + case 6:{if (m_pTextSymbol->DrawAText(pClsCS, x - textW / 2, y + dotY + textH, sUTF8,0,1)) flag = true; break; }
  838 + case 7:{if (m_pTextSymbol->DrawAText(pClsCS, x - dotX - textW, y + dotY + textH, sUTF8,-1,1)) flag = true; break; }
  839 + case 8:{if (m_pTextSymbol->DrawAText(pClsCS, x - dotX - textW, y + textH / 2, sUTF8,-1,0)) flag = true; break; }
  840 + default:break;
  841 + }
  842 + if (flag)
  843 + break;
  844 + }
  845 + break;
  846 + }
  847 + case SimpleLabelRenderer::dmapPointLabelPositionError:break;
  848 + default:break;
  849 + }
  850 +
  851 + return true;
  852 +}
  853 +
  854 +bool SimpleLabelRenderer::DrawMLine(clsCrSurf* pClsCS, clsStruct::MLINE* pStrMLine, char* sUTF8)
  855 +{
  856 + this->DoSetLineLabelPositionPlaces();
  857 + //m_iLineLabelPositionDirection = 2;
  858 + switch (m_iLineLabelPositionDirection)
  859 + {
  860 + case dmapLineLabelPositionLevel:
  861 + this->DrawMLineLevel(pClsCS, pStrMLine, sUTF8);
  862 + break;
  863 + case dmapLineLabelPositionParallel:
  864 + this->DrawMLineParallel(pClsCS, pStrMLine, sUTF8);
  865 + break;
  866 + case dmapLineLabelPositionCurved:
  867 + this->DrawMLineCurve5(pClsCS, pStrMLine, sUTF8);
  868 + break;
  869 + case dmapLineLabelPositionVertical:
  870 + this->DrawMLineVertical(pClsCS, pStrMLine, sUTF8);
  871 + break;
  872 + default:
  873 + break;
  874 + }
  875 + return true;
  876 +}
  877 +
  878 +bool SimpleLabelRenderer::DrawMLineLevel(clsCrSurf* pClsCS, clsStruct::MLINE* pStrMLine, char* sUTF8)
  879 +{
  880 + double x = 0, y = 0;
  881 +
  882 + clsStruct::GetGravity(x, y, pStrMLine);
  883 +
  884 + /*switch (m_iLineLabelPositionStartOrEnd)
  885 + {
  886 + case dmapLineLabelPositionStart:
  887 + x = pStrMLine->p->p->x;
  888 + y = pStrMLine->p->p->y;
  889 + break;
  890 + case dmapLineLabelPositionEnd:
  891 + clsStruct::GetGravity(x, y, pStrMLine);
  892 + break;
  893 + case dmapLineLabelPositionCenter:
  894 + clsStruct::LINE* pLine = pStrMLine->p;
  895 + int nPoint = pLine->nPoint;
  896 + x = (pLine->p + nPoint - 1)->x;
  897 + y = (pLine->p + nPoint - 1)->y;
  898 + break;
  899 + default:
  900 + break;
  901 + }*/
  902 +
  903 + cairo_text_extents_t extents;
  904 + cairo_text_extents(pClsCS->m_pCr, sUTF8, &extents);
  905 +
  906 +
  907 +
  908 + x = x - extents.width / 2;
  909 + y = y + extents.height / 2;
  910 + m_pTextSymbol->DrawAText(pClsCS, x, y, sUTF8);
  911 + return true;
  912 +}
  913 +bool SimpleLabelRenderer::DrawMLineParallel(clsCrSurf* pClsCS, clsStruct::MLINE* pStrMLine, char* sUTF8)
  914 +{
  915 + //先区分在起点还是终点或者是中心点
  916 + double x1, y1, x2, y2;
  917 +
  918 +
  919 + switch (m_iLineLabelPositionStartOrEnd)
  920 + {
  921 + case dmapLineLabelPositionStart:
  922 + clsStruct::GetStart(pStrMLine, x1, y1, x2, y2);
  923 + break;
  924 + case dmapLineLabelPositionEnd:
  925 + clsStruct::GetEnd(pStrMLine, x1, y1, x2, y2);
  926 + break;
  927 + case dmapLineLabelPositionCenter:
  928 + clsStruct::GetCenter(pStrMLine, x1, y1, x2, y2);
  929 + break;
  930 + default:
  931 + x1 = x2 = y1 = y2 = 0;
  932 + break;
  933 + }
  934 +
  935 +
  936 +
  937 + cairo_text_extents_t extents;
  938 + cairo_text_extents(pClsCS->m_pCr, sUTF8, &extents);
  939 + double dW = extents.x_advance;
  940 + double dH = extents.height;
  941 +
  942 +
  943 +
  944 + double dAngle = atan((y2 - y1) / (x2 - x1));
  945 + if (x1 > x2)
  946 + dAngle += M_PI;
  947 + bool bHaveDraw = false;
  948 +
  949 +
  950 + for (int i = 0; i < 3; i++)
  951 + {
  952 + int iLineLabelPositionPlace = m_LineLabelPositionPlaces[i];
  953 +
  954 + switch (iLineLabelPositionPlace)
  955 + {
  956 + case dmapLineLabelPositionLeft:
  957 + {
  958 + if (x1 <= x2 && y1 <= y2)
  959 + {
  960 + double x = x1 + sin(dAngle)*WordIntervalLine;
  961 + double y = y1 - cos(dAngle)*WordIntervalLine;
  962 + bHaveDraw = m_pTextSymbol->DrawAText(pClsCS, x, y, sUTF8, dAngle);
  963 + }
  964 + else
  965 + if (x1 >= x2 && y1 >= y2)
  966 + {
  967 + double dAngle__ = dAngle - M_PI;
  968 + double x__ = x1 - sin(dAngle__)* (WordIntervalLine + dH);
  969 + double y__ = y1 + cos(dAngle__)* (WordIntervalLine + dH);
  970 + double x = x__ - cos(dAngle__)*dW;
  971 + double y = y__ - sin(dAngle__)*dW;
  972 + bHaveDraw = m_pTextSymbol->DrawAText(pClsCS, x, y, sUTF8, dAngle__);
  973 + }
  974 + else
  975 + if (x1 > x2 && y1 < y2)
  976 + {
  977 + double dAngle__ = dAngle - M_PI / 2;
  978 + double x__ = x1 + cos(dAngle__)*(WordIntervalLine + dH);
  979 + double y__ = y1 + sin(dAngle__)*(WordIntervalLine + dH);
  980 + double x = x__ - sin(dAngle__)*dW;
  981 + double y = y__ + cos(dAngle__)*dW;
  982 + bHaveDraw = m_pTextSymbol->DrawAText(pClsCS, x, y, sUTF8, dAngle__ - M_PI / 2);
  983 + }
  984 + else
  985 + if (x1 < x2&& y1> y2)
  986 + {
  987 + double dAngle__ = 2 * M_PI - dAngle;
  988 + double x = x1 - sin(dAngle__)*WordIntervalLine;
  989 + double y = y1 - cos(dAngle__)*WordIntervalLine;
  990 + bHaveDraw = m_pTextSymbol->DrawAText(pClsCS, x, y, sUTF8, -dAngle__);
  991 + }
  992 + break;
  993 + }
  994 + case dmapLineLabelPositionRight:
  995 + {
  996 + if (x1 <= x2 && y1 <= y2)
  997 + {
  998 + double x = x1 - sin(dAngle)*(WordIntervalLine + dH);
  999 + double y = y1 + cos(dAngle)*(WordIntervalLine + dH);
  1000 + bHaveDraw = m_pTextSymbol->DrawAText(pClsCS, x, y, sUTF8, dAngle);
  1001 + }
  1002 + else
  1003 + if (x1 >= x2 && y1 >= y2)
  1004 + {
  1005 + double dAngle__ = dAngle - M_PI;
  1006 + double x__ = x1 + sin(dAngle__)*WordIntervalLine;
  1007 + double y__ = y1 - cos(dAngle__)*WordIntervalLine;
  1008 + double x = x__ - cos(dAngle__)*dW;
  1009 + double y = y__ - sin(dAngle__)*dW;
  1010 + bHaveDraw = m_pTextSymbol->DrawAText(pClsCS, x, y, sUTF8, dAngle__);
  1011 +
  1012 + }
  1013 + else
  1014 + if (x1 > x2 && y1 < y2)
  1015 + {
  1016 + double dAngle__ = dAngle - M_PI / 2;
  1017 + double x__ = x1 - cos(dAngle__)*WordIntervalLine;
  1018 + double y__ = y1 - sin(dAngle__)*WordIntervalLine;
  1019 + double x = x__ - sin(dAngle__)*dW;
  1020 + double y = y__ + cos(dAngle__)*dW;
  1021 + bHaveDraw = m_pTextSymbol->DrawAText(pClsCS, x, y, sUTF8, dAngle__ - M_PI / 2);
  1022 +
  1023 +
  1024 +
  1025 +
  1026 +
  1027 + }
  1028 + else
  1029 + if (x1 < x2&& y1> y2)
  1030 + {
  1031 + double dAngle__ = 2 * M_PI - dAngle;
  1032 + double x = x1 + sin(dAngle__)*(WordIntervalLine + dH);
  1033 + double y = y1 + cos(dAngle__)*(WordIntervalLine + dH);
  1034 + bHaveDraw = m_pTextSymbol->DrawAText(pClsCS, x, y, sUTF8, -dAngle__);
  1035 +
  1036 +
  1037 +
  1038 +
  1039 +
  1040 + /*{ cairo_t* cr = pClsCS->m_pCr;
  1041 + cairo_set_source_rgba(cr, 1, 0.2, 0.2, 1);
  1042 + cairo_arc(cr, x1, y1, 5, 0, 2 * M_PI);
  1043 + cairo_fill(cr);
  1044 + cairo_arc(cr, x2, y2, 10, 0, 2 * M_PI);
  1045 + cairo_fill(cr);
  1046 + }*/
  1047 + }
  1048 + break;
  1049 + }
  1050 + case dmapLineLabelPositionOnTop:
  1051 + {
  1052 + if (x1 <= x2 && y1 <= y2)
  1053 + {
  1054 + double x = x1 - sin(dAngle)*dH / 2;
  1055 + double y = y1 + cos(dAngle)*dH / 2;
  1056 + bHaveDraw = m_pTextSymbol->DrawAText(pClsCS, x, y, sUTF8, dAngle);
  1057 + }
  1058 + else
  1059 + if (x1 >= x2 && y1 >= y2)
  1060 + {
  1061 +
  1062 + double dAngle__ = dAngle - M_PI;
  1063 + double x__ = x1 - sin(dAngle__)*dH / 2;
  1064 + double y__ = y1 + cos(dAngle__)*dH / 2;
  1065 + double x = x__ - cos(dAngle__)*dW;
  1066 + double y = y__ - sin(dAngle__)*dW;
  1067 + bHaveDraw = m_pTextSymbol->DrawAText(pClsCS, x, y, sUTF8, dAngle__);
  1068 +
  1069 + }
  1070 + else
  1071 + if (x1 > x2 && y1 < y2)
  1072 + {
  1073 +
  1074 + double dAngle__ = dAngle - M_PI / 2;
  1075 + double x__ = x1 + cos(dAngle__)*dH / 2;
  1076 + double y__ = y1 + sin(dAngle__)*dH / 2;
  1077 + double x = x__ - sin(dAngle__)*dW;
  1078 + double y = y__ + cos(dAngle__)*dW;
  1079 + bHaveDraw = m_pTextSymbol->DrawAText(pClsCS, x, y, sUTF8, dAngle__ - M_PI / 2);
  1080 +
  1081 + }
  1082 + else
  1083 + if (x1 < x2&& y1> y2)
  1084 + {
  1085 + double dAngle__ = 2 * M_PI - dAngle;
  1086 + double x = x1 + sin(dAngle__)*dH / 2;
  1087 + double y = y1 + cos(dAngle__)*dH / 2;
  1088 + bHaveDraw = m_pTextSymbol->DrawAText(pClsCS, x, y, sUTF8, -dAngle__);
  1089 +
  1090 +
  1091 +
  1092 + /*{ cairo_t* cr = pClsCS->m_pCr;
  1093 + cairo_set_source_rgba(cr, 1, 0.2, 0.2, 1);
  1094 + cairo_arc(cr, x1, y1, 5, 0, 2 * M_PI);
  1095 + cairo_fill(cr);
  1096 + cairo_arc(cr, x2, y2, 10, 0, 2 * M_PI);
  1097 + cairo_fill(cr);
  1098 + }*/
  1099 + }
  1100 + break;
  1101 + }
  1102 + case dmapLineLabelPositionAbove:
  1103 + {
  1104 + if (x1 <= x2 && y1 <= y2)
  1105 + {
  1106 + double x = x1 + sin(dAngle)*WordIntervalLine;
  1107 + double y = y1 - cos(dAngle)*WordIntervalLine;
  1108 + bHaveDraw = m_pTextSymbol->DrawAText(pClsCS, x, y, sUTF8, dAngle);
  1109 + }
  1110 + else
  1111 + if (x1 >= x2 && y1 >= y2)
  1112 + {
  1113 + double dAngle__ = dAngle - M_PI;
  1114 + double x__ = x1 + sin(dAngle__)*WordIntervalLine;
  1115 + double y__ = y1 - cos(dAngle__)*WordIntervalLine;
  1116 + double x = x__ - cos(dAngle__)*dW;
  1117 + double y = y__ - sin(dAngle__)*dW;
  1118 + bHaveDraw = m_pTextSymbol->DrawAText(pClsCS, x, y, sUTF8, dAngle__);
  1119 +
  1120 +
  1121 +
  1122 + }
  1123 + else
  1124 + if (x1 > x2 && y1 < y2)
  1125 + {
  1126 + double dAngle__ = dAngle - M_PI / 2;
  1127 + double x__ = x1 - cos(dAngle__)*WordIntervalLine;
  1128 + double y__ = y1 - sin(dAngle__)*WordIntervalLine;
  1129 + double x = x__ - sin(dAngle__)*dW;
  1130 + double y = y__ + cos(dAngle__)*dW;
  1131 + bHaveDraw = m_pTextSymbol->DrawAText(pClsCS, x, y, sUTF8, dAngle__ - M_PI / 2);
  1132 + }
  1133 + else
  1134 + if (x1 < x2&& y1> y2)
  1135 + {
  1136 + double dAngle__ = 2 * M_PI - dAngle;
  1137 + double x = x1 - sin(dAngle__)*WordIntervalLine;
  1138 + double y = y1 - cos(dAngle__)*WordIntervalLine;
  1139 + bHaveDraw = m_pTextSymbol->DrawAText(pClsCS, x, y, sUTF8, -dAngle__);
  1140 + }
  1141 + break;
  1142 + }
  1143 + case dmapLineLabelPositionBelow:
  1144 + {
  1145 + if (x1 <= x2 && y1 <= y2)
  1146 + {
  1147 + double x = x1 - sin(dAngle)*(WordIntervalLine + dH);
  1148 + double y = y1 + cos(dAngle)*(WordIntervalLine + dH);
  1149 + bHaveDraw = m_pTextSymbol->DrawAText(pClsCS, x, y, sUTF8, dAngle);
  1150 + }
  1151 + else
  1152 + if (x1 >= x2 && y1 >= y2)
  1153 + {
  1154 +
  1155 + double dAngle__ = dAngle - M_PI;
  1156 + double x__ = x1 - sin(dAngle__)* (WordIntervalLine + dH);
  1157 + double y__ = y1 + cos(dAngle__)* (WordIntervalLine + dH);
  1158 + double x = x__ - cos(dAngle__)*dW;
  1159 + double y = y__ - sin(dAngle__)*dW;
  1160 + bHaveDraw = m_pTextSymbol->DrawAText(pClsCS, x, y, sUTF8, dAngle__);
  1161 +
  1162 + }
  1163 + else
  1164 + if (x1 > x2 && y1 < y2)
  1165 + {
  1166 + double dAngle__ = dAngle - M_PI / 2;
  1167 + double x__ = x1 + cos(dAngle__)*(WordIntervalLine + dH);
  1168 + double y__ = y1 + sin(dAngle__)*(WordIntervalLine + dH);
  1169 + double x = x__ - sin(dAngle__)*dW;
  1170 + double y = y__ + cos(dAngle__)*dW;
  1171 + bHaveDraw = m_pTextSymbol->DrawAText(pClsCS, x, y, sUTF8, dAngle__ - M_PI / 2);
  1172 + }
  1173 + else
  1174 + if (x1 < x2&& y1> y2)
  1175 + {
  1176 + double dAngle__ = 2 * M_PI - dAngle;
  1177 + double x = x1 + sin(dAngle__)*(WordIntervalLine + dH);
  1178 + double y = y1 + cos(dAngle__)*(WordIntervalLine + dH);
  1179 + bHaveDraw = m_pTextSymbol->DrawAText(pClsCS, x, y, sUTF8, -dAngle__);
  1180 + }
  1181 + break;
  1182 + }
  1183 + default:
  1184 + break;
  1185 + }
  1186 + if (bHaveDraw)
  1187 + break;
  1188 + }
  1189 + return true;
  1190 +}
  1191 +
  1192 +bool SimpleLabelRenderer::DrawLegend(clsCrSurf* pClsCS, shared_ptr<legendParamater> pLegendParamater,
  1193 + int layerType,char* pFlag)
  1194 +{
  1195 + return true;
  1196 +}
  1197 +
  1198 +bool SimpleLabelRenderer::DrawMLineCurve(clsCrSurf* pClsCS, clsStruct::MLINE* pStrMLine, char* sUTF8)
  1199 +{
  1200 + //计算出文字总长
  1201 + cairo_t* cr = pClsCS->m_pCr;
  1202 + cairo_text_extents_t extents;
  1203 + m_pTextSymbol->SetCairo(pClsCS);
  1204 + cairo_text_extents(cr, sUTF8, &extents);
  1205 + double x_advance_all = extents.x_advance;
  1206 + double y_height = extents.height;
  1207 +
  1208 + //计算出标签的放置位置
  1209 + double x, y; int iIndex;
  1210 + clsStruct::GetGravity(x, y,iIndex, pStrMLine);
  1211 +
  1212 +
  1213 + //分割文字
  1214 + //暂时不考虑中文,直接分割每个字符
  1215 + int len = strlen(sUTF8);
  1216 +
  1217 + //计算每个文字的弧度
  1218 + double dAdvanceCollect = 0;
  1219 + double dHalfAdvance = x_advance_all / 2;
  1220 + double x_show, y_show;
  1221 + int i = len / 2;
  1222 + double x_show_next = x, y_show_next = y;
  1223 + for (i--; i >=0; i--)
  1224 + {
  1225 + char s_[2] = { sUTF8[i], '\0' };
  1226 + cairo_text_extents(cr, s_, &extents);
  1227 + double x_advance = extents.x_advance;
  1228 + x_show = x_show_next;
  1229 + y_show = y_show_next;
  1230 + double dRadia = CalculateRadianRight(pStrMLine->p, x_advance, i, x_show, y_show, x_show_next, y_show_next);
  1231 + m_pTextSymbol->DrawAText(pClsCS, x_show, y_show, s_, dRadia);
  1232 + }
  1233 +
  1234 + x_show_next = x, y_show_next = y;
  1235 + for (i = len / 2; i < len; i++)
  1236 + {
  1237 + char s_[2] = { sUTF8[i], '\0' };
  1238 + cairo_text_extents(cr, s_, &extents);
  1239 + double x_advance = extents.x_advance;
  1240 + x_show = x_show_next;
  1241 + y_show = y_show_next;
  1242 + double dRadia = CalculateRadianLeft(pStrMLine->p, x_advance, i, x_show, y_show, x_show_next, y_show_next);
  1243 + m_pTextSymbol->DrawAText(pClsCS, x_show, y_show, s_, dRadia);
  1244 + }
  1245 +
  1246 + return true;
  1247 +}
  1248 +
  1249 +bool SimpleLabelRenderer::DrawMLineVertical(clsCrSurf* pClsCS, clsStruct::MLINE* pStrMLine, char* sUTF8)
  1250 +{
  1251 + double x1, y1, x2, y2;
  1252 + cairo_t* cr = pClsCS->m_pCr;
  1253 +
  1254 +
  1255 + switch (m_iLineLabelPositionStartOrEnd)
  1256 + {
  1257 + case dmapLineLabelPositionStart:
  1258 + clsStruct::GetStart(pStrMLine, x1, y1, x2, y2);
  1259 + break;
  1260 + case dmapLineLabelPositionEnd:
  1261 + clsStruct::GetEnd(pStrMLine, x1, y1, x2, y2);
  1262 + break;
  1263 + case dmapLineLabelPositionOnTop:
  1264 + clsStruct::GetCenter(pStrMLine, x1, y1, x2, y2);
  1265 + break;
  1266 + default:
  1267 + break;
  1268 + }
  1269 +
  1270 +
  1271 + double dAngle = atan((y2 - y1) / (x2 - x1));
  1272 + if (x1 > x2)
  1273 + dAngle += M_PI;
  1274 + bool bHaveDraw = false;
  1275 +
  1276 +
  1277 +
  1278 + cairo_text_extents_t extents;
  1279 + cairo_text_extents(pClsCS->m_pCr, sUTF8, &extents);
  1280 + double dW = extents.x_advance;
  1281 + double dH = extents.height;
  1282 +
  1283 +
  1284 +
  1285 + for (int i = 0; i < 3; i++)
  1286 + {
  1287 + int iLineLabelPositionPlace = m_LineLabelPositionPlaces[i];
  1288 +
  1289 + switch (iLineLabelPositionPlace)
  1290 + {
  1291 + case dmapLineLabelPositionLeft:
  1292 + {
  1293 + if ((y1 <= y2) && (x1 <= x2)) //第一象限
  1294 + {
  1295 + double dAngle__ = dAngle - M_PI / 2.0;
  1296 + double x = x1 + cos(dAngle)*dH;
  1297 + double y = y1 + sin(dAngle)*dH;
  1298 + bHaveDraw = m_pTextSymbol->DrawAText(pClsCS, x, y, sUTF8, dAngle__);
  1299 + }
  1300 + else
  1301 + if (x1 >= x2 && y1 >= y2) //第三象限
  1302 + {
  1303 + double dAngle__ = 3.0*M_PI / 2 - dAngle;
  1304 + double a = cos(dAngle__);
  1305 + a = sin(dAngle__);
  1306 + double x = x1 - cos(dAngle__)*dW;
  1307 + double y = y1 + sin(dAngle__)*dW;
  1308 + bHaveDraw = m_pTextSymbol->DrawAText(pClsCS, x, y, sUTF8, -dAngle__);
  1309 + }
  1310 + else
  1311 + if (x1 > x2 && y1 < y2)
  1312 + {
  1313 + double dAngle__ = dAngle - M_PI / 2;
  1314 + double x = x1 - sin(dAngle__)*dH;
  1315 + double y = y1 + cos(dAngle__)*dH;
  1316 + bHaveDraw = m_pTextSymbol->DrawAText(pClsCS, x, y, sUTF8, dAngle__);
  1317 + }
  1318 + else
  1319 + if (x1 < x2 && y1 > y2)
  1320 + {
  1321 + double dAngle__ = dAngle - 3.0*M_PI / 2;
  1322 + double x = x1 - cos(dAngle__)*dW;
  1323 + double y = y1 - sin(dAngle__)*dW;
  1324 + bHaveDraw = m_pTextSymbol->DrawAText(pClsCS, x, y, sUTF8, dAngle__);
  1325 + }
  1326 + break;
  1327 + }
  1328 + case dmapLineLabelPositionRight:
  1329 + {
  1330 + if (x1 <= x2 && y1 <= y2)
  1331 + {
  1332 + double dAngle__ = M_PI / 2 - dAngle;
  1333 + double x__ = x1 - cos(dAngle__)*dW;
  1334 + double y__ = y1 + sin(dAngle__)*dW;
  1335 + double x = x__ + cos(dAngle)*dH;
  1336 + double y = y__ + sin(dAngle)*dH;
  1337 + bHaveDraw = m_pTextSymbol->DrawAText(pClsCS, x, y, sUTF8, -dAngle__);
  1338 + }
  1339 + else
  1340 + if (x1 >= x2 && y1 >= y2)
  1341 + {
  1342 + double dAngle__ = 3.0*M_PI / 2 - dAngle;
  1343 + bHaveDraw = m_pTextSymbol->DrawAText(pClsCS, x1, y1, sUTF8, -dAngle__);
  1344 + }
  1345 + else
  1346 + if (x1 > x2 && y1 < y2)
  1347 + {
  1348 + double dAngle__ = M_PI - dAngle;
  1349 + double x__ = x1 - sin(dAngle__)* dW;
  1350 + double y__ = y1 - cos(dAngle__)*dW;
  1351 + double x = x__ - cos(dAngle__)*dH;
  1352 + double y = y__ + sin(dAngle__)*dH;
  1353 + bHaveDraw = m_pTextSymbol->DrawAText(pClsCS, x, y, sUTF8, M_PI / 2 - dAngle__);
  1354 + }
  1355 + else
  1356 + if (x1 < x2 && y1 > y2)
  1357 + {
  1358 + double dAngle__ = dAngle - 3 * M_PI / 2;
  1359 + bHaveDraw = m_pTextSymbol->DrawAText(pClsCS, x1, y1, sUTF8, dAngle__);
  1360 + }
  1361 + break;
  1362 + }
  1363 +
  1364 + case dmapLineLabelPositionOnTop:
  1365 + {
  1366 + if (x1 <= x2 && y1 <= y2)
  1367 + {
  1368 + double x = x1 - sin(dAngle)*dW / 2;
  1369 + double y = y1 + cos(dAngle)*dW / 2;
  1370 + bHaveDraw = m_pTextSymbol->DrawAText(pClsCS, x, y, sUTF8, dAngle - M_PI / 2);
  1371 + }
  1372 + else
  1373 + if (x1 >= x2 && y1 >= y2)
  1374 + {
  1375 + double dAngle__ = dAngle - M_PI;
  1376 + double x = x1 - sin(dAngle__)*dW / 2;
  1377 + double y = y1 + cos(dAngle__)*dW / 2;
  1378 +
  1379 + {
  1380 + cairo_set_source_rgba(cr, 1, 0.2, 0.2, 1);
  1381 + cairo_arc(cr, x1, y1, 3, 0, 2 * M_PI);
  1382 + cairo_fill(cr);
  1383 + cairo_arc(cr, x2, y2, 3, 0, 2 * M_PI);
  1384 + cairo_fill(cr);
  1385 + }
  1386 +
  1387 + bHaveDraw = m_pTextSymbol->DrawAText(pClsCS, x, y, sUTF8, dAngle__ - M_PI / 2);
  1388 + }
  1389 + else
  1390 + if (x1 > x2 && y1 < y2)
  1391 + {
  1392 + double dAngle__ = dAngle - M_PI / 2;
  1393 + double x__ = x1 - cos(dAngle__)*dW / 2;
  1394 + double y__ = y1 - sin(dAngle__)*dW / 2;
  1395 + double x = x__ - sin(dAngle__)*dH;
  1396 + double y = y__ + cos(dAngle__)*dH;
  1397 + bHaveDraw = m_pTextSymbol->DrawAText(pClsCS, x, y, sUTF8, dAngle__);
  1398 +
  1399 + }
  1400 + else
  1401 + if (x1 < x2 && y1 > y2)
  1402 + {
  1403 + double dAngle__ = 2 * M_PI - dAngle;
  1404 + double x = x1 - sin(dAngle__)*dW / 2;
  1405 + double y = y1 - cos(dAngle__)*dW / 2;
  1406 + bHaveDraw = m_pTextSymbol->DrawAText(pClsCS, x, y, sUTF8, M_PI / 2 - dAngle__);
  1407 + }
  1408 + break;
  1409 + }
  1410 + case dmapLineLabelPositionAbove:
  1411 + {
  1412 + if (x1 <= x2 && y1 <= y2)
  1413 + {
  1414 + double dAngle__ = dAngle - M_PI / 2.0;
  1415 + double x = x1 + cos(dAngle)*dH;
  1416 + double y = y1 + sin(dAngle)*dH;
  1417 + bHaveDraw = m_pTextSymbol->DrawAText(pClsCS, x, y, sUTF8, dAngle__);
  1418 + }
  1419 + else
  1420 + if (x1 >= x2 && y1 >= y2)
  1421 + {
  1422 + double dAngle__ = 3.0*M_PI / 2 - dAngle;
  1423 + bHaveDraw = m_pTextSymbol->DrawAText(pClsCS, x1, y1, sUTF8, -dAngle__);
  1424 + }
  1425 + else
  1426 + if (x1 > x2 && y1 < y2)
  1427 + {
  1428 + double dAngle__ = M_PI - dAngle;
  1429 + double x__ = x1 - sin(dAngle__)* dW;
  1430 + double y__ = y1 - cos(dAngle__)*dW;
  1431 + double x = x__ - cos(dAngle__)*dH;
  1432 + double y = y__ + sin(dAngle__)*dH;
  1433 + bHaveDraw = m_pTextSymbol->DrawAText(pClsCS, x, y, sUTF8, M_PI / 2 - dAngle__);
  1434 + }
  1435 + else
  1436 + if (x1 < x2 && y1 > y2)
  1437 + {
  1438 + double dAngle__ = dAngle - 3.0*M_PI / 2;
  1439 + double x = x1 - cos(dAngle__)*dW;
  1440 + double y = y1 - sin(dAngle__)*dW;
  1441 + bHaveDraw = m_pTextSymbol->DrawAText(pClsCS, x, y, sUTF8, dAngle__);
  1442 + }
  1443 + break;
  1444 + }
  1445 + case dmapLineLabelPositionBelow:
  1446 + {
  1447 + if (x1 <= x2 && y1 <= y2)
  1448 + {
  1449 + double dAngle__ = M_PI / 2 - dAngle;
  1450 + double x__ = x1 - cos(dAngle__)*dW;
  1451 + double y__ = y1 + sin(dAngle__)*dW;
  1452 + double x = x__ + cos(dAngle)*dH;
  1453 + double y = y__ + sin(dAngle)*dH;
  1454 + bHaveDraw = m_pTextSymbol->DrawAText(pClsCS, x, y, sUTF8, -dAngle__);
  1455 + }
  1456 + else if (x1 >= x2 && y1 >= y2)
  1457 + {
  1458 + double dAngle__ = 3.0*M_PI / 2 - dAngle;
  1459 + double a = cos(dAngle__);
  1460 + a = sin(dAngle__);
  1461 + double x = x1 - cos(dAngle__)*dW;
  1462 + double y = y1 + sin(dAngle__)*dW;
  1463 + bHaveDraw = m_pTextSymbol->DrawAText(pClsCS, x, y, sUTF8, -dAngle__);
  1464 + }
  1465 + else if (x1 > x2 && y1 < y2)
  1466 + {
  1467 + double dAngle__ = dAngle - M_PI / 2;
  1468 + double x = x1 - sin(dAngle__)*dH;
  1469 + double y = y1 + cos(dAngle__)*dH;
  1470 + bHaveDraw = m_pTextSymbol->DrawAText(pClsCS, x, y, sUTF8, dAngle__);
  1471 + }
  1472 + else if (x1 < x2 && y1 > y2)
  1473 + {
  1474 + double dAngle__ = dAngle - 3 * M_PI / 2;
  1475 + bHaveDraw = m_pTextSymbol->DrawAText(pClsCS, x1, y1, sUTF8, dAngle__);
  1476 + }
  1477 + break;
  1478 + }
  1479 + default:
  1480 + break;
  1481 + }
  1482 +
  1483 + if (bHaveDraw)
  1484 + break;
  1485 +
  1486 +
  1487 + }
  1488 +
  1489 + return true;
  1490 +}
  1491 +
  1492 +double SimpleLabelRenderer::CalculateRadianRight(clsStruct::LINE* pStrLine, double dTextWidth, int iIndex, double x, double y, double&x_show, double&y_show)
  1493 +{
  1494 + //尝试一次性写下该文本
  1495 + double x1 = (pStrLine->p + iIndex)->x;
  1496 + double y1 = (pStrLine->p + iIndex)->y;
  1497 + double dLength = sqrt((x-x1)*(x-x1) + (y-y1)*(y-y1));
  1498 + if (dLength > dTextWidth)
  1499 + {
  1500 + //计算弧度
  1501 + //求导
  1502 + double dDerivative = (y - y1) / (x - x1);
  1503 + //求出x,y方向上的距离
  1504 + double x_ = sqrt(dTextWidth / (dDerivative*dDerivative + 1));
  1505 + if (x<x1)
  1506 + x_ = -x_;
  1507 + double y_ = dDerivative*x_;
  1508 +
  1509 + x_show = x - x_;
  1510 + y_show = y - y_;
  1511 +
  1512 + double dRadia = atan(y_ / x_);
  1513 + return dRadia;
  1514 + }
  1515 + else
  1516 + {
  1517 + //连接该点与上一个点,该连线是否可以写下这个文本,不够的话再往上找点
  1518 + for (iIndex--; iIndex >= 0; iIndex--)
  1519 + {
  1520 + x1 = (pStrLine->p + iIndex)->x;
  1521 + y1 = (pStrLine->p + iIndex)->y;
  1522 + dLength = sqrt((x - x1)*(x - x1) + (y - y1)*(y - y1));
  1523 + if (dLength > dTextWidth)
  1524 + break;
  1525 + }
  1526 +
  1527 + double dDerivative = (y - y1) / (x - x1);
  1528 + //求出x,y方向上的距离
  1529 + double x_ = sqrt(dTextWidth / (dDerivative*dDerivative + 1));
  1530 + if (x<x1)
  1531 + x_ = -x_;
  1532 + double y_ = dDerivative*x_;
  1533 +
  1534 +
  1535 + x_show = x - x_;
  1536 + y_show = y - y_;
  1537 + double dRadia = atan(y_ / x_);
  1538 +
  1539 + return dRadia;
  1540 + }
  1541 +}
  1542 +
  1543 +double SimpleLabelRenderer::CalculateRadianLeft(clsStruct::LINE* pStrLine, double dTextWidth, int iIndex, double x, double y, double&x_show, double& y_show)
  1544 +{
  1545 + //尝试一次性写下该文本
  1546 + double x1 = (pStrLine->p + iIndex+1)->x;
  1547 + double y1 = (pStrLine->p + iIndex+1)->y;
  1548 + double dLength = sqrt((x - x1)*(x - x1) + (y - y1)*(y - y1));
  1549 + if (dLength > dTextWidth)
  1550 + {
  1551 + //计算弧度
  1552 + //求导
  1553 + double dDerivative = (y1 - y) / (x1 - x);
  1554 + //求出x,y方向上的距离
  1555 + double x_ = sqrt(dTextWidth / (dDerivative*dDerivative + 1));
  1556 + if (x<x1)
  1557 + x_ = -x_;
  1558 + double y_ = dDerivative*x_;
  1559 +
  1560 + x_show = x + x_;
  1561 + y_show = y + y_;
  1562 +
  1563 + double dRadia = atan(y_ / x_);
  1564 + return dRadia;
  1565 + }
  1566 + else
  1567 + {
  1568 + //连接该点与下一个点,该连线是否可以写下这个文本,不够的话再往上找点
  1569 + int nPoint = pStrLine->nPoint;
  1570 + for (iIndex++; iIndex < nPoint; iIndex++)
  1571 + {
  1572 + x1 = (pStrLine->p + iIndex+1)->x;
  1573 + y1 = (pStrLine->p + iIndex+1)->y;
  1574 + dLength = sqrt((x - x1)*(x - x1) + (y - y1)*(y - y1));
  1575 + if (dLength > dTextWidth)
  1576 + break;
  1577 + }
  1578 +
  1579 + double dDerivative = (y - y1) / (x - x1);
  1580 + //求出x,y方向上的距离
  1581 + double x_ = sqrt(dTextWidth / (dDerivative*dDerivative + 1));
  1582 +
  1583 + if (x<x1)
  1584 + x_ = -x_;
  1585 +
  1586 + double y_ = dDerivative*x_;
  1587 +
  1588 + x_show = x + x_;
  1589 + y_show = y + y_;
  1590 +
  1591 + double dRadia = atan(y_ / x_);
  1592 +
  1593 + return dRadia;
  1594 + }
  1595 + return true;
  1596 +}
  1597 +
  1598 +bool SimpleLabelRenderer::DrawMLineCurve2(clsCrSurf* pClsCS, clsStruct::MLINE* pStrMLine, char* sUTF8)
  1599 +{
  1600 +
  1601 + //文字距离
  1602 + cairo_t* cr = pClsCS->m_pCr;
  1603 + cairo_text_extents_t extents;
  1604 + m_pTextSymbol->SetCairo(pClsCS);
  1605 + cairo_text_extents(cr, sUTF8, &extents);
  1606 + double x_advance_all = extents.x_advance;
  1607 + int strLen = strlen(sUTF8);
  1608 + double x_advance = x_advance_all / strLen;
  1609 +
  1610 +
  1611 + //中心点
  1612 + double x_gravity, y_gravity; int iIndex;
  1613 + clsStruct::GetGravity(x_gravity, y_gravity, iIndex, pStrMLine);
  1614 +
  1615 + //计算出每个文字的弧度和位置,书写
  1616 + int iHalfLen = strLen / 2;
  1617 +
  1618 + //x_show = x_gravity,y_show = y_gravity
  1619 + int iThisPointIndex = iIndex;
  1620 + double x_show, y_show;
  1621 + double x_show_next = x_gravity, y_show_next = y_gravity;
  1622 + for (int i = iHalfLen; i < strLen; i++)
  1623 + {
  1624 + x_show = x_show_next; y_show = y_show_next;
  1625 + double dRadia = this->CalculateRadianRight2(pStrMLine->p, x_advance,iThisPointIndex,x_show,y_show,x_show_next,y_show_next);
  1626 +
  1627 + char s_[2] = {sUTF8[i],'\0'};
  1628 + m_pTextSymbol->DrawAText(pClsCS, x_show, y_show,s_,dRadia);
  1629 + }
  1630 +
  1631 +
  1632 +
  1633 + return true;
  1634 +}
  1635 +double SimpleLabelRenderer::CalculateRadianRight2(clsStruct::LINE* pStrLine, double dTextWidth, int& iIndex, double x_show, double y_show, double &x_show_next, double&y_show_next)
  1636 +{
  1637 + /*
  1638 + 参数解释:
  1639 + dTextWidth,当前单个文字的宽度
  1640 + iIndex , 当前书写文本时在线条上的上一个点的索引
  1641 + x_show , 当前书写文字的开始位置
  1642 + y_show ,
  1643 + x_show_next, 得出下一个文字开始书写的位置
  1644 + y_show_next
  1645 +
  1646 +
  1647 + 通过计算,得出当前这个文字的旋转弧度,得出下一个文字的其实位置,得出下一个文字落在第几个点到下一个点之间
  1648 + */
  1649 +
  1650 +
  1651 + //尝试一次性写下该文字
  1652 + double x1 = x_show;
  1653 + double y1 = y_show;
  1654 + double x2 = (pStrLine->p + iIndex + 1)->x;
  1655 + double y2 = (pStrLine->p + iIndex + 1)->y;
  1656 + double dLength = sqrt((x1 - x2)*(x1 - x2) + (y1 - y2)*(y1- y2));
  1657 +
  1658 + if (dLength > dTextWidth)
  1659 + {
  1660 + //一次性可以写下
  1661 +
  1662 + //求导
  1663 + double dDerivative = (y2 - y1) / (x2-x1);
  1664 + double dRadia = atan(dDerivative); //计算出弧度
  1665 + this->CalculateIntersection(dTextWidth, x_show, y_show, x1, y1, x2, y2, x_show_next, y_show_next); //计算出下一个文字的位置
  1666 +
  1667 + return dRadia;
  1668 + }
  1669 + else
  1670 + {
  1671 + //计算出另一端在哪两个点之间
  1672 + int iPointCount = pStrLine->nPoint;
  1673 + for (iIndex++; iIndex < iPointCount - 1; iIndex++)
  1674 + {
  1675 + x2 = (pStrLine->p + iIndex + 1)->x;
  1676 + y2 = (pStrLine->p + iIndex + 1)->y;
  1677 + double dLength = sqrt((x1 - x2)*(x1 - x2) + (y1 - y2)*(y1 - y2));
  1678 + if (dLength > dTextWidth)
  1679 + break;
  1680 + }
  1681 +
  1682 + this->CalculateIntersection(dTextWidth, x_show, y_show, (pStrLine->p + iIndex)->x, (pStrLine->p + iIndex)->y, (pStrLine->p + iIndex + 1)->x, (pStrLine->p + iIndex + 1)->y,x_show_next,y_show_next);
  1683 + double dRadia = (y_show_next - y_show) / (x_show_next-x_show);
  1684 + return dRadia;
  1685 + }
  1686 +
  1687 + return 0;
  1688 +}
  1689 +double SimpleLabelRenderer::CalculateRadianLeft2(clsStruct::LINE* pStrLine, double dTextWidth, int &iIndex, double x_show, double y_show, double&x_show_next, double&y_show_next)
  1690 +{
  1691 + return 0;
  1692 +}
  1693 +void SimpleLabelRenderer::CalculateIntersection(double dWidth, double x_from, double y_from, double x1, double y1, double x2, double y2, double&x_to, double&y_to)
  1694 +{
  1695 + //计算交点
  1696 + //从(x_from,y_from)为圆心,以dWidth为半径,与(x1,y1),(x2,y2)所连成的直线相交,得到交点(x_to,y_to)
  1697 +
  1698 + //x1,y1,x2,y2计算直线式 y = k*x + b;
  1699 + double k_, b_, a, b, c;
  1700 + k_ = (y2 - y1) / (x2 - x1);
  1701 + b_ = y1 - k_*x1;
  1702 +
  1703 + //由于距离已确定
  1704 + // (x_to - x_from) * (x_to - x_from ) + (y_to - y_from) * (y_to - y_from) = dWidth*dWidth
  1705 + //加上 y = k*x + b
  1706 + //组成2元方程式,可解
  1707 + a = k_*k_ + 1;
  1708 + b = 2 * k_*b_ - 2 * k_*y_from - 2 * x_from;
  1709 + c = b_*b_ - 2 * b_*y_from + y_from*y_from + x_from*x_from - dWidth*dWidth;
  1710 + double dDelta = b*b - 4 * a*c; // 无需考虑,前面计算落在哪两个点之间时已经可以确定此时必然有交点
  1711 + double dResult_x1 = (-b + sqrt(dDelta)) / (2 * a);
  1712 + double dResult_x2 = (-b - sqrt(dDelta)) / (2 * a);
  1713 + if (((dResult_x1 > x1) && (dResult_x1 < x2)) || ((dResult_x1 < x1) && (dResult_x1 > x2)))
  1714 + x_to = dResult_x1;
  1715 + else
  1716 + x_to = dResult_x2;
  1717 + y_to = k_*x_to + b_;
  1718 +
  1719 +}
  1720 +
  1721 +
  1722 +
  1723 +
  1724 +
  1725 +
  1726 +
  1727 +
  1728 +bool SimpleLabelRenderer::DrawMLineCurve3(clsCrSurf* pClsCS, clsStruct::MLINE* pStrMLine, char* sUTF8)
  1729 +{
  1730 +// printf("11\r\n");
  1731 + //平滑处理成一条新的线
  1732 + vector<double> vX, vY;
  1733 + this->LineToSmooth(pStrMLine->p, vX, vY);
  1734 + //这个算法太耗资源了,时间也长
  1735 + printf("vx size = %ld\r\n", vX.size());
  1736 +
  1737 + //挑选最平滑的一段书写
  1738 + //这个步骤好像不对,不需要这样做
  1739 +
  1740 + cairo_t* cr = pClsCS->m_pCr;
  1741 + //计算每个文字的弧度和位置并书写
  1742 + {
  1743 +
  1744 + //将虚拟线条绘制出来
  1745 +
  1746 + /*cairo_set_line_width(cr, 1);
  1747 + cairo_set_source_rgba(cr, 1, 0, 0, 0.3);
  1748 + int sz = (int)(vX.size());
  1749 + cairo_move_to(cr, vX[0], vY[0]);
  1750 + for (int i = 1; i < sz; i++)
  1751 + cairo_line_to(cr,vX[i], vY[i]);
  1752 + cairo_stroke(cr);*/
  1753 + }
  1754 + //printf("22\r\n");
  1755 + cairo_text_extents_t extents;
  1756 + cairo_text_extents(cr, sUTF8, &extents);
  1757 +
  1758 + double x_advance_all = extents.x_advance;
  1759 +
  1760 + if (extents.x_advance == 0)
  1761 + {
  1762 + //printf("*****return\r\n");
  1763 + return false;
  1764 + }
  1765 +
  1766 + //计算开始书写第一个文字的位置
  1767 + double x_show_begin, y_show_begin;
  1768 + int iPointIndex;
  1769 + bool flag = this->CalculateShowBegin(vX, vY, x_advance_all, x_show_begin, y_show_begin, iPointIndex);
  1770 +
  1771 + if (!flag)
  1772 + return false;
  1773 +
  1774 + int len = strlen(sUTF8);
  1775 + double x_advance = x_advance_all / len;
  1776 +
  1777 + int iIndex = iPointIndex;
  1778 + double x_show, y_show;
  1779 + double x_show_next = x_show_begin, y_show_next = y_show_begin;
  1780 + double dRadia_this, dRadia_last;
  1781 + for (int i = 0; i < len; i++)
  1782 + {
  1783 + x_show = x_show_next; y_show = y_show_next;
  1784 +
  1785 + dRadia_this = this->CalculateRadianRight3(vX, vY, x_advance, iIndex, x_show, y_show, x_show_next, y_show_next);
  1786 +
  1787 + {
  1788 + //atan计算出的弧度只在 (-π/2,π/2)
  1789 +
  1790 + //如果文字向下走,旋转弧度在 [0,π)之间
  1791 + //如果文字向上走,旋转弧度在 [π,2π)之间
  1792 + if ((y_show_next > y_show) && (dRadia_this < 0))
  1793 + dRadia_this = dRadia_this + M_PI;
  1794 + if ((y_show_next < y_show) && (dRadia_this> 0))
  1795 + dRadia_this = dRadia_this + M_PI;
  1796 +
  1797 + }
  1798 +
  1799 +
  1800 +
  1801 + if (!i)
  1802 + dRadia_last = dRadia_this;
  1803 + double dRadiaDisMax = M_PI / 6; // 旋转弧度落差范围,上一个文字旋转弧度与下一个文字旋转弧度不得超过30度
  1804 + if ((dRadia_this - dRadia_last) >dRadiaDisMax)
  1805 + dRadia_this = dRadia_last + dRadiaDisMax;
  1806 + if (dRadia_this - dRadia_last < -dRadiaDisMax)
  1807 + dRadia_this = dRadia_last - dRadiaDisMax;
  1808 + char s_[2] = { sUTF8[i], '\0' };
  1809 + m_pTextSymbol->DrawAText(pClsCS, x_show, y_show, s_, dRadia_this);
  1810 + dRadia_last = dRadia_this;
  1811 + }
  1812 + //("33\r\n");
  1813 + return true;
  1814 +}
  1815 +
  1816 +
  1817 +bool SimpleLabelRenderer::LineToSmooth(clsStruct::LINE* pStrLine, vector<double>& vX, vector<double>& vY)
  1818 +{
  1819 + int iPointCount = pStrLine->nPoint;
  1820 + clsStruct::POINT* pp = pStrLine->p;
  1821 + for (int i = 0; i < iPointCount; i++,pp++)
  1822 + {
  1823 + vX.push_back(pp->x);
  1824 + vY.push_back(pp->y);
  1825 + }
  1826 +
  1827 + this->Douglas_Peucker_algorithm(vX, vY);
  1828 +
  1829 + int sz = (int)(vX.size());
  1830 + double x1 = vX[0];
  1831 + double x2 = vX[sz - 1];
  1832 + if (x1 > x2)
  1833 + {
  1834 + //反转
  1835 + vX.reserve(vX.size());
  1836 + vY.reserve(vY.size());
  1837 + //vX.reverse(vX.begin(), vX.end());
  1838 + //reverse(vY.begin(), vY.end());
  1839 + }
  1840 +
  1841 + return true;
  1842 +}
  1843 +
  1844 +
  1845 +bool SimpleLabelRenderer::Douglas_Peucker_algorithm(vector<double> &vX, vector<double>& vY)
  1846 +{
  1847 + double dTolerance = 5; // 限差
  1848 +
  1849 + double x1 = vX[0], y1 = vY[0];
  1850 + int sz = (int)(vX.size());
  1851 + double x2 = vX[sz - 1], y2 = vY[sz - 1];
  1852 +
  1853 + double x0, y0;
  1854 + double dDistanceMax = 0;
  1855 + int iMaxIndex = 0;
  1856 + for (int i = 1; i < sz - 1; i++)
  1857 + {
  1858 + x0 = vX[i]; y0 = vY[i];
  1859 + double dDistance = this->CalculateDistance(x0, y0, x1, y1, x2, y2);
  1860 + if (dDistance > dDistanceMax)
  1861 + {
  1862 + dDistanceMax = dDistance;
  1863 + iMaxIndex = i;
  1864 + }
  1865 + }
  1866 +
  1867 + if (dDistanceMax < dTolerance)
  1868 + {
  1869 + vX.clear(); vY.clear();
  1870 + vX.push_back(x1); vX.push_back(x2);
  1871 + vY.push_back(y1); vY.push_back(y2);
  1872 + return false;
  1873 + }
  1874 + else
  1875 + {
  1876 + vector<double> vX_left, vY_left, vX_right, vY_right;
  1877 + copy(vX.begin(), vX.begin() + iMaxIndex, back_inserter(vX_left));
  1878 + copy(vY.begin(), vY.begin() + iMaxIndex, back_inserter(vY_left));
  1879 + copy(vX.begin() + iMaxIndex, vX.end(), back_inserter(vX_right));
  1880 + copy(vY.begin() + iMaxIndex, vY.end(), back_inserter(vY_right));
  1881 +
  1882 + this->Douglas_Peucker_algorithm(vX_left, vY_left);
  1883 + this->Douglas_Peucker_algorithm(vX_right, vY_right);
  1884 +
  1885 + vX.clear(); vY.clear();
  1886 + copy(vX_left.begin(), vX_left.end(), back_inserter(vX));
  1887 + copy(vY_left.begin(), vY_left.end(), back_inserter(vY));
  1888 + copy(vX_right.begin()+1, vX_right.end(), back_inserter(vX));
  1889 + copy(vY_right.begin()+1, vY_right.end(), back_inserter(vY));
  1890 +
  1891 + return true;
  1892 + }
  1893 +}
  1894 +
  1895 +
  1896 +double SimpleLabelRenderer::CalculateDistance(double x0, double y0, double x1, double y1, double x2, double y2)
  1897 +{
  1898 + //(x1,y1)和(x2,y2) 组成直线,计算(x0,y0)到该直线的距离
  1899 +
  1900 + //(x1,y1)和(x2,y2)组成直线 y = k1 * x + b1;
  1901 +
  1902 + double k1, b1, k2, b2;
  1903 + k1 = (y2 - y1) / (x2 - x1);
  1904 + b1 = y1 - x1*k1;
  1905 +
  1906 + k2 = 1 / k1;
  1907 + b2 = y0 - k2*x0;
  1908 +
  1909 + /*
  1910 + y = k1 * x + b1 与 y = k2 * x + b2 相交, 得到交点
  1911 + */
  1912 + double x = (b2 - b1) / (k1 - k2);
  1913 + double y = k1 * x + b1;
  1914 +
  1915 + double dDistance = sqrt((x - x0)*(x-x0) + (y-y0)*(y-y0));
  1916 + //此处应该可以取巧,不用求根,直接将距离的平方作为返回值也可以
  1917 +
  1918 + return dDistance;
  1919 +}
  1920 +
  1921 +bool SimpleLabelRenderer::CalculateShowBegin(vector<double> vX, vector<double> vY, double dW , double& x_show_begin, double& y_show_begin,int & iPointIndex)
  1922 +{
  1923 + int sz = (int)(vX.size());
  1924 +
  1925 + double x1, y1, x2, y2;
  1926 +
  1927 + x2 = vX[0]; y2 = vY[0];
  1928 +
  1929 + double dLength = 0, dL;
  1930 + for (int i = 1; i < sz; i++)
  1931 + {
  1932 + x1 = x2; y1 = y2;
  1933 + x2 = vX[i]; y2 = vY[i];
  1934 + dL = sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
  1935 + dLength += dL;
  1936 + }
  1937 +
  1938 + if (dLength < dW)
  1939 + return false;
  1940 + double dLengthBegin = (dLength - dW) / 2;
  1941 +
  1942 + x2 = vX[0]; y2 = vY[0];
  1943 + double dLCollect = 0;
  1944 + int i = 1;
  1945 + for (; i < sz; i++)
  1946 + {
  1947 + x1 = x2; y1 = y2;
  1948 + x2 = vX[i]; y2 = vY[i];
  1949 + dL = sqrt((x1 - x2)*(x1 - x2) + (y1 - y2)*(y1 - y2));
  1950 + dLCollect += dL;
  1951 + if (dLCollect >= dLengthBegin)
  1952 + break;
  1953 + }
  1954 +
  1955 + double dDis = dLCollect - dLengthBegin;
  1956 + x_show_begin = x2 - (x2 - x1)*dDis / dL;
  1957 + y_show_begin = y2 - (y2 - y1)*dDis / dL;
  1958 +
  1959 + iPointIndex = i - 1;
  1960 + return true;
  1961 +
  1962 +}
  1963 +
  1964 +double SimpleLabelRenderer::CalculateRadianRight3(vector<double> vX, vector<double> vY, double dTextWidth, int& iIndex, double x_show, double y_show, double &x_show_next, double&y_show_next)
  1965 +{
  1966 + /*
  1967 + 参数解释:
  1968 + dTextWidth,当前单个文字的宽度
  1969 + iIndex , 当前书写文本时在线条上的上一个点的索引
  1970 + x_show , 当前书写文字的开始位置
  1971 + y_show ,
  1972 + x_show_next, 得出下一个文字开始书写的位置
  1973 + y_show_next
  1974 +
  1975 +
  1976 + 通过计算,得出当前这个文字的旋转弧度,得出下一个文字的其实位置,得出下一个文字落在第几个点到下一个点之间
  1977 + */
  1978 + //尝试一次性写下该文字
  1979 + double x1 = x_show;
  1980 + double y1 = y_show;
  1981 + double x2 = vX[iIndex + 1];
  1982 + double y2 = vY[iIndex + 1];
  1983 + double dLength = sqrt((x1 - x2)*(x1 - x2) + (y1 - y2)*(y1 - y2));
  1984 +
  1985 + if (dLength > dTextWidth)
  1986 + {
  1987 + //一次性可以写下
  1988 +
  1989 + //求导
  1990 + double dDerivative = (y2 - y1) / (x2 - x1);
  1991 + double dRadia = atan(dDerivative); //计算出弧度
  1992 + this->CalculateIntersection(dTextWidth, x_show, y_show, x1, y1, x2, y2, x_show_next, y_show_next); //计算出下一个文字的位置
  1993 +
  1994 + return dRadia;
  1995 + }
  1996 + else
  1997 + {
  1998 + //计算出另一端在哪两个点之间
  1999 + int iPointCount = (int)(vX.size());
  2000 + for (iIndex++; iIndex < iPointCount - 1; iIndex++)
  2001 + {
  2002 + x2 = vX[iIndex + 1];
  2003 + y2 = vY[iIndex + 1];
  2004 + double dLength = sqrt((x1 - x2)*(x1 - x2) + (y1 - y2)*(y1 - y2));
  2005 + if (dLength > dTextWidth)
  2006 + break;
  2007 + }
  2008 +
  2009 + this->CalculateIntersection(dTextWidth, x_show, y_show, vX[iIndex], vY[iIndex], vX[iIndex+1], vY[iIndex+1], x_show_next, y_show_next);
  2010 + double dRadia = atan ((y_show_next - y_show) / (x_show_next - x_show));
  2011 +
  2012 + return dRadia;
  2013 + }
  2014 +}
  2015 +
  2016 +bool SimpleLabelRenderer::DrawMLineCurve4(clsCrSurf* pClsCS, clsStruct::MLINE* pStrMLine, char* sUTF8)
  2017 +{
  2018 + cairo_t* cr = pClsCS->m_pCr;
  2019 + cairo_text_extents_t extents;
  2020 + cairo_text_extents(cr, sUTF8, &extents);
  2021 + double x_advance_all = extents.x_advance;
  2022 +
  2023 + clsStruct::LINE* pLine = pStrMLine->p;
  2024 +
  2025 +
  2026 + //计算开始书写第一个文字的位置
  2027 + double x_show_begin, y_show_begin; int iPointIndex;
  2028 + bool flag = this->CalculateShowBegin(pLine, x_advance_all, x_show_begin, y_show_begin, iPointIndex);
  2029 +
  2030 + if (!flag)
  2031 + return false;
  2032 +
  2033 + string words[500];
  2034 + for (int i = 0; i < 50; i++)
  2035 + words[i] = "";
  2036 +
  2037 + //拆分字符串成文字数组
  2038 + int iWordsCount = this->SplitUTF8(sUTF8, words, 50);
  2039 +
  2040 + double x_show_this, y_show_this, x_show_next, y_show_next;
  2041 +
  2042 + x_show_this = x_show_begin; y_show_this = y_show_begin;
  2043 +
  2044 + //cairo_text_extents_t exents;
  2045 + //{
  2046 + // //检查整个字符串的文字避让
  2047 + //}
  2048 +
  2049 + double dRadia_this, dRadia_last;
  2050 + for (int i = 0; i < iWordsCount; i++)
  2051 + {
  2052 + char ss[5]; const char* ss__ = words[i].c_str(); strcpy(ss, ss__);
  2053 + cairo_text_extents(cr, ss, &extents);
  2054 + double dWordWidth = extents.x_advance;
  2055 + int iIndex = iPointIndex;
  2056 + dRadia_this = this->CalculateRadianRight4(pLine, dWordWidth, iIndex, x_show_this, y_show_this, x_show_next, y_show_next);
  2057 +
  2058 + if (!i)
  2059 + dRadia_last = dRadia_this;
  2060 + double dRadiaDisMax = M_PI / 12; // 旋转弧度落差范围,上一个文字旋转弧度与下一个文字旋转弧度不得超过30度
  2061 + if ((dRadia_this - dRadia_last) >dRadiaDisMax)
  2062 + dRadia_this = dRadia_last + dRadiaDisMax;
  2063 + if (dRadia_this - dRadia_last < -dRadiaDisMax)
  2064 + dRadia_this = dRadia_last - dRadiaDisMax;
  2065 +
  2066 +
  2067 + bool bb = m_pTextSymbol->DrawAText(pClsCS, x_show_this, y_show_this, ss, dRadia_this);
  2068 + bb = bb;
  2069 + dRadia_last = dRadia_this;
  2070 +
  2071 +
  2072 + x_show_this = x_show_next; y_show_this = y_show_next;
  2073 + }
  2074 +
  2075 +
  2076 +
  2077 + return true;
  2078 +
  2079 +
  2080 +}
  2081 +
  2082 +
  2083 +
  2084 +bool SimpleLabelRenderer::DrawMLineCurve5(clsCrSurf* pClsCS, clsStruct::MLINE* pStrMLine, char* sUTF8)
  2085 +{
  2086 + cairo_t* cr = pClsCS->m_pCr;
  2087 + cairo_text_extents_t extents;
  2088 + cairo_text_extents(cr, sUTF8, &extents);
  2089 + double x_advance_all = extents.x_advance;
  2090 +
  2091 + clsStruct::LINE* pLine = pStrMLine->p;
  2092 +
  2093 +
  2094 + //计算开始书写第一个文字的位置
  2095 + double x_show_begin, y_show_begin; int iPointIndex;
  2096 +
  2097 + double dRadia = 0;
  2098 + bool flag = this->CalculateShowBegin5(pLine, x_advance_all, x_show_begin, y_show_begin, iPointIndex, dRadia, pClsCS->m_iW, pClsCS->m_iH);
  2099 +
  2100 + if (!flag)
  2101 + return false;
  2102 + if (pLine->nPoint<iPointIndex + 2) return false;
  2103 +
  2104 + double x_show_this, y_show_this, x_show_next, y_show_next;
  2105 +
  2106 + x_show_this = x_show_begin; y_show_this = y_show_begin;
  2107 +
  2108 + if (pLine->p[iPointIndex + 1].x > x_show_begin)
  2109 + {
  2110 + x_show_next = pLine->p[iPointIndex + 2].x;
  2111 + y_show_next = pLine->p[iPointIndex + 2].y;
  2112 + }
  2113 + else
  2114 + {
  2115 +
  2116 + x_show_next = x_show_begin;
  2117 + y_show_next = y_show_begin;
  2118 +
  2119 + x_show_begin = pLine->p[iPointIndex + 2].x;
  2120 + y_show_begin = pLine->p[iPointIndex + 2].y;
  2121 + }
  2122 +
  2123 + dRadia = atan2((y_show_next - y_show_begin),(x_show_next - x_show_begin));
  2124 +
  2125 + m_pTextSymbol->DrawAText(pClsCS, x_show_begin, y_show_begin, sUTF8, dRadia);
  2126 +
  2127 +
  2128 + return true;
  2129 +}
  2130 +
  2131 +
  2132 +/*
  2133 +
  2134 +bool SimpleLabelRenderer::DrawMLineCurve5(clsCrSurf* pClsCS, clsStruct::MLINE* pStrMLine, char* sUTF8)
  2135 +{
  2136 + cairo_t* cr = pClsCS->m_pCr;
  2137 + cairo_text_extents_t extents;
  2138 + cairo_text_extents(cr, sUTF8, &extents);
  2139 + double x_advance_all = extents.x_advance;
  2140 +
  2141 + clsStruct::LINE* pLine = pStrMLine->p;
  2142 +
  2143 +
  2144 + //计算开始书写第一个文字的位置
  2145 + double x_show_begin, y_show_begin; int iPointIndex;
  2146 +
  2147 + double dRadia = 0;
  2148 + bool flag = this->CalculateShowBegin5(pLine, x_advance_all, x_show_begin, y_show_begin, iPointIndex, dRadia, pClsCS->m_iW, pClsCS->m_iH);
  2149 +
  2150 + if (!flag)
  2151 + return false;
  2152 +
  2153 + string words[500];
  2154 + for (int i = 0; i < 50; i++)
  2155 + words[i] = "";
  2156 +
  2157 + //拆分字符串成文字数组
  2158 + int iWordsCount = this->SplitUTF8(sUTF8, words, 50);
  2159 +
  2160 + double x_show_this, y_show_this, x_show_next, y_show_next;
  2161 +
  2162 + x_show_this = x_show_begin; y_show_this = y_show_begin;
  2163 +
  2164 + bool bb = m_pTextSymbol->DrawAText(pClsCS, x_show_this, y_show_this, sUTF8, dRadia);
  2165 + //m_pTextSymbol->DrawAText(pClsCS, x_show_begin, y_show_begin, sUTF8);
  2166 + return true;
  2167 + //cairo_text_extents_t exents;
  2168 + //{
  2169 + // //检查整个字符串的文字避让
  2170 + //}
  2171 +
  2172 + double dRadia_this, dRadia_last;
  2173 + for (int i = 0; i < iWordsCount; i++)
  2174 + {
  2175 + char ss[5]; const char* ss__ = words[i].c_str(); strcpy(ss, ss__);
  2176 + cairo_text_extents(cr, ss, &extents);
  2177 + double dWordWidth = extents.x_advance;
  2178 + int iIndex = iPointIndex;
  2179 + dRadia_this = this->CalculateRadianRight4(pLine, dWordWidth, iIndex, x_show_this, y_show_this, x_show_next, y_show_next);
  2180 +
  2181 + if (!i)
  2182 + dRadia_last = dRadia_this;
  2183 + double dRadiaDisMax = M_PI / 12; // 旋转弧度落差范围,上一个文字旋转弧度与下一个文字旋转弧度不得超过30度
  2184 + if ((dRadia_this - dRadia_last) >dRadiaDisMax)
  2185 + dRadia_this = dRadia_last + dRadiaDisMax;
  2186 + if (dRadia_this - dRadia_last < -dRadiaDisMax)
  2187 + dRadia_this = dRadia_last - dRadiaDisMax;
  2188 +
  2189 + if (dRadia_this == dRadia_this)
  2190 + {
  2191 + bool bb = m_pTextSymbol->DrawAText(pClsCS, x_show_this, y_show_this, sUTF8, dRadia_this);
  2192 + bb = bb;
  2193 + dRadia_last = dRadia_this;
  2194 + x_show_this = x_show_next; y_show_this = y_show_next;
  2195 + break;
  2196 + }
  2197 + else
  2198 + {
  2199 + printf("%f \r\n", dRadia_this);
  2200 + return false;
  2201 + }
  2202 +
  2203 + }
  2204 +
  2205 + return true;
  2206 +}
  2207 +
  2208 +*/
  2209 +
  2210 +bool SimpleLabelRenderer::CalculateShowBegin(clsStruct::LINE* pLine, double dW, double& x_show_begin, double& y_show_begin, int & iPointIndex)
  2211 +{
  2212 + switch (m_iLineLabelPositionStartOrEnd)
  2213 + {
  2214 + case dmapLineLabelPositionStart:
  2215 + {
  2216 +
  2217 + clsStruct::POINT* pPoint = pLine->p;
  2218 + int nPoint = pLine->nPoint;
  2219 +
  2220 + double dLength = 0;
  2221 +
  2222 + double x1, x2, y1, y2;
  2223 +
  2224 + clsStruct::POINT* pp = pPoint;
  2225 + x2 = pp->x;
  2226 + y2 = pp->y;
  2227 +
  2228 +
  2229 + if (nPoint > 5)
  2230 + {
  2231 + int index = nPoint / 2;
  2232 + pp += index;
  2233 + x1 = x2; y1 = y2;
  2234 + x2 = pp->x;
  2235 + y2 = pp->y;
  2236 + double dL = sqrt((x1 - x2)*(x1 - x2) + (y1 - y2)*(y1 - y2));
  2237 + dLength += dL;
  2238 + }
  2239 +
  2240 + if (nPoint > 1)
  2241 + {
  2242 + int index = nPoint - 1;
  2243 + pp += index;
  2244 + x1 = x2; y1 = y2;
  2245 + x2 = pp->x;
  2246 + y2 = pp->y;
  2247 + double dL = sqrt((x1 - x2)*(x1 - x2) + (y1 - y2)*(y1 - y2));
  2248 + dLength += dL;
  2249 + }
  2250 +
  2251 + if (dLength > dW*1.5)
  2252 + {
  2253 + clsStruct::POINT* pp = pPoint;
  2254 + x2 = pp->x;
  2255 + y2 = pp->y;
  2256 + }
  2257 + else
  2258 + {
  2259 + return false;
  2260 + }
  2261 + return dLength;
  2262 +
  2263 + break;
  2264 + }
  2265 + case dmapLineLabelPositionEnd:
  2266 + {
  2267 + clsStruct::POINT* p = pLine->p;
  2268 + int nPoint = pLine->nPoint;
  2269 +
  2270 +
  2271 + double x1, y1, x2, y2;
  2272 +
  2273 + int i = nPoint - 2;
  2274 + double dDistance = 0;
  2275 +
  2276 +
  2277 + double dD;
  2278 + while ((dDistance < dW) && (i >= 0))
  2279 + {
  2280 + i--;
  2281 + x1 = (p + i)->x;
  2282 + y1 = (p + i)->y;
  2283 + x2 = (p + i + 1)->x;
  2284 + y2 = (p + i + 1)->y;
  2285 + dD = sqrt((x1 - x2)*(x1 - x2) + (y1 - y2)*(y1 - y2));
  2286 +
  2287 + dDistance += dD;
  2288 + }
  2289 + if (i < 0)
  2290 + return false;
  2291 + iPointIndex = i;
  2292 +
  2293 + double dSurplus = dDistance - dW;
  2294 +
  2295 + double x_begin1 = (p + iPointIndex)->x;
  2296 + double y_begin1 = (p + iPointIndex)->y;
  2297 + double x_begin2 = (p + iPointIndex + 1)->x;
  2298 + double y_begin2 = (p + iPointIndex + 1)->y;
  2299 +
  2300 + x_show_begin = dSurplus / dD *(x2 - x1) + x1;
  2301 + y_show_begin = dSurplus / dD *(y2 - y1) + y1;
  2302 +
  2303 +
  2304 +
  2305 + break;
  2306 + }
  2307 + case dmapLineLabelPositionCenter:
  2308 + {
  2309 + clsStruct::POINT* p = pLine->p;
  2310 + int nPoint = pLine->nPoint;
  2311 +
  2312 + int iIndex;
  2313 + double x_gravity, y_gravity;
  2314 + clsStruct::GetGravity(x_gravity, y_gravity, iIndex, pLine);
  2315 +
  2316 + int i = iIndex + 1;
  2317 + double dDistance = 0;
  2318 +
  2319 + double x1, y1, x2, y2, dD;
  2320 + while ((dDistance < dW) && (i >= 0))
  2321 + {
  2322 + i--;
  2323 + x1 = (p + i)->x;
  2324 + y1 = (p + i)->y;
  2325 + x2 = (p + i + 1)->x;
  2326 + y2 = (p + i + 1)->y;
  2327 + dD = sqrt((x1 - x2)*(x1 - x2) + (y1 - y2)*(y1 - y2));
  2328 +
  2329 + dDistance += dD;
  2330 + }
  2331 +
  2332 + if (i < 0 || dDistance == 0)
  2333 + return false;
  2334 + iPointIndex = i;
  2335 +
  2336 + double dSurplus = dDistance - dW;
  2337 +
  2338 + double x_begin1 = (p + iPointIndex)->x;
  2339 + double y_begin1 = (p + iPointIndex)->y;
  2340 + double x_begin2 = (p + iPointIndex + 1)->x;
  2341 + double y_begin2 = (p + iPointIndex + 1)->y;
  2342 +
  2343 + x_show_begin = dSurplus / dD *(x2 - x1) + x1;
  2344 + y_show_begin = dSurplus / dD *(y2 - y1) + y1;
  2345 +
  2346 + break;
  2347 + }
  2348 + default:
  2349 + break;
  2350 + }
  2351 +
  2352 + return true;
  2353 +}
  2354 +//
  2355 +//bool SimpleLabelRenderer::CalculateShowBegin(clsStruct::LINE* pLine, double dW, double& x_show_begin, double& y_show_begin, int & iPointIndex)
  2356 +//{
  2357 +// switch (m_iLineLabelPositionStartOrEnd)
  2358 +// {
  2359 +// case dmapLineLabelPositionStart:
  2360 +// {
  2361 +//
  2362 +// clsStruct::POINT* pPoint = pLine->p;
  2363 +// int nPoint = pLine->nPoint;
  2364 +//
  2365 +// double dLength = 0;
  2366 +//
  2367 +// double x1, x2, y1, y2;
  2368 +//
  2369 +// clsStruct::POINT* pp = pPoint;
  2370 +// x2 = pp->x;
  2371 +// y2 = pp->y;
  2372 +//
  2373 +//
  2374 +// if (nPoint > 5)
  2375 +// {
  2376 +// int index = nPoint / 2;
  2377 +// pp += index;
  2378 +// x1 = x2; y1 = y2;
  2379 +// x2 = pp->x;
  2380 +// y2 = pp->y;
  2381 +// double dL = sqrt((x1 - x2)*(x1 - x2) + (y1 - y2)*(y1 - y2));
  2382 +// dLength += dL;
  2383 +// }
  2384 +//
  2385 +// if (nPoint > 1)
  2386 +// {
  2387 +// int index = nPoint -1;
  2388 +// pp += index;
  2389 +// x1 = x2; y1 = y2;
  2390 +// x2 = pp->x;
  2391 +// y2 = pp->y;
  2392 +// double dL = sqrt((x1 - x2)*(x1 - x2) + (y1 - y2)*(y1 - y2));
  2393 +// dLength += dL;
  2394 +// }
  2395 +//
  2396 +// if (dLength > dW*1.2)
  2397 +// {
  2398 +//
  2399 +// }
  2400 +//
  2401 +// return dLength;
  2402 +//
  2403 +//
  2404 +// //double dLength = clsStruct::GetLength(pLine);
  2405 +// //if (dW > dLength)
  2406 +// // return false;
  2407 +// //clsStruct::POINT* p = pLine->p;
  2408 +// //x_show_begin = p->x;
  2409 +// //y_show_begin = p->y;
  2410 +// //iPointIndex = 0;
  2411 +//
  2412 +//
  2413 +// break;
  2414 +// }
  2415 +// case dmapLineLabelPositionEnd:
  2416 +// {
  2417 +// clsStruct::POINT* p = pLine->p;
  2418 +// int nPoint = pLine->nPoint;
  2419 +//
  2420 +//
  2421 +// double x1, y1, x2, y2;
  2422 +//
  2423 +// int i = nPoint -2;
  2424 +// double dDistance = 0;
  2425 +//
  2426 +//
  2427 +// double dD;
  2428 +// while ((dDistance < dW) && (i >= 0))
  2429 +// {
  2430 +// i--;
  2431 +// x1 = (p + i)->x;
  2432 +// y1 = (p + i)->y;
  2433 +// x2 = (p + i + 1)->x;
  2434 +// y2 = (p + i + 1)->y;
  2435 +// dD = sqrt((x1 - x2 )*(x1-x2) + (y1 - y2)*(y1 - y2));
  2436 +//
  2437 +// dDistance += dD ;
  2438 +// }
  2439 +// if (i < 0)
  2440 +// return false;
  2441 +// iPointIndex = i;
  2442 +//
  2443 +// double dSurplus = dDistance - dW;
  2444 +//
  2445 +// double x_begin1 = (p + iPointIndex)->x;
  2446 +// double y_begin1 = (p + iPointIndex)->y;
  2447 +// double x_begin2 = (p + iPointIndex + 1)->x;
  2448 +// double y_begin2 = (p + iPointIndex + 1)->y;
  2449 +//
  2450 +// x_show_begin = dSurplus / dD *(x2 - x1) + x1;
  2451 +// y_show_begin = dSurplus / dD *(y2 - y1) + y1;
  2452 +//
  2453 +//
  2454 +//
  2455 +// break;
  2456 +// }
  2457 +// case dmapLineLabelPositionCenter:
  2458 +// {
  2459 +// clsStruct::POINT* p = pLine->p;
  2460 +// int nPoint = pLine->nPoint;
  2461 +//
  2462 +// int iIndex;
  2463 +// double x_gravity, y_gravity;
  2464 +// clsStruct::GetGravity(x_gravity, y_gravity, iIndex, pLine);
  2465 +//
  2466 +// int i = iIndex + 1;
  2467 +// double dDistance = 0;
  2468 +//
  2469 +// double x1, y1, x2, y2,dD;
  2470 +// while ((dDistance < dW) && (i >= 0))
  2471 +// {
  2472 +// i--;
  2473 +// x1 = (p + i)->x;
  2474 +// y1 = (p + i)->y;
  2475 +// x2 = (p + i + 1)->x;
  2476 +// y2 = (p + i + 1)->y;
  2477 +// dD = sqrt((x1 - x2)*(x1 - x2) + (y1 - y2)*(y1 - y2));
  2478 +//
  2479 +// dDistance += dD;
  2480 +// }
  2481 +//
  2482 +// if (i < 0 || dDistance==0)
  2483 +// return false;
  2484 +// iPointIndex = i;
  2485 +//
  2486 +// double dSurplus = dDistance - dW;
  2487 +//
  2488 +// double x_begin1 = (p + iPointIndex)->x;
  2489 +// double y_begin1 = (p + iPointIndex)->y;
  2490 +// double x_begin2 = (p + iPointIndex + 1)->x;
  2491 +// double y_begin2 = (p + iPointIndex + 1)->y;
  2492 +//
  2493 +// x_show_begin = dSurplus / dD *(x2 - x1) + x1;
  2494 +// y_show_begin = dSurplus / dD *(y2 - y1) + y1;
  2495 +//
  2496 +// break;
  2497 +// }
  2498 +// default:
  2499 +// break;
  2500 +// }
  2501 +//
  2502 +// return true;
  2503 +//}
  2504 +//
  2505 +
  2506 +
  2507 +bool SimpleLabelRenderer::CalculateShowBegin5(clsStruct::LINE* pLine, double dW, double& x_show_begin, double& y_show_begin, int & iPointIndex,double& dRadia, int width, int height)
  2508 +{
  2509 + switch (m_iLineLabelPositionStartOrEnd)
  2510 + {
  2511 + case dmapLineLabelPositionStart:
  2512 + {
  2513 + double dLength = clsStruct::GetLength5(pLine, iPointIndex, x_show_begin, y_show_begin, dRadia, width, height, dW);
  2514 + if (dW > dLength)
  2515 + return false;
  2516 + break;
  2517 + }
  2518 + case dmapLineLabelPositionEnd:
  2519 + {
  2520 + clsStruct::POINT* p = pLine->p;
  2521 + int nPoint = pLine->nPoint;
  2522 +
  2523 +
  2524 + double x1, y1, x2, y2;
  2525 +
  2526 + int i = nPoint - 2;
  2527 + double dDistance = 0;
  2528 +
  2529 +
  2530 + double dD;
  2531 + while ((dDistance < dW) && (i >= 0))
  2532 + {
  2533 + i--;
  2534 + x1 = (p + i)->x;
  2535 + y1 = (p + i)->y;
  2536 + x2 = (p + i + 1)->x;
  2537 + y2 = (p + i + 1)->y;
  2538 + dD = sqrt((x1 - x2)*(x1 - x2) + (y1 - y2)*(y1 - y2));
  2539 +
  2540 + dDistance += dD;
  2541 + }
  2542 + if (i < 0)
  2543 + return false;
  2544 + iPointIndex = i;
  2545 +
  2546 + double dSurplus = dDistance - dW;
  2547 +
  2548 + double x_begin1 = (p + iPointIndex)->x;
  2549 + double y_begin1 = (p + iPointIndex)->y;
  2550 + double x_begin2 = (p + iPointIndex + 1)->x;
  2551 + double y_begin2 = (p + iPointIndex + 1)->y;
  2552 +
  2553 + x_show_begin = dSurplus / dD *(x2 - x1) + x1;
  2554 + y_show_begin = dSurplus / dD *(y2 - y1) + y1;
  2555 +
  2556 +
  2557 +
  2558 + break;
  2559 + }
  2560 + case dmapLineLabelPositionCenter:
  2561 + {
  2562 + clsStruct::POINT* p = pLine->p;
  2563 + int nPoint = pLine->nPoint;
  2564 +
  2565 + int iIndex;
  2566 + double x_gravity, y_gravity;
  2567 + clsStruct::GetGravity(x_gravity, y_gravity, iIndex, pLine);
  2568 +
  2569 + int i = iIndex + 1;
  2570 + double dDistance = 0;
  2571 +
  2572 + double x1, y1, x2, y2, dD;
  2573 + while ((dDistance < dW) && (i >= 0))
  2574 + {
  2575 + i--;
  2576 + x1 = (p + i)->x;
  2577 + y1 = (p + i)->y;
  2578 + x2 = (p + i + 1)->x;
  2579 + y2 = (p + i + 1)->y;
  2580 + dD = sqrt((x1 - x2)*(x1 - x2) + (y1 - y2)*(y1 - y2));
  2581 +
  2582 + dDistance += dD;
  2583 + }
  2584 +
  2585 + if (i < 0 || dDistance == 0)
  2586 + return false;
  2587 + iPointIndex = i;
  2588 +
  2589 + double dSurplus = dDistance - dW;
  2590 +
  2591 + double x_begin1 = (p + iPointIndex)->x;
  2592 + double y_begin1 = (p + iPointIndex)->y;
  2593 + double x_begin2 = (p + iPointIndex + 1)->x;
  2594 + double y_begin2 = (p + iPointIndex + 1)->y;
  2595 +
  2596 + x_show_begin = dSurplus / dD *(x2 - x1) + x1;
  2597 + y_show_begin = dSurplus / dD *(y2 - y1) + y1;
  2598 +
  2599 + break;
  2600 + }
  2601 + default:
  2602 + break;
  2603 + }
  2604 +
  2605 + return true;
  2606 +}
  2607 +
  2608 +
  2609 +
  2610 +
  2611 +double SimpleLabelRenderer::CalculateRadianRight4(clsStruct::LINE* pLine, double dTextWidth, int & iIndex, double x_show, double y_show, double &x_show_next, double& y_show_next)
  2612 +{
  2613 + /*
  2614 + 参数解释:
  2615 + dTextWidth,当前单个文字的宽度
  2616 + iIndex , 当前书写文本时在线条上的上一个点的索引
  2617 + x_show , 当前书写文字的开始位置
  2618 + y_show ,
  2619 + x_show_next, 得出下一个文字开始书写的位置
  2620 + y_show_next
  2621 + */
  2622 +
  2623 +
  2624 + /*
  2625 + 通过计算, 得出当前这个文字的旋转弧度, 得出下一个文字的其实位置, 得出下一个文字落在第几个点到下一个点之间
  2626 + */
  2627 + //尝试一次性写下该文字
  2628 + clsStruct::POINT* p = pLine->p;
  2629 + int nPoint = pLine->nPoint;
  2630 +
  2631 + double x1 = x_show;
  2632 + double y1 = y_show;
  2633 + double x2 = (p + iIndex + 1)->x;
  2634 + double y2 = (p + iIndex + 1)->y;
  2635 + double dLength = sqrt((x1 - x2)*(x1 - x2) + (y1 - y2)*(y1 - y2));
  2636 +
  2637 + if (dLength > dTextWidth)
  2638 + {
  2639 + //一次性可以写下
  2640 +
  2641 + //求导
  2642 + double dDerivative = (y2 - y1) / (x2 - x1);
  2643 + double dRadia = atan(dDerivative); //计算出弧度
  2644 + this->CalculateIntersection(dTextWidth, x_show, y_show, x1, y1, x2, y2, x_show_next, y_show_next); //计算出下一个文字的位置
  2645 +
  2646 + return dRadia;
  2647 + }
  2648 + else
  2649 + {
  2650 + //计算出另一端在哪两个点之间
  2651 + for (iIndex++; iIndex < nPoint - 1; iIndex++)
  2652 + {
  2653 + double x2 = (p + iIndex + 1)->x;
  2654 + double y2 = (p + iIndex + 1)->y;
  2655 + double dLength = sqrt((x1 - x2)*(x1 - x2) + (y1 - y2)*(y1 - y2));
  2656 + if (dLength > dTextWidth)
  2657 + break;
  2658 + }
  2659 +
  2660 + double x1__, y1__, x2__, y2__;
  2661 + x1__ = (p + iIndex)->x; y1__ = (p + iIndex)->y;
  2662 + x2__ = (p + iIndex + 1)->x; y2__ = (p + iIndex + 1)->y;
  2663 + this->CalculateIntersection(dTextWidth, x_show, y_show, x1__, y1__, x2__, y2__, x_show_next, y_show_next);
  2664 + double dRadia = atan((y_show_next - y_show) / (x_show_next - x_show));
  2665 +
  2666 + return dRadia;
  2667 + }
  2668 + return 0;
  2669 +}
  2670 +
  2671 +int SimpleLabelRenderer::SplitUTF8(char* sUTF8, string* pStr, int iStrCount)
  2672 +{
  2673 + int len = strlen(sUTF8);
  2674 + if (len > iStrCount)
  2675 + return -1;
  2676 + for (int i = 0; i < len; i++)
  2677 + {
  2678 + char s_[5]; memset(s_, 0, 5);
  2679 + s_[0] = sUTF8[i];
  2680 + pStr[i] = s_;
  2681 + string s = pStr[i];
  2682 + }
  2683 +
  2684 + return len;
  2685 +}
  2686 +
  2687 +
  2688 +bool SimpleLabelRenderer::DrawMPolygon(clsCrSurf* pClsCS, clsStruct::MPOLYGON* pStrMPolygon, char* sUTF8)
  2689 +{
  2690 + switch (m_iPolygonLabelPositionDirection)
  2691 + {
  2692 + case dmapPolygonLabelPositionParallel:
  2693 + this->DrawMPolygonParallel(pClsCS, pStrMPolygon, sUTF8);
  2694 + break;
  2695 + case dmapPolygonLabelPositionStraight:
  2696 + this->DrawMPolygonStraight(pClsCS, pStrMPolygon, sUTF8);
  2697 + break;
  2698 + case dmapPolygonLabelPositionParallelAndStraight:
  2699 + this->DrawMPolygonParallelAndStraight(pClsCS, pStrMPolygon, sUTF8);
  2700 + break;
  2701 + default:
  2702 + break;
  2703 + }
  2704 +
  2705 +
  2706 + return true;
  2707 +}
  2708 +
  2709 +
  2710 +bool SimpleLabelRenderer::DrawMPolygonParallel(clsCrSurf* pClsCS, clsStruct::MPOLYGON* pStrMPolygon, char* sUTF8)
  2711 +{
  2712 +
  2713 + int iPolygonIndex = 0, iRingIndex = 0;
  2714 + clsStruct::GetMaxRing(pStrMPolygon, iPolygonIndex, iRingIndex);
  2715 + clsStruct::LINE* pMaxRing = (pStrMPolygon->p + iPolygonIndex)->p + iRingIndex;
  2716 +
  2717 + double x, y;
  2718 + clsStruct::GetRingGravity(x, y, pMaxRing);
  2719 +
  2720 +
  2721 + cairo_text_extents_t extents;
  2722 + cairo_text_extents(pClsCS->m_pCr, sUTF8, &extents);
  2723 + double dTextW = extents.x_advance;
  2724 + double dTextH = extents.height;
  2725 + double x_show = x - dTextW / 2;
  2726 + double y_show = y + dTextH / 2;
  2727 +
  2728 + if (m_bLabelInPolygon)
  2729 + {
  2730 + double x2, y2, x3, y3, x4, y4;
  2731 + x2 = x_show; y2 = y_show - dTextH;
  2732 + x3 = x_show + dTextW; y3 = y_show - dTextH;
  2733 + x4 = x_show + dTextW; y4 = y_show;
  2734 +
  2735 + bool flag1 = clsStruct::GetIsInRing(pMaxRing, x_show, y_show);
  2736 + bool flag2 = clsStruct::GetIsInRing(pMaxRing, x2, y2);
  2737 + bool flag3 = clsStruct::GetIsInRing(pMaxRing, x3, y3);
  2738 + bool flag4 = clsStruct::GetIsInRing(pMaxRing, x4, y4);
  2739 +
  2740 + if (flag1 && flag2 && flag3 && flag4)
  2741 + return m_pTextSymbol->DrawAText(pClsCS, x_show, y_show, sUTF8);
  2742 + else
  2743 + return false;
  2744 + }
  2745 + else
  2746 + {
  2747 + bool flag = m_pTextSymbol->DrawAText(pClsCS, x_show, y_show, sUTF8);
  2748 + return flag;
  2749 + }
  2750 +}
  2751 +
  2752 +bool SimpleLabelRenderer::DrawMPolygonStraight(clsCrSurf* pClsCS, clsStruct::MPOLYGON* pStrMPolygon, char* sUTF8)
  2753 +{
  2754 + int iPolygonIndex, iRingIndex;
  2755 + clsStruct::GetMaxRing(pStrMPolygon, iPolygonIndex,iRingIndex);
  2756 + clsStruct::LINE* pMaxRing = (pStrMPolygon->p + iPolygonIndex)->p + iRingIndex;
  2757 +
  2758 + vector<double> vX, vY;
  2759 + clsStruct::GetConvexRing(pMaxRing, vX, vY);
  2760 +
  2761 +
  2762 +
  2763 +
  2764 + double x1, y1, x2, y2, x3, y3, x4, y4;
  2765 + this->OBB_Algorithm(vX, vY, x1, y1, x2, y2, x3, y3, x4, y4, pClsCS);
  2766 +
  2767 +
  2768 +
  2769 + double dW = sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2));
  2770 + double dH = sqrt((x3 - x2)*(x3 - x2) + (y3 - y2)*(y3 - y2));
  2771 +
  2772 +
  2773 +
  2774 + double dXW1,dYW1, dXW2, dYW2;
  2775 + dXW1 = x2; dYW1 = y2;
  2776 + if (dW >= dH)
  2777 + {
  2778 + dXW2 = x1;
  2779 + dYW2 = y1;
  2780 + }
  2781 + else
  2782 + {
  2783 + dXW2 = x3;
  2784 + dYW2 = y3;
  2785 + }
  2786 +
  2787 + if (dXW1 > dXW2)
  2788 + {
  2789 + double x_temp = dXW1; double y_temp = dYW1;
  2790 + dXW1 = dXW2; dYW1 = dYW2;
  2791 + dXW2 = x_temp; dYW2 = y_temp;
  2792 + }
  2793 +
  2794 + double dAngle;
  2795 +
  2796 + if (dXW1 == dXW2)
  2797 + {
  2798 + if (dYW1 > dYW2)
  2799 + dAngle = 3 * M_PI / 2;
  2800 + else
  2801 + dAngle = M_PI / 2;
  2802 + }
  2803 + else
  2804 + dAngle = atan((dYW2-dYW1) / (dXW2 - dXW1));
  2805 +
  2806 +
  2807 + double x_gravity, y_gravity;
  2808 +
  2809 + clsStruct::GetGravity(x_gravity, y_gravity, pStrMPolygon);
  2810 +
  2811 +
  2812 + double dTextW, dTextH;
  2813 +
  2814 + cairo_text_extents_t extents;
  2815 + cairo_text_extents(pClsCS->m_pCr, sUTF8, &extents);
  2816 + dTextW = extents.x_advance;
  2817 + dTextH = extents.height;
  2818 +
  2819 + double x_ = x_gravity - cos(dAngle)*dTextW / 2;
  2820 + double y_ = y_gravity - sin(dAngle)*dTextW / 2;
  2821 + double x_show = x_ - sin(dAngle)*dTextH / 2;
  2822 + double y_show = y_ + cos(dAngle)*dTextH / 2;
  2823 +
  2824 + double x2_ = x_ + sin(dAngle)*dTextH / 2;
  2825 + double y2_ = y_ - cos(dAngle)*dTextH / 2;
  2826 +
  2827 + double x___ = x_gravity + cos(dAngle)*dTextW / 2;
  2828 + double y___ = y_gravity + sin(dAngle)*dTextW / 2;
  2829 + double x3_ = x___ + sin(dAngle)*dTextH / 2;
  2830 + double y3_ = y___ - cos(dAngle)*dTextH / 2;
  2831 + double x4_ = x___ - sin(dAngle)*dTextH / 2;
  2832 + double y4_ = y___ + cos(dAngle)*dTextH / 2;
  2833 +
  2834 +
  2835 + /*{
  2836 + cairo_t* cr = pClsCS->m_pCr;
  2837 + cairo_set_source_rgba(cr, 1, 1, 0, 0.5);
  2838 + cairo_set_line_width(cr, 1);
  2839 + cairo_move_to(cr, x_show, y_show);
  2840 + cairo_line_to(cr, x2_, y2_);
  2841 + cairo_line_to(cr, x3_, y3_);
  2842 + cairo_line_to(cr, x4_, y4_);
  2843 + cairo_close_path(cr);
  2844 + cairo_stroke(cr);
  2845 +
  2846 + cairo_new_path(cr); cairo_arc(cr, x_gravity, y_gravity, 5, 0, 2 * M_PI); cairo_fill(cr);
  2847 + }*/
  2848 + //四个点都必须在多边形内部
  2849 + bool flag1 = clsStruct::GetIsInRing(pMaxRing, x_show, y_show);
  2850 + bool flag2 = clsStruct::GetIsInRing(pMaxRing, x2_, y2_);
  2851 + bool flag3 = clsStruct::GetIsInRing(pMaxRing, x3_, y3_);
  2852 + bool flag4 = clsStruct::GetIsInRing(pMaxRing, x4_, y4_);
  2853 +
  2854 + if (flag1 && flag2 && flag3 && flag4)
  2855 + {
  2856 + bool flag = m_pTextSymbol->DrawAText(pClsCS, x_show, y_show, sUTF8, dAngle);
  2857 + return flag;
  2858 + }
  2859 + return false;
  2860 +
  2861 +
  2862 +
  2863 +
  2864 +
  2865 + //计算最小外包矩形 OBB
  2866 +
  2867 + /*int nPoint = pMaxRing->nPoint;*/
  2868 +
  2869 + /*{
  2870 +
  2871 + cairo_t* cr = pClsCS->m_pCr;
  2872 + cairo_set_source_rgba(cr, 0, 1, 1, 0.5);
  2873 + cairo_set_line_width(cr, 4);
  2874 +
  2875 + int sz = (int)vX.size();
  2876 + double x, y;
  2877 +
  2878 + for (int i = 0; i < sz; i++)
  2879 + {
  2880 + x = vX[i]; y = vY[i];
  2881 +
  2882 + if (i == 0)
  2883 + cairo_move_to(cr, x, y);
  2884 + else
  2885 + cairo_line_to(cr, x, y);
  2886 + }
  2887 + cairo_close_path(cr);
  2888 + cairo_stroke(cr);
  2889 + }*/
  2890 +
  2891 + /*{
  2892 + int nPoint = pMaxRing->nPoint;
  2893 + clsStruct::POINT* p = pMaxRing->p;
  2894 +
  2895 + cairo_t* cr = pClsCS->m_pCr;
  2896 + cairo_set_source_rgba(cr, 1, 0.2, 0.2, 1);
  2897 + cairo_set_line_width(cr, 1);
  2898 +
  2899 + for (int i = 0; i < nPoint; i++)
  2900 + {
  2901 + double x = (p + i)->x;
  2902 + double y = (p + i)->y;
  2903 + if (i == 0)
  2904 + {
  2905 + cairo_move_to(cr, x, y);
  2906 + }
  2907 + else
  2908 + {
  2909 + cairo_line_to(cr, x, y);
  2910 + }
  2911 + }
  2912 + cairo_close_path(cr);
  2913 + cairo_stroke(cr);
  2914 + }*/
  2915 +
  2916 + //计算最小外包矩形OBB
  2917 +
  2918 +
  2919 +
  2920 + ////调整矩形, (x1,y1) (x2,y2)所在边为较长边
  2921 + //double dW = sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2));
  2922 + //double dH = sqrt((x2-x3)*(x2-x3) + (y2-y3)*(y2-y3));
  2923 +
  2924 + //if (dW < dH)
  2925 + //{
  2926 + // double d_temp = dW;
  2927 + // dW = dH; dH = d_temp;
  2928 +
  2929 + // double x_temp = x1;
  2930 + // double y_temp = y1;
  2931 + // {
  2932 + // x1 = x2; x2 = x3; x3 = x4; x4 = x_temp;
  2933 + // y1 = y2; y2 = y3; y3 = y4; y4 = y_temp;
  2934 + // }
  2935 + //}
  2936 +
  2937 +
  2938 + //double x_center = (x1 + x2) / 2;
  2939 + //double y_center = (y1 + y2) / 2;
  2940 +
  2941 + ////在该矩形的中心书写文字,且必须要写在多边形内部
  2942 + //cairo_text_extents_t extents;
  2943 + //cairo_text_extents(pClsCS->m_pCr, sUTF8, &extents);
  2944 + //double dTextW = extents.x_advance;
  2945 + //double dTextH = extents.height;
  2946 +
  2947 + //double dAngle = atan((y2 - y1)/(x2 -x1));
  2948 + //if (x1 > x2)
  2949 + // dAngle += M_PI;
  2950 +
  2951 + //if (x1 <= x2 && y1 <= y2)
  2952 + //{
  2953 + // double dAngle__ = 2 * M_PI - dAngle;
  2954 +
  2955 + // double x__ = x_center - cos(dAngle__)*dW / 2;
  2956 + // double y__ = y_center - sin(dAngle__)*dW / 2;
  2957 + // double x = x__ - sin(dAngle__)*dH / 2;
  2958 + // double y = y__ + cos(dAngle__)*dH / 2;
  2959 +
  2960 + // m_pTextSymbol->DrawAText(pClsCS, x, y, sUTF8, dAngle__);
  2961 +
  2962 + //}
  2963 + //else if (x1 >= x2 && y1 >= y2)
  2964 + //{
  2965 + // double dAngle__ = M_PI - dAngle;
  2966 +
  2967 + // double x__ = x_center - cos(dAngle__)*dW / 2;
  2968 + // double y__ = y_center - sin(dAngle__)*dW / 2;
  2969 + // double x = x__ - sin(dAngle__)*dH / 2;
  2970 + // double y = y__ + cos(dAngle__)*dH / 2;
  2971 +
  2972 + // m_pTextSymbol->DrawAText(pClsCS, x, y, sUTF8, dAngle__);
  2973 + //}
  2974 + //else if (x1 < x2 && y1 > y2)
  2975 + //{
  2976 + // double x__ = x_center - cos(dAngle)*dTextW / 2;
  2977 + // double y__ = y_center + sin(dAngle)*dTextW / 2;
  2978 + // double x = x__ + cos(dAngle)*dTextH / 2;
  2979 + // double y = y__ + sin(dAngle)*dTextH / 2;
  2980 +
  2981 + // m_pTextSymbol->DrawAText(pClsCS, x, y, sUTF8, -dAngle);
  2982 + //}
  2983 + //else if (x1 > x2 && y1 < y2)
  2984 + //{
  2985 + // double dAngle__ = dAngle - M_PI;
  2986 + // double x__ = x_center - cos(dAngle__)*dTextW / 2;
  2987 + // double y__ = y_center + sin(dAngle__)*dTextW / 2;
  2988 + // double x = x__ + cos(dAngle__)*dTextH / 2;
  2989 + // double y = y__ + sin(dAngle__)*dTextH / 2;
  2990 +
  2991 + // m_pTextSymbol->DrawAText(pClsCS, x, y, sUTF8, -dAngle__);
  2992 + //}
  2993 +
  2994 + return true;
  2995 +}
  2996 +bool SimpleLabelRenderer::DrawMPolygonParallelAndStraight(clsCrSurf* pClsCS, clsStruct::MPOLYGON* pStrMPolygon, char* sUTF8)// 先水平,其次平直
  2997 +{
  2998 +
  2999 + bool bHaveDraw = this->DrawMPolygonParallel(pClsCS, pStrMPolygon, sUTF8);
  3000 + if (bHaveDraw)
  3001 + return true;
  3002 +
  3003 + return this->DrawMPolygonStraight(pClsCS, pStrMPolygon, sUTF8);
  3004 +}
  3005 +
  3006 +
  3007 +bool SimpleLabelRenderer::OBB_Algorithm(std::vector<double> vX, std::vector<double> vY, double& x1, double& y1, double& x2, double& y2, double& x3, double& y3, double& x4, double& y4, clsCrSurf* pClsCS)
  3008 +{
  3009 +
  3010 + int nPoint = (int)(vX.size());
  3011 +
  3012 + double dMinArea;
  3013 +
  3014 + int iMinAreaIndex = 0;
  3015 +
  3016 + for (int i = 0; i < nPoint; i++)
  3017 + {
  3018 + double dArea = OBB_GetMBR(vX, vY, i, pClsCS);
  3019 +
  3020 + if (i == 0)
  3021 + {
  3022 + dMinArea = dArea;
  3023 + iMinAreaIndex = 0;
  3024 + }
  3025 + else
  3026 + {
  3027 + if (dArea < dMinArea)
  3028 + {
  3029 + dMinArea = dArea;
  3030 + iMinAreaIndex = i;
  3031 + }
  3032 + }
  3033 + }
  3034 +
  3035 + this->OBB_GetMBR(vX,vY, iMinAreaIndex, x1, y1, x2, y2, x3, y3, x4, y4, pClsCS);
  3036 +
  3037 + return true;
  3038 +}
  3039 +
  3040 +double SimpleLabelRenderer::OBB_GetMBR(std::vector<double> vX, std::vector<double> vY, int iPointIndex, clsCrSurf* pClsCS)
  3041 +{
  3042 + int nPoint = (int)(vX.size());
  3043 +
  3044 + double x1 = vX[iPointIndex];
  3045 + double y1 = vY[iPointIndex];
  3046 +
  3047 + double x2, y2;
  3048 + if (iPointIndex == nPoint - 1)
  3049 + {
  3050 + x2 = vX[0];
  3051 + y2 = vY[0];
  3052 + }
  3053 + else
  3054 + {
  3055 + x2 = vX[iPointIndex + 1];
  3056 + y2 = vY[iPointIndex + 1];
  3057 + }
  3058 +
  3059 + bool bHaveChanged = false;
  3060 + if (x1 > x2)
  3061 + {
  3062 + double x_temp, y_temp;
  3063 + x_temp = x1; x1 = x2; x2 = x_temp;
  3064 + y_temp = y1; y1 = y2; y2 = y_temp;
  3065 + bHaveChanged = true;
  3066 + }
  3067 +
  3068 + double dAngle;
  3069 + if (x2 == x1)
  3070 + {
  3071 + if (y2 > y1)
  3072 + dAngle = M_PI / 2;
  3073 + else
  3074 + dAngle = 3 * M_PI / 2;
  3075 + }
  3076 +
  3077 + else
  3078 + {
  3079 + dAngle = atan((y2 - y1) / (x2 - x1));
  3080 + if (x2 < x1)
  3081 + dAngle += M_PI;
  3082 + }
  3083 +
  3084 + dAngle = -dAngle;
  3085 +
  3086 + double dLeft = x1, dRight = x1, dTop = 0;
  3087 + int iLeftIndex, iRightIndex, iTopIndex;
  3088 + if (bHaveChanged)
  3089 + {
  3090 + if (iPointIndex == nPoint - 1)
  3091 + iLeftIndex = iRightIndex = iTopIndex = 0;
  3092 + else
  3093 + iLeftIndex = iRightIndex = iTopIndex = iPointIndex + 1;
  3094 + }
  3095 + else
  3096 + iLeftIndex = iRightIndex = iTopIndex = iPointIndex;
  3097 +
  3098 +
  3099 + for (int i = 0; i < nPoint; i++)
  3100 + {
  3101 + double x_ = vX[i];
  3102 + double y_ = vY[i];
  3103 +
  3104 + double x_new = (x_ - x1)*cos(dAngle) - (y_ - y1)* sin(dAngle) + x1;
  3105 + double y_new = (x_ - x1)*sin(dAngle) + (y_ - y1)* cos(dAngle) + y1;
  3106 +
  3107 + if (x_new < dLeft)
  3108 + {
  3109 + dLeft = x_new;
  3110 + iLeftIndex = i;
  3111 + }
  3112 + if (x_new > dRight)
  3113 + {
  3114 + dRight = x_new;
  3115 + iRightIndex = i;
  3116 + }
  3117 + if (fabs(y_new - y1) > dTop)
  3118 + {
  3119 + dTop = fabs(y_new - y1);
  3120 + iTopIndex = i;
  3121 + }
  3122 + }
  3123 +
  3124 +
  3125 + //直接先得出旋转后的矩形
  3126 + // x_rect_rotate_1
  3127 +
  3128 +
  3129 + double x_rr_1, y_rr_1, x_rr_2, y_rr_2, x_rr_3, y_rr_3, x_rr_4, y_rr_4;
  3130 + double x_l, y_l, x_r, y_r, x_t, y_t;
  3131 + double x_l_new, y_l_new, x_r_new, y_r_new, x_t_new, y_t_new;
  3132 + x_l = vX[iLeftIndex]; y_l = vY[iLeftIndex]; x_l_new = (x_l - x1)*cos(dAngle) - (y_l - y1)*sin(dAngle) + x1; y_l_new = (x_l - x1)*sin(dAngle) + (y_l - y1)*cos(dAngle) + y1;
  3133 +
  3134 + x_r = vX[iRightIndex]; y_r = vY[iRightIndex]; x_r_new = (x_r - x1)*cos(dAngle) - (y_r - y1)*sin(dAngle) + x1; y_r_new = (x_r - x1)*sin(dAngle) + (y_r - y1)*cos(dAngle) + y1;
  3135 + x_t = vX[iTopIndex]; y_t = vY[iTopIndex]; x_t_new = (x_t - x1)*cos(dAngle) - (y_t - y1)*sin(dAngle) + x1; y_t_new = (x_t - x1)*sin(dAngle) + (y_t - y1)*cos(dAngle) + y1;
  3136 +
  3137 +
  3138 + x_rr_1 = x_l_new; y_rr_1 = y_t_new;
  3139 + x_rr_2 = x_r_new; y_rr_2 = y_t_new;
  3140 + x_rr_3 = x_r_new; y_rr_3 = y1;
  3141 + x_rr_4 = x_l_new; y_rr_4 = y1;
  3142 +
  3143 +
  3144 +
  3145 +
  3146 +
  3147 + double dW = sqrt((x_rr_2 - x_rr_1)*(x_rr_2 - x_rr_1) + (y_rr_2 - y_rr_1)*((y_rr_2 - y_rr_1)));
  3148 + double dH = sqrt((x_rr_2 - x_rr_3)*(x_rr_2 - x_rr_3) + (y_rr_2 - y_rr_3)*((y_rr_2 - y_rr_3)));
  3149 + double dArea = dW*dH;
  3150 +
  3151 +
  3152 + return dArea;
  3153 +}
  3154 +
  3155 +bool SimpleLabelRenderer::OBB_GetMBR(std::vector<double> vX, std::vector<double> vY, int iPointIndex, double& x01, double& y01, double& x02, double& y02, double& x03, double& y03, double& x04, double& y04, clsCrSurf* pClsCS)
  3156 +{
  3157 +
  3158 + int nPoint = (int)(vX.size());
  3159 +
  3160 + double x1 = vX[iPointIndex];
  3161 + double y1 = vY[iPointIndex];
  3162 +
  3163 + double x2, y2;
  3164 + if (iPointIndex == nPoint - 1)
  3165 + {
  3166 + x2 = vX[0];
  3167 + y2 = vY[0];
  3168 + }
  3169 + else
  3170 + {
  3171 + x2 = vX[iPointIndex + 1];
  3172 + y2 = vY[iPointIndex + 1];
  3173 + }
  3174 +
  3175 + bool bHaveChanged = false;
  3176 + if (x1 > x2)
  3177 + {
  3178 + double x_temp, y_temp;
  3179 + x_temp = x1; x1 = x2; x2 = x_temp;
  3180 + y_temp = y1; y1 = y2; y2 = y_temp;
  3181 + bHaveChanged = true;
  3182 + }
  3183 +
  3184 + double dAngle;
  3185 + if (x2 == x1)
  3186 + {
  3187 + if (y2 > y1)
  3188 + dAngle = M_PI / 2;
  3189 + else
  3190 + dAngle = 3 * M_PI / 2;
  3191 + }
  3192 +
  3193 + else
  3194 + {
  3195 + dAngle = atan((y2 - y1) / (x2 - x1));
  3196 + if (x2 < x1)
  3197 + dAngle += M_PI;
  3198 + }
  3199 +
  3200 + dAngle = -dAngle;
  3201 +
  3202 + double dLeft = x1, dRight = x1, dTop = 0;
  3203 + int iLeftIndex, iRightIndex, iTopIndex;
  3204 + if (bHaveChanged)
  3205 + {
  3206 + if (iPointIndex == nPoint - 1)
  3207 + iLeftIndex = iRightIndex = iTopIndex = 0;
  3208 + else
  3209 + iLeftIndex = iRightIndex = iTopIndex = iPointIndex + 1;
  3210 + }
  3211 + else
  3212 + iLeftIndex = iRightIndex = iTopIndex = iPointIndex;
  3213 +
  3214 +
  3215 + for (int i = 0; i < nPoint; i++)
  3216 + {
  3217 + double x_ = vX[i];
  3218 + double y_ = vY[i];
  3219 +
  3220 + double x_new = (x_ - x1)*cos(dAngle) - (y_ - y1)* sin(dAngle) + x1;
  3221 + double y_new = (x_ - x1)*sin(dAngle) + (y_ - y1)* cos(dAngle) + y1;
  3222 +
  3223 + if (x_new < dLeft)
  3224 + {
  3225 + dLeft = x_new;
  3226 + iLeftIndex = i;
  3227 + }
  3228 + if (x_new > dRight)
  3229 + {
  3230 + dRight = x_new;
  3231 + iRightIndex = i;
  3232 + }
  3233 + if (fabs(y_new - y1) > dTop)
  3234 + {
  3235 + dTop = fabs(y_new - y1);
  3236 + iTopIndex = i;
  3237 + }
  3238 + }
  3239 +
  3240 +
  3241 + //直接先得出旋转后的矩形
  3242 + // x_rect_rotate_1
  3243 +
  3244 +
  3245 + double x_rr_1, y_rr_1, x_rr_2, y_rr_2, x_rr_3, y_rr_3, x_rr_4, y_rr_4;
  3246 + double x_l, y_l, x_r, y_r, x_t, y_t;
  3247 + double x_l_new, y_l_new, x_r_new, y_r_new, x_t_new, y_t_new;
  3248 + x_l = vX[iLeftIndex]; y_l = vY[iLeftIndex]; x_l_new = (x_l - x1)*cos(dAngle) - (y_l - y1)*sin(dAngle) + x1; y_l_new = (x_l - x1)*sin(dAngle) + (y_l - y1)*cos(dAngle) + y1;
  3249 +
  3250 + x_r = vX[iRightIndex]; y_r = vY[iRightIndex]; x_r_new = (x_r - x1)*cos(dAngle) - (y_r - y1)*sin(dAngle) + x1; y_r_new = (x_r - x1)*sin(dAngle) + (y_r - y1)*cos(dAngle) + y1;
  3251 + x_t = vX[iTopIndex]; y_t = vY[iTopIndex]; x_t_new = (x_t - x1)*cos(dAngle) - (y_t - y1)*sin(dAngle) + x1; y_t_new = (x_t - x1)*sin(dAngle) + (y_t - y1)*cos(dAngle) + y1;
  3252 +
  3253 +
  3254 + x_rr_1 = x_l_new; y_rr_1 = y_t_new;
  3255 + x_rr_2 = x_r_new; y_rr_2 = y_t_new;
  3256 + x_rr_3 = x_r_new; y_rr_3 = y1;
  3257 + x_rr_4 = x_l_new; y_rr_4 = y1;
  3258 +
  3259 + double x_rect_1, y_rect_1, x_rect_2, y_rect_2, x_rect_3, y_rect_3, x_rect_4, y_rect_4;
  3260 +
  3261 + dAngle = -dAngle;
  3262 +
  3263 + x_rect_1 = (x_rr_1 - x1)*cos(dAngle) - (y_rr_1 - y1)*sin(dAngle) + x1; y_rect_1 = (x_rr_1 - x1)*sin(dAngle) + (y_rr_1 - y1)*cos(dAngle) + y1;
  3264 + x_rect_2 = (x_rr_2 - x1)*cos(dAngle) - (y_rr_2 - y1)*sin(dAngle) + x1; y_rect_2 = (x_rr_2 - x1)*sin(dAngle) + (y_rr_2 - y1)*cos(dAngle) + y1;
  3265 + x_rect_3 = (x_rr_3 - x1)*cos(dAngle) - (y_rr_3 - y1)*sin(dAngle) + x1; y_rect_3 = (x_rr_3 - x1)*sin(dAngle) + (y_rr_3 - y1)*cos(dAngle) + y1;
  3266 + x_rect_4 = (x_rr_4 - x1)*cos(dAngle) - (y_rr_4 - y1)*sin(dAngle) + x1; y_rect_4 = (x_rr_4 - x1)*sin(dAngle) + (y_rr_4 - y1)*cos(dAngle) + y1;
  3267 +
  3268 + x01 = x_rect_1; y01 = y_rect_1;
  3269 + x02 = x_rect_2; y02 = y_rect_2;
  3270 + x03 = x_rect_3; y03 = y_rect_3;
  3271 + x04 = x_rect_4; y04 = y_rect_4;
  3272 +
  3273 +
  3274 +
  3275 +
  3276 + return true;
  3277 +}
  3278 +
  3279 +}
  3280 +
  3281 +
  3282 +
  3283 +
  3284 +
  3285 +
  3286 +
  3287 +
  3288 +
  3289 +
  3290 +
  3291 +
  3292 +
  3293 +
  3294 +
  3295 +
  3296 +
  3297 +
  3298 +
  3299 +
  3300 +
  3301 +
  3302 +
  3303 +
  3304 +
  3305 +
  3306 +
  3307 +
  3308 +
  3309 +
  3310 +
  3311 +
  3312 +
  3313 +
  3314 +
  3315 +
  3316 +
  3317 +
  3318 +
  3319 +
  3320 +
  3321 +
  3322 +
  3323 +
  3324 +
  3325 +
  3326 +
  3327 +
  3328 +
  3329 +
  3330 +
  3331 +
  3332 +
  3333 +
  3334 +
  3335 +
  3336 +
  3337 +
  3338 +
  3339 +
  3340 +
  3341 +
  3342 +
  3343 +
  3344 +
  3345 +
  3346 +
  3347 +
  3348 +
  3349 +
  3350 +
  3351 +
  3352 +
  3353 +
  3354 +
  3355 +
  3356 +
  3357 +
  3358 +
  3359 +
  3360 +
  3361 +
  3362 +
  3363 +
  3364 +
  3365 +
  3366 +
  3367 +
  3368 +
  3369 +
  3370 +
  3371 +
  3372 +
  3373 +
  3374 +
  3375 +
  3376 +
  3377 +
  3378 +
  3379 +
  3380 +//
  3381 +//#include "SimpleLabelRenderer.h"
  3382 +//#include"TextSymbol.h"
  3383 +//#include"clsXML.h"
  3384 +//#include"DataCollection.h"
  3385 +//#include"clsStruct.h"
  3386 +//#include"clsCrSurf.h"
  3387 +//#include"clsMalloc.h"
  3388 +//#include"clsUtil.h"
  3389 +//#include"StringHelp.h"
  3390 +//
  3391 +//
  3392 +//#define dotX 5
  3393 +//#define dotY 5
  3394 +//
  3395 +//
  3396 +//SimpleLabelRenderer::SimpleLabelRenderer()
  3397 +//{
  3398 +// m_sField = "";
  3399 +// m_pTextSymbol = new TextSymbol();
  3400 +// m_sLabelPriorities = "2,2,1,4,5,3,2,4";
  3401 +// this->SetPriority();
  3402 +// m_iFeatureWeight=0;
  3403 +// m_iLabelWeight = 0;
  3404 +// m_iHowmanyLabels = 0;
  3405 +// m_dLabelBufferRatio = 0;
  3406 +// m_iLineLabelPosition = 0;
  3407 +// m_sRotationlAngles = "0";
  3408 +//}
  3409 +//
  3410 +//
  3411 +//SimpleLabelRenderer::~SimpleLabelRenderer()
  3412 +//{
  3413 +// if (m_pTextSymbol)
  3414 +// m_pTextSymbol->Release();
  3415 +//}
  3416 +//int SimpleLabelRenderer::RendererType()
  3417 +//{
  3418 +// return dmapSimpleLabelRenderer;
  3419 +//}
  3420 +//bool SimpleLabelRenderer::Parse(rapidxml::xml_pt<char>* pt, AppendBuffer *f)
  3421 +//{
  3422 +// if (!pt&&!f)return false;
  3423 +// clsXML clsX(f, "SIMPLELABELRENDERER");
  3424 +// clsXML::XMLAttrParse(pt, f, &m_sField, "field");
  3425 +// clsXML::XMLAttrParse(pt, f, &m_sLabelPriorities, "labelpriorities");
  3426 +// if (pt)
  3427 +// {
  3428 +// this->SetPriority();
  3429 +// }
  3430 +// clsX.closeProperties();
  3431 +// if (pt)
  3432 +// {
  3433 +// m_pTextSymbol->Parse(pt->first_pt(), NULL);
  3434 +// }
  3435 +// else
  3436 +// {
  3437 +// m_pTextSymbol->Parse(NULL, f);
  3438 +// }
  3439 +// //m_pTextSymbol->Parse(pt->first_pt(), f);
  3440 +// /*Renderer* pp = m_pTextSymbol;
  3441 +// if (pt)
  3442 +// {
  3443 +// clsXML::XMLParse(pt->first_pt(), NULL, &pp);
  3444 +// m_pTextSymbol = (TextSymbol*)pp;
  3445 +// }
  3446 +// else
  3447 +// clsXML::XMLParse(NULL, f, &pp);*/
  3448 +// return true;
  3449 +//}
  3450 +//
  3451 +//
  3452 +//
  3453 +//SimpleLabelRenderer* SimpleLabelRenderer::CreateNew()
  3454 +//{
  3455 +// SimpleLabelRenderer* dest = new SimpleLabelRenderer();
  3456 +// return dest;
  3457 +//}
  3458 +//const char* SimpleLabelRenderer::GetField()
  3459 +//{
  3460 +// return m_sField.c_str();
  3461 +//}
  3462 +//bool SimpleLabelRenderer::SetField(const char* sField)
  3463 +//{
  3464 +// m_sField = sField;
  3465 +// return true;
  3466 +//}
  3467 +//const char* SimpleLabelRenderer::GetLabelPriorities()
  3468 +//{
  3469 +// return m_sLabelPriorities.c_str();
  3470 +//}
  3471 +//bool SimpleLabelRenderer::SetLabelPriorities(const char* sLabelPriorities)
  3472 +//{
  3473 +// bool flag = this->TrackPriorityString(sLabelPriorities);
  3474 +// if (!flag)
  3475 +// return false;
  3476 +// m_sLabelPriorities = sLabelPriorities;
  3477 +// this->SetPriority();
  3478 +// return true;
  3479 +//}
  3480 +//TextSymbol* SimpleLabelRenderer::GetTextSymbol()
  3481 +//{
  3482 +// if (m_pTextSymbol)
  3483 +// m_pTextSymbol->AddRef();
  3484 +// return m_pTextSymbol;
  3485 +//}
  3486 +//bool SimpleLabelRenderer::SetTextSymbol(TextSymbol* ts)
  3487 +//{
  3488 +// if (!ts)
  3489 +// return false;
  3490 +// ts->AddRef();
  3491 +// if (m_pTextSymbol)
  3492 +// m_pTextSymbol->Release();
  3493 +// m_pTextSymbol = ts;
  3494 +// return true;
  3495 +//}
  3496 +//int SimpleLabelRenderer::GetFeatureWeight()
  3497 +//{
  3498 +// return m_iFeatureWeight;
  3499 +//}
  3500 +//bool SimpleLabelRenderer::SetFeatureWeight(int iFeatureWeight)
  3501 +//{
  3502 +// m_iFeatureWeight = iFeatureWeight;
  3503 +// return true;
  3504 +//}
  3505 +//int SimpleLabelRenderer::GetLabelWeight()
  3506 +//{
  3507 +// return m_iLabelWeight;
  3508 +//}
  3509 +//bool SimpleLabelRenderer::SetLabelWeight(int iLabelWeight)
  3510 +//{
  3511 +// m_iLabelWeight = iLabelWeight;
  3512 +// return true;
  3513 +//}
  3514 +//int SimpleLabelRenderer::GetHowmanyLabels()
  3515 +//{
  3516 +// return m_iHowmanyLabels;
  3517 +//}
  3518 +//bool SimpleLabelRenderer::SetHowmanyLabels(int iHowmanyLabels)
  3519 +//{
  3520 +// m_iHowmanyLabels = iHowmanyLabels;
  3521 +// return true;
  3522 +//}
  3523 +//double SimpleLabelRenderer::GetLabelBufferRatio()
  3524 +//{
  3525 +// return m_dLabelBufferRatio;
  3526 +//}
  3527 +//bool SimpleLabelRenderer::SetLabelBufferRatio(double dLabelBufferRatio)
  3528 +//{
  3529 +// m_dLabelBufferRatio = dLabelBufferRatio;
  3530 +// return true;
  3531 +//}
  3532 +//int SimpleLabelRenderer::GetLineLabelPosition()
  3533 +//{
  3534 +// return m_iLineLabelPosition;
  3535 +//}
  3536 +//bool SimpleLabelRenderer::SetLineLabelPosition(int iLineLabelPosition)
  3537 +//{
  3538 +// m_iLineLabelPosition = iLineLabelPosition;
  3539 +// return true;
  3540 +//}
  3541 +//const char* SimpleLabelRenderer::GetRotationalAngles()
  3542 +//{
  3543 +// return m_sRotationlAngles.c_str();
  3544 +//}
  3545 +//bool SimpleLabelRenderer::SetRotationalAngles(const char* sRotationalAngles)
  3546 +//{
  3547 +// m_sRotationlAngles = sRotationalAngles;
  3548 +// return true;
  3549 +//}
  3550 +//
  3551 +//
  3552 +//
  3553 +//
  3554 +///*
  3555 +//检查该字符串是否符合格式要求
  3556 +//格式为: "1,2,3,4,5,6,7,8"
  3557 +//8个数字用逗号或其他一字节符号隔开
  3558 +//*/
  3559 +//bool SimpleLabelRenderer::TrackPriorityString(const char* sPriority)
  3560 +//{
  3561 +// int len = strlen(sPriority);
  3562 +// if (len != 15)
  3563 +// return false;
  3564 +// for (int i = 0; i < 8; i++)
  3565 +// {
  3566 +// char c = sPriority[2 * i];
  3567 +// if (c>'9' || c < '0')
  3568 +// return false;
  3569 +// }
  3570 +// return true;
  3571 +//}
  3572 +//
  3573 +///*
  3574 +//处理传入的字符串,转化为8个数的数组,这8个数表示8个标签位的优先级
  3575 +//然后进一步处理,确定8个标签位先后出现的顺序,保存在 m_i8中
  3576 +//
  3577 +//比如 2 2 1 4 5 3 2 4
  3578 +//1 2 3 4 5 6 7 8
  3579 +//排序后 3 1 2 7 6 4 8 5
  3580 +//*/
  3581 +//bool SimpleLabelRenderer::SetPriority()
  3582 +//{
  3583 +// const char* ss = m_sLabelPriorities.c_str();
  3584 +//
  3585 +// int num[8]; // 这是从字符串接收来的8个数字
  3586 +//
  3587 +// for (int i = 0; i < 8; i++)
  3588 +// {
  3589 +// num[i] = ss[2 * i];
  3590 +// if (num[i] == 0)
  3591 +// num[i] = 9; //将0 暂时作为9处理
  3592 +// m_i8[i] = i;
  3593 +// }
  3594 +//
  3595 +// int temp;
  3596 +// for (int i = 0; i < 7; i++)
  3597 +// {
  3598 +// for (int j = 0; j < 7 - i; j++)
  3599 +// {
  3600 +// if (num[j] > num[j + 1])
  3601 +// {
  3602 +// temp = num[j]; num[j] = num[j + 1]; num[j + 1] = temp;
  3603 +// temp = m_i8[j]; m_i8[j] = m_i8[j + 1]; m_i8[j + 1] = temp;
  3604 +// }
  3605 +// }
  3606 +// }
  3607 +// return true;
  3608 +//}
  3609 +//
  3610 +//bool SimpleLabelRenderer::DrawData(clsCrSurf* pClsCS, DataCollection* data, char* pFlag)
  3611 +//{
  3612 +// int iPartCount = data->m_iPartCount;
  3613 +// cairo_surface_t* surface = pClsCS->m_pSurf;
  3614 +// double surf_w = cairo_image_surface_get_width(surface);
  3615 +// double surf_h = cairo_image_surface_get_height(surface);
  3616 +//
  3617 +// m_lpt = this->GetLabelPositionType();
  3618 +//
  3619 +// for (int i = 0; i < iPartCount; i++)
  3620 +// this->DrawStruct(pClsCS, data, i, pFlag, (int)(surf_w), (int)(surf_h));
  3621 +// return true;
  3622 +//}
  3623 +//void SimpleLabelRenderer::TryAddField(vector<string>&pvField)
  3624 +//{
  3625 +// vector<string>::iterator it = find(pvField->begin(), pvField->end(), m_sField);
  3626 +// if (it == pvField->end())
  3627 +// pvField->push_back(m_sField);
  3628 +//}
  3629 +////这个地方还是有些不好处理,需要额外传递字符串进来
  3630 +//bool SimpleLabelRenderer::DrawStruct(clsCrSurf* pClsCS, DataCollection* data, int index, char* pFlag, int dcW, int dcH)
  3631 +//{
  3632 +// int fieldCount = (int)(data->m_vFieldName.size());
  3633 +// int fieldID = -1;
  3634 +// for (int i = 0; i < fieldCount; i++)
  3635 +// {
  3636 +// if (m_sField == data->m_vFieldName[i])
  3637 +// {
  3638 +// fieldID = i;
  3639 +// break;
  3640 +// }
  3641 +// }
  3642 +// if (fieldID == -1)
  3643 +// return false;
  3644 +// string sText = data->m_vAllField[index][fieldID];
  3645 +//
  3646 +// double x = 0, y = 0;// 这是几何图形的中心点,绘制文本在此基础上偏移
  3647 +// int structType = data->m_iStructType;
  3648 +// switch (structType)
  3649 +// {
  3650 +// case clsStruct::Struct_Point:{clsStruct::POINT* pPoint = (clsStruct::POINT*)(data->m_pData); x = (pPoint + index)->x; y = (pPoint + index)->y; break; }
  3651 +// case clsStruct::Struct_Line:{clsStruct::LINE* pLine = (clsStruct::LINE*)(data->m_pData); clsStruct::GetCenter(x, y, pLine + index); break; }
  3652 +// case clsStruct::Struct_MLine:{clsStruct::MLINE* pMLine = (clsStruct::MLINE*)(data->m_pData); clsStruct::GetCenter(x, y, pMLine + index); break; }
  3653 +// case clsStruct::Struct_Polygon:{clsStruct::POLYGON* pPolygon = (clsStruct::POLYGON*)(data->m_pData); clsStruct::GetCenter(x, y, pPolygon + index); break; }
  3654 +// case clsStruct::Struct_MPolygon:{clsStruct::MPOLYGON* pMPolygon = (clsStruct::MPOLYGON*)(data->m_pData); clsStruct::GetCenter(x, y, pMPolygon + index); break; }
  3655 +// default:
  3656 +// break;
  3657 +// }
  3658 +//
  3659 +// /*
  3660 +// 开始绘制文本
  3661 +// */
  3662 +// const char* text_gbk = sText.c_str();
  3663 +// int lenout = strlen(text_gbk) * 3 / 2 + 100;
  3664 +// clsMalloc m(lenout);
  3665 +// char * utf8 = m.mem;
  3666 +// memset(utf8, 0, lenout);
  3667 +// clsUtil::ConvertEnc("GBK", "UTF-8", text_gbk, utf8, lenout);
  3668 +//
  3669 +// m_pTextSymbol->SetCairo(pClsCS);
  3670 +//
  3671 +// cairo_t* cr = pClsCS->m_pCr;
  3672 +// cairo_text_extents_t extents;
  3673 +// cairo_text_extents(cr, utf8, &extents);
  3674 +// double width_text = extents.width, height_text = extents.height;
  3675 +// int textW = (int)width_text;
  3676 +// int textH = (int)height_text;
  3677 +//
  3678 +// //strcpy(utf8, text_gbk);
  3679 +// for (int i = 0; i < 8; i++)
  3680 +// {
  3681 +// bool flag = false;
  3682 +// switch (m_i8[i])
  3683 +// {
  3684 +// case 1:{if (m_pTextSymbol->DrawAText(pClsCS, x - dotX - textW, y - dotY, utf8, textW, textH, pFlag, dcW, dcH)) flag = true; break; }
  3685 +// case 2:{if (m_pTextSymbol->DrawAText(pClsCS, x - textW / 2, y - dotY, utf8, textW, textH, pFlag, dcW, dcH)) flag = true; break; }
  3686 +// case 3:{if (m_pTextSymbol->DrawAText(pClsCS, x + dotX, y - dotY, utf8, textW, textH, pFlag, dcW, dcH)) flag = true; break; }
  3687 +// case 4:{if (m_pTextSymbol->DrawAText(pClsCS, x + dotX, y + textH / 2, utf8, textW, textH, pFlag, dcW, dcH)) flag = true; break; }
  3688 +// case 5:{if (m_pTextSymbol->DrawAText(pClsCS, x + dotX, y + dotY + textH, utf8, textW, textH, pFlag, dcW, dcH)) flag = true; break; }
  3689 +// case 6:{if (m_pTextSymbol->DrawAText(pClsCS, x - textW / 2, y + dotY + textH, utf8, textW, textH, pFlag, dcW, dcH)) flag = true; break; }
  3690 +// case 7:{if (m_pTextSymbol->DrawAText(pClsCS, x - dotX - textW, y + dotY + textH, utf8, textW, textH, pFlag, dcW, dcH)) flag = true; break; }
  3691 +// case 8:{if (m_pTextSymbol->DrawAText(pClsCS, x - dotX - textW, y + textH / 2, utf8, textW, textH, pFlag, dcW, dcH)) flag = true; break; }
  3692 +// default:break;
  3693 +// }
  3694 +// if (flag)
  3695 +// break;
  3696 +// }
  3697 +// return true;
  3698 +//}
  3699 +//
  3700 +//
  3701 +//bool SimpleLabelRenderer::DrawPOINT(clsCrSurf* pClsCS, clsStruct::POINT* pPoint, const char* sUTF8)
  3702 +//{
  3703 +// /*
  3704 +// 转字符集
  3705 +// */
  3706 +// ///////////////////////////////////////////////////////////////////////////////////////////////////
  3707 +// /*int lenout = strlen(text_gbk) * 3 / 2 + 100;
  3708 +// clsMalloc m(lenout);
  3709 +// char * utf8 = m.mem;
  3710 +// memset(utf8, 0, lenout);
  3711 +// clsUtil::ConvertEnc("GBK", "UTF-8", text_gbk, utf8, lenout);*/
  3712 +// ///////////////////////////////////////////////////////////////////////////////////////////////////
  3713 +//
  3714 +// m_pTextSymbol->SetCairo(pClsCS);
  3715 +//
  3716 +//
  3717 +// /*
  3718 +// 获取文本宽高
  3719 +// */
  3720 +// ///////////////////////////////////////////////////////////////////////////////////////////////////
  3721 +// cairo_t* cr = pClsCS->m_pCr;
  3722 +// cairo_text_extents_t extents; //这个对象重复构造?!!
  3723 +// cairo_text_extents(cr, sUTF8, &extents);
  3724 +// double width_text = extents.width, height_text = extents.height;
  3725 +// int textW = (int)width_text;
  3726 +// int textH = (int)height_text;
  3727 +// /////////////////////////////////////////////////////////////////////////////////////////////////////
  3728 +//
  3729 +//
  3730 +// double x = pPoint->x;
  3731 +// double y = pPoint->y;
  3732 +// /*
  3733 +// 四种位置
  3734 +// */
  3735 +// switch (m_lpt)
  3736 +// {
  3737 +// case SimpleLabelRenderer::dmapLabelPositionOnTopHorizontal:
  3738 +// {
  3739 +// x = x - textW/2.0;
  3740 +// y = y + textH / 2.0;
  3741 +// this->DrawAText(pClsCS, x, y, 0, sUTF8);
  3742 +// }
  3743 +// break;
  3744 +// case SimpleLabelRenderer::dmapLabelPositionAngleNumber:
  3745 +// {
  3746 +// int length = (int)(m_vdAngles.size());
  3747 +// bool flag = false;
  3748 +// for (int i = 0; i < length; i++)
  3749 +// {
  3750 +// double dAngle = m_vdAngles[i];
  3751 +// flag = this->DrawAText(pClsCS, x, y, dAngle, sUTF8);
  3752 +// if (flag)
  3753 +// break;
  3754 +// }
  3755 +// }
  3756 +// break;
  3757 +// case SimpleLabelRenderer::dmapLabelPositionAngleField:
  3758 +// {
  3759 +// //额外查询一次数据库
  3760 +//
  3761 +// }
  3762 +// break;
  3763 +// case SimpleLabelRenderer::dmapLabelPositionPeriphery:
  3764 +// {
  3765 +//
  3766 +// }
  3767 +// break;
  3768 +// default:
  3769 +// break;
  3770 +// }
  3771 +// return true;
  3772 +//}
  3773 +//bool SimpleLabelRenderer::DrawMPOINT(clsCrSurf* clsCr, clsStruct::LINE* pLine)
  3774 +//{
  3775 +// return true;
  3776 +//}
  3777 +//bool SimpleLabelRenderer::DrawAText(clsCrSurf* clsCS, double x, double y, double dAngle, const char* sUTF8)
  3778 +//{
  3779 +//
  3780 +//
  3781 +//
  3782 +// return true;
  3783 +//}
  3784 +//
  3785 +//bool SimpleLabelRenderer::TrackRotationalAngles(const char* sRotationalAngles)
  3786 +//{
  3787 +// char sAngleBackup[200];
  3788 +// memset(sAngleBackup, 0, 200);
  3789 +// int len = strlen(sRotationalAngles);
  3790 +// memcpy(sAngleBackup, sRotationalAngles, len);
  3791 +// char * ss[10];
  3792 +// StringHelp::ParseStringTok(sAngleBackup, ',', ss, 10);
  3793 +//
  3794 +// return true;
  3795 +//}
  3796 +//
  3797 +//SimpleLabelRenderer::LabelPositionType SimpleLabelRenderer::GetLabelPositionType()
  3798 +//{
  3799 +// if (m_sLabelPriorities == "LE_PlaceOnTopHorizontal")
  3800 +// return dmapLabelPositionOnTopHorizontal;
  3801 +// if (m_sLabelPriorities == "0,0,0,0,0,0,0,0")
  3802 +// {
  3803 +// if (m_sRotationlAngles != "")
  3804 +// {
  3805 +// //const char* ss = m_sRotationlAngles.c_str();
  3806 +// bool bTrackOK = this->TrackRotationalAngles(m_sRotationlAngles.c_str());
  3807 +// if (bTrackOK)
  3808 +// return dmapLabelPositionAngleNumber;
  3809 +// return dmapLabelPositionAngleField;
  3810 +// }
  3811 +// }
  3812 +// return dmapLabelPositionPeriphery;
  3813 +//}
  3814 +//
  3815 +//bool SimpleLabelRenderer::CalculateAngles()
  3816 +//{
  3817 +// const char* sAngles = m_sRotationlAngles.c_str();
  3818 +// char sAngleBackup[200];
  3819 +// memset(sAngleBackup, 0, 200);
  3820 +// int len = strlen(sAngles);
  3821 +// memcpy(sAngleBackup, sAngles, len);
  3822 +// char * ss[10];
  3823 +// int count = StringHelp::ParseStringTok(sAngleBackup, ',', ss, 10);
  3824 +// for (int i = 0; i < count; i++)
  3825 +// {
  3826 +// m_vdAngles[i] = stod(ss[i], NULL);
  3827 +// }
  3828 +//
  3829 +// return true;
  3830 +//}
... ...
  1 +#pragma once
  2 +#ifndef _SimpleLabelRenderer_H_
  3 +#define _SimpleLabelRenderer_H_
  4 +#include<string>
  5 +#include<vector>
  6 +using namespace std;
  7 +#include"Renderer.h"
  8 +#include"TextSymbol.h"
  9 +#include"clsStruct.h"
  10 +#define LLPSZ 10 //dmapLineLabelPosition__Size
  11 +
  12 +namespace DmapCore_30
  13 +{
  14 + class CORE_EXPORT SimpleLabelRenderer :public Renderer
  15 + {
  16 + public:
  17 + SimpleLabelRenderer();
  18 + ~SimpleLabelRenderer();
  19 + int RendererType();
  20 + virtual bool Parse(boost::property_tree::ptree &pt, AppendBuffer *f);
  21 + virtual void ToJson(AppendBuffer *ab);
  22 + //virtual bool RendererString(Renderer** ppRen, const char** psXML);
  23 + virtual bool DrawData(clsCrSurf* pClsCS, DataCollection* data, bool drawSimpleData, char* pFlag = NULL);
  24 + virtual bool DrawData(clsCrSurf* pClsCS, DataCollection* data, int dataIndex, char* pFlag = NULL);
  25 + virtual bool DrawLegend(clsCrSurf* pClsCS, shared_ptr<legendParamater> pLegendParamater,int layerType, char* pFlag= NULL);
  26 + string m_sField;
  27 + TextSymbol* m_pTextSymbol;
  28 +
  29 +
  30 + string m_sLabelPriorities;
  31 + string m_sRotationAngles;
  32 + //int m_iRotateMethod;
  33 + string m_sRotationAngleField;
  34 + bool m_bIsVerticalToAngle;
  35 +
  36 + /*
  37 + LineLabelPosition分成3属性
  38 + */
  39 + int m_iLineLabelPositionDirection;
  40 + int m_iLineLabelPositionStartOrEnd;
  41 + string m_sLineLabelPositionPlaces;
  42 + int m_LineLabelPositionPlaces[3];
  43 +
  44 +
  45 + int m_iPolygonLabelPositionDirection;
  46 + bool m_bLabelInPolygon;
  47 +
  48 +
  49 +
  50 +
  51 + bool DoSetLineLabelPositionPlaces();
  52 +
  53 + void TryAddField(vector<string>&pvField);
  54 + bool TryFindHeatRenderer(){ return false; }
  55 +
  56 +
  57 +
  58 + static SimpleLabelRenderer* CreateNew();
  59 + const char* GetField();
  60 + bool SetField(const char* sField);
  61 + const char* GetLabelPriorities();
  62 + bool SetLabelPriorities(const char* sLableLabelPriorities);
  63 + TextSymbol* GetTextSymbol();
  64 + bool SetTextSymbol(TextSymbol* ts);
  65 + const char* GetRotationAngles();
  66 + bool SetRotationAngles(const char* sRotationalAngles);
  67 + const char*GetRotationAngleField();
  68 + bool SetRotationAngleField(const char* sAngleField);
  69 + //int GetRotateMethod(); //只对点有效
  70 + //bool SetRotateMethod(int iRotateMethod);
  71 + int GetLineLabelPositionDirection();
  72 + bool SetLineLabelPositionDirection(int iLineLabelPositionDirection);
  73 + const char*GetLineLabelPositionPlace();
  74 + bool SetLineLabelPositionPlace(const char* iLineLabelPositionPlace);
  75 + int GetLineLabelPositionStartOrEnd();
  76 + bool SetLineLabelPositionStartOrEnd(int iLineLabelPositionStartOrEnd);
  77 + int GetPolygonLabelPositionDirection();
  78 + bool SetPolygonLabelPositionDirection(int iPolygonLabelPositionDirection);
  79 + bool GetLabelInPolygon();
  80 + bool SetLabelInPolygon(bool bLabelInPolygon);
  81 + bool GetIsVerticalToAngle();
  82 + bool SetIsVerticalToAngle(bool bIsVerticalToAngle);
  83 +
  84 +
  85 +
  86 + private:
  87 +
  88 + /*
  89 + 点样式类型使用规定
  90 + 1.优先使用 m_sLabelPriorities , m_sLabelPriorities 可以赋值3种,第一种,确定各标签位优先级的8个数字,第二种,使用 DMap_PlaceOnTopHorizontal, 在点之上
  91 + 第三种,使用8个0,则使用旋转角度书写文本
  92 + 2. 优先使用AngleField,但每次设置旋转角度时,将AngleField重置为""
  93 + 3. 使用旋转角度
  94 + */
  95 + enum PointLabelPositionType
  96 + {
  97 + dmapPointLabelPositionOnTopHorizontal = 0,
  98 + dmapPointLabelPositionAngleNumber = 1,
  99 + dmapPointLabelPositionAngleField = 2,
  100 + dmapPointLabelPositionPeriphery = 3,
  101 + dmapPointLabelPositionError,
  102 + };
  103 + PointLabelPositionType m_plpt;
  104 + SimpleLabelRenderer::PointLabelPositionType DoSetPointLabelPositionType(); //每次调用此函数,维护位置的类型 m_lpt
  105 +
  106 +
  107 +
  108 + private:
  109 +
  110 + vector<double> m_vdAngles;
  111 + int m_i8[8]; //
  112 +
  113 +
  114 + bool CalculatePrioritiesNumber(); //处理 字符串,按8个标签的优先级排序1-8
  115 + bool CalculateAngles(); //处理 m_sRotationalAngles,存到 m_dAngles
  116 + bool TrackPriorityString(const char* sPriority); //判断 m_sPriorities 字符串是否是8个数字
  117 + bool TrackRotationAngles(const char* sRotationalAngles);
  118 +
  119 +
  120 +
  121 +
  122 +
  123 + /*
  124 + Draw部分
  125 + */
  126 + public:
  127 + bool DrawStruct(clsCrSurf* pClsCS, DataCollection* data, int index);
  128 +
  129 + /*
  130 + Point
  131 + */
  132 + bool DrawPoint(clsCrSurf* pClsCS, DataCollection* data, int index, char* sUTF8);
  133 +
  134 + /*
  135 + MLine
  136 + */
  137 + bool DrawMLine(clsCrSurf* pClsCS, clsStruct::MLINE* pStrMLine, char* sUTF8);
  138 + bool DrawMLineLevel(clsCrSurf* pClsCS, clsStruct::MLINE* pStrMLine, char* sUTF8); //水平放置
  139 + bool DrawMLineParallel(clsCrSurf* pClsCS, clsStruct::MLINE* pStrMLine, char* sUTF8); //平行放置
  140 + bool DrawMLineCurve(clsCrSurf* pClsCS, clsStruct::MLINE* pStrMLine, char* sUTF8); //弯曲
  141 + bool DrawMLineVertical(clsCrSurf* pClsCS, clsStruct::MLINE* pStrMLine, char* sUTF8); //垂直
  142 +
  143 + double CalculateRadianRight(clsStruct::LINE* pStrLine, double dTextWidth, int iIndex, double x, double y, double&x_show, double&y_show);
  144 + double CalculateRadianLeft(clsStruct::LINE* pStrLine, double dTextWidth, int iIndex, double x, double y, double&x_show, double& y_show);
  145 +
  146 + bool DrawMLineCurve2(clsCrSurf* pClsCS, clsStruct::MLINE* pStrMLine, char* sUTF8); //弯曲
  147 + double CalculateRadianRight2(clsStruct::LINE* pStrLine, double dTextWidth, int& iIndex, double x_show, double y_show, double &x_show_next, double&y_show_next);
  148 + double CalculateRadianLeft2(clsStruct::LINE* pStrLine, double dTextWidth, int& iIndex, double x_show, double y_show, double&x_show_next, double&y_show_next);
  149 + void CalculateIntersection(double dWidth, double x_from, double y_from, double x1, double y1, double x2, double y2, double&x_to, double&y_to);
  150 +
  151 + bool DrawMLineCurve3(clsCrSurf* pClsCS, clsStruct::MLINE* pStrMLine, char* sUTF8);
  152 + // DrawMLineCurve4(clsCrSurf* pClsCS, clsStruct::MLINE* pStrMLine, char* sUTF8);
  153 + bool LineToSmooth(clsStruct::LINE* pStrLine, vector<double>& vX, vector<double>& vY); //线条平滑处理
  154 + bool Douglas_Peucker_algorithm(vector<double> &vX, vector<double>& vY);
  155 +
  156 + bool CalculateShowBegin(vector<double> vX, vector<double> vY, double dW, double& x_show_begin, double& y_show_begin, int & iPointIndex);
  157 + double CalculateRadianRight3(vector<double> vX, vector<double> vY, double dTextWidth, int& iIndex, double x_show, double y_show, double &x_show_next, double&y_show_next);
  158 +
  159 +
  160 + bool DrawMLineCurve4(clsCrSurf* pClsCS, clsStruct::MLINE* pStrMLine, char* sUTF8);
  161 + bool DrawMLineCurve5(clsCrSurf* pClsCS, clsStruct::MLINE* pStrMLine, char* sUTF8);
  162 +
  163 + double CalculateDistance(double x0, double y0, double x1, double y1, double x2, double y2);
  164 + bool CalculateShowBegin(clsStruct::LINE* pLine, double dW, double& x_show_begin, double& y_show_begin, int & iPointIndex);
  165 + bool CalculateShowBegin5(clsStruct::LINE* pLine, double dW, double& x_show_begin, double& y_show_begin, int & iPointIndex, double& dRadia, int width, int height);
  166 + double CalculateRadianRight4(clsStruct::LINE* pLine, double dTextWidth, int & iIndex, double x_show, double y_show, double &x_show_next, double& y_show_next);
  167 + int SplitUTF8(char* sUTF8, string* pStr, int iStrCount);
  168 +
  169 +
  170 +
  171 +
  172 + bool DrawMPolygon(clsCrSurf* pClsCS, clsStruct::MPOLYGON* pStrMPolygon, char* sUTF8);
  173 + bool DrawMPolygonParallel(clsCrSurf* pClsCS, clsStruct::MPOLYGON* pStrMPolygon, char* sUTF8); //平行放置
  174 + bool DrawMPolygonStraight(clsCrSurf* pClsCS, clsStruct::MPOLYGON* pStrMPolygon, char* sUTF8); //平直
  175 + bool DrawMPolygonParallelAndStraight(clsCrSurf* pClsCS, clsStruct::MPOLYGON* pStrMPolygon, char* sUTF8); // 先水平,其次平直
  176 +
  177 +
  178 + bool OBB_Algorithm(std::vector<double> vX, std::vector<double> vY, double& x1, double& y1, double& x2, double& y2, double& x3, double& y3, double& x4, double& y4, clsCrSurf* pClsCS);
  179 + double OBB_GetMBR(std::vector<double> vX, std::vector<double> vY, int i, clsCrSurf* pClsCS);
  180 + bool OBB_GetMBR(std::vector<double> vX, std::vector<double> vY, int iPointIndex, double& x1, double& y1, double& x2, double& y2, double& x3, double& y3, double& x4, double& y4, clsCrSurf* pClsCS);
  181 +
  182 +
  183 +
  184 + };
  185 +
  186 +
  187 +
  188 +}
  189 +#endif
  190 +
  191 +
  192 +
  193 +
  194 +
  195 +
  196 +
  197 +
  198 +
  199 +
  200 +
  201 +
  202 +
  203 +
  204 +
  205 +
  206 +
  207 +
  208 +
  209 +
  210 +
  211 +
  212 +
  213 +
  214 +
  215 +
  216 +
  217 +
  218 +
  219 +
  220 +
  221 +
  222 +
  223 +
  224 +
  225 +
  226 +
  227 +
  228 +
  229 +
  230 +
  231 +
  232 +
  233 +
  234 +
  235 +
  236 +
  237 +
  238 +
  239 +
  240 +
  241 +
  242 +
  243 +
  244 +
  245 +
  246 +
  247 +
  248 +
  249 +
  250 +
  251 +
  252 +
  253 +
  254 +
  255 +
  256 +
  257 +
  258 +
  259 +
  260 +
  261 +
  262 +
  263 +
  264 +
  265 +
  266 +
  267 +
  268 +
  269 +
  270 +
  271 +
  272 +
  273 +
  274 +
  275 +
  276 +
  277 +
  278 +
  279 +
  280 +
  281 +
  282 +
  283 +
  284 +
  285 +
  286 +
  287 +
  288 +
  289 +
  290 +
  291 +
  292 +
  293 +
  294 +
  295 +
  296 +
  297 +
  298 +
  299 +
  300 +
  301 +
  302 +
  303 +
  304 +
  305 +
  306 +
  307 +
  308 +
  309 +
  310 +
  311 +
  312 +
  313 +
  314 +
  315 +
  316 +
  317 +
  318 +
  319 +
  320 +
  321 +
  322 +
  323 +
  324 +
  325 +
  326 +
  327 +
  328 +
  329 +
  330 +
  331 +
  332 +
  333 +
  334 +
  335 +
  336 +
  337 +
  338 +
  339 +
  340 +
  341 +
  342 +
  343 +
  344 +
  345 +
  346 +
  347 +
  348 +
  349 +
  350 +
  351 +
  352 +
  353 +
  354 +
  355 +
  356 +
  357 +
  358 +
  359 +
  360 +
  361 +
  362 +
  363 +
  364 +
  365 +
  366 +
  367 +//#pragma once
  368 +//#include<string>
  369 +//using namespace std;
  370 +//#include"Renderer.h"
  371 +//#include"clsStruct.h"
  372 +//class TextSymbol;
  373 +//class clsCrSurf;
  374 +//class DataCollection;
  375 +//class SimpleLabelRenderer:public Renderer
  376 +//{
  377 +//public:
  378 +// SimpleLabelRenderer();
  379 +// ~SimpleLabelRenderer();
  380 +// int RendererType();
  381 +// virtual bool Parse(rapidxml::xml_node<char>* node, AppendBuffer *f);
  382 +// virtual bool DrawData(clsCrSurf* pClsCS, DataCollection* data, char* pFlag);
  383 +//
  384 +// string m_sField;
  385 +// string m_sLabelPriorities;
  386 +// TextSymbol* m_pTextSymbol;
  387 +// int m_iFeatureWeight;
  388 +// int m_iLabelWeight;
  389 +// int m_iHowmanyLabels;
  390 +// double m_dLabelBufferRatio;
  391 +// int m_iLineLabelPosition;
  392 +// string m_sRotationalAngles;
  393 +//
  394 +//
  395 +//
  396 +// static SimpleLabelRenderer* CreateNew();
  397 +// const char* GetField();
  398 +// bool SetField(const char* sField);
  399 +// const char* GetLabelPriorities();
  400 +// bool SetLabelPriorities(const char* sLableLabelPriorities);
  401 +// TextSymbol* GetTextSymbol();
  402 +// bool SetTextSymbol(TextSymbol* ts);
  403 +// int GetFeatureWeight();
  404 +// bool SetFeatureWeight(int iFeatureWeight);
  405 +// int GetLabelWeight();
  406 +// bool SetLabelWeight(int iLabelWeight);
  407 +// int GetHowmanyLabels();
  408 +// bool SetHowmanyLabels(int iHowmanyLabels);
  409 +// double GetLabelBufferRatio();
  410 +// bool SetLabelBufferRatio(double dLabelBufferRatio);
  411 +// int GetLineLabelPosition();
  412 +// bool SetLineLabelPosition(int iLineLabelPosition);
  413 +// const char* GetRotationalAngles();
  414 +// bool SetRotationalAngles(const char* sRotationalAngles);
  415 +//
  416 +//
  417 +// void TryAddField(vector<string>&pvField);
  418 +// bool DrawStruct(clsCrSurf* pClsCS, DataCollection* data, int index, char* pFlag, int dcW, int dcH);
  419 +//
  420 +//
  421 +// bool DrawPOINT(clsCrSurf* clsCS, clsStruct::POINT* pPoint, const char* sText);
  422 +// bool DrawMPOINT(clsCrSurf* clsCr, clsStruct::LINE* pLine);
  423 +//
  424 +// bool DrawAText(clsCrSurf* clsCS, double x, double y,double dAngle, const char* sUTF8);
  425 +//
  426 +//
  427 +// //bool DrawPOINT(clsCairo* clsCr, clsStruct::POINT* pPoint);
  428 +//
  429 +//private:
  430 +//
  431 +// /*
  432 +// 1. labelPriorities优先,只在 labelPriorities 为"0,0,0,0,0,0,0,0"时,考虑 rotationalangles 属性
  433 +// 2. labelPriorities 可以赋值为 "LE_PlaceOnTopHorizontal" ,在点之上放置,或者面内部,或者在线上
  434 +// 3. rotationalAngles可以被赋值为 "45,30,60" 或者"objectid"两种方式
  435 +// */
  436 +//
  437 +//
  438 +//
  439 +// bool TrackPriorityString(const char* sPriority);
  440 +// bool SetPriority();
  441 +// bool TrackRotationalAngles(const char* sRotationalAngles);
  442 +//
  443 +//
  444 +// /*
  445 +// 标签位置部分
  446 +// */
  447 +// static enum LabelPositionType
  448 +// {
  449 +// dmapLabelPositionOnTopHorizontal = 0, //在点上,或者面上
  450 +// dmapLabelPositionAngleNumber = 1, //使用数字弧度(固定值)
  451 +// dmapLabelPositionAngleField = 2, //使用指定字段作为弧度
  452 +// dmapLabelPositionPeriphery = 3, //使用周边的8个标签位 水平放置
  453 +// };
  454 +// LabelPositionType m_lpt;
  455 +// vector<double> m_vdAngles;
  456 +// int m_i8[8]; // 这是从LabelPriorities直接分割出来的数字
  457 +// int m_iLabelPriorities[8]; //这是经过处理后,依次优先的标签位置的顺序
  458 +//
  459 +// SimpleLabelRenderer::LabelPositionType GetLabelPositionType();
  460 +// bool CalculatePrioritiesNumber(); //处理 m_i8,得出 m_iLabelPriorities
  461 +// bool CalculateAngles(); //处理 m_sRotationalAngles,存到 m_dAngles
  462 +//
  463 +//
  464 +//
  465 +//
  466 +//
  467 +//};
  468 +//
... ...
  1 +
  2 +#include "SimpleLineSymbol.h"
  3 +#include "clsUtil.h"
  4 +#include"clsXML.h"
  5 +#include"clsCrSurf.h"
  6 +#include "clsJson.h"
  7 +#define _USE_MATH_DEFINES
  8 +#include<math.h>
  9 +namespace DmapCore_30
  10 +{
  11 +
  12 + SimpleLineSymbol::SimpleLineSymbol()
  13 + {
  14 + m_iAntialiasing = CAIRO_ANTIALIAS_DEFAULT;
  15 + m_iColor = clsUtil::RandomColor();
  16 + clsUtil::ToCairoColor(m_iColor, r, g, b, a);
  17 + //m_pClsSurfBackup = NULL;
  18 + m_iType = 0;
  19 + m_sPNG = "";
  20 + m_dWidth = 1;
  21 + m_iCapType = 0;
  22 + m_iJionType = 0;
  23 + m_sXML = "";
  24 + //png = 0;
  25 + m_mustReloadPng = true;
  26 + m_simpleRenderer = true;
  27 + }
  28 + SimpleLineSymbol::~SimpleLineSymbol()
  29 + {
  30 + //if (png)
  31 + //{
  32 + // delete png;
  33 + //}
  34 + }
  35 + SimpleLineSymbol* SimpleLineSymbol::CreateNew()
  36 + {
  37 + SimpleLineSymbol * dest = new SimpleLineSymbol();
  38 + return dest;
  39 + }
  40 + int SimpleLineSymbol::RendererType()
  41 + {
  42 + return dmapSimpleLineSymbol;
  43 + }
  44 +
  45 + bool SimpleLineSymbol::Parse(boost::property_tree::ptree &pt, AppendBuffer *f)
  46 + {
  47 + //if (!node&&!f)return false;
  48 + clsXML clsX(f, "SIMPLELINESYMBOL");
  49 + clsXML::ParseEnum("antialiasing", pt, f, &m_iAntialiasing, "antialias_default", "antialias_none", "antialias_gray", "antialias_subpixel", "antialias_fase", "antialias_good", "antialias_best", "true", "false");
  50 + clsXML::XMLAttrParse(pt, f, &m_sPNG, "png");
  51 + clsXML::ParseEnum("type", pt, f, &m_iType, "solid", "dash", "dot", "dash_dot", "dash_dot_dot");
  52 + clsXML::XMLAttrParseColor(pt, f, &m_iColor, "color", "transparency");
  53 + clsXML::XMLAttrParse(pt, f, &m_dWidth, "width");
  54 + clsXML::ParseEnum("captype", pt, f, &m_iCapType, "cap_butt", "cap_round", "cap_square");
  55 + clsXML::ParseEnum("jiontype", pt, f, &m_iJionType, "jion_miter", "jion_round", "jion_bevel");
  56 +
  57 + if (m_sPNG != "")
  58 + {
  59 + m_sPNG = GetFilePath(m_sPNG);
  60 + if (FILE *file = fopen(m_sPNG.c_str(), "r")) {
  61 + fclose(file);
  62 + }
  63 + else {
  64 + m_sPNG = "";
  65 + }
  66 + }
  67 + clsUtil::ToCairoColor(m_iColor, r, g, b, a);
  68 + m_mustReloadPng = true;
  69 + return true;
  70 + }
  71 +
  72 + void SimpleLineSymbol::ToJson(AppendBuffer *ab)
  73 + {
  74 + char buff[300] = {0};
  75 + char resultbuff[5000] = {0};
  76 + strcat(resultbuff, R"("SIMPLELINESYMBOL":{"antialiasing":"antialias_default",)");
  77 + clsJson::JsonAttrParse("icon", resultbuff, buff, this->m_sPNG);
  78 + //clsJson::ParseEnum("type", resultbuff, buff, m_iAntialiasing, "antialias_default", "antialias_none", "antialias_gray", "antialias_subpixel", "antialias_fase", "antialias_good", "antialias_best", "true", "false");
  79 + clsJson::ParseEnum("type", resultbuff, buff, m_iType, "solid", "dash", "dot", "dash_dot", "dash_dot_dot");
  80 + clsJson::JsonAttrParseColor("color", "transparency", resultbuff, buff, m_iColor);
  81 + clsJson::JsonAttrParse("width", resultbuff, buff, m_dWidth);
  82 +
  83 + clsJson::ParseEnum("captype", resultbuff, buff, m_iCapType, "cap_butt", "cap_round", "cap_square");
  84 + clsJson::ParseEnum("jiontype", resultbuff, buff, m_iJionType, "jion_miter", "jion_round", "jion_bevel");
  85 +
  86 + clsJson::JsonAttrEnd(resultbuff);
  87 + ab->AppendString(resultbuff);
  88 + }
  89 +
  90 + int SimpleLineSymbol::GetAntialiasing()
  91 + {
  92 + return m_iAntialiasing;
  93 + }
  94 + bool SimpleLineSymbol::SetAntialiasing(int newVal)
  95 + {
  96 + m_iAntialiasing = newVal;
  97 + return true;
  98 + }
  99 + unsigned int SimpleLineSymbol::GetColor()
  100 + {
  101 + return m_iColor;
  102 + }
  103 + bool SimpleLineSymbol::SetColor(unsigned int color)
  104 + {
  105 + m_iColor = color;
  106 + clsUtil::ToCairoColor(color, r, g, b, a);
  107 + return true;
  108 + }
  109 + int SimpleLineSymbol::GetType()
  110 + {
  111 + return m_iType;
  112 + }
  113 + bool SimpleLineSymbol::SetType(int type)
  114 + {
  115 + m_iType = type;
  116 + return true;
  117 + }
  118 + const char* SimpleLineSymbol::GetPNG()
  119 + {
  120 + //m_sPNG = "中国人";
  121 + //clsMalloc clsM2;
  122 + //bool flag = clsUtil::ConvertEncGB18030_UTF8(m_sPNG.c_str(), clsM2);
  123 + //m_sPNG = clsM2.mem;
  124 + return m_sPNG.c_str();
  125 + }
  126 + bool SimpleLineSymbol::SetPNG(const char* png)
  127 + {
  128 + m_sPNG = png;
  129 + m_mustReloadPng = true;
  130 + png = 0;
  131 + return true;
  132 + }
  133 + double SimpleLineSymbol::GetWidth()
  134 + {
  135 + return m_dWidth;
  136 + }
  137 + bool SimpleLineSymbol::SetWidth(double width)
  138 + {
  139 + if (width < 0)return false;
  140 + m_dWidth = width;
  141 + return true;
  142 + }
  143 + int SimpleLineSymbol::GetCapType()
  144 + {
  145 + return m_iCapType;
  146 + }
  147 + bool SimpleLineSymbol::SetCapType(int iCapType)
  148 + {
  149 + m_iCapType = iCapType;
  150 + return true;
  151 + }
  152 + int SimpleLineSymbol::GetJionType()
  153 + {
  154 + return m_iJionType;
  155 + }
  156 + bool SimpleLineSymbol::SetJionType(int iJionType)
  157 + {
  158 + m_iJionType = iJionType;
  159 + return true;
  160 + }
  161 +
  162 + /*
  163 + */
  164 + int SimpleLineSymbol::BytesPerLine(int nWidth, int nBitsPerPixel) //像素宽度、每个像素多少位
  165 + {
  166 + return ((nWidth * nBitsPerPixel + 31) & (~31)) / 8;
  167 + }
  168 +
  169 +
  170 + bool SimpleLineSymbol::DrawLINESimple(clsCrSurf* clsCS, clsStruct::LINE*pLine)
  171 + {
  172 + if(pLine == NULL || pLine->p == NULL)
  173 + return false;
  174 + cairo_t* cr = clsCS->m_pCr;
  175 + clsUtil::DoSetAntialias(m_iAntialiasing, cr);
  176 +
  177 + int nPoint = pLine->nPoint;
  178 + clsStruct::POINT* pPoint = pLine->p;
  179 + cairo_new_path(cr);
  180 + for (int i = 0; i < nPoint; i++)
  181 + {
  182 + double x = pPoint[i].x;
  183 + double y = pPoint[i].y;
  184 +
  185 + if (i == 0)
  186 + {
  187 + cairo_move_to(cr, x, y);
  188 + }
  189 + else
  190 + cairo_line_to(cr, x, y);
  191 + }
  192 + clsUtil::DoSetLineType(m_iType, cr);
  193 + cairo_set_source_rgba(cr, r, g, b, a);
  194 + cairo_set_line_width(cr, m_dWidth);
  195 + cairo_set_line_cap(cr, (cairo_line_cap_t)m_iCapType);
  196 + cairo_set_line_join(cr, (cairo_line_join_t)m_iJionType);
  197 + cairo_stroke(cr);
  198 + return true;
  199 + }
  200 +
  201 + bool SimpleLineSymbol::DrawMLINESimple(clsCrSurf* clsCS, clsStruct::MLINE*pMLine)
  202 + {
  203 +
  204 + if(pMLine == NULL || pMLine->p == NULL) return false;
  205 + cairo_t* cr = clsCS->m_pCr;
  206 + clsUtil::DoSetAntialias(m_iAntialiasing, cr);
  207 +
  208 + int nLine = pMLine->nLine;
  209 + clsStruct::LINE* pLine = pMLine->p;
  210 + cairo_new_path(cr);
  211 +
  212 + for (int i = 0; i < nLine; i++)
  213 + {
  214 + int nPoint = (pLine + i)->nPoint;
  215 + clsStruct::POINT* pPoint = (pLine + i)->p;
  216 +
  217 + if(pPoint == NULL) continue;
  218 + for (int j = 0; j < nPoint; j++)
  219 + {
  220 + double x = pPoint[j].x;
  221 + double y = pPoint[j].y;
  222 + if (j == 0)
  223 + {
  224 + cairo_move_to(cr, x, y);
  225 + }
  226 + else
  227 + cairo_line_to(cr, x, y);
  228 + }
  229 + }
  230 + clsUtil::DoSetLineType(m_iType, cr);
  231 + cairo_set_source_rgba(cr, r, g, b, a);
  232 + cairo_set_line_width(cr, m_dWidth);
  233 + cairo_set_line_cap(cr, (cairo_line_cap_t)m_iCapType);
  234 + cairo_set_line_join(cr, (cairo_line_join_t)m_iJionType);
  235 + cairo_stroke(cr);
  236 +
  237 + return true;
  238 + }
  239 +
  240 + bool SimpleLineSymbol::DrawData(clsCrSurf* pClsCS, DataCollection* data, bool drawSimpleData, char* pFlag)
  241 + {
  242 + /***********************************************************************************************/
  243 + /*
  244 + patta
  245 + */
  246 + /*
  247 + if (m_sPNG != "")
  248 + {
  249 + if (m_pPatta != NULL)
  250 + TryDelete(m_pPatta);
  251 + this->TryCreatePatta(pClsCS);
  252 + }
  253 + */
  254 + /***********************************************************************************************/
  255 +
  256 + int structType = data->m_iStructType;
  257 + int iPartCount = data->m_iPartCount;
  258 +
  259 + if (m_sPNG != "")
  260 + {
  261 + cairo_t* cr = pClsCS->m_pCr;
  262 + cairo_new_path(cr);
  263 + cairo_arc(cr, 0, 0, 1, 0, 1 * M_PI);
  264 + cairo_set_source_rgba(cr, 1, 1, 1, 0.01);
  265 + cairo_fill(cr); //不留边框填充
  266 + }
  267 +
  268 + switch (structType)
  269 + {
  270 + case clsStruct::Struct_Line:
  271 + {
  272 + for (int i = 0; i < iPartCount; i++)
  273 + {
  274 + clsStruct::LINE* pLine = (clsStruct::LINE*)data->m_pData;
  275 + this->DrawLINE(pClsCS, pLine + i);
  276 + }
  277 + break;
  278 + }
  279 + case clsStruct::Struct_MLine:
  280 + {
  281 + for (int i = 0; i < iPartCount; i++)
  282 + {
  283 + clsStruct::MLINE* pMLine = (clsStruct::MLINE*)data->m_pData;
  284 + this->DrawMLINE(pClsCS, pMLine + i);
  285 + }
  286 + break;
  287 + }
  288 + default:
  289 + break;
  290 + }
  291 + return true;
  292 + }
  293 +
  294 + bool SimpleLineSymbol::DrawData(clsCrSurf* pClsCS, DataCollection* data, int dataIndex, char* pFlag)
  295 + {
  296 + /***********************************************************************************************/
  297 + /*
  298 + patta
  299 + */
  300 + /*
  301 + if (m_sPNG != "")
  302 + {
  303 + if (m_pPatta != NULL)
  304 + TryDelete(m_pPatta);
  305 + this->TryCreatePatta(pClsCS);
  306 + }
  307 + */
  308 + /***********************************************************************************************/
  309 +
  310 + int structType = data->m_iStructType;
  311 + int iPartCount = data->m_iPartCount;
  312 +
  313 +
  314 + switch (structType)
  315 + {
  316 + case clsStruct::Struct_Line:
  317 + {
  318 + clsStruct::LINE* pLine = (clsStruct::LINE*)data->m_pData;
  319 + this->DrawLINE(pClsCS, pLine + dataIndex);
  320 + break;
  321 + }
  322 + case clsStruct::Struct_MLine:
  323 + {
  324 + clsStruct::MLINE* pMLine = (clsStruct::MLINE*)data->m_pData;
  325 + this->DrawMLINE(pClsCS, pMLine + dataIndex);
  326 + break;
  327 + }
  328 + default:
  329 + break;
  330 + }
  331 + return true;
  332 + }
  333 +
  334 + bool SimpleLineSymbol::DrawLegend(clsCrSurf* pClsCS, shared_ptr<legendParamater> pLegendParamater,int layerType, char* pFlag)
  335 + {
  336 + if(layerType != 1)
  337 + return false;
  338 +
  339 + pLegendParamater->next(pFlag);
  340 +
  341 + cairo_t *cr = pClsCS->m_pCr;
  342 + if (pFlag)
  343 + {
  344 + cairo_set_source_rgb(cr, 0, 0, 0); //设置画笔颜色,也就是红,绿,蓝,这里设置成绿色。
  345 + cairo_select_font_face(cr, pLegendParamater->font.c_str(),
  346 + CAIRO_FONT_SLANT_NORMAL,
  347 + pLegendParamater->isbold? CAIRO_FONT_WEIGHT_BOLD:CAIRO_FONT_WEIGHT_NORMAL);
  348 +
  349 + cairo_set_font_size(cr, pLegendParamater->fontSize);
  350 + cairo_move_to(cr, pLegendParamater->pixXIndex + pLegendParamater->size_x + 10,
  351 + pLegendParamater->pixYIndex + pLegendParamater->size_y - 3);
  352 +
  353 + cairo_show_text(cr, pFlag);
  354 + }
  355 + if (m_sPNG != "")
  356 + {
  357 + //cairo_t* cr = pClsCS->m_pCr;
  358 + cairo_new_path(cr);
  359 + cairo_arc(cr, 0, 0, 1, 0, 1 * M_PI);
  360 + cairo_set_source_rgba(cr, 1, 1, 1, 0.01);
  361 + cairo_fill(cr); //不留边框填充
  362 + }
  363 +
  364 + clsUtil::DoSetAntialias(m_iAntialiasing, cr);
  365 +
  366 + //int nPoint = pLine->nPoint;
  367 + //clsStruct::POINT* pPoint = pLine->p;
  368 + cairo_new_path(cr);
  369 + cairo_move_to(cr, pLegendParamater->pixXIndex, pLegendParamater->pixYIndex + pLegendParamater->size_y/2);
  370 + cairo_line_to(cr, pLegendParamater->pixXIndex + pLegendParamater->size_x, pLegendParamater->pixYIndex + pLegendParamater->size_y/2);
  371 +
  372 + clsUtil::DoSetLineType(m_iType, cr);
  373 + cairo_set_source_rgba(cr, r, g, b, a);
  374 + cairo_set_line_width(cr, m_dWidth);
  375 + cairo_set_line_cap(cr, (cairo_line_cap_t)m_iCapType);
  376 + cairo_set_line_join(cr, (cairo_line_join_t)m_iJionType);
  377 + cairo_stroke(cr);
  378 + return true;
  379 + }
  380 +
  381 + bool SimpleLineSymbol::DrawLINE(clsCrSurf* pClsCS, clsStruct::LINE * pLine)
  382 + {
  383 + if (m_sPNG == "")
  384 + return this->DrawLINESimple(pClsCS, pLine);
  385 + else
  386 + return this->DrawLINEPNG(pClsCS, pLine);
  387 + }
  388 +
  389 +
  390 + bool SimpleLineSymbol::DrawMLINE(clsCrSurf* pClsCS, clsStruct::MLINE* pMLine)
  391 + {
  392 + if (m_sPNG == "")
  393 + return this->DrawMLINESimple(pClsCS, pMLine);
  394 + else
  395 + return this->DrawMLINEPNG(pClsCS, pMLine);
  396 + }
  397 +
  398 + bool SimpleLineSymbol::DrawLINEPNG(clsCrSurf* pClsCS, clsStruct::LINE* pLine)
  399 + {
  400 + return true;
  401 + }
  402 + bool SimpleLineSymbol::DrawMLINEPNG(clsCrSurf* pClsCS, clsStruct::MLINE* pMLine)
  403 + {
  404 +
  405 + // return true;
  406 + /*if (m_mustReloadPng == true || m_LastBGColor != pClsCS->m_iBGColor)
  407 + {
  408 + TryReadPng(pClsCS->m_iBGColor);
  409 + }
  410 +
  411 +
  412 + cairo_surface_t* surface = pClsCS->m_pSurf;
  413 + int surf_w = cairo_image_surface_get_width(surface);
  414 + int surf_h = cairo_image_surface_get_height(surface);
  415 +
  416 + unsigned char* buffer = cairo_image_surface_get_data(surface);
  417 +
  418 + //agg::rendering_buffer m_pRBuf(buffer, (unsigned int)surf_w, (unsigned int)surf_h, (int)(surf_w * 4));
  419 + //pixfmt m_pf(m_pRBuf);
  420 + //renderer_base m_pRen_base(m_pf);
  421 + //renderer_type m_pRen_img(m_pRen_base, *(png->patta));
  422 + //rasterizer_type m_pRas_img(m_pRen_img);
  423 +
  424 + /*int nLine = pMLine->nLine;
  425 + clsStruct::LINE * pLine = pMLine->p;
  426 +
  427 + for (int j = 0; j < nLine; j++)
  428 + {
  429 + int nPoint = pLine[j].nPoint;
  430 + clsStruct::POINT * pPoint = pLine[j].p;
  431 +
  432 + agg::path_storage path;
  433 + for (int k = 0; k < nPoint; k++)
  434 + {
  435 + double x = pPoint[k].x;
  436 + double y = pPoint[k].y;
  437 + if (k == 0)
  438 + path.move_to(x, y);
  439 + else
  440 + path.line_to(x, y);
  441 + }
  442 + m_pRas_img.add_path(path);
  443 + }*/
  444 + return true;
  445 +
  446 +
  447 + }
  448 +
  449 +
  450 +
  451 + bool SimpleLineSymbol::TryReadPng(unsigned int colorThis)
  452 + {
  453 + //m_mustReloadPng = false;
  454 + //m_LastBGColor = colorThis;
  455 + //if (png)delete png; png = new clsPng();
  456 + //if (png->ReadPng(this->m_sPNG.c_str(), m_LastBGColor) == 1)
  457 + //{
  458 + // delete png; png = 0;
  459 + // return false;
  460 + //}
  461 +
  462 + return true;
  463 + }
  464 +
  465 + bool SimpleLineSymbol::TryCreatePatta(clsCrSurf * pClsCS)
  466 + {
  467 +
  468 + return true;
  469 + }
  470 + bool SimpleLineSymbol::TryCreateRendererBase()
  471 + {
  472 +
  473 + return true;
  474 + }
  475 +}
\ No newline at end of file
... ...
  1 +#pragma once
  2 +
  3 +#ifndef _SimpleLineSymbol_H_
  4 +#define _SimpleLineSymbol_H_
  5 +#include<string>
  6 +#include <boost/property_tree/ptree.hpp>
  7 +#include <boost/property_tree/xml_parser.hpp>
  8 +#include <boost/foreach.hpp>
  9 +#include "Renderer.h"
  10 +#include "clsStruct.h"
  11 +#include "clsCrSurf.h"
  12 +#include "DataCollection.h"
  13 +//#include "clsPng.h"
  14 +
  15 +using namespace std;
  16 +
  17 +namespace DmapCore_30
  18 +{
  19 + class clsCrSurf;
  20 + class Path;
  21 + class DataCollection;
  22 + class CORE_EXPORT SimpleLineSymbol :public Renderer
  23 + {
  24 + public:
  25 +
  26 + //没有实现 captype,jointype
  27 + SimpleLineSymbol();
  28 + ~SimpleLineSymbol();
  29 + static SimpleLineSymbol* CreateNew();
  30 + virtual int RendererType();
  31 + virtual bool Parse(boost::property_tree::ptree &pt, AppendBuffer *f);
  32 + virtual void ToJson(AppendBuffer *ab);
  33 + //virtual bool RendererString(Renderer** ppRen, const char** psXML);
  34 + virtual bool DrawData(clsCrSurf* clsCS, DataCollection* data, bool drawSimpleData, char* pFlag = NULL);
  35 + virtual bool DrawData(clsCrSurf* clsCS, DataCollection* data, int dataIndex, char* pFlag = NULL);
  36 + virtual bool DrawLegend(clsCrSurf* pClsCS, shared_ptr<legendParamater> pLegendParamater,int layerType, char* pFlag = NULL);
  37 +
  38 +
  39 + //clsPng *png;
  40 +
  41 + /*
  42 + 全局变量
  43 + */
  44 + int m_iAntialiasing;
  45 + unsigned int m_iColor;
  46 + int m_iType;
  47 + string m_sPNG;
  48 + double m_dWidth;
  49 + int m_iCapType;
  50 + int m_iJionType;
  51 +
  52 + double r, g, b, a;
  53 +
  54 + int GetAntialiasing();
  55 + bool SetAntialiasing(int newVal);
  56 + unsigned int GetColor();
  57 + bool SetColor(unsigned int color);
  58 + int GetType();
  59 + bool SetType(int type);
  60 + const char* GetPNG();
  61 + bool SetPNG(const char* png);
  62 + double GetWidth();
  63 + bool SetWidth(double width);
  64 + int GetCapType();
  65 + bool SetCapType(int iCapType);
  66 + int GetJionType();
  67 + bool SetJionType(int iJionType);
  68 +
  69 +
  70 + //此处传的 geom 都是屏幕坐标
  71 + int BytesPerLine(int nWidth, int nBitsPerPixel);
  72 +
  73 +
  74 +
  75 +
  76 + bool TryFindHeatRenderer(){ return false; }
  77 +
  78 +
  79 +
  80 + //线条有点难办啊, 需要传surface宽和高,还要传 绘图 buffer指针
  81 +
  82 + bool DrawLINE(clsCrSurf* clsCS, clsStruct::LINE * pLine);
  83 + bool DrawMLINE(clsCrSurf* clsCS, clsStruct::MLINE* pMLine);
  84 + bool DrawLINESimple(clsCrSurf* clsCS, clsStruct::LINE* pLine);
  85 + bool DrawLINEPNG(clsCrSurf* clsCS, clsStruct::LINE* pLine);
  86 + bool DrawMLINESimple(clsCrSurf* clsCS, clsStruct::MLINE* pMLine);
  87 + bool DrawMLINEPNG(clsCrSurf* clsCS, clsStruct::MLINE* pMLine);
  88 +
  89 +
  90 + private:
  91 + bool m_mustReloadPng;
  92 + unsigned int m_LastBGColor;
  93 + bool TryReadPng(unsigned int colorThis);
  94 + //clsCrSurf* m_pClsSurfBackup;
  95 + bool TryCreatePatta(clsCrSurf * clsCS);
  96 + bool TryCreateRendererBase();
  97 + };
  98 +
  99 +}
  100 +
  101 +#endif
\ No newline at end of file
... ...
  1 +
  2 +#include "SimpleMarkerSymbol.h"
  3 +#include "clsUtil.h"
  4 +#include "clsCrSurf.h"
  5 +#include "clsXML.h"
  6 +#include "DataCollection.h"
  7 +#include "clsJson.h"
  8 +#define _USE_MATH_DEFINES
  9 +#include <math.h>
  10 +namespace DmapCore_30
  11 +{
  12 + SimpleMarkerSymbol::SimpleMarkerSymbol()
  13 + {
  14 + m_iAntialiasing = CAIRO_ANTIALIAS_DEFAULT;
  15 + m_bBoundary = true;
  16 + m_iColor = clsUtil::RandomColor();
  17 + clsUtil::ToCairoColor(m_iColor, r, g, b, a);
  18 + m_iType = 0;
  19 + m_iOutline = 0xff000000;
  20 + clsUtil::ToCairoColor(m_iOutline, r1, g1, b1, a1);
  21 + m_sPNG = "";
  22 + m_dWidth = 1;
  23 + m_dSize = 5;
  24 + m_sXML = "";
  25 + m_simpleRenderer = false;
  26 + }
  27 +
  28 + SimpleMarkerSymbol::~SimpleMarkerSymbol()
  29 + {
  30 + if (surfImage)
  31 + {
  32 + cairo_surface_destroy(surfImage);
  33 + surfImage = nullptr;
  34 + }
  35 + }
  36 + SimpleMarkerSymbol* SimpleMarkerSymbol::CreateNew()
  37 + {
  38 + SimpleMarkerSymbol * dest = new SimpleMarkerSymbol();
  39 + return dest;
  40 + }
  41 +
  42 + int SimpleMarkerSymbol::RendererType()
  43 + {
  44 + return dmapSimpleMarkerSymbol;
  45 + }
  46 + bool SimpleMarkerSymbol::Parse(boost::property_tree::ptree &pt, AppendBuffer *f)
  47 + {
  48 +
  49 +
  50 + clsXML clsX(f, "SIMPLEMARKERSYMBOL");
  51 + clsXML::ParseEnum("antialiasing", pt, f, &m_iAntialiasing, "antialias_default", "antialias_none", "antialias_gray", "antialias_subpixel", "antialias_fase", "antialias_good", "antialias_best", "true", "false");
  52 + clsXML::XMLAttrParse(pt, f, &m_sPNG, "png");
  53 + clsXML::ParseEnum("type", pt, f, &m_iType, "circle", "triangle", "square", "cross", "star", "icon");
  54 + clsXML::XMLAttrParseColor(pt, f, &m_iColor, "color", "transparency");
  55 + clsXML::XMLAttrParse(pt, f, &m_bBoundary, "boundary");
  56 + clsXML::XMLAttrParseColor(pt, f, &m_iOutline, "outline", "outlinetransparency");
  57 + clsXML::XMLAttrParse(pt, f, &m_dWidth, "width");
  58 + clsXML::XMLAttrParse(pt, f, &m_dSize, "size");
  59 + //if (node)
  60 + {
  61 + clsUtil::ToCairoColor(m_iColor, r, g, b, a);
  62 + clsUtil::ToCairoColor(m_iOutline, r1, g1, b1, a1);
  63 + if (m_sPNG != "")
  64 + {
  65 + m_sPNG = GetFilePath(m_sPNG);
  66 + if (FILE *file = fopen(m_sPNG.c_str(), "r")) {
  67 + fclose(file);
  68 + surfImage = cairo_image_surface_create_from_png(m_sPNG.c_str());
  69 + }
  70 + else {
  71 + m_sPNG = "";
  72 + }
  73 + }
  74 + }
  75 + return true;
  76 + }
  77 +
  78 + void SimpleMarkerSymbol::ToJson(AppendBuffer* ab)
  79 + {
  80 +
  81 + char buff[300] = {0};
  82 + char resultbuff[5000] = {0};
  83 + sprintf(resultbuff, R"("SIMPLEMARKERSYMBOL":{"antialiasing":"antialias_default",)");
  84 + string png = this->m_sPNG;
  85 + if(png != "" && png.find("symbollib") != png.npos)
  86 + {
  87 + int pos = png.find("symbollib");
  88 + png = "../" + png.substr(pos,png.length() - pos);
  89 + }
  90 + clsJson::JsonAttrParse("png", resultbuff, buff, png);
  91 + clsJson::ParseEnum("type", resultbuff, buff, m_iType, "circle", "triangle", "square", "cross", "star", "icon");
  92 + clsJson::JsonAttrParseColor("color", "transparency", resultbuff, buff, m_iColor);
  93 + clsJson::JsonAttrParse("boundary", resultbuff, buff, m_bBoundary);
  94 + clsJson::JsonAttrParseColor("outline", "outlinetransparency", resultbuff, buff, m_iOutline);
  95 + clsJson::JsonAttrParse("width", resultbuff, buff, m_dWidth);
  96 + clsJson::JsonAttrParse("size", resultbuff, buff, m_dSize);
  97 + clsJson::JsonAttrEnd(resultbuff);
  98 + ab->AppendString(resultbuff);
  99 + }
  100 +
  101 + int SimpleMarkerSymbol::GetAntialiasing()
  102 + {
  103 + return m_iAntialiasing;
  104 + }
  105 + bool SimpleMarkerSymbol::SetAntialiasing(int iAntialiasing)
  106 + {
  107 + m_iAntialiasing = iAntialiasing;
  108 + return true;
  109 + }
  110 + unsigned int SimpleMarkerSymbol::GetColor()
  111 + {
  112 + return m_iColor;
  113 + }
  114 + bool SimpleMarkerSymbol::SetColor(unsigned int color)
  115 + {
  116 + clsUtil::ToCairoColor(color, r, g, b, a);
  117 + m_iColor = color;
  118 + return true;
  119 + }
  120 + int SimpleMarkerSymbol::GetType()
  121 + {
  122 + return m_iType;
  123 + }
  124 + bool SimpleMarkerSymbol::SetType(int type)
  125 + {
  126 + if (type<0 || type >6) return false;
  127 + m_iType = type;
  128 + return true;
  129 + }
  130 + bool SimpleMarkerSymbol::GetBoundary()
  131 + {
  132 + return m_bBoundary;
  133 + }
  134 + bool SimpleMarkerSymbol::SetBoundary(bool boundary)
  135 + {
  136 + m_bBoundary = boundary;
  137 + return true;
  138 + }
  139 + unsigned int SimpleMarkerSymbol::GetOutline()
  140 + {
  141 + return m_iOutline;
  142 + }
  143 + bool SimpleMarkerSymbol::SetOutline(unsigned int outline)
  144 + {
  145 + clsUtil::ToCairoColor(outline, r1, g1, b1, a1);
  146 + m_iOutline = outline;
  147 + return true;
  148 + }
  149 + const char* SimpleMarkerSymbol::GetPNG()
  150 + {
  151 + return m_sPNG.c_str();
  152 + }
  153 + bool SimpleMarkerSymbol::SetPNG(const char* png)
  154 + {
  155 + surfImage = nullptr;
  156 + if (png == 0)m_sPNG = "";
  157 + else m_sPNG = png;
  158 + if (m_sPNG.size() > 0)
  159 + {
  160 + surfImage = cairo_image_surface_create_from_png(png);
  161 + }
  162 + return true;
  163 + }
  164 + double SimpleMarkerSymbol::GetWidth()
  165 + {
  166 + return m_dWidth;
  167 + }
  168 + bool SimpleMarkerSymbol::SetWidth(double width)
  169 + {
  170 + if (width < 0)return false;
  171 + m_dWidth = width;
  172 + return true;
  173 + }
  174 + double SimpleMarkerSymbol::GetSize()
  175 + {
  176 + return m_dSize;
  177 + }
  178 + bool SimpleMarkerSymbol::SetSize(double Size)
  179 + {
  180 + if (Size < 0)return false;
  181 + m_dSize = Size;
  182 + return true;
  183 + }
  184 +
  185 +
  186 +
  187 + bool SimpleMarkerSymbol::DrawPOINT(clsCrSurf* clsCS, clsStruct::POINT*p)
  188 + {
  189 + double x = p->x;
  190 + double y = p->y;
  191 +
  192 + cairo_t* cr = clsCS->m_pCr;
  193 +
  194 +
  195 + double width = 0.5 * m_dSize;
  196 +
  197 + if (m_sPNG != "")
  198 + {
  199 + //这样做实现不了边框!!!
  200 + // 是否该用 png 平铺一样的实现,提供边框
  201 + cairo_surface_t* image = surfImage;// m_pImage->m_pSurf;
  202 + if (image == 0)return false;
  203 + double w = cairo_image_surface_get_width(image);
  204 + double h = cairo_image_surface_get_height(image);
  205 + cairo_set_source_surface(cr, image, x - 0.5*w, y - 0.5*h);
  206 + cairo_paint(cr);
  207 + }
  208 + else
  209 + {
  210 + switch (m_iType)
  211 + {
  212 + case dmapPointTypeCross:
  213 + {
  214 + cairo_move_to(cr, x - width, y);
  215 + cairo_line_to(cr, x + width, y);
  216 + cairo_move_to(cr, x, y - width);
  217 + cairo_line_to(cr, x, y + width);
  218 + cairo_set_source_rgba(cr, r, g, b, a);
  219 + cairo_set_line_width(cr, 1);
  220 + cairo_stroke(cr);
  221 + break;
  222 + }
  223 + case dmapPointTypeCircle:
  224 + {
  225 + cairo_new_path(cr);
  226 + cairo_arc(cr, x, y, width, 0, 2 * M_PI);
  227 + cairo_set_source_rgba(cr, r, g, b, a);
  228 + if (m_bBoundary)
  229 + {
  230 + cairo_fill_preserve(cr);//留边框填充
  231 + /* 接下来是画边框 */
  232 + cairo_set_line_width(cr, m_dWidth);
  233 + cairo_set_source_rgba(cr, r1, g1, b1, a1);
  234 + cairo_stroke(cr);
  235 + }
  236 + else
  237 + {
  238 + cairo_fill(cr); //不留边框填充
  239 + }
  240 + //cairo_fill(cr); //不留边框填充
  241 + break;
  242 + }
  243 + case dmapPointTypeTriangle:
  244 + {
  245 + cairo_new_sub_path(cr);
  246 + cairo_move_to(cr, x - width, y + width * 0.57735026918962576450914878050196);
  247 + cairo_line_to(cr, x + width, y + width * 0.57735026918962576450914878050196);
  248 + cairo_line_to(cr, x, y - width * 1.154700538379251529018297561004);
  249 + cairo_close_path(cr);
  250 + cairo_set_source_rgba(cr, r, g, b, a);
  251 +
  252 + if (m_bBoundary)
  253 + {
  254 + cairo_fill_preserve(cr);//留边框填充
  255 +
  256 + /* 接下来是画边框 */
  257 + cairo_set_line_width(cr, m_dWidth);
  258 + cairo_set_source_rgba(cr, r1, g1, b1, a1);
  259 + cairo_stroke(cr);
  260 + }
  261 + else
  262 + {
  263 + cairo_fill(cr); //不留边框填充
  264 + }
  265 + break;
  266 + }
  267 + case dmapPointTypeSquare:
  268 + {
  269 + cairo_new_sub_path(cr);
  270 + cairo_move_to(cr, x - width, y - width);
  271 + cairo_line_to(cr, x - width, y + width);
  272 + cairo_line_to(cr, x + width, y + width);
  273 + cairo_line_to(cr, x + width, y - width);
  274 + cairo_close_path(cr);
  275 + cairo_set_source_rgb(cr, r, g, b);
  276 +
  277 + if (m_bBoundary)
  278 + {
  279 + cairo_fill_preserve(cr);//留边框填充
  280 +
  281 + /* 接下来是画边框 */
  282 + cairo_set_line_width(cr, m_dWidth);
  283 + cairo_set_source_rgba(cr, r1, g1, b1, a1);
  284 + cairo_stroke(cr);
  285 + }
  286 + else
  287 + {
  288 + cairo_fill(cr); //不留边框填充
  289 + }
  290 + break;
  291 + }
  292 + case dmapPointTypeStar:
  293 + {
  294 + double radx[5] = { -7.0534, 7.0534, 11.4127, 0.0000, -11.4127 };
  295 + double rady[5] = { -9.7082, -9.7082, 3.7082, 12.0000, 3.7082 };
  296 + double Radx[5] = { -38.0423, -0.0000, 38.0423, 23.5114, -23.5114 };
  297 + double Rady[5] = { -12.3607, -40.0000, -12.3607, 32.3607, 32.3607 };
  298 + cairo_new_sub_path(cr);
  299 + double rat = width / 40;
  300 + for (int i = 0; i < 5; i++)
  301 + {
  302 + if (i == 0)
  303 + {
  304 + cairo_move_to(cr, x + Radx[i] * rat, y + Rady[i] * rat);
  305 + cairo_line_to(cr, x + radx[i] * rat, y + rady[i] * rat);
  306 + }
  307 + else
  308 + {
  309 + cairo_line_to(cr, x + Radx[i] * rat, y + Rady[i] * rat);
  310 + cairo_line_to(cr, x + radx[i] * rat, y + rady[i] * rat);
  311 + }
  312 + }
  313 + cairo_close_path(cr);
  314 + cairo_set_source_rgba(cr, r, g, b, a);
  315 +
  316 + if (m_bBoundary)
  317 + {
  318 + cairo_fill_preserve(cr);//留边框填充
  319 +
  320 + /* 接下来是画边框 */
  321 + cairo_set_line_width(cr, m_dWidth);
  322 + cairo_set_source_rgba(cr, r1, g1, b1, a1);
  323 + cairo_stroke(cr);
  324 + }
  325 + else
  326 + {
  327 + cairo_fill(cr); //不留边框填充
  328 + }
  329 + break;
  330 + }
  331 + default:
  332 + break;
  333 + }
  334 + }
  335 + return true;
  336 + }
  337 +
  338 + bool SimpleMarkerSymbol::DrawMPOINT(clsCrSurf* pClsCS, clsStruct::LINE* pLine)
  339 + {
  340 + int nPoint = pLine->nPoint;
  341 + clsStruct::POINT* pPoint = pLine->p;
  342 +
  343 + for (int i = 0; i < nPoint; i++)
  344 + this->DrawPOINT(pClsCS, pPoint + i);
  345 + return true;
  346 + }
  347 +
  348 +
  349 +
  350 + bool SimpleMarkerSymbol::DrawData(clsCrSurf* clsCS, DataCollection* data, bool drawSimpleData, char* pFlag)
  351 + {
  352 + int structType = data->m_iStructType;
  353 + int iPartCount = data->m_iPartCount;
  354 +
  355 + clsUtil::DoSetAntialias(m_iAntialiasing, clsCS->m_pCr);
  356 + switch (structType)
  357 + {
  358 + case clsStruct::Struct_Point:
  359 + {
  360 + clsStruct::POINT* pPoint = (clsStruct::POINT*)data->m_pData;
  361 +
  362 + for (int i = 0; i < iPartCount; i++)
  363 + {
  364 + this->DrawPOINT(clsCS, pPoint + i);
  365 + }
  366 + break;
  367 + }
  368 + case clsStruct::Struct_Line:
  369 + {
  370 + for (int i = 0; i < iPartCount; i++)
  371 + {
  372 + clsStruct::LINE* pMPoint = (clsStruct::LINE*)data->m_pData;
  373 + this->DrawMPOINT(clsCS, pMPoint + i);
  374 + }
  375 + break;
  376 + }
  377 + default:
  378 + break;
  379 + }
  380 + return true;
  381 + }
  382 +
  383 + bool SimpleMarkerSymbol::DrawData(clsCrSurf* clsCS, DataCollection* data, int dataIndex, char* pFlag)
  384 + {
  385 + int structType = data->m_iStructType;
  386 + int iPartCount = data->m_iPartCount;
  387 +
  388 + clsUtil::DoSetAntialias(m_iAntialiasing, clsCS->m_pCr);
  389 + switch (structType)
  390 + {
  391 + case clsStruct::Struct_Point:
  392 + {
  393 + clsStruct::POINT* pPoint = (clsStruct::POINT*)data->m_pData;
  394 +
  395 + this->DrawPOINT(clsCS, pPoint + dataIndex);
  396 + break;
  397 + }
  398 + case clsStruct::Struct_Line:
  399 + {
  400 + clsStruct::LINE* pMPoint = (clsStruct::LINE*)data->m_pData;
  401 + this->DrawMPOINT(clsCS, pMPoint + dataIndex);
  402 + break;
  403 + }
  404 + default:
  405 + break;
  406 + }
  407 + return true;
  408 + }
  409 +
  410 + bool SimpleMarkerSymbol::DrawLegend(clsCrSurf* pClsCS, shared_ptr<legendParamater> pLegendParamater,int layerType, char* pFlag)
  411 + {
  412 + if(layerType != 0)
  413 + return false;
  414 + pLegendParamater->next(pFlag);
  415 +
  416 + cairo_t* cr = pClsCS->m_pCr;
  417 + if(pFlag)
  418 + {
  419 + cairo_set_source_rgb(cr, 0, 0, 0); //设置画笔颜色,也就是红,绿,蓝,这里设置成绿色。
  420 + cairo_select_font_face(cr, pLegendParamater->font.c_str(),
  421 + CAIRO_FONT_SLANT_NORMAL,
  422 + pLegendParamater->isbold? CAIRO_FONT_WEIGHT_BOLD:CAIRO_FONT_WEIGHT_NORMAL);
  423 +
  424 + cairo_set_font_size(cr, pLegendParamater->fontSize);
  425 + cairo_move_to(cr, pLegendParamater->pixXIndex + pLegendParamater->size_x + 10,
  426 + pLegendParamater->pixYIndex + pLegendParamater->size_y -3);
  427 + cairo_show_text(cr, pFlag);
  428 + }
  429 + double x = pLegendParamater->pixXIndex + pLegendParamater->size_x/2;
  430 + double y = pLegendParamater->pixYIndex + pLegendParamater->size_y/2 - 1 ;
  431 +
  432 + double width = 0.5 * m_dSize;
  433 +
  434 + if (m_sPNG != "")
  435 + {
  436 + //这样做实现不了边框!!!
  437 + // 是否该用 png 平铺一样的实现,提供边框
  438 + cairo_surface_t* image = surfImage;// m_pImage->m_pSurf;
  439 + if (image == 0)return false;
  440 + double w = cairo_image_surface_get_width(image);
  441 + double h = cairo_image_surface_get_height(image);
  442 + cairo_set_source_surface(cr, image, x - 0.5*w, y - 0.5*h);
  443 + cairo_paint(cr);
  444 + }
  445 + else
  446 + {
  447 + switch (m_iType)
  448 + {
  449 + case dmapPointTypeCross:
  450 + {
  451 + cairo_move_to(cr, x - width, y);
  452 + cairo_line_to(cr, x + width, y);
  453 + cairo_move_to(cr, x, y - width);
  454 + cairo_line_to(cr, x, y + width);
  455 + cairo_set_source_rgba(cr, r, g, b, a);
  456 + cairo_set_line_width(cr, 1);
  457 + cairo_stroke(cr);
  458 + break;
  459 + }
  460 + case dmapPointTypeCircle:
  461 + {
  462 + cairo_new_path(cr);
  463 + cairo_arc(cr, x, y, width, 0, 2 * M_PI);
  464 + cairo_set_source_rgba(cr, r, g, b, a);
  465 + if (m_bBoundary)
  466 + {
  467 + cairo_fill_preserve(cr);//留边框填充
  468 + /* 接下来是画边框 */
  469 + cairo_set_line_width(cr, m_dWidth);
  470 + cairo_set_source_rgba(cr, r1, g1, b1, a1);
  471 + cairo_stroke(cr);
  472 + }
  473 + else
  474 + {
  475 + cairo_fill(cr); //不留边框填充
  476 + }
  477 + //cairo_fill(cr); //不留边框填充
  478 + break;
  479 + }
  480 + case dmapPointTypeTriangle:
  481 + {
  482 + cairo_new_sub_path(cr);
  483 + cairo_move_to(cr, x - width, y + width * 0.57735026918962576450914878050196);
  484 + cairo_line_to(cr, x + width, y + width * 0.57735026918962576450914878050196);
  485 + cairo_line_to(cr, x, y - width * 1.154700538379251529018297561004);
  486 + cairo_close_path(cr);
  487 + cairo_set_source_rgba(cr, r, g, b, a);
  488 +
  489 + if (m_bBoundary)
  490 + {
  491 + cairo_fill_preserve(cr);//留边框填充
  492 +
  493 + /* 接下来是画边框 */
  494 + cairo_set_line_width(cr, m_dWidth);
  495 + cairo_set_source_rgba(cr, r1, g1, b1, a1);
  496 + cairo_stroke(cr);
  497 + }
  498 + else
  499 + {
  500 + cairo_fill(cr); //不留边框填充
  501 + }
  502 + break;
  503 + }
  504 + case dmapPointTypeSquare:
  505 + {
  506 + cairo_new_sub_path(cr);
  507 + cairo_move_to(cr, x - width, y - width);
  508 + cairo_line_to(cr, x - width, y + width);
  509 + cairo_line_to(cr, x + width, y + width);
  510 + cairo_line_to(cr, x + width, y - width);
  511 + cairo_close_path(cr);
  512 + cairo_set_source_rgb(cr, r, g, b);
  513 +
  514 + if (m_bBoundary)
  515 + {
  516 + cairo_fill_preserve(cr);//留边框填充
  517 +
  518 + /* 接下来是画边框 */
  519 + cairo_set_line_width(cr, m_dWidth);
  520 + cairo_set_source_rgba(cr, r1, g1, b1, a1);
  521 + cairo_stroke(cr);
  522 + }
  523 + else
  524 + {
  525 + cairo_fill(cr); //不留边框填充
  526 + }
  527 + break;
  528 + }
  529 + case dmapPointTypeStar:
  530 + {
  531 + double radx[5] = { -7.0534, 7.0534, 11.4127, 0.0000, -11.4127 };
  532 + double rady[5] = { -9.7082, -9.7082, 3.7082, 12.0000, 3.7082 };
  533 + double Radx[5] = { -38.0423, -0.0000, 38.0423, 23.5114, -23.5114 };
  534 + double Rady[5] = { -12.3607, -40.0000, -12.3607, 32.3607, 32.3607 };
  535 + cairo_new_sub_path(cr);
  536 + double rat = width / 40;
  537 + for (int i = 0; i < 5; i++)
  538 + {
  539 + if (i == 0)
  540 + {
  541 + cairo_move_to(cr, x + Radx[i] * rat, y + Rady[i] * rat);
  542 + cairo_line_to(cr, x + radx[i] * rat, y + rady[i] * rat);
  543 + }
  544 + else
  545 + {
  546 + cairo_line_to(cr, x + Radx[i] * rat, y + Rady[i] * rat);
  547 + cairo_line_to(cr, x + radx[i] * rat, y + rady[i] * rat);
  548 + }
  549 + }
  550 + cairo_close_path(cr);
  551 + cairo_set_source_rgba(cr, r, g, b, a);
  552 +
  553 + if (m_bBoundary)
  554 + {
  555 + cairo_fill_preserve(cr);//留边框填充
  556 +
  557 + /* 接下来是画边框 */
  558 + cairo_set_line_width(cr, m_dWidth);
  559 + cairo_set_source_rgba(cr, r1, g1, b1, a1);
  560 + cairo_stroke(cr);
  561 + }
  562 + else
  563 + {
  564 + cairo_fill(cr); //不留边框填充
  565 + }
  566 + break;
  567 + }
  568 + default:
  569 + break;
  570 + }
  571 + }
  572 + return true;
  573 + }
  574 +
  575 +}
\ No newline at end of file
... ...
  1 +#pragma once
  2 +#ifndef _SimpleMarkerSymbol_H_
  3 +#define _SimpleMarkerSymbol_H_
  4 +#include<string>
  5 +using namespace std;
  6 +#include <boost/property_tree/ptree.hpp>
  7 +#include <boost/property_tree/xml_parser.hpp>
  8 +#include <boost/foreach.hpp>
  9 +//#include<cairo.h>
  10 +#include"clsStruct.h"
  11 +#include"Renderer.h"
  12 +
  13 +namespace DmapCore_30
  14 +{
  15 + class clsCrSurf;
  16 + class DataCollection;
  17 + class CORE_EXPORT SimpleMarkerSymbol :public Renderer
  18 + {
  19 + public:
  20 +
  21 + //没有实现 shadow,需要实现?
  22 + SimpleMarkerSymbol();
  23 + ~SimpleMarkerSymbol();
  24 + static SimpleMarkerSymbol* CreateNew();
  25 + virtual int RendererType();
  26 + virtual bool DrawData(clsCrSurf* clsCS, DataCollection* data, bool drawSimpleData, char* pFlag = NULL);
  27 + virtual bool DrawData(clsCrSurf* clsCS, DataCollection* data, int dataIndex, char* pFlag = NULL);
  28 + virtual bool DrawLegend(clsCrSurf* pClsCS, shared_ptr<legendParamater> pLegendParamater, int layerType,char* pFlag = NULL);
  29 + virtual bool Parse(boost::property_tree::ptree &pt, AppendBuffer *f);
  30 + virtual void ToJson(AppendBuffer* ab);
  31 +
  32 + bool TryFindHeatRenderer(){ return false; }
  33 +
  34 +
  35 + int m_iAntialiasing;
  36 + bool m_bBoundary;
  37 + unsigned int m_iColor;
  38 + int m_iType;
  39 + unsigned int m_iOutline;
  40 + string m_sPNG;
  41 + double m_dWidth; //边框宽度
  42 + double m_dSize; //大小
  43 +
  44 +
  45 + double r, g, b, a; //填充颜色
  46 + double r1, g1, b1, a1; //边框颜色
  47 +
  48 +
  49 +
  50 + int GetAntialiasing();
  51 + bool SetAntialiasing(int bAntialiasing);
  52 + unsigned int GetColor();
  53 + bool SetColor(unsigned int color);
  54 + int GetType();
  55 + bool SetType(int type);
  56 + bool GetBoundary();
  57 + bool SetBoundary(bool boundary);
  58 + unsigned int GetOutline();
  59 + bool SetOutline(unsigned int outline);
  60 + const char* GetPNG();
  61 + bool SetPNG(const char* png);
  62 + double GetWidth();
  63 + bool SetWidth(double width);
  64 + double GetSize();
  65 + bool SetSize(double Size);
  66 +
  67 +
  68 + /*
  69 + 2015_12_24最新
  70 + */
  71 + bool DrawPOINT(clsCrSurf* clsCS, clsStruct::POINT* pPoint);
  72 + bool DrawMPOINT(clsCrSurf* clsCr, clsStruct::LINE* pLine);
  73 +
  74 + private:
  75 + cairo_surface_t* surfImage = nullptr;
  76 + //clsCrSurf* m_pImage;
  77 + /*
  78 + 变量维护:
  79 + 1: 这个变量是 png 构造的surface 的包装类型, 初始为 NULL
  80 + 2.获取 Png surface 后,直接构造一个 m_pImage, destroy 动作交给 析构完成
  81 + 3.每次 SetPNG 时, 只要检测到字符串与当前字符串不一致, Release 前一个, 构造新一个
  82 + 4.绘制图形时,检测到有 m_pImage,并且长宽都不为0(PNG 字符串错误时, 构造 surface 完全正常, 只是长宽为0) , 必然使用PNG 绘制点
  83 + 5. 这样做有一个地方需要注意, 只要该样式中存在PNG 字符串, 想要使用其他点类型是不能实现的, 外界必须将字符串重置为""
  84 + */
  85 + };
  86 +
  87 +}
  88 +
  89 +#endif
\ No newline at end of file
... ...
  1 +
  2 +#include "SimplePolygonSymbol.h"
  3 +#include"clsUtil.h"
  4 +#include"clsCrSurf.h"
  5 +#include"clsXML.h"
  6 +#include "clsJson.h"
  7 +#include"clsStruct.h"
  8 +#include "DataCollection.h"
  9 +
  10 +namespace DmapCore_30
  11 +{
  12 + SimplePolygonSymbol::SimplePolygonSymbol()
  13 + {
  14 + m_iAntialiasing = CAIRO_ANTIALIAS_DEFAULT;
  15 + m_iBackgroundColor = clsUtil::RandomColor();
  16 + clsUtil::ToCairoColor(m_iBackgroundColor, r, g, b, a);
  17 + m_iLineType = 0;
  18 + m_dWidth = 0.3;
  19 + m_bBoundary = true;
  20 + m_iBoundaryColor = 0xff000000;
  21 + clsUtil::ToCairoColor(m_iBoundaryColor, r1, g1, b1, a1);
  22 + m_sPNG = "";
  23 + //m_sLinePNG = "";
  24 + //m_pPattern = NULL;
  25 + m_pRepeatSurface = NULL;
  26 + m_iFillType = 0;
  27 + m_iBoundaryCapType = 0;
  28 + m_iBoundaryJionType = 0;
  29 + m_lFillInterval = 25;
  30 + m_bNeedFill = false;
  31 + m_bNeedBackground = false;
  32 + m_iFillColor = 0xff000000;
  33 + m_simpleRenderer = true;
  34 + m_iFillsize = 10;
  35 + m_lCharacter = 33;
  36 + {
  37 + memset(m_sUTF8, 0, 5);
  38 + m_sUTF8[0] = 33;
  39 + }
  40 + }
  41 + SimplePolygonSymbol::~SimplePolygonSymbol()
  42 + {
  43 + if (m_pRepeatSurface)
  44 + {
  45 + delete m_pRepeatSurface;
  46 + }
  47 + if(m_Pattern )
  48 + {
  49 + cairo_pattern_destroy(m_Pattern);
  50 + m_Pattern= nullptr;
  51 + }
  52 + }
  53 + SimplePolygonSymbol* SimplePolygonSymbol::CreateNew()
  54 + {
  55 + SimplePolygonSymbol * dest = new SimplePolygonSymbol();
  56 + return dest;
  57 + }
  58 +
  59 +
  60 + int SimplePolygonSymbol::RendererType()
  61 + {
  62 + return dmapSimplePolygonSymbol;
  63 + }
  64 +
  65 + bool SimplePolygonSymbol::Parse(boost::property_tree::ptree &pt, AppendBuffer *f)
  66 + {
  67 + //公有属性 iFillType antialiasing fillcolor filltransparency boundary
  68 + //有属性 m_sPNG
  69 + //如果有边框 有属性 boundarywidth,boundarycolor,boundarytype,boundarytransparency
  70 +
  71 +
  72 + clsXML clsX(f, "SIMPLEPOLYGONSYMBOL");
  73 + clsXML::ParseEnum("antialiasing", pt, f, &m_iAntialiasing, "antialias_default", "antialias_none", "antialias_gray", "antialias_subpixel", "antialias_fase", "antialias_good", "antialias_best", "true", "false");
  74 + clsXML::XMLAttrParse(pt, f, &m_sPNG, "icon");
  75 +
  76 + clsXML::XMLAttrParse(pt, f, &m_bBoundary, "boundary");
  77 + clsXML::XMLAttrParse(pt, f, &m_dWidth, "width");
  78 + clsXML::ParseEnum("linetype", pt, f, &m_iLineType, "solid", "dash", "dot", "dash_dot", "dash_dot_dot");
  79 + clsXML::XMLAttrParseColor(pt, f, &m_iBoundaryColor, "boundarycolor", "boundarytransparency");
  80 + clsXML::XMLAttrParse(pt, f, &m_lFillInterval, "fillinterval");
  81 +
  82 + clsXML::ParseEnum("filltype", pt, f, &m_iFillType, "solid", "bdiagonal", "fdiagonal", "cross", "diagcross", "horizontal", "vertical", "gray", "lightgray", "darkgray", "icon", "character");
  83 +
  84 +
  85 + clsXML::XMLAttrParse(pt, f, &m_bNeedFill, "needfill");
  86 + clsXML::XMLAttrParseColor(pt, f, &m_iFillColor, "fillcolor", "filltransparency");
  87 +
  88 + clsXML::XMLAttrParse(pt, f, &m_bNeedBackground, "needbackground");
  89 + clsXML::XMLAttrParseColor(pt, f, &m_iBackgroundColor, "backgroundcolor", "backgroundtransparency");
  90 +
  91 + clsXML::XMLAttrParse(pt, f, &m_iFillsize, "fillsize");
  92 + clsXML::XMLAttrParse(pt, f, &m_diagalignment, "diagalignment");
  93 +
  94 + if(m_iFillType == dmapFillTypeCharacter)
  95 + {
  96 + clsXML::XMLAttrParse(pt, f, &m_lCharacter, "character");
  97 + clsXML::XMLAttrParse(pt, f, &m_sFont, "font");
  98 + clsXML::XMLAttrParse(pt, f, &m_sFontname, "fontname");
  99 +
  100 + if(m_sFont == "" || m_sFontname == "")
  101 + {
  102 + m_bNeedFill = false;
  103 + }
  104 +
  105 + if (m_iFillType == dmapFillTypeCharacter)
  106 + {
  107 + this->SetCharacter(m_lCharacter);
  108 + }
  109 + }
  110 +
  111 +
  112 + {
  113 + clsUtil::ToCairoColor(m_iFillColor, r, g, b, a);
  114 + clsUtil::ToCairoColor(m_iBoundaryColor, r1, g1, b1, a1);
  115 + clsUtil::ToCairoColor(m_iBackgroundColor, r_b, g_b, b_b, a_b);
  116 +
  117 + this->SetFillType(m_iFillType);
  118 + if (m_sPNG != "")
  119 + {
  120 +
  121 + if(m_sPNG.find("symbollib") == string::npos && m_sPNG.find("/")!=0 && m_sPNG.find(".")!=0)
  122 + {
  123 + m_sJDPNG = GetFilePath("../symbollib/" + m_sPNG);
  124 + }
  125 + this->SetPNG(m_sJDPNG.c_str());
  126 + }
  127 + }
  128 + return true;
  129 + }
  130 + void SimplePolygonSymbol::ToJson(AppendBuffer *ab)
  131 + {
  132 + char buff[300] = {0};
  133 + char resultbuff[5000] = {0};
  134 + strcat(resultbuff, R"("SIMPLEPOLYGONSYMBOL":{"antialiasing":"antialias_default",)");
  135 + clsJson::JsonAttrParse("icon", resultbuff, buff, this->m_sPNG);
  136 + clsJson::ParseEnum("filltype", resultbuff, buff, m_iFillType, "solid", "bdiagonal", "fdiagonal", "cross", "diagcross", "horizontal", "vertical", "gray", "lightgray", "darkgray", "icon","character" ),
  137 + clsJson::JsonAttrParseColor("fillcolor", "filltransparency", resultbuff, buff, m_iFillColor);
  138 +
  139 + clsJson::JsonAttrParse("boundary", resultbuff, buff, m_bBoundary);
  140 + clsJson::JsonAttrParse("width", resultbuff, buff, m_dWidth);
  141 + clsJson::ParseEnum("linetype", resultbuff, buff, m_iLineType, "solid", "dash", "dot", "dash_dot", "dash_dot_dot");
  142 + clsJson::JsonAttrParseColor("boundarycolor", "boundarytransparency", resultbuff, buff, m_iBoundaryColor);
  143 + clsJson::JsonAttrParse("fillinterval", resultbuff, buff, m_lFillInterval);
  144 + clsJson::JsonAttrParse("needfill", resultbuff, buff, m_bNeedFill);
  145 +
  146 + clsJson::JsonAttrParse("needbackground", resultbuff, buff, m_bNeedBackground);
  147 + clsJson::JsonAttrParseColor("backgroundcolor", "backgroundtransparency", resultbuff, buff, m_iBackgroundColor);
  148 +
  149 + clsJson::JsonAttrParse("fillsize", resultbuff, buff, m_iFillsize);
  150 +
  151 + clsJson::JsonAttrParse("diagalignment", resultbuff, buff, m_diagalignment);
  152 + if(m_iFillType == dmapFillTypeCharacter)
  153 + {
  154 + clsJson::JsonAttrParse("character", resultbuff, buff, m_lCharacter);
  155 + clsJson::JsonAttrParse("font", resultbuff, buff, m_sFont);
  156 + clsJson::JsonAttrParse("fontname", resultbuff, buff, m_sFontname);
  157 + }
  158 +
  159 + clsJson::JsonAttrEnd(resultbuff);
  160 + ab->AppendString(resultbuff);
  161 + }
  162 +
  163 + bool SimplePolygonSymbol::SetCharacter(long lCharacter)
  164 + {
  165 + m_lCharacter = lCharacter;
  166 + memset(m_sUTF8, 0, 5);
  167 + if (lCharacter < 256)
  168 + {
  169 + m_sUTF8[0] = ((char*)(&lCharacter))[0];
  170 + }
  171 + else
  172 + {
  173 + m_sUTF8[0] = ((char*)(&m_lCharacter))[1];
  174 + m_sUTF8[1] = ((char*)(&m_lCharacter))[0];
  175 + }
  176 +
  177 + int flag = this->GetRepeatSurface(); //尝试用 PNG 构造 surface
  178 + if (flag == false) //这里只有 png 构造错误的情况下返回 false
  179 + {
  180 + m_sPNG = ""; //注意 png 字符串重置
  181 + return false;
  182 + }
  183 + return true;
  184 + }
  185 +
  186 + int SimplePolygonSymbol::GetAntialiasing()
  187 + {
  188 + return m_iAntialiasing;
  189 + }
  190 + bool SimplePolygonSymbol::SetAntialiasing(int newVal)
  191 + {
  192 + m_iAntialiasing = (newVal);
  193 + //重新构造平铺模型
  194 + this->SetFillType(m_iFillType);
  195 + return true;
  196 + }
  197 + unsigned int SimplePolygonSymbol::GetColor()
  198 + {
  199 + return m_iFillColor;
  200 + }
  201 + bool SimplePolygonSymbol::SetColor(unsigned int color)
  202 + {
  203 + m_iFillColor = color;
  204 + clsUtil::ToCairoColor(color, r, g, b, a);
  205 + //重新构造平铺模型?
  206 + this->SetFillType(m_iFillType);
  207 + return true;
  208 + }
  209 + int SimplePolygonSymbol::GetLineType()
  210 + {
  211 + return m_iLineType;
  212 + }
  213 + bool SimplePolygonSymbol::SetLineType(int type)
  214 + {
  215 + m_iLineType = type;
  216 + return true;
  217 + }
  218 + const char* SimplePolygonSymbol::GetPNG()
  219 + {
  220 + return m_sPNG.c_str();
  221 + }
  222 + bool SimplePolygonSymbol::SetPNG(const char* png)
  223 + {
  224 + if (png == 0)m_sPNG = "";
  225 + //else m_sPNG = png;
  226 + int flag = this->GetRepeatSurface(); //尝试用 PNG 构造 surface
  227 + if (flag == false) //这里只有 png 构造错误的情况下返回 false
  228 + {
  229 + m_sPNG = ""; //注意 png 字符串重置
  230 + return false;
  231 + }
  232 + if (m_pRepeatSurface == NULL)
  233 + return true;
  234 +
  235 + cairo_surface_t* surface = m_pRepeatSurface->m_pSurf;
  236 + cairo_pattern_t* pattern = cairo_pattern_create_for_surface(surface);
  237 +
  238 + /*
  239 + delete 查下资料, 千万不能出错
  240 + */
  241 + cairo_pattern_set_extend(pattern, CAIRO_EXTEND_REPEAT); //平铺模板
  242 + cairo_matrix_t matrix;
  243 +
  244 +
  245 + cairo_matrix_init_scale(&matrix, 1, 1); //平铺模型,转换模型 , 表示长宽都是 1倍的图片大小, 不缩放
  246 + cairo_pattern_set_matrix(pattern, &matrix);
  247 +
  248 + if(m_Pattern )
  249 + {
  250 + cairo_pattern_destroy(m_Pattern);
  251 + m_Pattern= nullptr;
  252 + }
  253 + m_Pattern = pattern;
  254 +
  255 + return true;
  256 + }
  257 + double SimplePolygonSymbol::GetWidth()
  258 + {
  259 + return m_dWidth;
  260 + }
  261 + bool SimplePolygonSymbol::SetWidth(double width)
  262 + {
  263 +
  264 + if (width < 0)return false;
  265 + m_dWidth = (width);
  266 + return true;
  267 + }
  268 + bool SimplePolygonSymbol::GetBoundary()
  269 + {
  270 +
  271 + return m_bBoundary;
  272 + }
  273 + bool SimplePolygonSymbol::SetBoundary(bool boundary)
  274 + {
  275 + m_bBoundary = (boundary);
  276 + return true;
  277 + }
  278 + unsigned int SimplePolygonSymbol::GetBoundaryColor()
  279 + {
  280 + return m_iBoundaryColor;
  281 + }
  282 + bool SimplePolygonSymbol::SetBoundaryColor(unsigned int boundaryColor)
  283 + {
  284 + m_iBoundaryColor = (boundaryColor);
  285 + clsUtil::ToCairoColor(boundaryColor, r1, g1, b1, a1);
  286 + return true;
  287 + }
  288 + //const char* SimplePolygonSymbol::GetLinePNG()
  289 + //{
  290 + // return m_sLinePNG.c_str();
  291 + //}
  292 + //bool SimplePolygonSymbol::SetLinePNG(const char* png)
  293 + //{
  294 + // m_sLinePNG = png;
  295 + // return true;
  296 + //}
  297 + int SimplePolygonSymbol::GetFillType()
  298 + {
  299 + return m_iFillType;
  300 + }
  301 + bool SimplePolygonSymbol::SetFillType(int iFillType)
  302 + {
  303 + m_iFillType = iFillType;
  304 +
  305 + //尝试构造 平铺 surface,如果不为 NULL, 构造 pattern
  306 + if (m_sPNG != "")
  307 + return true; //如果有PNG 字段,无需构造,使用 PNG 平铺
  308 +
  309 + if ((iFillType == dmapFillTypeSolid) || (iFillType == dmapFillTypeGray) || (iFillType == dmapFillTypeLightGray) || (iFillType == dmapFillTypeDarkGray))
  310 + {
  311 + //如果是三种纯色填充,重置平铺pattern
  312 + if(m_Pattern )
  313 + {
  314 + cairo_pattern_destroy(m_Pattern);
  315 + m_Pattern= nullptr;
  316 + }
  317 + m_Pattern = nullptr;
  318 + if (m_pRepeatSurface)
  319 + {
  320 + delete m_pRepeatSurface;
  321 + m_pRepeatSurface = NULL;
  322 + }
  323 + }
  324 + this->GetRepeatSurface(); // 返回值无用
  325 +
  326 + if (m_pRepeatSurface == NULL)
  327 + return true; // 如果构造出的为 NULL, 使用颜色填充, 如果 filltype 为 灰色等,需要在画图的时候进一步处理
  328 +
  329 +
  330 + cairo_surface_t* surface = m_pRepeatSurface->m_pSurf;
  331 + cairo_pattern_t* pattern = cairo_pattern_create_for_surface(surface);
  332 + cairo_pattern_set_extend(pattern, CAIRO_EXTEND_REPEAT); //平铺模板
  333 + cairo_matrix_t matrix;
  334 + cairo_matrix_init_scale(&matrix, 1, 1); //平铺模型,转换模型 , 表示长宽都是 1倍的图片大小, 不缩放
  335 + cairo_pattern_set_matrix(pattern, &matrix);
  336 + if(m_Pattern )
  337 + {
  338 + cairo_pattern_destroy(m_Pattern);
  339 + m_Pattern= nullptr;
  340 + }
  341 + m_Pattern = pattern;
  342 +
  343 + return true;
  344 + }
  345 +
  346 + int SimplePolygonSymbol::GetBoundaryCapType()
  347 + {
  348 + return m_iBoundaryCapType;
  349 + }
  350 + bool SimplePolygonSymbol::SetBoundaryCapType(int iBoundaryCapType)
  351 + {
  352 + m_iBoundaryCapType = iBoundaryCapType;
  353 + return true;
  354 + }
  355 + int SimplePolygonSymbol::GetBoundaryJionType()
  356 + {
  357 + return m_iBoundaryJionType;
  358 + }
  359 + bool SimplePolygonSymbol::SetBoundaryJionType(int iBoundaryJionType)
  360 + {
  361 + m_iBoundaryJionType = iBoundaryJionType;
  362 + return true;
  363 + }
  364 + long SimplePolygonSymbol::GetFillInterval()
  365 + {
  366 + return m_lFillInterval;
  367 + }
  368 + bool SimplePolygonSymbol::SetFillInterval(long lFillInterval)
  369 + {
  370 + m_lFillInterval = lFillInterval;
  371 + this->SetFillType(m_iFillType);
  372 + return true;
  373 + }
  374 + bool SimplePolygonSymbol::GetNeedFill()
  375 + {
  376 + return m_bNeedFill;
  377 + }
  378 + bool SimplePolygonSymbol::SetNeedFill(bool bNeedFill)
  379 + {
  380 + m_bNeedFill = bNeedFill;
  381 + return true;
  382 + }
  383 +
  384 +
  385 +
  386 + bool SimplePolygonSymbol::SetBackground(cairo_t* cr,double dSurfW,double dSurfH)
  387 + {
  388 + if(m_bNeedBackground)
  389 + {
  390 + double r = 0, g = 0, b = 0, a = 1;
  391 + clsUtil::ToCairoColor(m_iBackgroundColor, r, g, b, a);
  392 + cairo_set_source_rgba(cr, r, g, b, a);
  393 + cairo_rectangle (cr, 0, 0, dSurfW, dSurfH);
  394 + cairo_fill(cr);
  395 + return true;
  396 + }
  397 + return false;
  398 + }
  399 +
  400 + //注意, 这里是有可能PNG路径错误
  401 + //此函数只做一件事, 构造 平铺需要的 surface,构造出来的 surface 保存在类变量 m_pRepeatSurface 中
  402 + //此函数必然重置 m_pRepeatSurface ,不使用平铺则为NULL
  403 + //这里的返回值只有一个作用, 就是 png 路径错误返回 false, 但 构造的 surface 同样不为 NULL
  404 +#define G2 1.4142135623730950488016887242097
  405 + bool SimplePolygonSymbol::GetRepeatSurface()
  406 + {
  407 + if (m_pRepeatSurface) //这个判定可靠吗??? 不存在必然是 NULL吗? PNG 构造时路径错误,也不为NULL,销毁是否能正常执行?
  408 + {
  409 + m_pRepeatSurface->Release();
  410 + m_pRepeatSurface = NULL;
  411 + }
  412 +
  413 + if (m_sPNG != "")
  414 + {
  415 + cairo_surface_t *image_surface = cairo_image_surface_create_from_png(m_sJDPNG.c_str());
  416 + clsCrSurf mClsSurfDC(image_surface);
  417 + double w = cairo_image_surface_get_width(image_surface);
  418 + double h = cairo_image_surface_get_height(image_surface);
  419 +
  420 + if(w ==0 || h == 0)
  421 + {
  422 + cairo_surface_t* surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, 100, 100);
  423 + m_pRepeatSurface = new clsCrSurf(surface);
  424 + cairo_t *cr = m_pRepeatSurface->m_pCr;
  425 + this->SetBackground( m_pRepeatSurface->m_pCr,100, 100);
  426 + return true;
  427 + }
  428 +
  429 + double size = 5 + max(w,h) + m_lFillInterval;
  430 +
  431 + if (m_diagalignment)
  432 + {
  433 +
  434 + cairo_surface_t *surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, size*2, size * 2 );
  435 + if (m_pRepeatSurface)
  436 + {
  437 + delete m_pRepeatSurface;
  438 + m_pRepeatSurface = 0;
  439 + }
  440 + m_pRepeatSurface = new clsCrSurf(surface);
  441 + cairo_t *cr = m_pRepeatSurface->m_pCr;
  442 +
  443 + this->SetBackground(cr,size*2, size * 2);
  444 +
  445 + cairo_set_source_surface(cr, image_surface,2, 2 + m_iFillsize);
  446 + cairo_paint(cr);
  447 +
  448 + cairo_set_source_surface(cr, image_surface,2, 2 + m_iFillsize);
  449 + cairo_paint(cr);
  450 + return true;
  451 + }
  452 + else
  453 + {
  454 +
  455 + cairo_surface_t *surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, size, size);
  456 + if (m_pRepeatSurface)
  457 + {
  458 + delete m_pRepeatSurface;
  459 + m_pRepeatSurface = 0;
  460 + }
  461 + m_pRepeatSurface = new clsCrSurf(surface);
  462 + cairo_t *cr = m_pRepeatSurface->m_pCr;
  463 +
  464 + this->SetBackground(cr,size, size);
  465 +
  466 + cairo_set_source_surface(cr, image_surface,2, 2 + m_iFillsize);
  467 + cairo_paint(cr);
  468 + return true;
  469 + }
  470 +
  471 +
  472 + }
  473 +
  474 + if (m_iFillType == dmapFillTypeCharacter)
  475 + {
  476 + if (m_diagalignment)
  477 + {
  478 + int size = 5 + m_iFillsize + m_lFillInterval;
  479 +
  480 + cairo_surface_t *surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, size*2, size * 2 );
  481 + if (m_pRepeatSurface)
  482 + {
  483 + delete m_pRepeatSurface;
  484 + m_pRepeatSurface = 0;
  485 + }
  486 + m_pRepeatSurface = new clsCrSurf(surface);
  487 + cairo_t *cr = m_pRepeatSurface->m_pCr;
  488 +
  489 + this->SetBackground(cr,size*2, size * 2);
  490 +
  491 + double r = 0, g = 0, b = 0, a = 1;
  492 + clsUtil::ToCairoColor(m_iFillColor, r, g, b, a);
  493 + cairo_set_source_rgba(cr, r, g, b, a);
  494 + cairo_select_font_face(cr, m_sFont.c_str(), CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_BOLD);
  495 + cairo_set_font_size(cr, m_iFillsize);
  496 +
  497 + cairo_move_to(cr, 2, 2 + m_iFillsize);
  498 + cairo_show_text(cr, m_sUTF8);
  499 +
  500 + cairo_move_to(cr, 2+ size, 2 + m_iFillsize + size);
  501 + cairo_show_text(cr, m_sUTF8);
  502 +
  503 + return true;
  504 + }
  505 + else
  506 + {
  507 + int size = 5 + m_iFillsize + m_lFillInterval;
  508 +
  509 + cairo_surface_t *surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, size, size);
  510 + if (m_pRepeatSurface)
  511 + {
  512 + delete m_pRepeatSurface;
  513 + m_pRepeatSurface = 0;
  514 + }
  515 + m_pRepeatSurface = new clsCrSurf(surface);
  516 + cairo_t *cr = m_pRepeatSurface->m_pCr;
  517 +
  518 + this->SetBackground(cr,size, size);
  519 +
  520 + double r = 0, g = 0, b = 0, a = 1;
  521 + clsUtil::ToCairoColor(m_iFillColor, r, g, b, a);
  522 + cairo_set_source_rgba(cr, r, g, b, a);
  523 + cairo_select_font_face(cr, m_sFont.c_str(), CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_BOLD);
  524 + cairo_set_font_size(cr, m_iFillsize);
  525 + cairo_move_to(cr, 2, 2 + m_iFillsize);
  526 + cairo_show_text(cr, m_sUTF8);
  527 + return true;
  528 + }
  529 + }
  530 +
  531 + if(m_lFillInterval==0)m_lFillInterval=1;
  532 + if (m_iFillType == dmapFillTypeBDiagonal ||
  533 + m_iFillType == dmapFillTypeFDiagonal ||
  534 + m_iFillType == dmapFillTypeCross ||
  535 + m_iFillType == dmapFillTypeDiagCross ||
  536 + m_iFillType == dmapFillTypeHorizontal ||
  537 + m_iFillType == dmapFillTypeVertical)
  538 + {
  539 + if (m_lFillInterval == 0)
  540 + {
  541 + cairo_surface_t* surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, 100, 100);
  542 + if (m_pRepeatSurface)
  543 + {
  544 + delete m_pRepeatSurface;
  545 + m_pRepeatSurface = 0;
  546 + }
  547 + m_pRepeatSurface = new clsCrSurf(surface);
  548 + cairo_t* cr = m_pRepeatSurface->m_pCr;
  549 + cairo_set_source_rgba(cr, 0, 0, 0, 1);
  550 + cairo_fill(cr);
  551 + return true;
  552 + }
  553 + }
  554 +
  555 +
  556 +
  557 + if(m_iFillType == dmapFillTypeBDiagonal ||
  558 + m_iFillType == dmapFillTypeFDiagonal ||
  559 + m_iFillType == dmapFillTypeCross ||
  560 + m_iFillType == dmapFillTypeDiagCross ||
  561 + m_iFillType == dmapFillTypeHorizontal ||
  562 + m_iFillType == dmapFillTypeVertical
  563 + ){
  564 +
  565 +
  566 + double dLineWidth = 2;
  567 + double m = 25;
  568 + int n = 10;
  569 + m = m_lFillInterval;
  570 +
  571 + n = (int) (128/ (m_lFillInterval + dLineWidth));
  572 + m = 128.0/n - dLineWidth;
  573 +
  574 + double dSurfW = 128;
  575 + double dSurfH = 128;
  576 +
  577 + cairo_surface_t* surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, (int)dSurfW, (int)dSurfH);
  578 + //cairo_surface_t* surface = cairo_pdf_surface_create_for_stream(nullptr,nullptr, (int)dSurfW, (int)dSurfH);
  579 + if (m_pRepeatSurface)
  580 + {
  581 + delete m_pRepeatSurface;
  582 + m_pRepeatSurface = 0;
  583 + }
  584 + m_pRepeatSurface = new clsCrSurf(surface);
  585 + cairo_t* cr = m_pRepeatSurface->m_pCr;
  586 + cairo_set_antialias(cr, (cairo_antialias_t)m_iAntialiasing);
  587 +
  588 + this->SetBackground(cr,dSurfW, dSurfH);
  589 +
  590 +
  591 +
  592 +
  593 +
  594 + double x, y;
  595 + double x_dis, y_dis;
  596 +
  597 + switch (m_iFillType)
  598 + {
  599 + //构造 100*100的画布,做平铺使用
  600 + case dmapFillTypeBDiagonal:
  601 + {
  602 + for (int i = 0; i <= 2*n; i++)
  603 + {
  604 + x = -1;
  605 + y = i* (m + dLineWidth) +1;
  606 + x_dis = y;
  607 + y_dis = -x_dis;
  608 + cairo_move_to(cr, x, y);
  609 + cairo_rel_line_to(cr, x_dis, y_dis);
  610 + }
  611 +
  612 + /* for (int i = 0; i < n; i++)
  613 + {
  614 + x = dLineWidth*G2 / 2 + i*G2 *(m + dLineWidth);
  615 + y = dSurfH;
  616 + x_dis = dSurfH - x;
  617 + y_dis = -x_dis;
  618 + cairo_move_to(cr, x, y);
  619 + cairo_rel_line_to(cr, x_dis, y_dis);
  620 + }*/
  621 +
  622 + /*for (int i = 0; i < n; i++)
  623 + {
  624 + x = 0;
  625 + y = i*G2*(m + dLineWidth) + dLineWidth*G2 / 2 ;
  626 + x_dis = y;
  627 + y_dis = -x_dis;
  628 + cairo_move_to(cr, x, y);
  629 + cairo_rel_line_to(cr, x_dis, y_dis);
  630 + }*/
  631 + break;
  632 + }
  633 + case dmapFillTypeFDiagonal:
  634 + {
  635 + for (int i = 0; i <= 2*n; i++)
  636 + {
  637 + x = -1 - dSurfW + i* (m + dLineWidth);
  638 + y = -1;
  639 + x_dis = dSurfW + 2;
  640 + y_dis = dSurfW + 2;
  641 + cairo_move_to(cr, x, y);
  642 + cairo_rel_line_to(cr, x_dis, y_dis);
  643 + }
  644 +
  645 +
  646 + /* for (int i = 0; i < n; i++)
  647 + {
  648 + x = dLineWidth*G2 / 2 + i*G2 *(m + dLineWidth);
  649 + y = 0;
  650 + x_dis = dSurfH - x;
  651 + y_dis = x_dis;
  652 + cairo_move_to(cr, x, y);
  653 + cairo_rel_line_to(cr, x_dis, y_dis);
  654 + }
  655 + for (int i = 0; i < n; i++)
  656 + {
  657 + x = 0;
  658 + y = dSurfH - i*G2*(m + dLineWidth) - dLineWidth*G2 / 2;
  659 + x_dis = dSurfH - y;
  660 + y_dis = x_dis;
  661 + cairo_move_to(cr, x, y);
  662 + cairo_rel_line_to(cr, x_dis, y_dis);
  663 + }*/
  664 +
  665 + break;
  666 + }
  667 +
  668 + case dmapFillTypeCross:
  669 + {
  670 + for (int i = 0; i < n; i++)
  671 + {
  672 + x = dLineWidth / 2 + i *(m + dLineWidth);
  673 + y = 0;
  674 + x_dis = 0;
  675 + y_dis = dSurfH;
  676 + cairo_move_to(cr, x, y);
  677 + cairo_rel_line_to(cr, x_dis, y_dis);
  678 + }
  679 + for (int i = 0; i < n; i++)
  680 + {
  681 + x = 0;
  682 + y = i*(m + dLineWidth) + dLineWidth / 2;
  683 + x_dis = dSurfW;
  684 + y_dis = 0;
  685 + cairo_move_to(cr, x, y);
  686 + cairo_rel_line_to(cr, x_dis, y_dis);
  687 + }
  688 + break;
  689 + }
  690 + case dmapFillTypeDiagCross:
  691 + {
  692 + for (int i = 0; i <= 2*n; i++)
  693 + {
  694 + x = -1;
  695 + y = i* (m + dLineWidth) +1;
  696 + x_dis = y;
  697 + y_dis = -x_dis;
  698 + cairo_move_to(cr, x, y);
  699 + cairo_rel_line_to(cr, x_dis, y_dis);
  700 + }
  701 + for (int i = 0; i <= 2*n; i++)
  702 + {
  703 + x = -1 - dSurfW + i* (m + dLineWidth);
  704 + y = -1;
  705 + x_dis = dSurfW + 2;
  706 + y_dis = dSurfW + 2;
  707 + cairo_move_to(cr, x, y);
  708 + cairo_rel_line_to(cr, x_dis, y_dis);
  709 + }
  710 +
  711 + /* for (int i = 0; i < n; i++)
  712 + {
  713 + x = dLineWidth*G2 / 2 + i*G2 *(m + dLineWidth);
  714 + y = dSurfH;
  715 + x_dis = dSurfH - x;
  716 + y_dis = -x_dis;
  717 + cairo_move_to(cr, x, y);
  718 + cairo_rel_line_to(cr, x_dis, y_dis);
  719 + }
  720 + for (int i = 0; i < n; i++)
  721 + {
  722 + x = 0;
  723 + y = i*G2*(m + dLineWidth) + dLineWidth*G2 / 2;
  724 + x_dis = y;
  725 + y_dis = -x_dis;
  726 + cairo_move_to(cr, x, y);
  727 + cairo_rel_line_to(cr, x_dis, y_dis);
  728 + }
  729 + for (int i = 0; i < n; i++)
  730 + {
  731 + x = dLineWidth*G2 / 2 + i*G2 *(m + dLineWidth);
  732 + y = 0;
  733 + x_dis = dSurfH - x;
  734 + y_dis = x_dis;
  735 + cairo_move_to(cr, x, y);
  736 + cairo_rel_line_to(cr, x_dis, y_dis);
  737 + }
  738 + for (int i = 0; i < n; i++)
  739 + {
  740 + x = 0;
  741 + y = dSurfH - i*G2*(m + dLineWidth) - dLineWidth*G2 / 2;
  742 + x_dis = dSurfH - y;
  743 + y_dis = x_dis;
  744 + cairo_move_to(cr, x, y);
  745 + cairo_rel_line_to(cr, x_dis, y_dis);
  746 + }*/
  747 +
  748 + break;
  749 + }
  750 + case dmapFillTypeHorizontal:
  751 + {
  752 + for (int i = 0; i < n; i++)
  753 + {
  754 + x = 0;
  755 + y = i*(m + dLineWidth) + dLineWidth / 2;
  756 + x_dis = dSurfW;
  757 + y_dis = 0;
  758 + cairo_move_to(cr, x, y);
  759 + cairo_rel_line_to(cr, x_dis, y_dis);
  760 + }
  761 + break;
  762 + }
  763 + case dmapFillTypeVertical:
  764 + {
  765 +
  766 + for (int i = 0; i < n; i++)
  767 + {
  768 + x = dLineWidth / 2 + i *(m + dLineWidth);
  769 + y = 0;
  770 + x_dis = 0;
  771 + y_dis = dSurfH;
  772 + cairo_move_to(cr, x, y);
  773 + cairo_rel_line_to(cr, x_dis, y_dis);
  774 + }
  775 +
  776 + break;
  777 + }
  778 + default:
  779 + break;
  780 + }
  781 +
  782 + double r = 0, g = 0, b = 0, a = 1;
  783 + clsUtil::ToCairoColor(m_iFillColor, r, g, b, a);
  784 + cairo_set_line_width(cr, dLineWidth);
  785 + cairo_set_source_rgba(cr, r, g, b, a);
  786 + cairo_stroke(cr);
  787 +
  788 +
  789 + }
  790 +
  791 +
  792 +
  793 +
  794 + return true;
  795 + }
  796 +#undef G2
  797 +
  798 + //这里的指针是一个环
  799 + bool SimplePolygonSymbol::DrawRING(clsCrSurf* clsCS, clsStruct::LINE* pRing)
  800 + {
  801 + cairo_t* cr = clsCS->m_pCr;
  802 + clsUtil::DoSetAntialias(m_iAntialiasing, cr);
  803 + if(pRing ==NULL || pRing->p == NULL)
  804 + return false;
  805 + int nPoint = pRing->nPoint;
  806 + clsStruct::POINT* pPoint = pRing->p;
  807 + cairo_new_path(cr);
  808 + for (int i = 0; i < nPoint; i++)
  809 + {
  810 + double x = pPoint[i].x;
  811 + double y = pPoint[i].y;
  812 +
  813 + if (i == 0)
  814 + {
  815 + cairo_move_to(cr, x, y);
  816 + }
  817 +
  818 + else if (i == nPoint - 1)
  819 + cairo_close_path(cr);
  820 + else
  821 + cairo_line_to(cr, x, y);
  822 + }
  823 +
  824 +
  825 + //加一块不需要填充的部分
  826 + if (!m_bNeedFill )
  827 + {
  828 + if(m_bNeedBackground)
  829 + {
  830 + cairo_set_source_rgba(cr, r_b, g_b, b_b, a_b);
  831 + }
  832 +
  833 + if (m_bBoundary)
  834 + {
  835 + clsUtil::DoSetLineType(m_iLineType, cr);
  836 + cairo_set_source_rgba(cr, r1, g1, b1, a1);
  837 + cairo_set_line_width(cr, m_dWidth);
  838 + cairo_set_line_cap(cr, (cairo_line_cap_t)m_iBoundaryCapType);
  839 + cairo_set_line_join(cr, (cairo_line_join_t)m_iBoundaryJionType);
  840 + cairo_stroke(cr);
  841 + }
  842 + return true;
  843 + }
  844 +
  845 + if(m_bNeedBackground)
  846 + {
  847 + cairo_set_source_rgba(cr, r_b, g_b, b_b, a_b);
  848 + }
  849 +
  850 + if (m_Pattern)
  851 + {
  852 + cairo_set_source(cr, m_Pattern);
  853 + }
  854 + //此处需要进一步判断是哪种 纯颜色填充
  855 + //这里只考虑纯颜色填充的四种填充方式
  856 + switch (m_iFillType)
  857 + {
  858 + case dmapFillTypeSolid:
  859 + cairo_set_source_rgba(cr, r, g, b, a);
  860 + break;
  861 + case dmapFillTypeGray:
  862 + {
  863 + //灰色颜色为 169 169 169
  864 + double r_, g_, b_;
  865 + r_ = g_ = b_ = ((double)169) / 255;
  866 + cairo_set_source_rgba(cr, r_, g_, b_, 1.0);
  867 + break;
  868 + }
  869 + case dmapFillTypeLightGray:
  870 + {
  871 + //浅灰色颜色为 211 211 211
  872 + double r_, g_, b_;
  873 + r_ = g_ = b_ = ((double)211) / 255;
  874 + cairo_set_source_rgba(cr, r_, g_, b_, 1.0);
  875 + break;
  876 + }
  877 + case dmapFillTypeDarkGray:
  878 + {
  879 + //深灰色颜色为 128 128 128
  880 + double r_, g_, b_;
  881 + r_ = g_ = b_ = ((double)128) / 255;
  882 + cairo_set_source_rgba(cr, r_, g_, b_, 1.0);
  883 + break;
  884 + }
  885 + default:
  886 + return false; // 这里表示已出错
  887 + break;
  888 + }
  889 + if (m_bBoundary)
  890 + {
  891 + cairo_fill_preserve(cr);
  892 + clsUtil::DoSetLineType(m_iLineType, cr);
  893 + cairo_set_source_rgba(cr, r1, g1, b1, a1);
  894 + cairo_set_line_width(cr, m_dWidth);
  895 + cairo_set_line_cap(cr, (cairo_line_cap_t)m_iBoundaryCapType);
  896 + cairo_set_line_join(cr, (cairo_line_join_t)m_iBoundaryJionType);
  897 + cairo_stroke(cr);
  898 + }
  899 + else
  900 + {
  901 + cairo_fill(cr);
  902 + }
  903 +
  904 + return true;
  905 + }
  906 + bool SimplePolygonSymbol::DrawPOLYGON(clsCrSurf* clsCS, clsStruct::POLYGON* pPolygon)
  907 + {
  908 + cairo_t* cr = clsCS->m_pCr;
  909 +
  910 + //这个结构会用???
  911 + return true;
  912 + }
  913 + bool SimplePolygonSymbol::DrawMPOLYGON(clsCrSurf* clsCS, clsStruct::MPOLYGON* pMPolygon)
  914 + {
  915 + cairo_t* cr = clsCS->m_pCr;
  916 + clsUtil::DoSetAntialias(m_iAntialiasing, cr);
  917 + if(pMPolygon ==NULL || pMPolygon->p == NULL)
  918 + return false;
  919 + int nPolygon = pMPolygon->nPolygon;
  920 + clsStruct::POLYGON* pPolygon = pMPolygon->p;
  921 +
  922 + cairo_new_path(cr);
  923 + for (int i = 0; i < nPolygon; i++)
  924 + {
  925 + int nRing = pPolygon[i].nRing;
  926 + clsStruct::LINE* pRing = pPolygon[i].p;
  927 + if(pRing == NULL)continue;
  928 + for (int j = 0; j < nRing; j++)
  929 + {
  930 + int nPoint = pRing[j].nPoint;
  931 + clsStruct::POINT* pPoint = pRing[j].p;
  932 + if(pPoint == NULL)continue;
  933 + if(nPoint == 1)
  934 + {//小比例尺
  935 + if (m_bBoundary)
  936 + {
  937 + double x = pPoint[0].x;
  938 + double y = pPoint[0].y;
  939 + cairo_new_path(cr);
  940 + cairo_arc(cr, x, y, 1.3, 0, 2 * M_PI);
  941 + cairo_set_source_rgba(cr, r1, g1, b1, a1);
  942 + //cairo_set_source_rgba(cr, r, g, b, a);
  943 + cairo_fill(cr);
  944 + return true;
  945 + }
  946 + else if(m_bNeedBackground)
  947 + {
  948 + double x = pPoint[0].x;
  949 + double y = pPoint[0].y;
  950 + cairo_new_path(cr);
  951 + cairo_arc(cr, x, y, 1.3, 0, 2 * M_PI);
  952 + //cairo_set_source_rgba(cr, r1, g1, b1, a1);
  953 + cairo_set_source_rgba(cr, r_b, g_b, b_b, a_b);
  954 + cairo_fill(cr);
  955 + return true;
  956 + }
  957 +
  958 + }
  959 + else
  960 + {
  961 + for (int k = 0; k < nPoint; k++)
  962 + {
  963 + double x = pPoint[k].x;
  964 + double y = pPoint[k].y;
  965 +
  966 + if (k == 0)
  967 + {
  968 + cairo_move_to(cr, x, y);
  969 + }
  970 + else if (k == nPoint - 1)
  971 + cairo_close_path(cr);
  972 + else
  973 + cairo_line_to(cr, x, y);
  974 + }
  975 + }
  976 + }
  977 + }
  978 +
  979 +
  980 +
  981 +
  982 + /*
  983 + 加一块不需要填充的部分
  984 + */
  985 + if (!m_bNeedFill)
  986 + {
  987 + if(m_bNeedBackground)
  988 + {
  989 + cairo_set_source_rgba(cr, r_b, g_b, b_b, a_b);
  990 + cairo_fill_preserve(cr);
  991 + }
  992 +
  993 + if (m_bBoundary)
  994 + {
  995 + clsUtil::DoSetLineType(m_iLineType, cr);
  996 + cairo_set_source_rgba(cr, r1, g1, b1, a1);
  997 + cairo_set_line_width(cr, m_dWidth);
  998 + cairo_set_line_cap(cr, (cairo_line_cap_t)m_iBoundaryCapType);
  999 + cairo_set_line_join(cr, (cairo_line_join_t)m_iBoundaryJionType);
  1000 + cairo_stroke(cr);
  1001 + }
  1002 + return true;
  1003 + }
  1004 +
  1005 +
  1006 + //cairo_set_source_rgba(cr, 1, 0.5, 0.5, 0.5);
  1007 + //cairo_fill_preserve(cr);
  1008 +
  1009 +
  1010 + /*
  1011 + 接下来是对应各种样式, 填充
  1012 + */
  1013 + cairo_set_fill_rule(cr, CAIRO_FILL_RULE_EVEN_ODD);
  1014 + if (m_Pattern)
  1015 + {
  1016 + cairo_set_source(cr, m_Pattern);
  1017 + }
  1018 + else
  1019 + {
  1020 + //此处需要进一步判断是哪种 纯颜色填充
  1021 + //这里只考虑纯颜色填充的四种填充方式
  1022 + switch (m_iFillType)
  1023 + {
  1024 + case dmapFillTypeSolid:
  1025 + cairo_set_source_rgba(cr, r, g, b, a);
  1026 + break;
  1027 + case dmapFillTypeGray:
  1028 + {
  1029 + //灰色颜色为 169 169 169
  1030 + double r_, g_, b_;
  1031 + r_ = g_ = b_ = ((double)169) / 255;
  1032 + cairo_set_source_rgba(cr, r_, g_, b_, 1.0);
  1033 + break;
  1034 + }
  1035 + case dmapFillTypeLightGray:
  1036 + {
  1037 + //浅灰色颜色为 211 211 211
  1038 + double r_, g_, b_;
  1039 + r_ = g_ = b_ = ((double)211) / 255;
  1040 + cairo_set_source_rgba(cr, r_, g_, b_, 1.0);
  1041 + break;
  1042 + }
  1043 + case dmapFillTypeDarkGray:
  1044 + {
  1045 + //深灰色颜色为 128 128 128
  1046 + double r_, g_, b_;
  1047 + r_ = g_ = b_ = ((double)128) / 255;
  1048 + cairo_set_source_rgba(cr, r_, g_, b_, 1.0);
  1049 + break;
  1050 + }
  1051 + default:
  1052 + return false; // 这里表示已出错
  1053 + break;
  1054 + }
  1055 + }
  1056 + if (m_bBoundary)
  1057 + {
  1058 + //cairo_set_source_rgba(cr, 1, 0.5, 0.5, 0.5);
  1059 + cairo_fill_preserve(cr);
  1060 + clsUtil::DoSetLineType(m_iLineType, cr);
  1061 + cairo_set_source_rgba(cr, r1, g1, b1, a1);
  1062 + cairo_set_line_width(cr, m_dWidth);
  1063 + cairo_set_line_cap(cr, (cairo_line_cap_t)m_iBoundaryCapType);
  1064 + cairo_set_line_join(cr, (cairo_line_join_t)m_iBoundaryJionType);
  1065 + cairo_stroke(cr);
  1066 + }
  1067 + else
  1068 + {
  1069 + cairo_fill(cr);
  1070 + }
  1071 + return true;
  1072 + }
  1073 +
  1074 + bool SimplePolygonSymbol::DrawTexture(clsCrSurf* pClsCS,clsStruct::MPOLYGON* pMPolygon)
  1075 + {
  1076 + return false;
  1077 +
  1078 + }
  1079 +
  1080 +
  1081 + bool SimplePolygonSymbol::DrawData(clsCrSurf *pClsCS, DataCollection* data, bool drawSimpleData, char* pFlag)
  1082 + {
  1083 + int structType = data->m_iStructType;
  1084 + int iPartCount = data->m_iPartCount;
  1085 +
  1086 + switch (structType)
  1087 + {
  1088 + case clsStruct::Struct_Line:
  1089 + {
  1090 + for (int i = 0; i < iPartCount; i++)
  1091 + {
  1092 + clsStruct::LINE* pRing = (clsStruct::LINE*)data->m_pData;
  1093 + this->DrawRING(pClsCS, pRing + i);
  1094 + }
  1095 + break;
  1096 + }
  1097 + case clsStruct::Struct_Polygon:
  1098 + {
  1099 + for (int i = 0; i < iPartCount; i++)
  1100 + {
  1101 + clsStruct::POLYGON*pPolygon = (clsStruct::POLYGON*)data->m_pData;
  1102 + this->DrawPOLYGON(pClsCS, pPolygon + i);
  1103 + }
  1104 + break;
  1105 + }
  1106 + case clsStruct::Struct_MPolygon:
  1107 + {
  1108 + for (int i = 0; i < iPartCount; i++)
  1109 + {
  1110 + clsStruct::MPOLYGON* pMPolygon = (clsStruct::MPOLYGON*)data->m_pData;
  1111 + this->DrawMPOLYGON(pClsCS, pMPolygon + i);
  1112 + }
  1113 + break;
  1114 + }
  1115 + default:
  1116 + break;
  1117 + }
  1118 + return true;
  1119 + }
  1120 +
  1121 +
  1122 + bool SimplePolygonSymbol::DrawData(clsCrSurf *pClsCS, DataCollection* data, int dataIndex, char* pFlag)
  1123 + {
  1124 + int structType = data->m_iStructType;
  1125 + int iPartCount = data->m_iPartCount;
  1126 + if (iPartCount <= dataIndex)return false;
  1127 + switch (structType)
  1128 + {
  1129 + case clsStruct::Struct_Line:
  1130 + {
  1131 + // for (int i = 0; i < iPartCount; i++)
  1132 + {
  1133 + clsStruct::LINE* pRing = (clsStruct::LINE*)data->m_pData;
  1134 + this->DrawRING(pClsCS, pRing + dataIndex);
  1135 + }
  1136 + break;
  1137 + }
  1138 + case clsStruct::Struct_Polygon:
  1139 + {
  1140 + // for (int i = 0; i < iPartCount; i++)
  1141 + {
  1142 + clsStruct::POLYGON*pPolygon = (clsStruct::POLYGON*)data->m_pData;
  1143 + this->DrawPOLYGON(pClsCS, pPolygon + dataIndex);
  1144 + }
  1145 + break;
  1146 + }
  1147 + case clsStruct::Struct_MPolygon:
  1148 + {
  1149 + // for (int i = 0; i < iPartCount; i++)
  1150 + {
  1151 + clsStruct::MPOLYGON* pMPolygon = (clsStruct::MPOLYGON*)data->m_pData;
  1152 + this->DrawMPOLYGON(pClsCS, pMPolygon + dataIndex);
  1153 + }
  1154 + break;
  1155 + }
  1156 + default:
  1157 + break;
  1158 + }
  1159 + return true;
  1160 + }
  1161 +
  1162 +
  1163 + bool SimplePolygonSymbol::DrawLegend(clsCrSurf* pClsCS, shared_ptr<legendParamater> pLegendParamater,int layerType, char* pFlag)
  1164 + {
  1165 + if(layerType != 2)
  1166 + return false;
  1167 + pLegendParamater->next(pFlag);
  1168 +
  1169 + cairo_t *cr = pClsCS->m_pCr;
  1170 + clsUtil::DoSetAntialias(m_iAntialiasing, cr);
  1171 +
  1172 + if(pFlag)
  1173 + {
  1174 + cairo_set_source_rgb(cr, 0, 0, 0); //设置画笔颜色,也就是红,绿,蓝,这里设置成绿色。
  1175 + cairo_select_font_face(cr, pLegendParamater->font.c_str(),
  1176 + CAIRO_FONT_SLANT_NORMAL,
  1177 + pLegendParamater->isbold? CAIRO_FONT_WEIGHT_BOLD:CAIRO_FONT_WEIGHT_NORMAL);
  1178 + cairo_set_font_size(cr, pLegendParamater->fontSize);
  1179 + cairo_move_to(cr, pLegendParamater->pixXIndex + pLegendParamater->size_x + 10, pLegendParamater->pixYIndex + pLegendParamater->size_y -3);
  1180 + cairo_show_text(cr, pFlag);
  1181 + }
  1182 +
  1183 + cairo_new_path(cr);
  1184 + cairo_move_to(cr, pLegendParamater->pixXIndex, pLegendParamater->pixYIndex );
  1185 + cairo_line_to(cr, pLegendParamater->pixXIndex, pLegendParamater->pixYIndex + pLegendParamater->size_y);
  1186 + cairo_line_to(cr, pLegendParamater->pixXIndex + pLegendParamater->size_x, pLegendParamater->pixYIndex + pLegendParamater->size_y);
  1187 + cairo_line_to(cr, pLegendParamater->pixXIndex + pLegendParamater->size_x, pLegendParamater->pixYIndex);
  1188 + cairo_close_path(cr);
  1189 +
  1190 + /*
  1191 + 加一块不需要填充的部分
  1192 + */
  1193 + if (!m_bNeedFill)
  1194 + {
  1195 + if (m_bNeedBackground)
  1196 + {
  1197 + cairo_set_source_rgba(cr, r_b, g_b, b_b, a_b);
  1198 + cairo_fill_preserve(cr);
  1199 + }
  1200 +
  1201 + if (m_bBoundary)
  1202 + {
  1203 + clsUtil::DoSetLineType(m_iLineType, cr);
  1204 + cairo_set_source_rgba(cr, r1, g1, b1, a1);
  1205 + cairo_set_line_width(cr, m_dWidth);
  1206 + cairo_set_line_cap(cr, (cairo_line_cap_t)m_iBoundaryCapType);
  1207 + cairo_set_line_join(cr, (cairo_line_join_t)m_iBoundaryJionType);
  1208 + cairo_stroke(cr);
  1209 + }
  1210 + return true;
  1211 + }
  1212 +
  1213 + //cairo_set_source_rgba(cr, 1, 0.5, 0.5, 0.5);
  1214 + //cairo_fill_preserve(cr);
  1215 +
  1216 + /*
  1217 + 接下来是对应各种样式, 填充
  1218 + */
  1219 + cairo_set_fill_rule(cr, CAIRO_FILL_RULE_EVEN_ODD);
  1220 + if (m_Pattern)
  1221 + {
  1222 + cairo_set_source(cr, m_Pattern);
  1223 + }
  1224 + else
  1225 + {
  1226 + //此处需要进一步判断是哪种 纯颜色填充
  1227 + //这里只考虑纯颜色填充的四种填充方式
  1228 + switch (m_iFillType)
  1229 + {
  1230 + case dmapFillTypeSolid:
  1231 + cairo_set_source_rgba(cr, r, g, b, a);
  1232 + break;
  1233 + case dmapFillTypeGray:
  1234 + {
  1235 + //灰色颜色为 169 169 169
  1236 + double r_, g_, b_;
  1237 + r_ = g_ = b_ = ((double)169) / 255;
  1238 + cairo_set_source_rgba(cr, r_, g_, b_, 1.0);
  1239 + break;
  1240 + }
  1241 + case dmapFillTypeLightGray:
  1242 + {
  1243 + //浅灰色颜色为 211 211 211
  1244 + double r_, g_, b_;
  1245 + r_ = g_ = b_ = ((double)211) / 255;
  1246 + cairo_set_source_rgba(cr, r_, g_, b_, 1.0);
  1247 + break;
  1248 + }
  1249 + case dmapFillTypeDarkGray:
  1250 + {
  1251 + //深灰色颜色为 128 128 128
  1252 + double r_, g_, b_;
  1253 + r_ = g_ = b_ = ((double)128) / 255;
  1254 + cairo_set_source_rgba(cr, r_, g_, b_, 1.0);
  1255 + break;
  1256 + }
  1257 + default:
  1258 + return false; // 这里表示已出错
  1259 + break;
  1260 + }
  1261 + }
  1262 + if (m_bBoundary)
  1263 + {
  1264 + //cairo_set_source_rgba(cr, 1, 0.5, 0.5, 0.5);
  1265 + cairo_fill_preserve(cr);
  1266 + clsUtil::DoSetLineType(m_iLineType, cr);
  1267 + cairo_set_source_rgba(cr, r1, g1, b1, a1);
  1268 + cairo_set_line_width(cr, m_dWidth);
  1269 + cairo_set_line_cap(cr, (cairo_line_cap_t)m_iBoundaryCapType);
  1270 + cairo_set_line_join(cr, (cairo_line_join_t)m_iBoundaryJionType);
  1271 + cairo_stroke(cr);
  1272 + }
  1273 + else
  1274 + {
  1275 + cairo_fill(cr);
  1276 + }
  1277 + return true;
  1278 + }
  1279 +}
\ No newline at end of file
... ...
  1 +#pragma once
  2 +#ifndef _SimplePolygonSymbol_H_
  3 +#define _SimplePolygonSymbol_H_
  4 +#include<string>
  5 +
  6 +#include <boost/property_tree/ptree.hpp>
  7 +#include <boost/property_tree/xml_parser.hpp>
  8 +#include <boost/foreach.hpp>
  9 +#include"Renderer.h"
  10 +#include"clsStruct.h"
  11 +#include <math.h>
  12 +using namespace std;
  13 +namespace DmapCore_30
  14 +{
  15 +
  16 + enum PolygonFillType
  17 +{
  18 + dmapFillTypeSolid = 0, //实体填充
  19 + dmapFillTypeBDiagonal = 1, //左下到右上
  20 + dmapFillTypeFDiagonal = 2, //左上到右下
  21 + dmapFillTypeCross = 3, //十字架
  22 + dmapFillTypeDiagCross = 4, //斜十字架
  23 + dmapFillTypeHorizontal = 5, //横线
  24 + dmapFillTypeVertical = 6, //竖线
  25 + dmapFillTypeGray = 7, //灰色
  26 + dmapFillTypeLightGray = 8, //浅灰色
  27 + dmapFillTypeDarkGray = 9, //深灰色
  28 +
  29 + dmapFillTypeIcon = 10, //图片纹理
  30 + dmapFillTypeCharacter = 11 //字体纹理
  31 +};
  32 +
  33 + class clsCrSurf;
  34 + class DataCollection;
  35 + class CORE_EXPORT SimplePolygonSymbol :public Renderer
  36 + {
  37 + public:
  38 + SimplePolygonSymbol();
  39 + ~SimplePolygonSymbol();
  40 + static SimplePolygonSymbol* CreateNew();
  41 + virtual int RendererType();
  42 + virtual bool Parse(boost::property_tree::ptree &pt, AppendBuffer *f);
  43 + virtual bool DrawData(clsCrSurf* pClsCS, DataCollection* data, bool drawSimpleData, char* pFlag = NULL);
  44 + virtual bool DrawData(clsCrSurf* pClsCS, DataCollection* data, int dataIndex, char* pFlag = NULL);
  45 + virtual bool DrawLegend(clsCrSurf* pClsCS, shared_ptr<legendParamater> pLegendParamater,int layerType, char* pFlag = NULL);
  46 + virtual void ToJson(AppendBuffer *ab);
  47 + int m_iAntialiasing;
  48 +
  49 + bool TryFindHeatRenderer(){ return false; }
  50 +
  51 + string m_sPNG;
  52 + string m_sJDPNG;
  53 + double m_dWidth;
  54 + bool m_bBoundary;
  55 + unsigned int m_iBoundaryColor;
  56 + int m_iLineType;
  57 + int m_iFillType;
  58 + int m_iBoundaryCapType;
  59 + int m_iBoundaryJionType;
  60 + long m_lFillInterval;
  61 +
  62 + bool m_bNeedBackground;
  63 + unsigned int m_iBackgroundColor;
  64 +
  65 +
  66 + string m_sFont;
  67 + string m_sFontname;
  68 + char m_sUTF8[5];
  69 + long m_lCharacter;
  70 + long m_iFillsize;
  71 +
  72 +
  73 + bool m_diagalignment;
  74 + bool m_bNeedFill;
  75 + //是否设置填充颜色
  76 + // bool m_bNeedFillTextureColor;
  77 + unsigned int m_iFillColor;
  78 +
  79 + double r, g, b, a;
  80 + double r1, g1, b1, a1;
  81 + double r_b, g_b, b_b, a_b;
  82 +
  83 + cairo_pattern_t* m_Pattern = nullptr;
  84 + /*
  85 + 设置纯颜色填充时,重置为NULL
  86 + */
  87 + clsCrSurf* m_pRepeatSurface; //这个 surface 虽然不直接调用, 但也不能作为局部变量, 因为他必须在 pattern 的整个生命期存在, 他甚至比 Pattern 后销毁
  88 + /*
  89 + 此变量小心维护:
  90 + 1. 只要不是简单的填充颜色, 都是使用 此 pattern平铺
  91 + 2. 初始化为 NULL
  92 + 3. 绘图时, 检测到有 png 字段, 构造 png surface , 只要 surface 长宽都不为0 , 使用 png 填充
  93 + 4. 在设置 Png或者 filltype 时 维护, 绘图时直接调用
  94 + */
  95 +
  96 + //cairo_surface_t* m_pRepeatSurface;
  97 +
  98 +
  99 + bool SetCharacter(long lCharacter);
  100 +
  101 + int GetAntialiasing();
  102 + bool SetAntialiasing(int newVal);
  103 + unsigned int GetColor();
  104 + bool SetColor(unsigned int color);
  105 + int GetLineType();
  106 + bool SetLineType(int type);
  107 + const char* GetPNG();
  108 + bool SetPNG(const char* png);
  109 + double GetWidth();
  110 + bool SetWidth(double width);
  111 + bool GetBoundary();
  112 + bool SetBoundary(bool boundary);
  113 + unsigned int GetBoundaryColor();
  114 + bool SetBoundaryColor(unsigned int boundaryColor);
  115 + /*const char* GetLinePNG();
  116 + bool SetLinePNG(const char* png);*/
  117 + int GetFillType();
  118 + bool SetFillType(int iFillType);
  119 + int GetBoundaryCapType();
  120 + bool SetBoundaryCapType(int iBoundaryCapType);
  121 + int GetBoundaryJionType();
  122 + bool SetBoundaryJionType(int iBoundaryJionType);
  123 + long GetFillInterval();
  124 + bool SetFillInterval(long iFillInterval);
  125 + bool GetNeedFill();
  126 + bool SetNeedFill(bool bNeedFill);
  127 +
  128 +
  129 +
  130 + bool GetRepeatSurface();
  131 + bool SetBackground(cairo_t* cr,double dSurfW,double dSurfH);
  132 +
  133 + bool DrawRING(clsCrSurf* pClsCS, clsStruct::LINE* pRing);
  134 + bool DrawPOLYGON(clsCrSurf* pClsCS, clsStruct::POLYGON* pPolygon);
  135 + bool DrawMPOLYGON(clsCrSurf* pClsCS, clsStruct::MPOLYGON* pMPolygon);
  136 +
  137 + bool DrawTexture(clsCrSurf* pClsCS,clsStruct::MPOLYGON* pMPolygon);
  138 + };
  139 +}
  140 +
  141 +#endif
\ No newline at end of file
... ...
  1 +
  2 +#include "SimpleRenderer.h"
  3 +#include"clsXML.h"
  4 +#include"clsUtil.h"
  5 +
  6 +#include"DataCollection.h"
  7 +#include"SimpleMarkerSymbol.h"
  8 +#include"SimpleLabelRenderer.h"
  9 +#include"SimpleLineSymbol.h"
  10 +#include"SimplePolygonSymbol.h"
  11 +#include"ValueMapRenderer.h"
  12 +//#include"RangeMapRenderer.h"
  13 +#include"GroupRenderer.h"
  14 +namespace DmapCore_30
  15 +{
  16 + SimpleRenderer::SimpleRenderer()
  17 + {
  18 + m_pRen = NULL;
  19 + m_dUpper = 1e308;
  20 + m_dLower = 0;
  21 + m_alwaysShow = true;
  22 + this->m_simpleRenderer = true;
  23 + }
  24 +
  25 +
  26 + SimpleRenderer::~SimpleRenderer()
  27 + {
  28 + if (m_pRen)
  29 + m_pRen->Release();
  30 + }
  31 +
  32 + int SimpleRenderer::RendererType()
  33 + {
  34 + return dmapSimpleRenderer;
  35 + }
  36 +
  37 + bool SimpleRenderer::DrawData(clsCrSurf* pClsCS, DataCollection* data, bool drawSimpleData, char* pFlag)
  38 + {
  39 + double r = data->m_dScaleDenominator;
  40 + //double r = r__ / (3779.52755905);
  41 + if (r <m_dLower || (r > m_dUpper && m_dUpper< 100000000) || m_pRen == 0)
  42 + return false;
  43 + return m_pRen->DrawData(pClsCS, data, pFlag);
  44 + }
  45 +
  46 + bool SimpleRenderer::DrawData(clsCrSurf* pClsCS, DataCollection* data, int dataIndex, char* pFlag)
  47 + {
  48 + double r = data->m_dScaleDenominator;
  49 + //double r = r__ / (3779.52755905);
  50 + if (r <m_dLower || r > m_dUpper || m_pRen == 0)
  51 + return false;
  52 + return m_pRen->DrawData(pClsCS, data, dataIndex, pFlag);
  53 + }
  54 +
  55 + bool SimpleRenderer::Parse(boost::property_tree::ptree &pt, AppendBuffer *f)
  56 + {
  57 + clsXML clsX(f, "SIMPLERENDERER");
  58 + //bool alwaysShow = true; //
  59 + clsXML::XMLAttrParse(pt, f, &m_dUpper, "maxscale");
  60 + clsXML::XMLAttrParse(pt, f, &m_dLower, "minscale");
  61 +
  62 + bool definedAlwaysShow = this->m_dLower == 0 && this->m_dUpper>10000000000;
  63 + clsXML::XMLAttrParse(pt, f, &m_alwaysShow, "alwaysShow",definedAlwaysShow);
  64 +
  65 +
  66 + clsX.closeProperties();
  67 + //if (node)
  68 + {
  69 + //rapidxml::xml_node<char>* node__ = node->first_node();
  70 + for(auto ptchild = pt.begin(); ptchild != pt.end(); ptchild++)
  71 + {
  72 + if(ptchild->first == "<xmlattr>")
  73 + continue;
  74 + clsXML::XMLParse(ptchild->first, ptchild->second, &m_pRen);
  75 + if (m_pRen == 0)
  76 + {
  77 + return false;
  78 + }
  79 + }
  80 +
  81 +
  82 + this->m_simpleRenderer = m_pRen->m_simpleRenderer;
  83 + return true;
  84 + }
  85 + //clsXML::XMLParse(NULL, f, &m_pRen);
  86 +
  87 + if (m_pRen != NULL)
  88 + {
  89 + this->m_simpleRenderer = m_pRen->m_simpleRenderer;
  90 + }
  91 +
  92 +
  93 + return true;
  94 + }
  95 +
  96 + void SimpleRenderer::ToJson(AppendBuffer *ab)
  97 + {
  98 + char buff[600];
  99 + //bool alwaysShow = this->m_dLower == 0 && this->m_dUpper>10000000000;
  100 +
  101 + char buff_maxscale[100];
  102 + char buff_minscale[100];
  103 + if(this->m_dUpper>100000000)
  104 + {
  105 + sprintf(buff_maxscale,"%e", this->m_dUpper);
  106 + }
  107 + else
  108 + {
  109 + sprintf(buff_maxscale,"%.0f", this->m_dUpper);
  110 + }
  111 +
  112 + if(this->m_dLower>100000000)
  113 + {
  114 + sprintf(buff_minscale,"%e", this->m_dLower);
  115 + }
  116 + else
  117 + {
  118 + sprintf(buff_minscale,"%.0f", this->m_dLower);
  119 + }
  120 +
  121 +
  122 + sprintf(buff,R"({"maxscale":"%s", "minscale":"%s", "alwaysShow":"%s" %s )",
  123 + buff_maxscale,
  124 + buff_minscale,
  125 + m_alwaysShow?"true":"false",
  126 + this->m_pRen?",":"");
  127 +
  128 + //strcat(resultbuff,buff);
  129 + ab->AppendString(buff);
  130 + if(this->m_pRen)
  131 + {
  132 + this->m_pRen->ToJson(ab);
  133 + }
  134 + ab->AppendString("}");
  135 + //strcat(resultbuff,"}");
  136 + }
  137 +
  138 + bool SimpleRenderer::DrawLegend(clsCrSurf* pClsCS, shared_ptr<legendParamater> pLegendParamater,int layerType, char* pFlag)
  139 + {
  140 + double r = pLegendParamater->m_dScaleDenominator;
  141 + //double r = r__ / (3779.52755905);
  142 + if (r <m_dLower || (r > m_dUpper && m_dUpper< 100000000) || m_pRen == 0)
  143 + return false;
  144 + return m_pRen->DrawLegend(pClsCS, pLegendParamater,layerType, pFlag);
  145 + }
  146 +
  147 + bool SimpleRenderer::TryFindHeatRenderer()
  148 + {
  149 + if (m_pRen == 0)return false;
  150 + return m_pRen->TryFindHeatRenderer();
  151 + }
  152 +
  153 +
  154 +
  155 + void SimpleRenderer::TryAddField(vector<string>&pvField)
  156 + {
  157 + if (m_pRen == 0)return;
  158 + m_pRen->TryAddField(pvField);
  159 + }
  160 +
  161 + Renderer* SimpleRenderer::GetRenderer()
  162 + {
  163 + if (m_pRen)
  164 + m_pRen->AddRef();
  165 + return m_pRen;
  166 + }
  167 + bool SimpleRenderer::SetRenderer(Renderer* pRen)
  168 + {
  169 + if (!pRen)
  170 + return false;
  171 + pRen->AddRef();
  172 + m_pRen = pRen;
  173 + return true;
  174 + }
  175 +
  176 + double SimpleRenderer::GetUpper()
  177 + {
  178 + return m_dUpper;
  179 + }
  180 + bool SimpleRenderer::SetUpper(double dUpper)
  181 + {
  182 + m_dUpper = dUpper;
  183 + return true;
  184 + }
  185 + double SimpleRenderer::GetLower()
  186 + {
  187 + return m_dLower;
  188 + }
  189 + bool SimpleRenderer::SetLower(double dLower)
  190 + {
  191 + m_dLower = dLower;
  192 + return true;
  193 + }
  194 +}
\ No newline at end of file
... ...
  1 +#pragma once
  2 +#ifndef _SimpleRenderer_H_
  3 +#define _SimpleRenderer_H_
  4 +#include"Renderer.h"
  5 +#include<vector>
  6 +using namespace std;
  7 +namespace DmapCore_30
  8 +{
  9 + class CORE_EXPORT SimpleRenderer :public Renderer
  10 + {
  11 + public:
  12 + SimpleRenderer();
  13 + ~SimpleRenderer();
  14 + virtual int RendererType();
  15 + virtual bool DrawData(clsCrSurf* pClsCS, DataCollection* data, bool drawSimpleData, char* pFlag = NULL);
  16 + virtual bool DrawData(clsCrSurf* pClsCS, DataCollection* data, int dataIndex, char* pFlag = NULL);
  17 + virtual bool DrawLegend(clsCrSurf* pClsCS, shared_ptr<legendParamater> pLegendParamater,int layerType, char* pFlag = NULL);
  18 + virtual bool Parse(boost::property_tree::ptree &pt, AppendBuffer *f);
  19 + virtual void ToJson(AppendBuffer *ab);
  20 + void TryAddField(vector<string>&pvField);
  21 + bool TryFindHeatRenderer();
  22 +
  23 + Renderer* GetRenderer();
  24 + bool SetRenderer(Renderer* pRen);
  25 + double GetUpper();
  26 + bool SetUpper(double dUpper);
  27 + double GetLower();
  28 + bool SetLower(double dLower);
  29 +
  30 + private:
  31 + Renderer* m_pRen;
  32 + double m_dUpper;
  33 + double m_dLower;
  34 + bool m_alwaysShow;
  35 + };
  36 +
  37 +}
  38 +#endif
\ No newline at end of file
... ...
  1 +#include "TextSymbol.h"
  2 +#include"clsCrSurf.h"
  3 +#include"clsXML.h"
  4 +#include"clsUtil.h"
  5 +#include"clsMalloc.h"
  6 +#include "clsJson.h"
  7 +#include <math.h>
  8 +namespace DmapCore_30
  9 +{
  10 + TextSymbol::TextSymbol()
  11 + {
  12 + m_pCrExtents = new cairo_text_extents_t();
  13 + m_sFont = "Sans";
  14 + m_dXdis = 0;
  15 + m_dYdis = 0;
  16 + m_bBackGround = false;
  17 + m_bGlowing = false; //发光
  18 + m_bShadow = false; // 阴影
  19 + m_iAntialiasing = false; //防走样
  20 + m_iSlant = 0; //斜体
  21 + m_iWeight = 0; //加粗
  22 + m_iFontSize = 10; //字体大小
  23 + m_iFontColor = 0xff000000; //字体颜色 默认黑色
  24 + r_font = 0; g_font = 0; b_font = 0; a_font = 1;
  25 + m_iBGColor = 0xffffff00; //背景颜色,默认白色
  26 + r_bg = 1; g_bg = 1; b_bg = 0; a_bg = 1;
  27 + m_iGlowingColor = 0xffff3333; //发光色 默认(1,0.2,0.2,1)(rgba);
  28 + r_glowing = 1; g_glowing = 0.2; b_glowing = 0.2; a_glowing = 1;
  29 + m_iShadowColor = 0xff0000ff; //阴影色 默认蓝色
  30 + r_shadow = 0; g_shadow = 0; b_shadow = 1; a_shadow = 1;
  31 + }
  32 +
  33 +
  34 + TextSymbol::~TextSymbol()
  35 + {
  36 + if (m_pCrExtents)
  37 + delete m_pCrExtents;
  38 + }
  39 + bool TextSymbol::AddRef()
  40 + {
  41 + m_iN++;
  42 + return true;
  43 + }
  44 + bool TextSymbol::Release()
  45 + {
  46 + m_iN--;
  47 + if (m_iN < 0)
  48 + return false;
  49 + if (!m_iN)
  50 + delete this;
  51 + return true;
  52 + }
  53 +
  54 + int TextSymbol::RendererType()
  55 + {
  56 + return dmapTextSymbol;
  57 + }
  58 +
  59 + bool TextSymbol::DrawData(clsCrSurf* pClsCS, DataCollection* data, bool drawSimpleData, char* pFlag)
  60 + {
  61 + return true;
  62 + }
  63 + bool TextSymbol::DrawData(clsCrSurf* pClsCS, DataCollection* data, int dataIndex, char* pFlag)
  64 + {
  65 + return true;
  66 + }
  67 +
  68 + bool TextSymbol::Parse(boost::property_tree::ptree &pt, AppendBuffer *f)
  69 + {
  70 + clsXML clsX(f, "TEXTSYMBOL");
  71 + clsXML::XMLAttrParse(pt, f, &m_sFont, "font");
  72 + clsXML::XMLAttrParse(pt, f, &m_iFontSize, "fontsize");
  73 + clsXML::XMLAttrParseColor(pt, f, &m_iFontColor, "fontcolor", "fonttransparency");
  74 + clsXML::XMLAttrParse(pt, f, &m_dXdis, "x_dis");
  75 + clsXML::XMLAttrParse(pt, f, &m_dYdis, "y_dis");
  76 + clsXML::ParseEnum("antialiasing", pt, f, &m_iAntialiasing, "antialias_default", "antialias_none", "antialias_gray", "antialias_subpixel", "antialias_fase", "antialias_good", "antialias_best", "true", "false");
  77 + clsXML::ParseEnum("slant", pt, f, &m_iSlant, "normal", "italic", "oblique");
  78 + clsXML::ParseEnum("weight", pt, f, &m_iWeight, "normal", "bold");
  79 +
  80 + clsXML::XMLAttrParse(pt, f, &m_bBackGround, "background");
  81 + if (m_bBackGround)
  82 + clsXML::XMLAttrParseColor(pt, f, &m_iBGColor, "bgcolor", "bgtransparency");
  83 + clsXML::XMLAttrParse(pt, f, &m_bGlowing, "glowing");
  84 + if (m_bGlowing)
  85 + clsXML::XMLAttrParseColor(pt, f, &m_iGlowingColor, "glowingcolor", "glowingtransparency");
  86 + clsXML::XMLAttrParse(pt, f, &m_bShadow, "shadow");
  87 + if (m_bShadow)
  88 + clsXML::XMLAttrParseColor(pt, f, &m_iShadowColor, "shadowcolor", "shadowtransparency");
  89 + //if (pt)
  90 + {
  91 + this->SetFontColor(m_iFontColor);
  92 + this->SetBGColor(m_iBGColor);
  93 + this->SetShadowColor(m_iShadowColor);
  94 + this->SetGlowingColor(m_iGlowingColor);
  95 + }
  96 + return true;
  97 + }
  98 +
  99 + void TextSymbol::ToJson(AppendBuffer *ab)
  100 + {
  101 + char buff[300] = {0};
  102 + char resultbuff[5000] ={0};
  103 + sprintf(resultbuff, R"("TEXTSYMBOL":{"antialiasing":"antialias_default",)");
  104 + clsJson::JsonAttrParse("font", resultbuff, buff, this->m_sFont);
  105 + clsJson::JsonAttrParse("fontsize", resultbuff, buff, this->m_iFontSize);
  106 + //
  107 + clsJson::JsonAttrParseColor("fontcolor", "fonttransparency", resultbuff, buff, m_iFontColor);
  108 + clsJson::JsonAttrParse("x_dis", resultbuff, buff, this->m_dXdis);
  109 + clsJson::JsonAttrParse("y_dis", resultbuff, buff, this->m_dYdis);
  110 + //clsJson::ParseEnum("antialiasing", resultbuff, buff, m_iAntialiasing, "antialias_default", "antialias_none", "antialias_gray", "antialias_subpixel", "antialias_fase", "antialias_good", "antialias_best", "true", "false");
  111 + clsJson::ParseEnum("slant", resultbuff, buff, m_iSlant,"normal", "italic", "oblique");
  112 + clsJson::ParseEnum("weight", resultbuff, buff, m_iWeight, "normal", "bold");
  113 + clsJson::JsonAttrParse("background", resultbuff, buff, m_bBackGround);
  114 + if (m_bBackGround)
  115 + clsJson::JsonAttrParseColor("bgcolor", "bgtransparency", resultbuff, buff, m_iBGColor);
  116 +
  117 + clsJson::JsonAttrParse("glowing", resultbuff, buff, m_bGlowing);
  118 + if (m_bGlowing)
  119 + clsJson::JsonAttrParseColor("glowingcolor", "glowingtransparency", resultbuff, buff, m_iBGColor);
  120 +
  121 +
  122 + clsJson::JsonAttrParse("shadow", resultbuff, buff, m_bGlowing);
  123 + if (m_bGlowing)
  124 + clsJson::JsonAttrParseColor("shadowcolor", "shadowtransparency", resultbuff, buff, m_iShadowColor);
  125 +
  126 + clsJson::JsonAttrEnd(resultbuff);
  127 + ab->AppendString(resultbuff);
  128 + }
  129 +
  130 +
  131 + const char* TextSymbol::GetFont()
  132 + {
  133 + return m_sFont.c_str();
  134 + }
  135 + bool TextSymbol::SetFont(const char* sFont)
  136 + {
  137 + m_sFont = sFont;
  138 + return true;
  139 + }
  140 + double TextSymbol::GetXdis()
  141 + {
  142 + return m_dXdis;
  143 + }
  144 + bool TextSymbol::SetXdis(double dXdis)
  145 + {
  146 + m_dXdis = dXdis;
  147 + return true;
  148 + }
  149 + double TextSymbol::GetYdis()
  150 + {
  151 + return m_dYdis;
  152 + }
  153 + bool TextSymbol::SetYdis(double dYdis)
  154 + {
  155 + m_dYdis = dYdis;
  156 + return true;
  157 + }
  158 +
  159 + bool TextSymbol::GetBackGround()
  160 + {
  161 + return m_bBackGround;
  162 + }
  163 + bool TextSymbol::SetBackGround(bool bBackGround)
  164 + {
  165 + m_bBackGround = bBackGround;
  166 + return true;
  167 + }
  168 + bool TextSymbol::GetGlowing()
  169 + {
  170 + return m_bGlowing;
  171 + }
  172 + bool TextSymbol::SetGlowing(bool bGlowing)
  173 + {
  174 + m_bGlowing = bGlowing;
  175 + return true;
  176 + }
  177 + bool TextSymbol::GetShadow()
  178 + {
  179 + return m_bShadow;
  180 + }
  181 + bool TextSymbol::SetShadow(bool bShadow)
  182 + {
  183 + m_bShadow = bShadow;
  184 + return true;
  185 + }
  186 + int TextSymbol::GetAntialiasing()
  187 + {
  188 + return m_iAntialiasing;
  189 + }
  190 + bool TextSymbol::SetAntialiasing(int iAntialiasing)
  191 + {
  192 + m_iAntialiasing = iAntialiasing;
  193 + return true;
  194 + }
  195 +
  196 + int TextSymbol::GetFontSize()
  197 + {
  198 + return m_iFontSize;
  199 + }
  200 + bool TextSymbol::SetFontSize(int iFontSize)
  201 + {
  202 + m_iFontSize = iFontSize;
  203 + return true;
  204 + }
  205 + int TextSymbol::GetSlant()
  206 + {
  207 + return m_iSlant;
  208 + }
  209 + bool TextSymbol::SetSlant(int iSlant)
  210 + {
  211 + m_iSlant = iSlant;
  212 + return true;
  213 + }
  214 + int TextSymbol::GetWeight()
  215 + {
  216 + return m_iWeight;
  217 + }
  218 + bool TextSymbol::SetWeight(int iWeight)
  219 + {
  220 + m_iWeight = iWeight;
  221 + return true;
  222 + }
  223 + unsigned int TextSymbol::GetFontColor()
  224 + {
  225 + return m_iFontColor;
  226 + }
  227 + bool TextSymbol::SetFontColor(unsigned int iColor)
  228 + {
  229 + m_iFontColor = iColor;
  230 + clsUtil::ToCairoColor(iColor, r_font, g_font, b_font, a_font);
  231 + return true;
  232 + }
  233 + unsigned int TextSymbol::GetBGColor()
  234 + {
  235 + return m_iBGColor;
  236 + }
  237 + bool TextSymbol::SetBGColor(unsigned int iColor)
  238 + {
  239 + m_iBGColor = iColor;
  240 + clsUtil::ToCairoColor(iColor, r_bg, g_bg, b_bg, a_bg);
  241 + return true;
  242 + }
  243 + unsigned int TextSymbol::GetGlowingColor()
  244 + {
  245 + return m_iGlowingColor;
  246 + }
  247 + bool TextSymbol::SetGlowingColor(unsigned int iColor)
  248 + {
  249 + m_iGlowingColor = iColor;
  250 + clsUtil::ToCairoColor(iColor, r_glowing, g_glowing, b_glowing, a_glowing);
  251 + return true;
  252 + }
  253 + unsigned int TextSymbol::GetShadowColor()
  254 + {
  255 + return m_iShadowColor;
  256 + }
  257 + bool TextSymbol::SetShadowColor(unsigned int iColor)
  258 + {
  259 + m_iShadowColor = iColor;
  260 + clsUtil::ToCairoColor(iColor, r_shadow, g_shadow, b_shadow, a_shadow);
  261 + return true;
  262 + }
  263 +
  264 +
  265 + bool TextSymbol::SetCairo(clsCrSurf* pClsCS)
  266 + {
  267 + cairo_t* cr = pClsCS->m_pCr;
  268 +
  269 + clsMalloc clsM;
  270 + const char* utf8 = m_sFont.c_str();
  271 +
  272 + /*bool flag = clsUtil::ConvertEncGB18030_UTF8(ss, clsM);
  273 + if (!flag)
  274 + return false;
  275 +
  276 + char* utf8 = clsM.mem;*/
  277 + cairo_select_font_face(cr, utf8, (cairo_font_slant_t)m_iSlant, (cairo_font_weight_t)m_iWeight);
  278 + cairo_set_font_size(cr, m_iFontSize);
  279 +
  280 + return true;
  281 + }
  282 +
  283 +
  284 + bool TextSymbol::DrawAText(clsCrSurf* pClsCS, double x, double y, char* sUTF8)
  285 + {
  286 + x += m_dXdis;
  287 + y += m_dYdis;
  288 + cairo_t* cr = pClsCS->m_pCr;
  289 + //cairo_font_options_set_antialias(cfo, CAIRO_ANTIALIAS_GRAY);
  290 + cairo_text_extents(cr, sUTF8, m_pCrExtents);
  291 + int iX = (int)x; int iY = (int)y;
  292 + int iTextW = (int)(m_pCrExtents->x_advance); int iTextH = (int)(m_pCrExtents->height);
  293 + //int surf_w = pClsCS->m_iW; int surf_h = pClsCS->m_iH;
  294 +
  295 + /*
  296 + 文字避让部分
  297 + */
  298 +
  299 + /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  300 + int xFrom = iX / gridsize;
  301 + int xTo = (iX + iTextW) / gridsize;
  302 + int yTo = iY / gridsize;
  303 + int yFrom = (iY - iTextH) / gridsize;
  304 +
  305 + char * pFlag = pClsCS->m_pFlag;
  306 + int iFlagW = pClsCS->m_iFlagW;
  307 + int iFlagH = pClsCS->m_iFlagH;
  308 + /*if (xFrom < 0 || yFrom < 0 || xTo >= iFlagW || yTo >= iFlagH)
  309 + return false;*/
  310 +
  311 + if (xTo < 0 || xFrom >= iFlagW || yFrom >= iFlagH || yTo < 0)return true;
  312 + if (xFrom < 0)xFrom = 0;
  313 + if (xTo >= iFlagW)xTo = iFlagW - 1;
  314 + if (yFrom < 0)yFrom = 0;
  315 + if (yTo >= iFlagH)yTo = iFlagH - 1;
  316 +
  317 + /*if (xTo < 0)xTo = 0;
  318 + if (xFrom >= iFlagW)xFrom = iFlagW - 1;
  319 + if (yTo < 0)yTo = 0;
  320 + if (yFrom >= iFlagH)yFrom = iFlagH - 1;*/
  321 +
  322 +
  323 + /*
  324 + if (xFrom < 0)xFrom = 0;
  325 + if (xTo > iFlagW) xTo = iFlagW;
  326 + if (xFrom > xTo)
  327 + {
  328 + xFrom = xFrom;
  329 + }
  330 + if (yFrom < 0)yFrom = 0;
  331 + if (yTo > iFlagH) yTo = iFlagH;
  332 + */
  333 +
  334 + char *pFlagThis = pFlag + yFrom*iFlagW;
  335 + for (int i = yFrom; i <= yTo; i++, pFlagThis += iFlagW)
  336 + {
  337 + char *pFlagThisNow = pFlagThis + xFrom;
  338 + for (int j = xFrom; j <= xTo; j++, pFlagThisNow++)
  339 + {
  340 + if (*pFlagThisNow)return false;
  341 + //if (pFlag[iFlagW*i + j]) return false;
  342 + }
  343 + }
  344 + //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  345 +
  346 +
  347 + /*
  348 + 如果有背景,绘制背景
  349 + */
  350 + if (m_bBackGround)
  351 + {
  352 + cairo_new_path(cr);
  353 + cairo_rectangle(cr, x, y - iTextH, iTextW, iTextH);
  354 + cairo_set_source_rgba(cr, r_bg, g_bg, b_bg, a_bg);
  355 + cairo_fill(cr);
  356 + }
  357 +
  358 + /*
  359 + 绘制发光
  360 + */
  361 + if (m_bGlowing)
  362 + {
  363 + int iGlowingSize = 2;
  364 + cairo_set_source_rgba(cr, r_glowing, g_glowing, b_glowing, a_glowing);
  365 + for (int i = -GlowingSize; i <= GlowingSize; i++)
  366 + {
  367 + for (int j = -GlowingSize; j <= GlowingSize; j++)
  368 + {
  369 + cairo_move_to(cr, x + i, y + j);
  370 + cairo_show_text(cr, sUTF8);
  371 + }
  372 + }
  373 + }
  374 +
  375 + /*
  376 + 绘制阴影
  377 + */
  378 + if (m_bShadow)
  379 + {
  380 + cairo_set_source_rgba(cr, r_shadow, g_shadow, b_shadow, a_shadow);
  381 + if (m_bGlowing)
  382 + cairo_move_to(cr, x + ShadowSize + GlowingSize, y + ShadowSize + GlowingSize);
  383 + else
  384 + cairo_move_to(cr, x + ShadowSize, y + ShadowSize);
  385 + cairo_show_text(cr, sUTF8);
  386 + }
  387 +
  388 +
  389 + cairo_set_source_rgba(cr, r_font, g_font, b_font, a_font);
  390 + cairo_move_to(cr, x, y); cairo_show_text(cr, sUTF8);
  391 +
  392 +
  393 + /*
  394 + 标记避让
  395 + */
  396 + ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  397 +
  398 + pFlagThis = pFlag + yFrom*iFlagW;
  399 + for (int i = yFrom; i <= yTo; i++, pFlagThis += iFlagW)
  400 + {
  401 + memset(pFlagThis + xFrom, 1, (xTo - xFrom + 1));
  402 + }
  403 +
  404 + ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  405 +
  406 + return true;
  407 + }
  408 +
  409 +
  410 + bool TextSymbol::DrawAText(clsCrSurf* pClsCS, double x, double y, char* sUTF8, int xp, int yp)
  411 + {
  412 + x += m_dXdis*xp;
  413 + y += m_dYdis*yp;
  414 + cairo_t* cr = pClsCS->m_pCr;
  415 +
  416 + cairo_text_extents(cr, sUTF8, m_pCrExtents);
  417 + int iX = (int)x; int iY = (int)y;
  418 + int iTextW = (int)(m_pCrExtents->x_advance); int iTextH = (int)(m_pCrExtents->height);
  419 + //int surf_w = pClsCS->m_iW; int surf_h = pClsCS->m_iH;
  420 +
  421 + /*
  422 + 文字避让部分
  423 + */
  424 +
  425 + /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  426 + int xFrom = iX / gridsize;
  427 + int xTo = (iX + iTextW) / gridsize;
  428 + int yTo = iY / gridsize;
  429 + int yFrom = (iY - iTextH) / gridsize;
  430 +
  431 + char * pFlag = pClsCS->m_pFlag;
  432 + int iFlagW = pClsCS->m_iFlagW;
  433 + int iFlagH = pClsCS->m_iFlagH;
  434 + /*if (xFrom < 0 || yFrom < 0 || xTo >= iFlagW || yTo >= iFlagH)
  435 + return false;*/
  436 +
  437 + if (xTo < 0 || xFrom >= iFlagW || yFrom >= iFlagH || yTo < 0)return true;
  438 + if (xFrom < 0)xFrom = 0;
  439 + if (xTo >= iFlagW)xTo = iFlagW - 1;
  440 + if (yFrom < 0)yFrom = 0;
  441 + if (yTo >= iFlagH)yTo = iFlagH - 1;
  442 +
  443 + /*if (xTo < 0)xTo = 0;
  444 + if (xFrom >= iFlagW)xFrom = iFlagW - 1;
  445 + if (yTo < 0)yTo = 0;
  446 + if (yFrom >= iFlagH)yFrom = iFlagH - 1;*/
  447 +
  448 +
  449 + /*
  450 + if (xFrom < 0)xFrom = 0;
  451 + if (xTo > iFlagW) xTo = iFlagW;
  452 + if (xFrom > xTo)
  453 + {
  454 + xFrom = xFrom;
  455 + }
  456 + if (yFrom < 0)yFrom = 0;
  457 + if (yTo > iFlagH) yTo = iFlagH;
  458 + */
  459 +
  460 + char *pFlagThis = pFlag + yFrom*iFlagW;
  461 + for (int i = yFrom; i <= yTo; i++, pFlagThis += iFlagW)
  462 + {
  463 + char *pFlagThisNow = pFlagThis + xFrom;
  464 + for (int j = xFrom; j <= xTo; j++, pFlagThisNow++)
  465 + {
  466 + if (*pFlagThisNow)return false;
  467 + //if (pFlag[iFlagW*i + j]) return false;
  468 + }
  469 + }
  470 + //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  471 +
  472 +
  473 + /*
  474 + 如果有背景,绘制背景
  475 + */
  476 + if (m_bBackGround)
  477 + {
  478 + cairo_new_path(cr);
  479 + cairo_rectangle(cr, x, y - iTextH, iTextW, iTextH);
  480 + cairo_set_source_rgba(cr, r_bg, g_bg, b_bg, a_bg);
  481 + cairo_fill(cr);
  482 + }
  483 +
  484 + /*
  485 + 绘制发光
  486 + */
  487 + if (m_bGlowing)
  488 + {
  489 + int iGlowingSize = 2;
  490 + cairo_set_source_rgba(cr, r_glowing, g_glowing, b_glowing, a_glowing);
  491 + for (int i = -GlowingSize; i <= GlowingSize; i++)
  492 + {
  493 + for (int j = -GlowingSize; j <= GlowingSize; j++)
  494 + {
  495 + cairo_move_to(cr, x + i, y + j);
  496 + cairo_show_text(cr, sUTF8);
  497 + }
  498 + }
  499 + }
  500 +
  501 + /*
  502 + 绘制阴影
  503 + */
  504 + if (m_bShadow)
  505 + {
  506 + cairo_set_source_rgba(cr, r_shadow, g_shadow, b_shadow, a_shadow);
  507 + if (m_bGlowing)
  508 + cairo_move_to(cr, x + ShadowSize + GlowingSize, y + ShadowSize + GlowingSize);
  509 + else
  510 + cairo_move_to(cr, x + ShadowSize, y + ShadowSize);
  511 + cairo_show_text(cr, sUTF8);
  512 + }
  513 +
  514 +
  515 + cairo_set_source_rgba(cr, r_font, g_font, b_font, a_font);
  516 + cairo_move_to(cr, x, y); cairo_show_text(cr, sUTF8);
  517 +
  518 +
  519 + /*
  520 + 标记避让
  521 + */
  522 + ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  523 +
  524 + pFlagThis = pFlag + yFrom*iFlagW;
  525 + for (int i = yFrom; i <= yTo; i++, pFlagThis += iFlagW)
  526 + {
  527 + memset(pFlagThis + xFrom, 1, (xTo - xFrom + 1));
  528 + }
  529 +
  530 + ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  531 +
  532 + return true;
  533 + }
  534 +
  535 +
  536 +
  537 + bool TextSymbol::DrawAText(clsCrSurf* pClsCS, double x, double y, char* sUTF8, double dAngle)
  538 + {
  539 + x += m_dXdis;
  540 + y += m_dYdis;
  541 + //顺时针
  542 + if (dAngle == 0)
  543 + return this->DrawAText(pClsCS, x, y, sUTF8);
  544 +
  545 + cairo_t* cr = pClsCS->m_pCr;
  546 +
  547 + cairo_text_extents(cr, sUTF8, m_pCrExtents);
  548 + int iX = (int)x; int iY = (int)y;
  549 + int iTextW = (int)(m_pCrExtents->x_advance); int iTextH = (int)(m_pCrExtents->height);
  550 + int surf_w = pClsCS->m_iW; int surf_h = pClsCS->m_iH;
  551 +
  552 +
  553 +
  554 + /*
  555 + 检查文字避让
  556 + */
  557 + ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  558 + /*
  559 + 假设对图片上任意点(x,y),绕一个坐标点(rx0,ry0)逆时针旋转a角度后的新的坐标设为(x0, y0),有公式:
  560 + x0= (x - rx0)*cos(a) - (y - ry0)*sin(a) + rx0 ;
  561 + y0= (x - rx0)*sin(a) + (y - ry0)*cos(a) + ry0 ;
  562 + */
  563 + int xFrom = iX / gridsize;
  564 + int xTo = (iX + iTextW) / gridsize;
  565 + int yTo = iY / gridsize;
  566 + int yFrom = (iY - iTextH) / gridsize;
  567 +
  568 + char * pFlag = pClsCS->m_pFlag;
  569 + int iFlagW = pClsCS->m_iFlagW;
  570 + int iFlagH = pClsCS->m_iFlagH;
  571 +
  572 + if (xFrom < 0)xFrom = 0;
  573 + if (xTo >= iFlagW) xTo = iFlagW - 1;
  574 + if (yFrom < 0)yFrom = 0;
  575 + if (yTo >= iFlagH) yTo = iFlagH - 1;
  576 +
  577 +
  578 + //选择其实不对
  579 + for (int i = yFrom; i <= yTo; i++)
  580 + {
  581 + for (int j = xFrom; j <= xTo; j++)
  582 + {
  583 + double x_this = j*gridsize;
  584 + double y_this = i*gridsize;
  585 + double x_this_ = (x_this - x)*std::cos(dAngle) - (y_this - y)*std::sin(dAngle) + x;
  586 + double y_this_ = (x_this - x)*std::sin(dAngle) + (y_this - y)*std::cos(dAngle) + y;
  587 + if (x_this_ == x_this_ && y_this_ == y_this_)
  588 + {
  589 + int iXThis = ((int)(x_this_)) / gridsize;
  590 + int iYThis = ((int)(y_this_)) / gridsize;
  591 +
  592 + if (iYThis*iFlagW + iXThis<0 || pFlag[iYThis*iFlagW + iXThis])
  593 + return false;
  594 + }
  595 + else
  596 + {
  597 + return true;
  598 + }
  599 + }
  600 + }
  601 + ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  602 +
  603 +
  604 +
  605 +
  606 + {
  607 + /*
  608 + 如果有背景,绘制背景
  609 + */
  610 + if (m_bBackGround)
  611 + {
  612 + cairo_new_path(cr);
  613 + cairo_move_to(cr, x, y);
  614 + cairo_rotate(cr, dAngle);
  615 + //cairo_rectangle(cr, x, y - iTextH, iTextW, iTextH);
  616 +
  617 + {
  618 + cairo_rel_line_to(cr, iTextW, 0);
  619 + cairo_rel_line_to(cr, 0, -iTextH);
  620 + cairo_rel_line_to(cr, -iTextW, 0);
  621 + cairo_close_path(cr);
  622 + }
  623 + cairo_rotate(cr, -dAngle);
  624 + cairo_set_source_rgba(cr, r_bg, g_bg, b_bg, a_bg);
  625 + cairo_fill(cr);
  626 + }
  627 +
  628 + /*
  629 + 绘制发光
  630 + */
  631 + if (m_bGlowing)
  632 + {
  633 + int iGlowingSize = 2;
  634 + cairo_set_source_rgba(cr, r_glowing, g_glowing, b_glowing, a_glowing);
  635 + for (int i = -GlowingSize; i <= GlowingSize; i++)
  636 + {
  637 + for (int j = -GlowingSize; j <= GlowingSize; j++)
  638 + {
  639 + cairo_move_to(cr, x + i, y + j);
  640 + cairo_rotate(cr, dAngle);
  641 + cairo_show_text(cr, sUTF8);
  642 + cairo_rotate(cr, -dAngle);
  643 + }
  644 + }
  645 + }
  646 +
  647 + /*
  648 + 绘制阴影
  649 + */
  650 + if (m_bShadow)
  651 + {
  652 + int iShadowSize = 2;
  653 + cairo_set_source_rgba(cr, r_shadow, g_shadow, b_shadow, a_shadow);
  654 + if (m_bGlowing)
  655 + cairo_move_to(cr, x + ShadowSize + GlowingSize, y + ShadowSize + GlowingSize);
  656 + else
  657 + cairo_move_to(cr, x + ShadowSize, y + ShadowSize);
  658 + cairo_rotate(cr, dAngle); cairo_show_text(cr, sUTF8); cairo_rotate(cr, -dAngle);
  659 + }
  660 +
  661 +
  662 + cairo_set_source_rgba(cr, r_font, g_font, b_font, a_font);
  663 + cairo_move_to(cr, x, y);
  664 + cairo_rotate(cr, dAngle);
  665 + cairo_show_text(cr, sUTF8);
  666 + cairo_rotate(cr, -dAngle);
  667 +
  668 + /*cairo_set_source_rgba(cr, 1, 0.2, 0.2, 1);
  669 + cairo_set_line_width(cr, 1);
  670 + cairo_move_to(cr, x, y);
  671 + cairo_rotate(cr, dAngle);
  672 + cairo_rel_line_to(cr, iTextW,0);
  673 + cairo_rel_line_to(cr, 0, -iTextH);
  674 + cairo_rel_line_to(cr, -iTextW, 0);
  675 + cairo_close_path(cr);
  676 + cairo_stroke(cr);
  677 + cairo_rotate(cr, -dAngle);*/
  678 + }
  679 +
  680 + /*
  681 + 处理文字避让
  682 + */
  683 + for (int i = yFrom; i <= yTo; i++)
  684 + {
  685 + for (int j = xFrom; j <= xTo; j++)
  686 + {
  687 + double x_this = j*gridsize;
  688 + double y_this = i*gridsize;
  689 + double x_this_ = (x_this - x)*cos(dAngle) - (y_this - y)*sin(dAngle) + x;
  690 + double y_this_ = (x_this - x)*sin(dAngle) + (y_this - y)*cos(dAngle) + y;
  691 + int iXThis = ((int)(x_this_)) / gridsize;
  692 + int iYThis = ((int)(y_this_)) / gridsize;
  693 +
  694 + pFlag[iYThis*iFlagW + iXThis] = 1;
  695 + }
  696 + }
  697 +
  698 + return true;
  699 + }
  700 +
  701 + bool TextSymbol::DrawLegend(clsCrSurf* pClsCS, shared_ptr<legendParamater> pLegendParamater,int layerType, char* pFlag)
  702 + {
  703 +
  704 + return false;
  705 + }
  706 +
  707 +}
  708 +
... ...
  1 +#pragma once
  2 +//#include<cairo/cairo.h>
  3 +#ifndef _TextSymbol_H_
  4 +#define _TextSymbol_H_
  5 +#include<string>
  6 +#ifndef _Renderer_h_
  7 +#define _Renderer_h_
  8 +#include"Renderer.h"
  9 +#endif
  10 +using namespace std;
  11 +#define GlowingSize 1
  12 +#define ShadowSize 2
  13 +namespace DmapCore_30
  14 +{
  15 +
  16 + class clsCrSurf;
  17 + class CORE_EXPORT TextSymbol :public Renderer
  18 + {
  19 + public:
  20 + TextSymbol();
  21 + ~TextSymbol();
  22 + bool AddRef();
  23 + bool Release();
  24 +
  25 + int RendererType();
  26 + bool DrawData(clsCrSurf* pClsCS, DataCollection* data, bool drawSimpleData, char* pFlag = NULL);
  27 + bool DrawData(clsCrSurf* pClsCS, DataCollection* data, int dataIndex, char* pFlag = NULL);
  28 + virtual bool DrawLegend(clsCrSurf* pClsCS, shared_ptr<legendParamater> pLegendParamater, int layerType,char* pFlag = NULL);
  29 + bool Parse(boost::property_tree::ptree &pt, AppendBuffer *f);
  30 + virtual void ToJson(AppendBuffer *ab);
  31 + static bool RendererXmlParse(Renderer**pRen, const char* fileName);
  32 +
  33 + bool TryFindHeatRenderer(){ return false; }
  34 + private:
  35 + int m_iN;
  36 +
  37 + public:
  38 + string m_sFont;
  39 + double m_dXdis;
  40 + double m_dYdis;
  41 + bool m_bBackGround;
  42 + bool m_bGlowing; //发光
  43 + bool m_bShadow; // 阴影
  44 + bool m_iAntialiasing; //防走样
  45 + int m_iSlant; //斜体
  46 + int m_iWeight; //加粗
  47 + long m_iFontSize; //字体大小
  48 + unsigned int m_iFontColor; //字体颜色
  49 + unsigned int m_iBGColor; //背景颜色
  50 + unsigned int m_iGlowingColor; //发光色
  51 + unsigned int m_iShadowColor; //阴影色
  52 +
  53 +
  54 + const char* GetFont();
  55 + bool SetFont(const char* sFont);
  56 + double GetXdis();
  57 + bool SetXdis(double dXdis);
  58 + double GetYdis();
  59 + bool SetYdis(double dYdis);
  60 + bool GetBackGround();
  61 + bool SetBackGround(bool bBackGround);
  62 + bool GetGlowing();
  63 + bool SetGlowing(bool bGlowing);
  64 + bool GetShadow();
  65 + bool SetShadow(bool bShadow);
  66 + int GetAntialiasing();
  67 + bool SetAntialiasing(int iAntialiasing);
  68 +
  69 + int GetFontSize();
  70 + bool SetFontSize(int iFontSize);
  71 + int GetSlant();
  72 + bool SetSlant(int iSlant);
  73 + int GetWeight();
  74 + bool SetWeight(int iWeight);
  75 + unsigned int GetFontColor();
  76 + bool SetFontColor(unsigned int iColor);
  77 + unsigned int GetBGColor();
  78 + bool SetBGColor(unsigned int iColor);
  79 + unsigned int GetGlowingColor();
  80 + bool SetGlowingColor(unsigned int iColor);
  81 + unsigned int GetShadowColor();
  82 + bool SetShadowColor(unsigned int iColor);
  83 +
  84 + /*
  85 + 设置字体,文字大小等固定的一次性设置
  86 + */
  87 + bool SetCairo(clsCrSurf* pClsCS);
  88 +
  89 +
  90 + public:
  91 + double r_font, g_font, b_font, a_font;
  92 + double r_bg, g_bg, b_bg, a_bg;
  93 + double r_glowing, g_glowing, b_glowing, a_glowing;
  94 + double r_shadow, g_shadow, b_shadow, a_shadow;
  95 +
  96 + /*
  97 + Draw部分
  98 + */
  99 + public:
  100 + bool DrawAText(clsCrSurf* pClsCS, double x, double y, char* sUTF8);
  101 + bool DrawAText(clsCrSurf* pClsCS, double x, double y, char* sUTF8, double dAngle); //这个地方不认为在不需要旋转的情况下,旋转角度是0,因为旋转只在点中使用,大部分情况下不需要旋转,认为旋转0度必会影响效率
  102 + bool DrawAText(clsCrSurf* pClsCS, double x, double y, char* sUTF8,int xp,int yp);
  103 + //clsCrSurf* m_pClsCS; //这个是需要绘制文本的surface和cairo
  104 + char* m_pFlag; //这个是文字避让数组
  105 +
  106 + private:
  107 + cairo_text_extents_t* m_pCrExtents; //cairo定义的文本区域结构体
  108 + /*
  109 + 这个变量使用new构造,在类构造函数中创建,在类析构中释放,传入的文本改变时,需要维护
  110 + */
  111 +
  112 +
  113 + /*
  114 + 标签位置
  115 + */
  116 + public:
  117 +
  118 +
  119 + };
  120 +
  121 +
  122 +}
  123 +
  124 +#endif
... ...
  1 +
  2 +#include "TrueTypeMarkerSymbol.h"
  3 +#include"DataCollection.h"
  4 +#include"clsStruct.h"
  5 +#include"clsCrSurf.h"
  6 +#include"clsUtil.h"
  7 +#include"clsXML.h"
  8 +#include "clsJson.h"
  9 +#define _USE_MATH_DEFINES
  10 +#include<math.h>
  11 +#define ShadowSize 1
  12 +#define GlowingSize 1
  13 +
  14 +namespace DmapCore_30
  15 +{
  16 + TrueTypeMarkerSymbol::TrueTypeMarkerSymbol()
  17 + {
  18 + m_pbFlag = (char *)malloc(65536);
  19 + m_dAngle = 0;
  20 + m_sAngleField = "";
  21 + m_iAntialiasing = dmapAntialiasingDefault;
  22 + m_lCharacter = 33;
  23 + {
  24 + memset(m_sUTF8, 0, 5);
  25 + m_sUTF8[0] = 33;
  26 + }
  27 + m_dCharacterXdis = 0;
  28 + m_dCharacterYdis = 0;
  29 + m_sFont = ""; //m_sFont = "Sans";
  30 + m_iFontColor = 0xff000000;
  31 + clsUtil::ToCairoColor(m_iFontColor, r_font, g_font, b_font, a_font);
  32 + m_lFontSize = 20;
  33 + m_bHaveGlowing = false; //
  34 + m_iGlowingColor = 0xffff3333; //默认发光色 r=1,g=0.2,b=0.2
  35 + clsUtil::ToCairoColor(m_iGlowingColor, r_glowing, g_glowing, b_glowing, a_glowing);
  36 + m_bHaveOutline = false; //
  37 + m_iOutline = 0xff00ff00; //边框
  38 + clsUtil::ToCairoColor(m_iOutline, r_outline, g_outline, b_outline, a_outline);
  39 + //m_iRotateMethod = 0; //旋转方式,角度计算方式,使用枚举,具体见esri文档
  40 + m_bHaveShadow = false; //
  41 + m_iShadowColor = 0xff0000ff; //默认阴影蓝色
  42 + clsUtil::ToCairoColor(m_iShadowColor, r_shadow, g_shadow, b_shadow, a_shadow);
  43 + m_iSlant = (int)CAIRO_FONT_SLANT_NORMAL;
  44 + m_iWeight = (int)CAIRO_FONT_WEIGHT_NORMAL;
  45 + m_bHaveUnderLine = false;
  46 + m_bHaveDeleteLine = false;
  47 + m_simpleRenderer = false;
  48 +
  49 + }
  50 +
  51 +
  52 + TrueTypeMarkerSymbol::~TrueTypeMarkerSymbol()
  53 + {
  54 + free(m_pbFlag);
  55 + }
  56 +
  57 + int TrueTypeMarkerSymbol::RendererType()
  58 + {
  59 + return dmapTrueTypeMarkerSymbol;
  60 + }
  61 + bool TrueTypeMarkerSymbol::DrawData(clsCrSurf* pClsCS, DataCollection* data, bool drawSimpleData, char* pFlag)
  62 + {
  63 + this->SetCairo(pClsCS);
  64 + int structType = data->m_iStructType;
  65 + int iPartCount = data->m_iPartCount;
  66 +
  67 + switch (structType)
  68 + {
  69 + case clsStruct::Struct_Point:
  70 + {
  71 + for (int i = 0; i < iPartCount; i++)
  72 + {
  73 + clsStruct::POINT* pPoint = (clsStruct::POINT*)(data->m_pData) + i;
  74 + double x = pPoint->x;
  75 + double y = pPoint->y;
  76 +
  77 +
  78 + x += m_dCharacterXdis;
  79 + y += m_dCharacterYdis;
  80 +
  81 + if (m_sAngleField != "")
  82 + {
  83 + int iFieldIndex = -1;
  84 + int sz = (int)(data->m_vFieldName.size());
  85 + for (int j = 0; j < sz; j++)
  86 + {
  87 + if (m_sAngleField == data->m_vFieldName[j])
  88 + iFieldIndex = j;
  89 + }
  90 + if (iFieldIndex == -1)
  91 + break; //找不到该字段,直接跳出循环
  92 + string sAngle = data->m_vAllField[i][iFieldIndex];
  93 + double dAngle = stod(sAngle.c_str(), NULL);
  94 + this->DrawAText(pClsCS, x, y, dAngle);
  95 + }
  96 + else
  97 + {
  98 + if (m_dAngle == 0)
  99 + this->DrawAText(pClsCS, x, y);
  100 + else
  101 + this->DrawAText(pClsCS, x, y, m_dAngle);
  102 + }
  103 + }
  104 + break;
  105 + }
  106 + case clsStruct::Struct_MLine:
  107 + {
  108 + for (int i = 0; i < iPartCount; i++)
  109 + {
  110 + clsStruct::MLINE* pMLine = (clsStruct::MLINE*)data->m_pData;
  111 + double x, y;
  112 + clsStruct::GetCenter(x, y, pMLine + i);
  113 +
  114 + x += m_dCharacterXdis;
  115 + y += m_dCharacterYdis;
  116 +
  117 +
  118 + ////////////////////////////////////////////////////////////////////////////////////
  119 + if (m_sAngleField != "")
  120 + {
  121 + int iFieldIndex = -1;
  122 + int sz = (int)(data->m_vFieldName.size());
  123 + for (int j = 0; j < sz; j++)
  124 + {
  125 + if (m_sAngleField == data->m_vFieldName[j])
  126 + iFieldIndex = j;
  127 + }
  128 + if (iFieldIndex == -1)
  129 + break; //找不到该字段,直接跳出循环
  130 + string sAngle = data->m_vAllField[i][iFieldIndex];
  131 + double dAngle = stod(sAngle.c_str(), NULL);
  132 + this->DrawAText(pClsCS, x, y, dAngle);
  133 + }
  134 + else
  135 + {
  136 + if (m_dAngle == 0)
  137 + this->DrawAText(pClsCS, x, y);
  138 + else
  139 + this->DrawAText(pClsCS, x, y, m_dAngle);
  140 + }
  141 +
  142 + ////////////////////////////////////////////////////////////////////////////////////////
  143 + }
  144 + break;
  145 + }
  146 + case clsStruct::Struct_MPolygon:
  147 + {
  148 + for (int i = 0; i < iPartCount; i++)
  149 + {
  150 + clsStruct::MPOLYGON* pMPolygon = (clsStruct::MPOLYGON*)data->m_pData;
  151 + double x, y;
  152 + clsStruct::GetCenter(x, y, pMPolygon + i);
  153 +
  154 + x += m_dCharacterXdis;
  155 + y += m_dCharacterYdis;
  156 + ////////////////////////////////////////////////////////////////////////////////////
  157 + if (m_sAngleField != "")
  158 + {
  159 + int iFieldIndex = -1;
  160 + int sz = (int)(data->m_vFieldName.size());
  161 + for (int j = 0; j < sz; j++)
  162 + {
  163 + if (m_sAngleField == data->m_vFieldName[j])
  164 + iFieldIndex = j;
  165 + }
  166 + if (iFieldIndex == -1)
  167 + break; //找不到该字段,直接跳出循环
  168 + string sAngle = data->m_vAllField[i][iFieldIndex];
  169 + double dAngle = stod(sAngle.c_str(), NULL);
  170 + this->DrawAText(pClsCS, x, y, dAngle);
  171 + }
  172 + else
  173 + {
  174 + if (m_dAngle == 0)
  175 + this->DrawAText(pClsCS, x, y);
  176 + else
  177 + this->DrawAText(pClsCS, x, y, m_dAngle);
  178 + }
  179 +
  180 + ////////////////////////////////////////////////////////////////////////////////////////
  181 + }
  182 + break;
  183 + }
  184 + default:
  185 + break;
  186 + }
  187 +
  188 + return true;
  189 + }
  190 +
  191 + bool TrueTypeMarkerSymbol::DrawData(clsCrSurf* pClsCS, DataCollection* data, int dataIndex, char* pFlag)
  192 + {
  193 + this->SetCairo(pClsCS);
  194 + int structType = data->m_iStructType;
  195 + int iPartCount = data->m_iPartCount;
  196 + if (iPartCount <= dataIndex)return false;
  197 + switch (structType)
  198 + {
  199 + case clsStruct::Struct_Point:
  200 + {
  201 + // for (int i = 0; i < iPartCount; i++)
  202 + {
  203 + clsStruct::POINT* pPoint = (clsStruct::POINT*)(data->m_pData) + dataIndex;
  204 + double x = pPoint->x;
  205 + double y = pPoint->y;
  206 +
  207 +
  208 + x += m_dCharacterXdis;
  209 + y += m_dCharacterYdis;
  210 +
  211 + if (m_sAngleField != "")
  212 + {
  213 + int iFieldIndex = -1;
  214 + int sz = (int)(data->m_vFieldName.size());
  215 + for (int j = 0; j < sz; j++)
  216 + {
  217 + if (m_sAngleField == data->m_vFieldName[j])
  218 + iFieldIndex = j;
  219 + }
  220 + if (iFieldIndex == -1)
  221 + break; //找不到该字段,直接跳出循环
  222 + string sAngle = data->m_vAllField[dataIndex][iFieldIndex];
  223 + double dAngle = stod(sAngle.c_str(), NULL);
  224 + this->DrawAText(pClsCS, x, y, dAngle);
  225 + }
  226 + else
  227 + {
  228 + if (m_dAngle == 0)
  229 + this->DrawAText(pClsCS, x, y);
  230 + else
  231 + this->DrawAText(pClsCS, x, y, m_dAngle);
  232 + }
  233 + }
  234 + break;
  235 + }
  236 + case clsStruct::Struct_MLine:
  237 + {
  238 + //for (int i = 0; i < iPartCount; i++)
  239 + {
  240 + clsStruct::MLINE* pMLine = (clsStruct::MLINE*)data->m_pData;
  241 + double x, y;
  242 + clsStruct::GetCenter(x, y, pMLine + dataIndex);
  243 +
  244 + x += m_dCharacterXdis;
  245 + y += m_dCharacterYdis;
  246 +
  247 +
  248 + ////////////////////////////////////////////////////////////////////////////////////
  249 + if (m_sAngleField != "")
  250 + {
  251 + int iFieldIndex = -1;
  252 + int sz = (int)(data->m_vFieldName.size());
  253 + for (int j = 0; j < sz; j++)
  254 + {
  255 + if (m_sAngleField == data->m_vFieldName[j])
  256 + iFieldIndex = j;
  257 + }
  258 + if (iFieldIndex == -1)
  259 + break; //找不到该字段,直接跳出循环
  260 + string sAngle = data->m_vAllField[dataIndex][iFieldIndex];
  261 + double dAngle = stod(sAngle.c_str(), NULL);
  262 + this->DrawAText(pClsCS, x, y, dAngle);
  263 + }
  264 + else
  265 + {
  266 + if (m_dAngle == 0)
  267 + this->DrawAText(pClsCS, x, y);
  268 + else
  269 + this->DrawAText(pClsCS, x, y, m_dAngle);
  270 + }
  271 +
  272 + ////////////////////////////////////////////////////////////////////////////////////////
  273 + }
  274 + break;
  275 + }
  276 + case clsStruct::Struct_MPolygon:
  277 + {
  278 + // for (int i = 0; i < iPartCount; i++)
  279 + {
  280 + clsStruct::MPOLYGON* pMPolygon = (clsStruct::MPOLYGON*)data->m_pData;
  281 + double x, y;
  282 + clsStruct::GetCenter(x, y, pMPolygon + dataIndex);
  283 +
  284 + x += m_dCharacterXdis;
  285 + y += m_dCharacterYdis;
  286 + ////////////////////////////////////////////////////////////////////////////////////
  287 + if (m_sAngleField != "")
  288 + {
  289 + int iFieldIndex = -1;
  290 + int sz = (int)(data->m_vFieldName.size());
  291 + for (int j = 0; j < sz; j++)
  292 + {
  293 + if (m_sAngleField == data->m_vFieldName[j])
  294 + iFieldIndex = j;
  295 + }
  296 + if (iFieldIndex == -1)
  297 + break; //找不到该字段,直接跳出循环
  298 + string sAngle = data->m_vAllField[dataIndex][iFieldIndex];
  299 + double dAngle = stod(sAngle.c_str(), NULL);
  300 + this->DrawAText(pClsCS, x, y, dAngle);
  301 + }
  302 + else
  303 + {
  304 + if (m_dAngle == 0)
  305 + this->DrawAText(pClsCS, x, y);
  306 + else
  307 + this->DrawAText(pClsCS, x, y, m_dAngle);
  308 + }
  309 +
  310 + ////////////////////////////////////////////////////////////////////////////////////////
  311 + }
  312 + break;
  313 + }
  314 + default:
  315 + break;
  316 + }
  317 +
  318 + return true;
  319 + }
  320 +
  321 + bool TrueTypeMarkerSymbol::DrawLegend(clsCrSurf* pClsCS, shared_ptr<legendParamater> pLegendParamater,
  322 + int layerType, char* pFlag)
  323 + {
  324 + if(layerType != 0)
  325 + return false;
  326 + pLegendParamater->next(pFlag);
  327 + cairo_t *cr = pClsCS->m_pCr;
  328 + if(pFlag)
  329 + {
  330 + cairo_set_source_rgb(cr, 0, 0, 0); //设置画笔颜色,也就是红,绿,蓝,这里设置成绿色。
  331 + cairo_select_font_face(cr, pLegendParamater->font.c_str(),
  332 + CAIRO_FONT_SLANT_NORMAL,
  333 + pLegendParamater->isbold? CAIRO_FONT_WEIGHT_BOLD:CAIRO_FONT_WEIGHT_NORMAL);
  334 + cairo_set_font_size(cr, pLegendParamater->fontSize);
  335 + cairo_move_to(cr, pLegendParamater->pixXIndex + pLegendParamater->size_x + 10,
  336 + pLegendParamater->pixYIndex + pLegendParamater->size_y -3);
  337 + cairo_show_text(cr, pFlag);
  338 + }
  339 + double x = pLegendParamater->pixXIndex + pLegendParamater->size_x/2;
  340 + double y = pLegendParamater->pixYIndex + pLegendParamater->size_y/2;
  341 +
  342 + x += m_dCharacterXdis;
  343 + y += m_dCharacterYdis;
  344 +
  345 + this->SetCairo(pClsCS);
  346 + this->DrawAText(pClsCS, x, y);
  347 +
  348 + return false;
  349 + }
  350 +
  351 +
  352 + bool TrueTypeMarkerSymbol::Parse(boost::property_tree::ptree &pt, AppendBuffer *f)
  353 + {
  354 + clsXML clsX(f, "TRUETYPEMARKERSYMBOL");
  355 + clsXML::XMLAttrParse(pt, f, &m_dAngle, "angle");
  356 + clsXML::XMLAttrParse(pt, f, &m_sAngleField, "anglefield");
  357 + clsXML::ParseEnum("antialiasing", pt, f, &m_iAntialiasing, "default", "none", "gray", "subpixel", "fast", "good", "best", "true", "false");
  358 +
  359 +
  360 + clsXML::XMLAttrParse(pt, f, &m_lCharacter, "character");
  361 + //if (pt)
  362 + {
  363 + this->SetCharacter(m_lCharacter);
  364 + }
  365 + clsXML::XMLAttrParse(pt, f, &m_dCharacterXdis, "characterxdis");
  366 + clsXML::XMLAttrParse(pt, f, &m_dCharacterYdis, "characterydis");
  367 + clsXML::XMLAttrParse(pt, f, &m_sFont, "font");
  368 + clsXML::XMLAttrParseColor(pt, f, &m_iFontColor, "fontcolor");
  369 + clsXML::XMLAttrParse(pt, f, &m_lFontSize, "fontsize");
  370 + clsXML::XMLAttrParse(pt, f, &m_bHaveGlowing, "haveglowing");
  371 + clsXML::XMLAttrParse(pt, f, &m_fontname, "fontname");
  372 +
  373 + if (m_bHaveGlowing)clsXML::XMLAttrParseColor(pt, f, &m_iGlowingColor, "glowingcolor");
  374 + clsXML::XMLAttrParse(pt, f, &m_bHaveOutline, "haveoutline");
  375 + if (m_bHaveOutline) clsXML::XMLAttrParseColor(pt, f, &m_iOutline, "outline");
  376 + //clsXML::ParseEnum("rotatemethod", pt, f, &m_iRotateMethod, "geographic","arithmetic","mod_arithmetic");
  377 + clsXML::XMLAttrParse(pt, f, &m_bHaveShadow, "haveshashow");
  378 + if (m_bHaveShadow)clsXML::XMLAttrParseColor(pt, f, &m_iShadowColor, "shashowcolor");
  379 + clsXML::ParseEnum("slant", pt, f, &m_iSlant, "normal", "italic", "oblique");
  380 + clsXML::ParseEnum("weight", pt, f, &m_iWeight, "normal", "bold");
  381 + clsXML::XMLAttrParse(pt, f, &m_bHaveUnderLine, "haveunderline");
  382 + clsXML::XMLAttrParse(pt, f, &m_bHaveDeleteLine, "havedeleteline");
  383 +
  384 + return true;
  385 + }
  386 +
  387 + void TrueTypeMarkerSymbol::ToJson(AppendBuffer *ab)
  388 + {
  389 + char buff[300] = {0};
  390 + char resultbuff[5000] = {0};
  391 + strcat(resultbuff, R"("TRUETYPEMARKERSYMBOL":{"antialiasing":"antialias_default",)");
  392 + clsJson::JsonAttrParse("angle", resultbuff, buff, m_dAngle);
  393 + clsJson::JsonAttrParse("anglefield", resultbuff, buff, m_sAngleField);
  394 + clsJson::ParseEnum("antialiasing", resultbuff, buff, m_iAntialiasing,"default", "none", "gray", "subpixel", "fast", "good", "best", "true", "false");
  395 + clsJson::JsonAttrParse("character", resultbuff, buff, m_lCharacter);
  396 + clsJson::JsonAttrParseColor("fontcolor", "fonttransparency", resultbuff, buff, m_iFontColor);
  397 +
  398 + clsJson::JsonAttrParse("fontname",resultbuff,buff,m_fontname);
  399 + clsJson::JsonAttrParse("characterxdis", resultbuff, buff, m_dCharacterXdis);
  400 + clsJson::JsonAttrParse("characterydis", resultbuff, buff, m_dCharacterYdis);
  401 + clsJson::JsonAttrParse("font", resultbuff, buff, m_sFont);
  402 + clsJson::JsonAttrParseColor("glowingcolor", "glowingtransparency", resultbuff, buff, m_iFontColor);
  403 + clsJson::JsonAttrParse("fontsize", resultbuff, buff, m_lFontSize);
  404 +
  405 + clsJson::JsonAttrParse("haveglowing", resultbuff, buff, m_bHaveGlowing);
  406 + if (m_bHaveGlowing)
  407 + {
  408 + clsJson::JsonAttrParseColor("haveglowing", "fonttransparency", resultbuff, buff, m_iGlowingColor);
  409 + }
  410 + clsJson::JsonAttrParse("haveglowing", resultbuff, buff, m_bHaveGlowing);
  411 + //if (m_iOutline)
  412 + //{
  413 + // clsJson::JsonAttrParse("outline", resultbuff, buff, (long)m_iOutline);
  414 + //}
  415 +
  416 + //clsXML::ParseEnum("rotatemethod", node, f, &m_iRotateMethod, "geographic","arithmetic","mod_arithmetic");
  417 + //clsXML::XMLAttrParse(node, f, &m_bHaveShadow, "haveshashow");
  418 + //if (m_bHaveShadow)clsXML::XMLAttrParseColor(node, f, &m_iShadowColor, "shashowcolor");
  419 +
  420 + clsJson::ParseEnum("linetype", resultbuff, buff, m_iSlant,"normal", "italic", "oblique");
  421 + clsJson::ParseEnum("linetype", resultbuff, buff, m_iWeight,"normal", "bold");
  422 + clsJson::JsonAttrParse("haveunderline", resultbuff, buff, m_bHaveUnderLine);
  423 + clsJson::JsonAttrParse("havedeleteline", resultbuff, buff, m_bHaveDeleteLine);
  424 +
  425 +
  426 + clsJson::JsonAttrEnd(resultbuff);
  427 + ab->AppendString(resultbuff);
  428 + }
  429 +
  430 + double TrueTypeMarkerSymbol::GetAngle()
  431 + {
  432 + return m_dAngle / M_PI * 180;
  433 + }
  434 + bool TrueTypeMarkerSymbol::SetAngle(double dAngle)
  435 + {
  436 + m_dAngle = dAngle / 180 * M_PI;
  437 + return true;
  438 + }
  439 + const char* TrueTypeMarkerSymbol::GetAngleField()
  440 + {
  441 + return m_sAngleField.c_str();
  442 + }
  443 + bool TrueTypeMarkerSymbol::SetAngleField(const char* sAngleField)
  444 + {
  445 + m_sAngleField = sAngleField;
  446 + return true;
  447 + }
  448 + int TrueTypeMarkerSymbol::GetAntialiasing()
  449 + {
  450 + return m_iAntialiasing;
  451 + }
  452 + bool TrueTypeMarkerSymbol::SetAntialiasing(int iAntialiasing)
  453 + {
  454 + m_iAntialiasing = iAntialiasing;
  455 + return true;
  456 + }
  457 + long TrueTypeMarkerSymbol::GetCharacter()
  458 + {
  459 + return m_lCharacter;
  460 + }
  461 + bool TrueTypeMarkerSymbol::SetCharacter(long lCharacter)
  462 + {
  463 + m_lCharacter = lCharacter;
  464 + memset(m_sUTF8, 0, 5);
  465 + if (lCharacter < 256)
  466 + {
  467 + m_sUTF8[0] = ((char*)(&lCharacter))[0];
  468 + }
  469 + else
  470 + {
  471 + m_sUTF8[0] = ((char*)(&m_lCharacter))[1];
  472 + m_sUTF8[1] = ((char*)(&m_lCharacter))[0];
  473 + }
  474 + return true;
  475 + }
  476 + bool TrueTypeMarkerSymbol::GetCharacterDis(double* pdXdis, double* pdYdis)
  477 + {
  478 + *pdXdis = m_dCharacterXdis;
  479 + *pdYdis = m_dCharacterYdis;
  480 + return true;
  481 + }
  482 + bool TrueTypeMarkerSymbol::SetCharacterDis(double dXDis, double dYDis)
  483 + {
  484 + m_dCharacterXdis = dXDis;
  485 + m_dCharacterYdis = dYDis;
  486 + return true;
  487 + }
  488 + const char* TrueTypeMarkerSymbol::GetFont()
  489 + {
  490 + return m_sFont.c_str();
  491 + }
  492 + bool TrueTypeMarkerSymbol::SetFont(const char* sFont)
  493 + {
  494 + m_sFont = sFont;
  495 + return true;
  496 + }
  497 + unsigned int TrueTypeMarkerSymbol::GetFontColor()
  498 + {
  499 + return m_iFontColor;
  500 + }
  501 + bool TrueTypeMarkerSymbol::SetFontColor(unsigned int iFontColor)
  502 + {
  503 + m_iFontColor = iFontColor;
  504 + clsUtil::ToCairoColor(m_iFontColor, r_font, g_font, b_font, a_font);
  505 + return true;
  506 + }
  507 + long TrueTypeMarkerSymbol::GetFontSize()
  508 + {
  509 + return m_lFontSize;
  510 + }
  511 + bool TrueTypeMarkerSymbol::SetFontSize(long lFontSize)
  512 + {
  513 + m_lFontSize = lFontSize;
  514 + return true;
  515 + }
  516 + bool TrueTypeMarkerSymbol::GetGlowing(bool* pbHaveGlowing, unsigned int * piGlowingColor)
  517 + {
  518 + *pbHaveGlowing = m_bHaveGlowing;
  519 + *piGlowingColor = m_iGlowingColor;
  520 + return true;
  521 + }
  522 + bool TrueTypeMarkerSymbol::SetGlowingColor(bool bHaveGlowing, unsigned int iGlowingColor)
  523 + {
  524 + m_bHaveGlowing = bHaveGlowing;
  525 + m_iGlowingColor = iGlowingColor;
  526 + if (m_bHaveGlowing)
  527 + clsUtil::ToCairoColor(m_iGlowingColor, r_glowing, g_glowing, b_glowing, a_glowing);
  528 + return true;
  529 + }
  530 + //int TrueTypeMarkerSymbol::GetRotateMethod()
  531 + //{
  532 + // return m_iRotateMethod;
  533 + //}
  534 + //bool TrueTypeMarkerSymbol::SetRotateMethod(int iRotateMethod)
  535 + //{
  536 + // m_iRotateMethod = iRotateMethod;
  537 + // return true;
  538 + //}
  539 + bool TrueTypeMarkerSymbol::GetShadow(bool* pbHaveShadow, unsigned int* piShadowColor)
  540 + {
  541 + *pbHaveShadow = m_bHaveShadow;
  542 + *piShadowColor = m_iShadowColor;
  543 + return true;
  544 + }
  545 + bool TrueTypeMarkerSymbol::SetShadow(bool bHaveShadow, unsigned int iShadhowColor)
  546 + {
  547 + m_bHaveShadow = bHaveShadow;
  548 + m_iShadowColor = iShadhowColor;
  549 + if (m_bHaveShadow)
  550 + clsUtil::ToCairoColor(m_iShadowColor, r_shadow, g_shadow, b_shadow, a_shadow);
  551 + return true;
  552 + }
  553 + int TrueTypeMarkerSymbol::GetSlant()
  554 + {
  555 + return m_iSlant;
  556 + }
  557 + bool TrueTypeMarkerSymbol::SetSlant(int iSlant)
  558 + {
  559 + m_iSlant = iSlant;
  560 + return true;
  561 + }
  562 + int TrueTypeMarkerSymbol::GetWeight()
  563 + {
  564 + return m_iWeight;
  565 + }
  566 + bool TrueTypeMarkerSymbol::SetWeight(int iWeight)
  567 + {
  568 + m_iWeight = iWeight;
  569 + return true;
  570 + }
  571 + bool TrueTypeMarkerSymbol::GetHaveUnderLine()
  572 + {
  573 + return m_bHaveUnderLine;
  574 + return true;
  575 + }
  576 + bool TrueTypeMarkerSymbol::SetHaveUnderLine(bool bHaveUnderLine)
  577 + {
  578 + m_bHaveUnderLine = bHaveUnderLine;
  579 + return true;
  580 + }
  581 + bool TrueTypeMarkerSymbol::GetHaveDeleteLine()
  582 + {
  583 + return m_bHaveDeleteLine;
  584 + }
  585 + bool TrueTypeMarkerSymbol::SetHaveDeleteLine(bool bHaveDeleteLine)
  586 + {
  587 + m_bHaveDeleteLine = bHaveDeleteLine;
  588 + return true;
  589 + }
  590 +
  591 +
  592 + void TrueTypeMarkerSymbol::TryAddField(vector<string>&pvField)
  593 + {
  594 + TryAddField2(pvField, m_sAngleField);
  595 + }
  596 +
  597 + int TrueTypeMarkerSymbol::CalculateFontCount()
  598 + {
  599 + m_viFontCharacter.clear();
  600 +
  601 + cairo_surface_t* surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, 10, 10);
  602 + cairo_t* cr = cairo_create(surface);
  603 +
  604 + cairo_set_source_rgba(cr, 0, 0, 0, 1);
  605 + cairo_select_font_face(cr, m_sFont.c_str(), CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL);
  606 + cairo_set_font_size(cr, 8);
  607 +
  608 + unsigned char* buffer = cairo_image_surface_get_data(surface);
  609 + int ls = cairo_format_stride_for_width(CAIRO_FORMAT_ARGB32, 10);
  610 +
  611 +
  612 + for (int iWord = 0; iWord < 65536; iWord++)
  613 + {
  614 + char s_[5];
  615 + memset(s_, 0, 5);
  616 + if (iWord < 256)
  617 + s_[0] = iWord;
  618 + else
  619 + {
  620 + s_[0] = ((char*)(&iWord))[1];
  621 + s_[1] = iWord;
  622 + }
  623 +
  624 + cairo_move_to(cr, 0, 10);
  625 + cairo_show_text(cr, s_);
  626 +
  627 + bool bIsValid = false;
  628 + for (int i = 0; i < 10; i++)
  629 + {
  630 + for (int j = 0; j < 10; j++)
  631 + {
  632 + int color = ((int*)(buffer + (4 * 10 * i + 4 * j)))[0];
  633 + if (color)
  634 + {
  635 + bIsValid = true;
  636 + break;
  637 + }
  638 + }
  639 + if (bIsValid)
  640 + break;
  641 + }
  642 +
  643 + if (bIsValid)
  644 + {
  645 + m_viFontCharacter.push_back(iWord);
  646 + m_pbFlag[iWord] = true;
  647 + memset(buffer, 0, 400);
  648 + }
  649 + else
  650 + m_pbFlag[iWord] = false;
  651 + }
  652 +
  653 + cairo_destroy(cr);
  654 + cairo_surface_destroy(surface);
  655 +
  656 + int iCount = (int)(m_viFontCharacter.size());
  657 + return iCount;
  658 + }
  659 +/*
  660 + bool TrueTypeMarkerSymbol::DrawFont(Map* map, int iPerSize)
  661 + {
  662 + clsCrSurf* pClsCS = map->m_pClsSurfBuff;
  663 +
  664 + cairo_t* cr = pClsCS->m_pCr;
  665 + int iW = pClsCS->m_iW;
  666 + int iColumnCount = iW / iPerSize;
  667 + int sz = (int)m_viFontCharacter.size();
  668 + int iLineCount = sz / iColumnCount;
  669 + if (sz != iLineCount*iColumnCount)
  670 + iLineCount++;
  671 + int iH = iLineCount* iPerSize;
  672 + cairo_set_source_rgba(cr, 1, 1, 1, 1);
  673 + cairo_rectangle(cr, 0, 0, iW, iH);
  674 + cairo_fill(cr);
  675 +
  676 + cairo_select_font_face(cr, m_sFont.c_str(), CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL);
  677 + //m_sFont 是否要转字符集
  678 + cairo_set_font_size(cr, iPerSize);
  679 + cairo_set_source_rgba(cr, 0, 0, 0, 1);
  680 +
  681 +
  682 + unsigned char* buffer = cairo_image_surface_get_data(pClsCS->m_pSurf);
  683 +
  684 + int iColumnIndex = 0, iLineIndex = 0;
  685 +
  686 + for (int iWord = 0; iWord < 65536; iWord++)
  687 + {
  688 + if (m_pbFlag[iWord])
  689 + {
  690 + char s_[5];
  691 + memset(s_, 0, 5);
  692 + if (iWord < 256)
  693 + s_[0] = iWord;
  694 + else
  695 + {
  696 + s_[0] = ((char*)(&iWord))[1];
  697 + s_[1] = iWord;
  698 + }
  699 + cairo_text_extents_t extents;
  700 + cairo_text_extents(cr, s_, &extents);
  701 + double dw = extents.width;
  702 + double dh = extents.height;
  703 +
  704 + double x_center = iColumnIndex * iPerSize + iPerSize / 2.0;
  705 + double y_center = iLineIndex* iPerSize + iPerSize / 2.0;
  706 + double x_show = 0, y_show = 0;
  707 + this->GetToBeCenter(x_show, y_show, &extents, x_center, y_center);
  708 +
  709 + cairo_move_to(cr, x_show, y_show);
  710 + //cairo_move_to(cr, iColumnIndex*iPerSize + (iPerSize-dw)/2,(iLineIndex+1)*iPerSize - (iPerSize- dh)/2);
  711 + cairo_show_text(cr, s_);
  712 + iColumnIndex++;
  713 + }
  714 +
  715 + if (iColumnIndex >= iColumnCount)
  716 + {
  717 + iColumnIndex = 0;
  718 + iLineIndex++;
  719 + }
  720 + }
  721 +
  722 +
  723 + cairo_set_line_width(cr, 1);
  724 + cairo_set_source_rgba(cr, 0, 0, 0, 1);
  725 + for (int i = 0; i <= iColumnCount; i++)
  726 + {
  727 + cairo_move_to(cr, iPerSize*i, 0);
  728 + cairo_line_to(cr, iPerSize*i, iH);
  729 + }
  730 + for (int i = 0; i <= iLineCount; i++)
  731 + {
  732 + cairo_move_to(cr, 0, iPerSize*i);
  733 + cairo_line_to(cr, iW, iPerSize*i);
  734 + }
  735 + cairo_stroke(cr);
  736 +
  737 + map->BufferCopy();
  738 +
  739 + return true;
  740 + }
  741 +
  742 + bool TrueTypeMarkerSymbol::DrawFont(Map* map, int iPerSize, int iCharacter, double* x, double * y)
  743 + {
  744 + clsCrSurf* pClsCS = map->m_pClsSurfBuff;
  745 +
  746 + cairo_t* cr = pClsCS->m_pCr;
  747 + int iW = pClsCS->m_iW;
  748 + int iColumnCount = iW / iPerSize;
  749 + int sz = (int)m_viFontCharacter.size();
  750 + int iLineCount = sz / iColumnCount;
  751 + if (sz != iLineCount*iColumnCount)
  752 + iLineCount++;
  753 + int iH = iLineCount* iPerSize;
  754 + cairo_set_source_rgba(cr, 1, 1, 1, 1);
  755 + cairo_rectangle(cr, 0, 0, iW, iH);
  756 + cairo_fill(cr);
  757 +
  758 + cairo_select_font_face(cr, m_sFont.c_str(), CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL);
  759 + //需要转字符集?
  760 + cairo_set_font_size(cr, iPerSize);
  761 + cairo_set_source_rgba(cr, 0, 0, 0, 1);
  762 +
  763 +
  764 + unsigned char* buffer = cairo_image_surface_get_data(pClsCS->m_pSurf);
  765 +
  766 + int iColumnIndex = 0, iLineIndex = 0;
  767 +
  768 + for (int iWord = 0; iWord < 65536; iWord++)
  769 + {
  770 + if (m_pbFlag[iWord])
  771 + {
  772 + char s_[5];
  773 + memset(s_, 0, 5);
  774 + if (iWord < 256)
  775 + s_[0] = iWord;
  776 + else
  777 + {
  778 + s_[0] = ((char*)(&iWord))[1];
  779 + s_[1] = iWord;
  780 + }
  781 + cairo_text_extents_t extents;
  782 + cairo_text_extents(cr, s_, &extents);
  783 + double dw = extents.width;
  784 + double dh = extents.height;
  785 + double x_center = iColumnIndex * iPerSize + iPerSize / 2.0;
  786 + double y_center = iLineIndex* iPerSize + iPerSize / 2.0;
  787 + double x_show = 0, y_show = 0;
  788 + this->GetToBeCenter(x_show, y_show, &extents, x_center, y_center);
  789 +
  790 + if (iWord == iCharacter)
  791 + {
  792 + cairo_set_source_rgba(cr, 17.0 / 255, 150.0 / 255, 238.0 / 255, 1);
  793 + cairo_rectangle(cr, iColumnIndex*iPerSize, iLineIndex*iPerSize, iPerSize, iPerSize);
  794 + cairo_fill(cr);
  795 + cairo_set_source_rgba(cr, 1, 1, 1, 1);
  796 + *x = iColumnIndex*iPerSize;
  797 + *y = (iLineIndex + 1)* iPerSize;
  798 +
  799 +
  800 + cairo_move_to(cr, x_show, y_show);
  801 + //cairo_move_to(cr, iColumnIndex*iPerSize + (iPerSize - dw) / 2, (iLineIndex + 1)*iPerSize - (iPerSize - dh) / 2);
  802 + cairo_show_text(cr, s_);
  803 + iColumnIndex++;
  804 + }
  805 + else
  806 + {
  807 + cairo_set_source_rgba(cr, 0, 0, 0, 1);
  808 + cairo_move_to(cr, x_show, y_show);
  809 + //cairo_move_to(cr, iColumnIndex*iPerSize + (iPerSize - dw) / 2, (iLineIndex + 1)*iPerSize - (iPerSize - dh) / 2);
  810 + cairo_show_text(cr, s_);
  811 + iColumnIndex++;
  812 + }
  813 + }
  814 +
  815 + if (iColumnIndex >= iColumnCount)
  816 + {
  817 + iColumnIndex = 0;
  818 + iLineIndex++;
  819 + }
  820 + }
  821 +
  822 +
  823 + cairo_set_line_width(cr, 1);
  824 + cairo_set_source_rgba(cr, 0, 0, 0, 1);
  825 + for (int i = 0; i <= iColumnCount; i++)
  826 + {
  827 + cairo_move_to(cr, iPerSize*i, 0);
  828 + cairo_line_to(cr, iPerSize*i, iH);
  829 + }
  830 + for (int i = 0; i <= iLineCount; i++)
  831 + {
  832 + cairo_move_to(cr, 0, iPerSize*i);
  833 + cairo_line_to(cr, iW, iPerSize*i);
  834 + }
  835 + cairo_stroke(cr);
  836 +
  837 + map->BufferCopy();
  838 + return true;
  839 + }
  840 +
  841 + int TrueTypeMarkerSymbol::DrawAFont(double x, double y, Map* map_temp, Map* map, int iPerSize)
  842 + {
  843 + clsCrSurf* pClsCS = map->m_pClsSurfBuff;
  844 + int iW = pClsCS->m_iW;
  845 + int iColumnCount = iW / iPerSize;
  846 + int iLineIndex = (int)(y / iPerSize);
  847 + int iColumnIndex = (int)(x / iPerSize);
  848 + int iCharacterIndex = iColumnCount*iLineIndex + iColumnIndex; int iCharacterSize = (int)m_viFontCharacter.size();
  849 + if (iCharacterIndex >= iCharacterSize)
  850 + return -1;
  851 +
  852 + int iWord = m_viFontCharacter[iColumnCount* iLineIndex + iColumnIndex];
  853 +
  854 + char s_[5];
  855 + memset(s_, 0, 5);
  856 + if (iWord < 256)
  857 + s_[0] = iWord;
  858 + else
  859 + {
  860 + s_[0] = ((char*)(&iWord))[1];
  861 + s_[1] = iWord;
  862 + }
  863 +
  864 + int maptemp_w = (int)(map_temp->m_dWidth); // 视为正方形
  865 + int maptemp_h = maptemp_w;
  866 +
  867 + clsCrSurf* pClsCS_temp = map_temp->m_pClsSurfBuff;
  868 + cairo_t* cr = pClsCS_temp->m_pCr;
  869 + cairo_rectangle(cr, 0, 0, maptemp_w, maptemp_h);
  870 + cairo_set_source_rgba(cr, 17.0 / 255, 150.0 / 255, 238.0 / 255, 1);
  871 + cairo_fill(cr);
  872 + cairo_select_font_face(cr, m_sFont.c_str(), CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL);
  873 + cairo_set_source_rgba(cr, 1, 1, 1, 1);
  874 + cairo_set_font_size(cr, maptemp_w);
  875 + cairo_text_extents_t extents;
  876 +
  877 + cairo_text_extents(cr, s_, &extents);
  878 + double text_w = extents.width;
  879 + double text_h = extents.height;
  880 +
  881 +
  882 + double x_center = maptemp_w / 2.0;
  883 + double y_center = maptemp_h / 2.0;
  884 + double x_show = 0, y_show = 0;
  885 + this->GetToBeCenter(x_show, y_show, &extents, x_center, y_center);
  886 +
  887 + cairo_move_to(cr, x_show, y_show);
  888 + //cairo_move_to(cr, (maptemp_w - text_w)/2,maptemp_h - (maptemp_h - text_h)/2);
  889 + cairo_show_text(cr, s_);
  890 +
  891 + map_temp->BufferCopy();
  892 + return iWord;
  893 + }
  894 +*/
  895 +
  896 +
  897 + bool TrueTypeMarkerSymbol::DrawAText(clsCrSurf* clsCS, double x, double y)
  898 + {
  899 + //this->SetCairo(clsCS); //除非要精准控制,不然没必要在这里设置
  900 + cairo_t* cr = clsCS->m_pCr;
  901 + cairo_text_extents_t extents;
  902 + cairo_text_extents(cr, m_sUTF8, &extents);
  903 + /*x = x - extents.width / 2;
  904 + y = y + extents.height / 2;*/
  905 + x = x - (extents.x_advance) / 2;
  906 + y = y + (extents.height) / 2;
  907 +
  908 + /*
  909 + 阴影效果
  910 + */
  911 + if (m_bHaveShadow)
  912 + {
  913 + cairo_set_source_rgba(cr, r_shadow, g_shadow, b_shadow, a_shadow);
  914 + cairo_move_to(cr, x + ShadowSize + GlowingSize, y + ShadowSize + GlowingSize);
  915 + cairo_show_text(cr, m_sUTF8);
  916 + }
  917 +
  918 + /*
  919 + 发光效果
  920 + */
  921 + if (m_bHaveGlowing)
  922 + {
  923 + cairo_set_source_rgba(cr, r_glowing, g_glowing, b_glowing, a_glowing);
  924 + for (int i = -(GlowingSize); i <= GlowingSize; i++)
  925 + {
  926 + for (int j = -(GlowingSize); j <= GlowingSize; j++)
  927 + {
  928 + cairo_move_to(cr, x + i, y + j);
  929 + cairo_show_text(cr, m_sUTF8);
  930 + }
  931 + }
  932 + }
  933 +
  934 + this->SetFontColor(m_iFontColor);
  935 + cairo_set_source_rgba(cr, r_font, g_font, b_font, a_font);
  936 + cairo_set_line_width(cr, 10);
  937 + cairo_move_to(cr, x, y);
  938 + /*cairo_rel_line_to(cr, 10, 0);
  939 + cairo_stroke(cr)*/;
  940 + cairo_show_text(cr, m_sUTF8);
  941 + int iTextW = (int)extents.x_advance; int iTextH = (int)extents.height;
  942 + if (m_bHaveDeleteLine)
  943 + {
  944 + cairo_set_line_width(cr, 1);
  945 + cairo_move_to(cr, x + extents.x_bearing, y - iTextH / 2.0 + extents.y_bearing + extents.height);
  946 + cairo_rel_line_to(cr, iTextW, 0);
  947 + cairo_stroke(cr);
  948 + }
  949 + if (m_bHaveUnderLine)
  950 + {
  951 + cairo_set_line_width(cr, 1);
  952 + cairo_move_to(cr, x + extents.x_bearing, y + extents.y_bearing + extents.height);
  953 + cairo_rel_line_to(cr, iTextW, 0);
  954 + cairo_stroke(cr);
  955 + }
  956 + return true;
  957 + }
  958 +
  959 + bool TrueTypeMarkerSymbol::DrawAText(clsCrSurf* pClsCS, double x, double y, double dAngle)
  960 + {
  961 +
  962 + cairo_t* cr = pClsCS->m_pCr;
  963 + cairo_text_extents_t extents;
  964 + cairo_text_extents(cr, m_sUTF8, &extents);
  965 + int iX = (int)x; int iY = (int)y;
  966 + int iTextW = (int)(extents.x_advance); int iTextH = (int)(extents.height);
  967 + int surf_w = pClsCS->m_iW; int surf_h = pClsCS->m_iH;
  968 +
  969 +
  970 +
  971 + {
  972 + //检查文字避让
  973 + //不避让,因为这个不认为是文字,而是看做是一个点的样式
  974 + }
  975 +
  976 +
  977 + {
  978 +
  979 + /*
  980 + 绘制发光
  981 + */
  982 + if (m_bHaveGlowing)
  983 + {
  984 + int iGlowingSize = 2;
  985 + cairo_set_source_rgba(cr, r_glowing, g_glowing, b_glowing, a_glowing);
  986 + for (int i = -GlowingSize; i <= GlowingSize; i++)
  987 + {
  988 + for (int j = -GlowingSize; j <= GlowingSize; j++)
  989 + {
  990 + cairo_move_to(cr, x + i, y + j);
  991 + cairo_rotate(cr, dAngle);
  992 + cairo_show_text(cr, m_sUTF8);
  993 + cairo_rotate(cr, -dAngle);
  994 + }
  995 + }
  996 + }
  997 +
  998 + /*
  999 + 绘制阴影
  1000 + */
  1001 + if (m_bHaveShadow)
  1002 + {
  1003 + int iShadowSize = 2;
  1004 + cairo_set_source_rgba(cr, r_shadow, g_shadow, b_shadow, a_shadow);
  1005 + if (m_bHaveGlowing)
  1006 + cairo_move_to(cr, x + ShadowSize + GlowingSize, y + ShadowSize + GlowingSize);
  1007 + else
  1008 + cairo_move_to(cr, x + ShadowSize, y + ShadowSize);
  1009 + cairo_rotate(cr, dAngle); cairo_show_text(cr, m_sUTF8); cairo_rotate(cr, -dAngle);
  1010 + }
  1011 +
  1012 +
  1013 + cairo_set_source_rgba(cr, r_font, g_font, b_font, a_font);
  1014 + cairo_move_to(cr, x, y);
  1015 + cairo_rotate(cr, dAngle);
  1016 + cairo_show_text(cr, m_sUTF8);
  1017 + cairo_rotate(cr, -dAngle);
  1018 + if (m_bHaveDeleteLine)
  1019 + {
  1020 + cairo_set_source_rgba(cr, r_font, g_font, b_font, a_font);
  1021 + cairo_set_line_width(cr, 1);
  1022 + cairo_move_to(cr, x + extents.x_bearing, y - iTextH / 2.0 + extents.y_bearing + extents.height);
  1023 + cairo_rotate(cr, dAngle);
  1024 + cairo_rel_line_to(cr, iTextW, 0);
  1025 + cairo_stroke(cr);
  1026 + cairo_rotate(cr, -dAngle);
  1027 + }
  1028 + if (m_bHaveUnderLine)
  1029 + {
  1030 + cairo_set_line_width(cr, 1);
  1031 + cairo_move_to(cr, x + extents.x_bearing, y + extents.y_bearing + extents.height);
  1032 + cairo_rotate(cr, dAngle);
  1033 + cairo_rel_line_to(cr, iTextW, 0);
  1034 + cairo_stroke(cr);
  1035 + cairo_rotate(cr, -dAngle);
  1036 + }
  1037 + }
  1038 + return false;
  1039 + }
  1040 +
  1041 + bool TrueTypeMarkerSymbol::SetCairo(clsCrSurf* pClsCS)
  1042 + {
  1043 + cairo_t* cr = pClsCS->m_pCr;
  1044 + cairo_select_font_face(cr, m_sFont.c_str(), (cairo_font_slant_t)m_iSlant, (cairo_font_weight_t)m_iWeight);
  1045 + cairo_set_font_size(cr, (double)m_lFontSize);
  1046 + clsUtil::DoSetAntialias(m_iAntialiasing, cr);
  1047 + return true;
  1048 + }
  1049 + bool TrueTypeMarkerSymbol::GetToBeCenter(double & x, double & y, cairo_text_extents_t* pExtents, double x_center, double y_center)
  1050 + {
  1051 + x = x_center - pExtents->width / 2 - pExtents->x_bearing;
  1052 + y = y_center - pExtents->height / 2 - pExtents->y_bearing;
  1053 + return true;
  1054 + }
  1055 +}
\ No newline at end of file
... ...
  1 +#pragma once
  2 +#ifndef _TrueTypeMarkerSymbol_H_
  3 +#define _TrueTypeMarkerSymbol_H_
  4 +#include"Renderer.h"
  5 +#include<string>
  6 +#include"clsStruct.h"
  7 +using namespace std;
  8 +
  9 +
  10 +namespace DmapCore_30
  11 +{
  12 + class Map;
  13 + class clsCrSurf;
  14 + class DataCollection;
  15 + class CORE_EXPORT TrueTypeMarkerSymbol :public Renderer
  16 + {
  17 + public:
  18 +
  19 + TrueTypeMarkerSymbol();
  20 + ~TrueTypeMarkerSymbol();
  21 +
  22 + virtual int RendererType();
  23 + virtual bool DrawData(clsCrSurf* pClsCS, DataCollection* data, bool drawSimpleData, char* pFlag = NULL);
  24 + virtual bool DrawData(clsCrSurf* pClsCS, DataCollection* data, int dataIndex, char* pFlag = NULL);
  25 + virtual bool DrawLegend(clsCrSurf* pClsCS, shared_ptr<legendParamater> pLegendParamater,int layerType, char* pFlag = NULL);
  26 + virtual bool Parse(boost::property_tree::ptree &pt, AppendBuffer *f);
  27 + virtual void ToJson(AppendBuffer *ab);
  28 +
  29 + double m_dAngle; //旋转角度固定值
  30 + string m_sAngleField; //旋转角度以某个字段的数据为依据,改数据获取后会转化成 0~2π
  31 + /*
  32 + 使用规定: 2016-02-18
  33 + 优先使用 m_sAngleField,设置 m_dAngle 的时候, m_sAngleField 同时设置为 ""
  34 + */
  35 +
  36 +
  37 + int m_iAntialiasing; //
  38 + long m_lCharacter; //文字所对应的数字 32-65535
  39 + double m_dCharacterXdis; //文字显示时的X偏移
  40 + double m_dCharacterYdis; //Y偏移
  41 + string m_sFont; //
  42 + unsigned int m_iFontColor; //
  43 + long m_lFontSize; //
  44 + //int m_iFontStyle; //字体风格
  45 +
  46 +
  47 + string m_fontname;
  48 + bool m_bHaveGlowing; //
  49 + unsigned int m_iGlowingColor; //发光
  50 + bool m_bHaveOutline; //
  51 + unsigned int m_iOutline; //边框
  52 + //int m_iRotateMethod; //旋转方式,角度计算方式,使用枚举,具体见esri文档
  53 + bool m_bHaveShadow; //
  54 + unsigned int m_iShadowColor; //阴影
  55 + /*
  56 + 文字四属性
  57 + */
  58 + int m_iSlant; //斜体
  59 + int m_iWeight; //加粗
  60 + bool m_bHaveUnderLine; // 下划线
  61 + bool m_bHaveDeleteLine; // 删除线
  62 +
  63 +
  64 + double GetAngle();
  65 + bool SetAngle(double dAngle);
  66 + const char* GetAngleField();
  67 + bool SetAngleField(const char* sAngleField);
  68 + int GetAntialiasing();
  69 + bool SetAntialiasing(int iAntialiasing);
  70 + long GetCharacter();
  71 + bool SetCharacter(long lCharacter);
  72 + bool GetCharacterDis(double* pdXdis, double* pdYdis);
  73 + bool SetCharacterDis(double xDis, double yDis);
  74 + const char* GetFont();
  75 + bool SetFont(const char* sFont);
  76 + unsigned int GetFontColor();
  77 + bool SetFontColor(unsigned int iFontColor);
  78 + long GetFontSize();
  79 + bool SetFontSize(long lFontSize);
  80 + bool GetGlowing(bool* pbHaveGlowing, unsigned int * piGlowingColor);
  81 + bool SetGlowingColor(bool bHaveGlowing, unsigned int iGlowingColor);
  82 + /*int GetRotateMethod();
  83 + bool SetRotateMethod(int iRotateMethod);*/
  84 + bool GetShadow(bool* pbHaveShadow, unsigned int* piShadowColor);
  85 + bool SetShadow(bool bHaveShadow, unsigned int iShadhowColor);
  86 + int GetSlant();
  87 + bool SetSlant(int iSlant);
  88 + int GetWeight();
  89 + bool SetWeight(int iBold);
  90 + bool GetHaveUnderLine();
  91 + bool SetHaveUnderLine(bool bHaveUnderLine);
  92 + bool GetHaveDeleteLine();
  93 + bool SetHaveDeleteLine(bool bHaveDeleteLine);
  94 +
  95 +
  96 + void TryAddField(vector<string>&pvField);
  97 + bool TryFindHeatRenderer(){ return false; }
  98 +
  99 + /*
  100 + DrawFont部分
  101 + */
  102 + vector<int> m_viFontCharacter;
  103 + char *m_pbFlag;
  104 + int CalculateFontCount();
  105 + //bool DrawFont(Map* map, int iPerSize);
  106 + //bool DrawFont(Map* map, int iPerSize, int iCharater, double* x, double * y);
  107 + int DrawAFont(double x, double y, Map* map_temp, Map* map, int iPerSize);
  108 +
  109 +
  110 + private:
  111 + bool DrawAText(clsCrSurf* clsCS, double x, double y);
  112 + bool DrawAText(clsCrSurf* pClsCS, double x, double y, double dAngle);
  113 + bool SetCairo(clsCrSurf* clsCS);
  114 + bool GetToBeCenter(double & x, double & y, cairo_text_extents_t* pExtents, double x_center, double y_center); //要以 x_center,y_center书写文字, 求x,y
  115 + char m_sUTF8[5];
  116 +
  117 + double r_font, g_font, b_font, a_font;
  118 + double r_glowing, g_glowing, b_glowing, a_glowing;
  119 + double r_outline, g_outline, b_outline, a_outline;
  120 + double r_shadow, g_shadow, b_shadow, a_shadow;
  121 +
  122 + };
  123 +
  124 +}
  125 +
  126 +#endif
\ No newline at end of file
... ...
  1 +
  2 +#include "ValueMapRenderer.h"
  3 +#include"clsXML.h"
  4 +#include "clsJson.h"
  5 +#include"ValueMapRendererComponent.h"
  6 +#include<map>
  7 +using namespace std;
  8 +#include"clsCrSurf.h"
  9 +#include"DataCollection.h"
  10 +#include"clsUtil.h"
  11 +#include <boost/dll/alias.hpp> // for BOOST_DLL_ALIAS
  12 +#include <boost/filesystem.hpp>
  13 +#include <boost/function.hpp>
  14 +#include <boost/make_shared.hpp>
  15 +#include <boost/algorithm/string.hpp>
  16 +namespace DmapCore_30
  17 +{
  18 +
  19 + ValueMapRenderer::ValueMapRenderer()
  20 + {
  21 + m_sTag = "";
  22 + m_pDefaultSymbol = NULL;
  23 + m_sField = "";
  24 + m_vComponents = {};
  25 + m_simpleRenderer = true;
  26 + }
  27 + ValueMapRenderer::~ValueMapRenderer()
  28 + {
  29 + if (m_pDefaultSymbol)
  30 + m_pDefaultSymbol->Release();
  31 + int length = (int)m_vComponents.size();
  32 + if (length)
  33 + {
  34 + for (int i = 0; i < length; i++)
  35 + m_vComponents[i]->Release();
  36 + m_vComponents.clear();
  37 + }
  38 + }
  39 + ValueMapRenderer* ValueMapRenderer::CreateNew()
  40 + {
  41 + ValueMapRenderer * dest = new ValueMapRenderer();
  42 + return dest;
  43 + }
  44 + bool ValueMapRenderer::Parse(boost::property_tree::ptree &pt, AppendBuffer *f)
  45 + {
  46 + // if (!node && !f)return false;
  47 +
  48 + //clsXML clsX(f, "VALUEMAPRENDERER");
  49 + clsXML::XMLAttrParse(pt, f, &m_sField, "lookupfield");
  50 + //clsX.closeProperties();
  51 +
  52 + for (auto ptchild = pt.begin(); ptchild != pt.end(); ++ptchild)
  53 + {
  54 + string sz = ptchild->first;
  55 + if (boost::iequals(sz, "OTHER"))
  56 + {
  57 + //rapidxml::xml_node<char>* node2 = node1->first_node();
  58 + clsXML::XMLParse(ptchild->first,ptchild->second, &m_pDefaultSymbol);
  59 + }
  60 + else if (boost::iequals(sz, "EXACT"))
  61 + {
  62 + string sValue = clsXML::XMLGetPropByString(ptchild->second, "value");
  63 +
  64 + //rapidxml::xml_node<char>* node2 = node1->first_node();//exact 只有一个子节点 ,存着简单样
  65 + Renderer* pSymbol = NULL;
  66 + clsXML::XMLParse(ptchild->first, ptchild->second, &pSymbol);
  67 +
  68 + ValueMapRendererComponent* vmrc = new ValueMapRendererComponent(pSymbol, sValue);
  69 +
  70 + m_vComponents.push_back(vmrc);//引用只需要一份, 无需AddRef
  71 + }
  72 + else{ ; }
  73 + }
  74 + return true;
  75 + }
  76 +
  77 + void ValueMapRenderer::ToJson(AppendBuffer *ab)
  78 + {
  79 + char buff[300] = {0};
  80 + //char resultbuff[5000] = {0};
  81 + sprintf(buff, R"("VALUEMAPRENDERER":{"lookupfield":"%s","EXACT":[)",m_sField.c_str());
  82 + //strcat(resultbuff,buff);
  83 + ab->AppendString(buff);
  84 + int length = (int)m_vComponents.size();
  85 + for (int i = 0; i < length; i++)
  86 + {
  87 + if(i>0)
  88 + {
  89 + ab->AppendString(",");
  90 + }
  91 +
  92 + ValueMapRendererComponent* vmrc = m_vComponents[i];
  93 + ab->AppendString("{");
  94 + sprintf(buff, R"("value":"%s",)",vmrc->m_sValue.c_str());
  95 + ab->AppendString(buff);
  96 + if(vmrc->m_pSymbol)
  97 + {
  98 + vmrc->m_pSymbol->ToJson(ab);
  99 + }
  100 + ab->AppendString("}");
  101 + }
  102 + ab->AppendString("]");
  103 + //strcat(resultbuff, "]");
  104 +
  105 + if (m_pDefaultSymbol)
  106 + {
  107 + ab->AppendString(",\"OTHER\":{");
  108 + this->m_pDefaultSymbol->ToJson(ab);
  109 + ab->AppendString("}");
  110 + }
  111 + ab->AppendString("}");
  112 + }
  113 +
  114 +
  115 + int ValueMapRenderer::RendererType()
  116 + {
  117 + return dmapValueMapRenderer;
  118 + }
  119 + const char* ValueMapRenderer::GetTag()
  120 + {
  121 + return m_sTag.c_str();
  122 + }
  123 + bool ValueMapRenderer::SetTag(const char* sTag)
  124 + {
  125 + if (!sTag)
  126 + return false;
  127 + m_sTag = sTag;
  128 + return true;
  129 + }
  130 + Renderer* ValueMapRenderer::GetDefaultSymbol()
  131 + {
  132 + if (m_pDefaultSymbol)m_pDefaultSymbol->AddRef();
  133 + return m_pDefaultSymbol;
  134 + }
  135 + bool ValueMapRenderer::SetDefaultSymbol(Renderer* defaultSymbol)
  136 + {
  137 + if (!defaultSymbol)
  138 + {
  139 + m_pDefaultSymbol = defaultSymbol;
  140 + return true;
  141 + }
  142 +
  143 + //int renType = defaultSymbol->RendererType();
  144 + //AddRef 必须先执行, 有可能传入的样式和原来的样式是同一个指针, 先 Release 会内存错误
  145 + defaultSymbol->AddRef();
  146 + if (m_pDefaultSymbol)
  147 + m_pDefaultSymbol->Release();
  148 + m_pDefaultSymbol = defaultSymbol;
  149 + return true;
  150 + }
  151 + const char* ValueMapRenderer::GetField()
  152 + {
  153 + return m_sField.c_str();
  154 + }
  155 + bool ValueMapRenderer::SetField(const char* sField)
  156 + {
  157 + if (!sField)
  158 + return false;
  159 + m_sField = sField;
  160 + return true;
  161 + }
  162 + int ValueMapRenderer::GetComponentCount()
  163 + {
  164 + int length = (int)m_vComponents.size();
  165 + return length;
  166 + }
  167 + ValueMapRendererComponent* ValueMapRenderer::GetComponent(int index)
  168 + {
  169 + //GetIndexP(index,m_vComponents);
  170 + int length = (int)(m_vComponents.size());
  171 +
  172 + if (index < 0 || index >= length)
  173 + return NULL;
  174 + m_vComponents[index]->AddRef();
  175 + return m_vComponents[index];
  176 +
  177 + }
  178 + bool ValueMapRenderer::SetComponent(int index, ValueMapRendererComponent* component)
  179 + {
  180 + //SetIndexP(index, component, m_vComponents);
  181 + if (!component)return false;
  182 + int length = (int)(m_vComponents.size());
  183 + if (index >= length)
  184 + return false;
  185 + component->AddRef();
  186 + if (index < 0)
  187 + m_vComponents.push_back(component);
  188 + else
  189 + {
  190 + m_vComponents[index]->Release();
  191 + m_vComponents[index] = component;
  192 + }
  193 + return true;
  194 + }
  195 + bool ValueMapRenderer::AddComponent(ValueMapRendererComponent* component)
  196 + {
  197 + return this->SetComponent(-1, component);
  198 + }
  199 + bool ValueMapRenderer::RemoveComponent(int index)
  200 + {
  201 + int length = (int)(m_vComponents.size());
  202 + if (index < 0 || index >= length)
  203 + return false;
  204 +
  205 + m_vComponents[index]->Release();
  206 + m_vComponents.erase(m_vComponents.begin() + index);
  207 + return true;
  208 + }
  209 + bool ValueMapRenderer::ClearComponents()
  210 + {
  211 + int length = (int)(m_vComponents.size());
  212 +
  213 + for (int i = 0; i < length; i++)
  214 + m_vComponents[i]->Release();
  215 + m_vComponents.clear();
  216 + return true;
  217 + }
  218 + bool ValueMapRenderer::DrawData(clsCrSurf* pClsCS, DataCollection* data, bool drawSimpleData, char* pFlag)
  219 + {
  220 + //找出 field 在 data 中字符串数组中的索引,这个对应的是列号
  221 + int index = -1;
  222 + int dataFieldCount = (int)(data->m_vFieldName.size());
  223 + for (int i = 0; i < dataFieldCount; i++)
  224 + {
  225 + if (m_sField == data->m_vFieldName[i])
  226 + {
  227 + index = i;
  228 + break;
  229 + }
  230 + }
  231 + if (index == -1)
  232 + return false;
  233 +
  234 + /*
  235 + 开始绘制每个结构体,调用 DrawStruct
  236 + */
  237 + int iPartCount = data->m_iPartCount;
  238 + //int structType = data->m_iStructType;
  239 + for (int i = 0; i < iPartCount; i++)
  240 + {
  241 + string sFieldValue = data->m_vAllField[i][index];
  242 + Renderer* renderer = NULL;
  243 + bool bHaveFind = false;
  244 +
  245 + int sz = m_vComponents.size();
  246 + for (int j = 0; j < sz; j++)
  247 + {
  248 + if (sFieldValue == m_vComponents[j]->m_sValue)
  249 + {
  250 + bHaveFind = true;
  251 + renderer = m_vComponents[j]->m_pSymbol;
  252 + break;
  253 + }
  254 + }
  255 + if (!bHaveFind)
  256 + renderer = m_pDefaultSymbol;
  257 +
  258 + if (!renderer)
  259 + continue;
  260 + renderer->DrawData(pClsCS, data, i, pFlag);
  261 + //clsUtil::DrawStruct(pClsCS, data, i, renderer);
  262 + }
  263 + return true;
  264 + }
  265 +
  266 + bool ValueMapRenderer::DrawData(clsCrSurf* pClsCS, DataCollection* data, int dataIndex, char* pFlag)
  267 + {
  268 + //找出 field 在 data 中字符串数组中的索引,这个对应的是列号
  269 + int index = -1;
  270 + int dataFieldCount = (int)(data->m_vFieldName.size());
  271 + for (int i = 0; i < dataFieldCount; i++)
  272 + {
  273 + if (m_sField == data->m_vFieldName[i])
  274 + {
  275 + index = i;
  276 + break;
  277 + }
  278 + }
  279 + if (index == -1)
  280 + return false;
  281 +
  282 + /*
  283 + 开始绘制每个结构体,调用 DrawStruct
  284 + */
  285 + //int iPartCount = data->m_iPartCount;
  286 + //int structType = data->m_iStructType;
  287 + //for (int i = 0; i < iPartCount; i++)
  288 + {
  289 + string sFieldValue = data->m_vAllField[dataIndex][index];
  290 + Renderer* renderer = NULL;
  291 + bool bHaveFind = false;
  292 +
  293 + int sz = m_vComponents.size();
  294 + for (int j = 0; j < sz; j++)
  295 + {
  296 + if (sFieldValue == m_vComponents[j]->m_sValue)
  297 + {
  298 + bHaveFind = true;
  299 + renderer = m_vComponents[j]->m_pSymbol;
  300 + break;
  301 + }
  302 + }
  303 + if (!bHaveFind)
  304 + renderer = m_pDefaultSymbol;
  305 +
  306 + if (!renderer)
  307 + return false;
  308 + renderer->DrawData(pClsCS, data, dataIndex, pFlag);
  309 + // clsUtil::DrawStruct(pClsCS, data, i, renderer);
  310 + }
  311 + return true;
  312 + }
  313 + bool ValueMapRenderer::DrawLegend(clsCrSurf* pClsCS, shared_ptr<legendParamater> pLegendParamater,int layerType, char* pFlag)
  314 + {
  315 + int index = -1;
  316 +
  317 + if(!pLegendParamater->showclassification)
  318 + {
  319 + return false;
  320 + }
  321 + /*
  322 + 开始绘制每个结构体,调用 DrawStruct
  323 + */
  324 +
  325 + int sz = m_vComponents.size();
  326 + for (int j = 0; j < sz; j++)
  327 + {
  328 + Renderer* renderer = m_vComponents[j]->m_pSymbol;
  329 + renderer->DrawLegend(pClsCS, pLegendParamater,layerType, (char *)m_vComponents[j]->m_sValue.c_str());
  330 + }
  331 + if(m_pDefaultSymbol)
  332 + {
  333 + m_pDefaultSymbol->DrawLegend(pClsCS, pLegendParamater,layerType, (char *)"其他");
  334 + }
  335 + return true;
  336 + }
  337 +
  338 + void ValueMapRenderer::TryAddField(vector<string>&pvField)
  339 + {
  340 + TryAddField2(pvField, m_sField);
  341 + }
  342 +}
  343 +
... ...
  1 +#pragma once
  2 +#ifndef _ValueMapRenderer_H_
  3 +#define _ValueMapRenderer_H_
  4 +#include<map>
  5 +using namespace std;
  6 +#include"Renderer.h"
  7 +#include <boost/property_tree/ptree.hpp>
  8 +#include <boost/property_tree/xml_parser.hpp>
  9 +#include <boost/foreach.hpp>
  10 +namespace DmapCore_30
  11 +{
  12 + class ValueMapRendererComponent;
  13 + class DataCollection;
  14 + class clsCrSurf;
  15 + class CORE_EXPORT ValueMapRenderer :public Renderer
  16 + {
  17 + public:
  18 + ValueMapRenderer();
  19 + ~ValueMapRenderer();
  20 + static ValueMapRenderer* CreateNew();
  21 + virtual int RendererType();
  22 + virtual bool Parse(boost::property_tree::ptree &pt, AppendBuffer *f);
  23 + virtual bool DrawData(clsCrSurf* pClsCS, DataCollection* data, bool drawSimpleData, char* pFlag = NULL);
  24 + virtual bool DrawData(clsCrSurf* pClsCS, DataCollection* data, int dataIndex, char* pFlag = NULL);
  25 + virtual bool DrawLegend(clsCrSurf* pClsCS, shared_ptr<legendParamater> pLegendParamater,int layerType, char* pFlag = NULL);
  26 + virtual void ToJson(AppendBuffer *ab);
  27 +
  28 + const char* GetTag();
  29 + bool SetTag(const char* sTag);
  30 + Renderer* GetDefaultSymbol();
  31 + bool SetDefaultSymbol(Renderer* defaultSymbol);
  32 + const char* GetField();
  33 + bool SetField(const char* sField);
  34 + int GetComponentCount();
  35 + ValueMapRendererComponent* GetComponent(int index);
  36 + bool SetComponent(int index, ValueMapRendererComponent* component);
  37 + bool AddComponent(ValueMapRendererComponent* component);
  38 + bool RemoveComponent(int index);
  39 + bool ClearComponents();
  40 +
  41 +
  42 + void TryAddField(vector<string>&pvField);
  43 + bool TryFindHeatRenderer(){ return false; }
  44 +
  45 +
  46 + string m_sTag;
  47 + Renderer* m_pDefaultSymbol;
  48 + string m_sField;
  49 + vector<ValueMapRendererComponent*> m_vComponents;
  50 + };
  51 +
  52 +}
  53 +
  54 +#endif
\ No newline at end of file
... ...
  1 +
  2 +#include "ValueMapRendererComponent.h"
  3 +
  4 +namespace DmapCore_30
  5 +{
  6 + int ValueMapRendererComponent::GetN()
  7 + {
  8 + return m_iN;
  9 + }
  10 + ValueMapRendererComponent::ValueMapRendererComponent()
  11 + {
  12 + m_iN = 1;
  13 + m_pSymbol = NULL;
  14 + m_sValue = "";
  15 + }
  16 + ValueMapRendererComponent::ValueMapRendererComponent(Renderer* pSymbol, string sValue)
  17 + {
  18 + m_iN = 1;
  19 + m_pSymbol = pSymbol;
  20 + m_sValue = sValue;
  21 + }
  22 + ValueMapRendererComponent::~ValueMapRendererComponent()
  23 + {
  24 + if (m_pSymbol)
  25 + m_pSymbol->Release();
  26 + }
  27 + ValueMapRendererComponent* ValueMapRendererComponent::CreateNew()
  28 + {
  29 + ValueMapRendererComponent * dest = new ValueMapRendererComponent();
  30 + return dest;
  31 + }
  32 + bool ValueMapRendererComponent::AddRef()
  33 + {
  34 + m_iN++;
  35 + return true;
  36 + }
  37 + bool ValueMapRendererComponent::Release()
  38 + {
  39 + m_iN--;
  40 + if (m_iN < 0)
  41 + return false;
  42 + if (!m_iN)
  43 + delete this;
  44 + return true;
  45 + }
  46 +
  47 + Renderer* ValueMapRendererComponent::GetSymbol()
  48 + {
  49 + m_pSymbol->AddRef();
  50 + return m_pSymbol;
  51 + }
  52 + bool ValueMapRendererComponent::SetSymbol(Renderer* pSymbol)
  53 + {
  54 + if (!pSymbol)
  55 + return false;
  56 + pSymbol->AddRef();
  57 + if (m_pSymbol)
  58 + m_pSymbol->Release();
  59 + m_pSymbol = pSymbol;
  60 + return true;
  61 + }
  62 + const char* ValueMapRendererComponent::GetValue()
  63 + {
  64 + return m_sValue.c_str();
  65 + }
  66 + bool ValueMapRendererComponent::SetValue(const char * sValue)
  67 + {
  68 + m_sValue = sValue;
  69 + return true;
  70 + }
  71 +}
\ No newline at end of file
... ...
  1 +#pragma once
  2 +#ifndef _ValueMapRendererComponent_H_
  3 +#define _ValueMapRendererComponent_H_
  4 +#include<string>
  5 +#ifndef _Renderer_h_
  6 +#define _Renderer_h_
  7 +#include "Renderer.h"
  8 +#endif
  9 +using namespace std;
  10 +namespace DmapCore_30
  11 +{
  12 + class Renderer;
  13 + class CORE_EXPORT ValueMapRendererComponent
  14 + {
  15 + public:
  16 + int GetN();
  17 + ValueMapRendererComponent();
  18 + ValueMapRendererComponent(Renderer* pSymbol, string sValue = "");
  19 + ~ValueMapRendererComponent();
  20 + static ValueMapRendererComponent* CreateNew();
  21 + bool AddRef();
  22 + bool Release();
  23 + Renderer* GetSymbol();
  24 + bool SetSymbol(Renderer* pSymbol);
  25 + const char* GetValue();
  26 + bool SetValue(const char * sValue);
  27 +
  28 + Renderer * m_pSymbol;
  29 + string m_sValue;
  30 + private:
  31 + int m_iN;
  32 + };
  33 +
  34 +}
  35 +#endif
\ No newline at end of file
... ...
  1 +
  2 +#include "clsCrSurf.h"
  3 +#include <malloc.h>
  4 +#include <string.h>
  5 +namespace DmapCore_30
  6 +{
  7 + clsCrSurf::clsCrSurf(cairo_surface_t* surface)
  8 + {
  9 + m_pSurf = surface;
  10 + m_pCr = cairo_create(m_pSurf);
  11 + //cairo_set_antialias(m_pCr,cairo_antialias_t::CAIRO_ANTIALIAS_BEST);
  12 + m_iN = 1;
  13 + m_iW = cairo_image_surface_get_width(surface);
  14 + m_iH = cairo_image_surface_get_height(surface);
  15 + m_iBGColor = 0Xffffffff;
  16 + m_pFlag = 0;
  17 + m_isImage = true;
  18 + }
  19 +
  20 + clsCrSurf::clsCrSurf(cairo_surface_t* surface,int w,int h,bool isImage)
  21 + {
  22 + m_pSurf = surface;
  23 + m_pCr = cairo_create(m_pSurf);
  24 + cairo_set_antialias(m_pCr,cairo_antialias_t::CAIRO_ANTIALIAS_BEST);
  25 + m_iN = 1;
  26 + m_iW = w;
  27 + m_iH = h;
  28 + m_iBGColor = 0Xffffffff;
  29 + m_pFlag = 0;
  30 + m_isImage = isImage;
  31 + }
  32 +
  33 +
  34 +
  35 +
  36 + clsCrSurf::~clsCrSurf()
  37 + {
  38 + this->DestroyCr();
  39 + this->DestroySurf();
  40 + if (m_pFlag)
  41 + {
  42 + free(m_pFlag);
  43 + m_pFlag = 0;
  44 + }
  45 + }
  46 +
  47 + bool clsCrSurf::Release()
  48 + {
  49 + m_iN--;
  50 + if (m_iN < 0)
  51 + return false;
  52 + if (!m_iN)
  53 + delete this;
  54 + return true;
  55 + }
  56 +
  57 + bool clsCrSurf::SetSurf(cairo_surface_t* surface)
  58 + {
  59 + if (surface == m_pSurf)
  60 + return true;
  61 + this->~clsCrSurf();
  62 +
  63 + m_pSurf = surface;
  64 + m_pCr = cairo_create(m_pSurf);
  65 + m_iW = cairo_image_surface_get_width(m_pSurf);
  66 + m_iH = cairo_image_surface_get_height(m_pSurf);
  67 +
  68 + return true;
  69 + }
  70 +
  71 +
  72 + void clsCrSurf::DestroyCr()
  73 + {
  74 + if (m_pCr)
  75 + {
  76 + cairo_destroy(m_pCr);
  77 + //free(m_pCr);
  78 + m_pCr = NULL;
  79 + }
  80 + }
  81 + //0x68E06B52 (libcairo - 2.dll) (DMap.exe 中)处有未经处理的异常: 0xC0000005 : 读取位置 0xFEEEFEFE 时发生访问冲突。
  82 + //0x68E06B52 (libcairo - 2.dll) (DMap.exe 中)处有未经处理的异常: 0xC0000005 : 读取位置 0xCDCDCDDD 时发生访问冲突。
  83 + void clsCrSurf::DestroySurf()
  84 + {
  85 + if (m_pSurf)
  86 + {
  87 + cairo_surface_destroy(m_pSurf);
  88 + //free(m_pSurf);
  89 + m_pSurf = NULL;
  90 + }
  91 + }
  92 +
  93 + bool clsCrSurf::InitFlag()
  94 + {
  95 + if (m_pFlag)
  96 + {
  97 + memset(m_pFlag, 0, m_iFlagW*m_iFlagH);
  98 + return true;
  99 + }
  100 + m_iFlagW = m_iW / gridsize;
  101 + m_iFlagH = m_iH / gridsize;
  102 + if (m_iW != (m_iFlagW*gridsize))
  103 + m_iFlagW++;
  104 + if (m_iH != (m_iFlagH*gridsize))
  105 + m_iFlagH++;
  106 +
  107 + m_pFlag = (char*)malloc(m_iFlagW*m_iFlagH);
  108 +
  109 + if (m_pFlag == 0)
  110 + return false;
  111 + memset(m_pFlag, 0, m_iFlagW*m_iFlagH);
  112 + return true;
  113 + }
  114 +}
\ No newline at end of file
... ...
  1 +/**************************************************************************
  2 +* file: clsCrSurf.h
  3 +
  4 +* Author: qingxiongf
  5 +* Date: 2021-12-12 22:58:23
  6 +* Email: qingxiongf@chinadci.com
  7 +* copyright: 广州城市信息研究所有限公司
  8 +***************************************************************************/
  9 +
  10 +#ifndef __clsCrSurf_h__
  11 +#define __clsCrSurf_h__
  12 +
  13 +#include "dmap_core.h"
  14 +#include<cairo/cairo.h>
  15 +
  16 +#define gridsize 2 //网格大小
  17 +namespace DmapCore_30
  18 +{
  19 + /*
  20 + 这个类是为了处理有些地方绘图需要传cairo_t,有些地方需要传 surface_t(比如agg绘线) 而出现的
  21 + 绘图过程中一律传递这类对象即可
  22 + */
  23 +
  24 +
  25 + /*
  26 + 是否改为这种包装??? 之前的包装不要了???
  27 + */
  28 + class CORE_EXPORT clsCrSurf
  29 + {
  30 + public:
  31 + clsCrSurf(cairo_surface_t* surface);
  32 + clsCrSurf(cairo_surface_t* surface,int w,int h,bool isImage);
  33 +
  34 + ~clsCrSurf();
  35 + bool Release();
  36 + bool SetSurf(cairo_surface_t* surface);
  37 + bool IsImage(bool b);
  38 +
  39 + cairo_t* m_pCr;
  40 + cairo_surface_t* m_pSurf;
  41 + int m_iW;
  42 + int m_iH;
  43 +
  44 + int m_iN; //引用计数
  45 +
  46 + /*
  47 + 文字避让部分
  48 + */
  49 + char* m_pFlag;
  50 + int m_iFlagW;
  51 + int m_iFlagH;
  52 + bool InitFlag(); // 文字避让数组初始化
  53 + unsigned int m_iBGColor;
  54 +
  55 + bool m_isImage = true;
  56 +
  57 +
  58 + private:
  59 + void DestroyCr();
  60 + void DestroySurf();
  61 + };
  62 +
  63 +}
  64 +
  65 +#endif // __clsCrSurf_h__
\ No newline at end of file
... ...
  1 +
  2 +
  3 +#include "clsJson.h"
  4 +#include <stdarg.h>
  5 +#include <string.h>
  6 +
  7 +namespace DmapCore_30
  8 +{
  9 + void clsJson::ParseEnum(const char *name, char *resultbuff, char* buff, int v, string a1, string a2 , string a3, string a4, string a5, string a6, string a7, string a8, string a9, string a10, string a11, string a12, string a13, string a14, string a15, string a16)
  10 + {
  11 +
  12 + string vstring = a1;
  13 + switch (v)
  14 + {
  15 + case 0: vstring = a1; break;
  16 + case 1: vstring = a2; break;
  17 + case 2: vstring = a3; break;
  18 + case 3: vstring = a4; break;
  19 + case 4: vstring = a5; break;
  20 + case 5: vstring = a6; break;
  21 + case 6: vstring = a7; break;
  22 + case 7: vstring = a8; break;
  23 + case 8: vstring = a9; break;
  24 + case 9: vstring = a10; break;
  25 + case 10: vstring = a11; break;
  26 + case 11: vstring = a12; break;
  27 + case 12: vstring = a13; break;
  28 + case 13: vstring = a14; break;
  29 + case 14: vstring = a15; break;
  30 + case 15: vstring = a16; break;
  31 + }
  32 + sprintf(buff, "\"%s\":\"%s\",", name, vstring.c_str());
  33 + strcat(resultbuff, buff);
  34 + }
  35 +
  36 + void clsJson::JsonAttrParse(const char* name,char* resultbuff,char* buff, string &v)
  37 + {
  38 + sprintf(buff, "\"%s\":\"%s\",", name, v.c_str());
  39 + strcat(resultbuff, buff);
  40 + }
  41 +
  42 + void clsJson::JsonAttrParse(const char* name,char* resultbuff,char* buff, bool &v)
  43 + {
  44 + sprintf(buff, "\"%s\":\"%s\",", name, v?"true":"false");
  45 + strcat(resultbuff, buff);
  46 + }
  47 +
  48 + void clsJson::JsonAttrParse(const char* name,char* resultbuff,char* buff, double &v)
  49 + {
  50 + sprintf(buff, "\"%s\":\"%0.2f\",", name,v);
  51 + strcat(resultbuff, buff);
  52 + }
  53 +
  54 + void clsJson::JsonAttrParse(const char* name,char* resultbuff,char* buff, int &v)
  55 + {
  56 + sprintf(buff, "\"%s\":\"%d\",", name, v);
  57 + strcat(resultbuff, buff);
  58 + }
  59 +
  60 + void clsJson::JsonAttrParse(const char* name,char* resultbuff,char* buff, long &v)
  61 + {
  62 + sprintf(buff, "\"%s\":\"%ld\",", name, v);
  63 + strcat(resultbuff, buff);
  64 + }
  65 +
  66 + void clsJson::JsonAttrEnd(char* resultbuff)
  67 + {
  68 + int len = strlen(resultbuff);
  69 + if(len>0 && resultbuff[len-1] == ',')
  70 + {
  71 + resultbuff[len-1] = '}';
  72 + }
  73 + else
  74 + {
  75 + resultbuff[len] = '}';
  76 + resultbuff[len+1] = 0;
  77 + }
  78 + }
  79 +
  80 +
  81 + void clsJson::JsonAttrParseColor(const char* name,const char*name2,char* resultbuff,char* buff,unsigned int& value)
  82 + {
  83 + string sColor = "", sTransparency = "";
  84 + //StringHelp::ColorToString(value, sColor, sTransparency);
  85 +
  86 + sprintf(buff, "\"%s\":\"%s\",\"%s\":\"%s\",", name, sColor.c_str(),name2,sTransparency.c_str());
  87 + strcat(resultbuff, buff);
  88 + }
  89 +
  90 +} // namespace DmapDll
\ No newline at end of file
... ...
  1 +#ifndef _clsJson_H_
  2 +#define _clsJson_H_
  3 +#include"string"
  4 +#include "AppendBuffer.h"
  5 +using namespace std;
  6 +namespace DmapCore_30
  7 +{
  8 + class Renderer;
  9 + class clsJson
  10 + {
  11 + public:
  12 + static void ParseEnum(const char* name,char* resultbuff,char * buff,int, string a1 = "", string a2 = "", string a3 = "", string a4 = "", string a5 = "", string a6 = "", string a7 = "", string a8 = "", string a9 = "", string a10 = "", string a11 = "", string a12 = "", string a13 = "", string a14 = "", string a15 = "", string a16 = "");
  13 + static void JsonAttrParse(const char* name,char* resultbuff,char* buff, string &v);
  14 + static void JsonAttrParse(const char* name,char* resultbuff,char* buff, bool &v);
  15 + static void JsonAttrParse(const char* name,char* resultbuff,char* buff, double &v);
  16 + static void JsonAttrParse(const char* name,char* resultbuff,char* buff, int &v);
  17 + static void JsonAttrParse(const char* name,char* resultbuff,char* buff, long &v);
  18 + static void JsonAttrEnd(char* resultbuff);
  19 +
  20 + static void JsonAttrParseColor(const char* name,const char*name2,char* resultbuff,char* buff, unsigned int&value);
  21 + };
  22 +}
  23 +
  24 +#endif
\ No newline at end of file
... ...
  1 +
  2 +#include<malloc.h>
  3 +#include "clsMalloc.h"
  4 +#include<cstring>
  5 +
  6 +namespace DmapCore_30
  7 +{
  8 + clsMalloc::clsMalloc()
  9 + {
  10 + m_iN = 1;
  11 + mem = NULL;
  12 + }
  13 + clsMalloc::clsMalloc(size_t size)
  14 + {
  15 + m_iN = 1;
  16 + mem = (char *)malloc(size);
  17 + std::memset(mem, 0, size);
  18 + }
  19 +
  20 + clsMalloc::clsMalloc(char *c)
  21 + {
  22 + m_iN = 1;
  23 + mem = c;
  24 + }
  25 +
  26 + clsMalloc::~clsMalloc(void)
  27 + {
  28 + if (mem)
  29 + {
  30 + free(mem);
  31 + mem = 0;
  32 + }
  33 + }
  34 + bool clsMalloc::AddRef()
  35 + {
  36 + m_iN++;
  37 + return true;
  38 + }
  39 + bool clsMalloc::Release()
  40 + {
  41 + m_iN--;
  42 + if (m_iN < 0)
  43 + return false;
  44 + if (!m_iN)
  45 + delete this;
  46 + return true;
  47 + }
  48 + bool clsMalloc::Destroy()
  49 + {
  50 + delete this;
  51 + return true;
  52 + }
  53 + bool clsMalloc::MemSet(int value, size_t size)
  54 + {
  55 + memset(mem, value, size);
  56 + return true;
  57 + }
  58 +
  59 + void clsMalloc::ReMalloc(size_t size)
  60 + {
  61 + free(mem);
  62 + mem = (char*)malloc(size);
  63 + memset(mem, 0, size);
  64 + }
  65 +
  66 + void clsMalloc::SetSize(size_t size)
  67 + {
  68 + this->size = size;
  69 + }
  70 +
  71 + size_t clsMalloc::GetSize()
  72 + {
  73 + return size;
  74 + }
  75 +}
\ No newline at end of file
... ...
  1 +#ifndef _clsMalloc_H_
  2 +#define _clsMalloc_H_
  3 +namespace DmapCore_30
  4 +{
  5 + class clsMalloc
  6 + {
  7 + public:
  8 + clsMalloc();
  9 + clsMalloc(char *c);
  10 + clsMalloc(size_t size);
  11 + ~clsMalloc(void);
  12 + bool AddRef();
  13 + bool Release();
  14 + bool Destroy();
  15 +
  16 + bool MemSet(int value, size_t size);
  17 + void ReMalloc(size_t size);
  18 +
  19 + void SetSize(size_t size);
  20 + size_t GetSize();
  21 +
  22 + char *mem;
  23 +
  24 + size_t size;
  25 +
  26 + private:
  27 + int m_iN;
  28 + };
  29 +
  30 +}
  31 +
  32 +#endif
\ No newline at end of file
... ...
  1 +#include "clsPng.h"
  2 +#include"clsCrSurf.h"
  3 +namespace DmapCore_30
  4 +{
  5 + clsPng::clsPng(void)
  6 + {
  7 + b = 0;
  8 + //b3=0;
  9 + //p1=0;
  10 + patta = 0;
  11 + }
  12 +
  13 + clsPng::~clsPng(void)
  14 + {
  15 + // if(p1){delete p1;p1=0;}
  16 + if (patta){ delete patta; patta = 0; };
  17 +
  18 + if (b){ free(b); b = 0; }
  19 + // if(b3){free(b3);b3=0;}
  20 + }
  21 +
  22 + int clsPng::ReadPng(const char * fileName, unsigned int colorThis_)
  23 + {
  24 + try
  25 + {
  26 + // b = (unsigned char *)malloc(1024);
  27 + unsigned int colorThis = colorThis_; ((char *)&colorThis)[3] = 0;
  28 + cairo_surface_t* image = cairo_image_surface_create_from_png(fileName);
  29 + clsCrSurf clsCS(image);
  30 + int width_image = cairo_image_surface_get_width(image); int height_image = cairo_image_surface_get_height(image);
  31 +
  32 + if (width_image == 0 || height_image == 0)return 1;
  33 + {
  34 + unsigned char* b3 = cairo_image_surface_get_data(image);
  35 + b = (unsigned char *)malloc(4 * width_image*height_image);
  36 + memcpy(b, b3, 4 * width_image*height_image);
  37 + }
  38 + for (int j = 0; j < height_image; j++)
  39 + {
  40 + int *c = ((int *)(b + 4 * (width_image * j)));
  41 + for (int i = 0; i < width_image; i++, c++)
  42 + {
  43 + if (((unsigned char *)c)[3] == 0)
  44 + {
  45 + c[0] = colorThis;
  46 + }
  47 + }
  48 + }
  49 + int beforCount = 0, endCount = 0;
  50 + for (int j = 0; j < height_image; j++)
  51 + {
  52 + bool found = false;
  53 + int *c = ((int *)(b + 4 * (width_image * j)));
  54 + for (int i = 0; i < width_image; i++, c++)
  55 + {
  56 + if (((unsigned char *)c)[3] == 0)continue;
  57 + found = true; break;
  58 + }
  59 + if (found)break;
  60 + beforCount++;
  61 + }
  62 + for (int j = height_image - 1; j >= 0; j--)
  63 + {
  64 + bool found = false;
  65 + int *c = ((int *)(b + 4 * (width_image * j)));
  66 + for (int i = 0; i < width_image; i++, c++)
  67 + {
  68 + if (((unsigned char *)c)[3] == 0)continue;
  69 + found = true; break;
  70 + }
  71 + if (found)break;
  72 + endCount++;
  73 + }
  74 + if (beforCount + endCount >= height_image){ return 1; }
  75 + if (beforCount>0)
  76 + {
  77 + int hTemp = height_image - (beforCount + endCount);
  78 + memmove(b, b + beforCount*width_image * 4, hTemp*width_image * 4);
  79 + height_image = hTemp;
  80 + }
  81 +
  82 + agg::rendering_buffer rbuf_img_aa;
  83 +
  84 + rbuf_img_aa.attach(b, width_image, height_image, (width_image)* 4);
  85 + pattern_src_brightness_to_alpha_rgba8 p1(rbuf_img_aa);
  86 + patta = new agg::line_image_pattern<agg::pattern_filter_bilinear_rgba8>(fltr, p1);
  87 + }
  88 + catch (...)
  89 + {
  90 + return (1);
  91 + }
  92 + return 0;
  93 +
  94 + /*
  95 + // globeLock.Log1Message("1","aa");
  96 + char sz[2000];
  97 + int len=strlen(fileName);
  98 + for(int i=0;i<=len;i++)
  99 + {
  100 + if(fileName[i]=='/')
  101 + {
  102 + sz[i]='\\';
  103 + }
  104 + else
  105 + {
  106 + sz[i]=fileName[i];
  107 + }
  108 + }
  109 + clsPngRead read;
  110 + ZeroFile zeroFile;
  111 + zeroFile.fp=fopen(sz,"rb");
  112 + FILE *fp = zeroFile.fp;
  113 + if (!fp)
  114 + {
  115 + return (1);
  116 + }
  117 + //globeLock.Log1Message("2","aa");
  118 + try
  119 + {
  120 + int k=read.readpng_init(fp,&width,&height);
  121 + png_uint_16 rr=0,gg=0,bb=0;
  122 + k=read.readpng_get_bgcolor(&rr,&gg,&bb);
  123 + //png_uint_32 rowbytes;
  124 + b=read.readpng_get_image(0,&channels,&rowbytes);
  125 + if(channels==3&&b)
  126 + {
  127 + int rowbytes1=4*rowbytes/3;
  128 + png_byte *b1=(png_byte *)malloc(width*height*4);
  129 + for(unsigned long j=0;j<height;j++)
  130 + {
  131 + for(unsigned long i=0;i<width;i++)
  132 + {
  133 + (b1+rowbytes1*j+i*4)[0]=(b+rowbytes*j+i*3)[0];
  134 + (b1+rowbytes1*j+i*4)[1]=(b+rowbytes*j+i*3)[1];
  135 + (b1+rowbytes1*j+i*4)[2]=(b+rowbytes*j+i*3)[2];
  136 + (b1+rowbytes1*j+i*4)[3]=255;
  137 + }
  138 + }
  139 + free(b);
  140 + b=b1;
  141 + rowbytes=4*rowbytes/3;
  142 + }
  143 +
  144 + read.readpng_cleanup(0);
  145 + //globeLock.Log1Message("3","aa");
  146 +
  147 + unsigned long j;
  148 + for(j=0;j<height;j++)
  149 + {
  150 + for(unsigned long i=0;i<width;i++)
  151 + {
  152 + png_byte rrr=(b+rowbytes*j+i*4)[0];
  153 + //png_byte ggg=(icon+rowbytes*j+i*4)[1];
  154 + png_byte ggg=(b+rowbytes*j+i*4)[1];
  155 + png_byte bbb=(b+rowbytes*j+i*4)[2];
  156 + //unsigned char aa[100];
  157 + //memcpy(aa,b,sizeof(aa));
  158 +
  159 + if(rrr==0&&ggg==0&&bbb==0)
  160 + {
  161 + rrr=1;
  162 + }
  163 + else if(rrr==255&&ggg==255&&bbb==255)
  164 + {
  165 + //rrr=254;
  166 + }
  167 +
  168 + (b+rowbytes*j+i*4)[0]=bbb;
  169 + //ggg(icon+rowbytes*j+i*4)[1];
  170 + (b+rowbytes*j+i*4)[2]=rrr;
  171 +
  172 + if(read.color_type==6)
  173 + {
  174 + if((b+rowbytes*j+i*4)[3]==0)
  175 + {
  176 + (b+rowbytes*j+i*4)[0]=255;
  177 + (b+rowbytes*j+i*4)[1]=255;
  178 + (b+rowbytes*j+i*4)[2]=255;
  179 + }
  180 + }
  181 + }
  182 + }
  183 + //globeLock.Log1Message("4","aa");
  184 + png_byte *b3=(png_byte *)malloc(width*height*3);
  185 + png_byte *t=b3;
  186 + for(j=0;j<height;j++)
  187 + {
  188 + for(unsigned long i=0;i<width;i++)
  189 + {
  190 + png_byte rrr=(b+rowbytes*j+i*4)[0];
  191 + png_byte ggg=(b+rowbytes*j+i*4)[1];
  192 + png_byte bbb=(b+rowbytes*j+i*4)[2];
  193 +
  194 + if((b+rowbytes*j+i*4)[3]==0)
  195 + {
  196 + rrr=ggg=bbb=255;
  197 + }
  198 +
  199 + t[0]=rrr;t++;
  200 + t[0]=ggg;t++;
  201 + t[0]=bbb;t++;
  202 + }
  203 + }
  204 + agg::rendering_buffer rbuf_img_aa;
  205 + rbuf_img_aa.attach(b3,width,height,width * 3);pattern_src_brightness_to_alpha_rgba8 p1(rbuf_img_aa);
  206 + //;p1=new pattern_src_brightness_to_alpha_rgba8(rbuf_img_aa);
  207 + patta=new agg::line_image_pattern<agg::pattern_filter_bilinear_rgba8>(fltr,p1);
  208 +
  209 + free(b);b=b3;
  210 + //free(p1);p1=0;
  211 + //globeLock.Log1Message("5","aa");
  212 + return 0;
  213 + }
  214 + catch(...)
  215 + {
  216 + return (1);
  217 + }
  218 + */
  219 + //return 0;
  220 + }
  221 +
  222 +
  223 +
  224 + /*
  225 + {
  226 + clsPngRead read;
  227 + FILE *fp = fopen("D:\\beijing\\temp\\2.png", "r+b");
  228 + if (!fp)
  229 + {
  230 + return (ERROR);
  231 + }
  232 + unsigned long width,height;
  233 + int k=read.readpng_init(fp,&width,&height);
  234 + png_uint_16 rr=0,gg=0,bb=0;
  235 + k=read.readpng_get_bgcolor(&rr,&gg,&bb);
  236 + int channels;png_uint_32 rowbytes;
  237 + png_byte *b=read.readpng_get_image(0,&channels,&rowbytes);
  238 +
  239 + HDC hdc=::GetDC(0);
  240 + int cc=RGB(255,255,255);
  241 + for(int j=0;j<height;j++);
  242 + {
  243 + png_byte *brow=b+j*rowbytes;
  244 + for(int i=0;i<width;i++,brow+=channels)
  245 + {
  246 + int c=RGB(brow[0],brow[1],brow[2]);
  247 + if(c!=cc){
  248 + // ::SetPixel(hdc,i,j,c);
  249 + }
  250 + }
  251 + }
  252 + width=width;
  253 + }
  254 + */
  255 +
  256 +}
\ No newline at end of file
... ...
  1 +#pragma once
  2 +
  3 +
  4 +namespace DmapCore_30
  5 +{
  6 + class pattern_src_brightness_to_alpha_rgba8
  7 + {
  8 + private:
  9 + agg::rendering_buffer* m_rb;
  10 + pixfmt m_pf;
  11 + public:
  12 + pattern_src_brightness_to_alpha_rgba8(agg::rendering_buffer& rb) :
  13 + m_rb(&rb), m_pf(*m_rb) {}
  14 +
  15 + unsigned width() const { return m_pf.width(); }
  16 + unsigned height() const { return m_pf.height(); }
  17 + agg::rgba8 pixel(int x, int y) const
  18 + {
  19 + agg::rgba8 c = m_pf.pixel(x, y);
  20 + // c.a = brightness_to_alpha[c.r + c.g + c.b]; //stbstb
  21 + // c.r=255;
  22 + // c.g=255;
  23 + // c.b=255;
  24 + c.a = 255; //brightness_to_alpha[c.r + c.g + c.b];
  25 + return c;
  26 + }
  27 + };
  28 +
  29 + class clsPng
  30 + {
  31 + public:
  32 + clsPng(void);
  33 + public:
  34 + ~clsPng(void);
  35 + //unsigned long width,height;
  36 + //int channels;
  37 + unsigned char *b;
  38 + public:
  39 + int ReadPng(const char * fileName, unsigned int colorThis);
  40 +
  41 + private:
  42 + agg::pattern_filter_bilinear_rgba8 fltr;
  43 + public:
  44 + agg::line_image_pattern<agg::pattern_filter_bilinear_rgba8> *patta;
  45 + };
  46 +}
\ No newline at end of file
... ...
  1 +
  2 +#include "clsRect.h"
  3 +#include <math.h>
  4 +
  5 +using namespace std;
  6 +namespace DmapCore_30
  7 +{
  8 + Rect::Rect()
  9 + {
  10 + m_dTop = 0;
  11 + m_dRight = 0;
  12 + m_dBottom = 0;
  13 + m_dLeft = 0;
  14 + }
  15 + Rect::Rect(double top, double right, double bottom, double left)
  16 + {
  17 + m_dTop = top;
  18 + m_dRight = right;
  19 + m_dBottom = bottom;
  20 + m_dLeft = left;
  21 + }
  22 +
  23 + Rect::~Rect()
  24 + {
  25 + }
  26 +
  27 +
  28 +
  29 + Rect * Rect::CreateNew()
  30 + {
  31 + Rect * dest = new Rect();
  32 + return dest;
  33 + }
  34 +
  35 + Rect * Rect::CreateNew(double top, double right, double bottom, double left)
  36 + {
  37 + Rect* dest = new Rect(top, right, bottom, left);
  38 + return dest;
  39 + }
  40 +
  41 + bool Rect::Normal()
  42 + {
  43 + double temp;
  44 + if (m_dLeft > m_dRight)
  45 + {
  46 + temp = m_dLeft;
  47 + m_dLeft = m_dRight;
  48 + m_dRight = temp;
  49 + }
  50 + if (m_dBottom > m_dTop)
  51 + {
  52 + temp = m_dTop;
  53 + m_dTop = m_dBottom;
  54 + m_dBottom = temp;
  55 + }
  56 + return true;
  57 + }
  58 + bool Rect::Scale(double num)
  59 + {
  60 + //中心点为标准?
  61 + this->Normal();
  62 +
  63 + double w = m_dRight - m_dLeft;
  64 + double h = m_dTop - m_dBottom;
  65 +
  66 + double x = (m_dRight + m_dLeft) / 2;
  67 + double y = (m_dTop + m_dBottom) / 2;
  68 +
  69 + double w_ = w * num;
  70 + double h_ = h * num;
  71 +
  72 + m_dTop = y + h_ / 2;
  73 + m_dRight = x + w_ / 2;
  74 + m_dBottom = y - h_ / 2;
  75 + m_dLeft = x - w_ / 2;
  76 +
  77 + return true;
  78 + }
  79 + double Rect::GetArea()
  80 + {
  81 + this->Normal();
  82 + double area = (m_dRight - m_dLeft)* (m_dTop - m_dBottom);
  83 + return area;
  84 + }
  85 +
  86 + bool Rect::GetExtent(double &boxX1, double& boxX2, double &boxY1, double &boxY2)
  87 + {
  88 + if (std::fmin(boxX1, boxX2) > this->m_dRight || std::fmax(boxX1, boxX2) < this->m_dLeft ||
  89 + std::fmin(boxY1, boxY2) > this->m_dTop || std::fmax(boxY1, boxY2) < this->m_dBottom)
  90 + {
  91 + if (!(std::fmin(boxY1, boxY2) > this->m_dRight || std::fmax(boxY1, boxY2) < this->m_dLeft ||
  92 + std::fmin(boxX1, boxX2) > this->m_dTop || std::fmax(boxX1, boxX2) < this->m_dBottom))
  93 + {
  94 + double x1 = boxX1;
  95 + boxX1 = boxY1;
  96 + boxY1 = x1;
  97 + double x2 = boxX2;
  98 + boxX2 = boxY2;
  99 + boxY2 = x2;
  100 + return true;
  101 + }
  102 + }
  103 +
  104 + return false;
  105 + }
  106 +
  107 +}
\ No newline at end of file
... ...
  1 +/**************************************************************************
  2 +* file: clsRect.h
  3 +
  4 +* Author: qingxiongf
  5 +* Date: 2021-12-12 23:02:19
  6 +* Email: qingxiongf@chinadci.com
  7 +* copyright: 广州城市信息研究所有限公司
  8 +***************************************************************************/
  9 +
  10 +#ifndef __clsRect_h__
  11 +#define __clsRect_h__
  12 +
  13 +#include "dmap_core.h"
  14 +
  15 +namespace DmapCore_30
  16 +{
  17 + class CORE_EXPORT Rect
  18 + {
  19 + public:
  20 + Rect();
  21 + ~Rect();
  22 + Rect(double top, double right, double bottom, double left);
  23 + bool AddRef();
  24 + bool Release();
  25 + static Rect * CreateNew();
  26 + static Rect * CreateNew(double top, double right, double bottom, double left);
  27 +
  28 + bool GetExtent(double &x1, double& x2, double &y1, double &y2);
  29 +
  30 + bool Normal();
  31 + bool Scale(double num); // 放大 2倍 num=2 缩小两倍 num = 0.5
  32 + double GetArea();
  33 +
  34 + double m_dLeft;
  35 + double m_dRight;
  36 + double m_dTop;
  37 + double m_dBottom;
  38 + };
  39 +}
  40 +
  41 +
  42 +#endif // __clsRect_h__
... ...
  1 +
  2 +#include "clsStruct.h"
  3 +#define _USE_MATH_DEFINES
  4 +#include<math.h>
  5 +namespace DmapCore_30
  6 +{
  7 +
  8 + clsStruct::clsStruct()
  9 + {
  10 + }
  11 +
  12 +
  13 + clsStruct::~clsStruct()
  14 + {
  15 + }
  16 +
  17 +
  18 + bool clsStruct::GetCenter(double& x, double& y, LINE* pLine)
  19 + {
  20 + int nPoint = pLine->nPoint;
  21 + POINT* pPoint = pLine->p;
  22 + double x_max, x_min, y_max, y_min;
  23 + double x_, y_;
  24 + for (int i = 0; i < nPoint; i++)
  25 + {
  26 + x_ = pPoint[i].x;
  27 + y_ = pPoint[i].y;
  28 + if (i == 0)
  29 + {
  30 + x_max = x_min = x_;
  31 + y_max = y_min = y_;
  32 + }
  33 + else
  34 + {
  35 + if (x_ > x_max)x_max = x_;
  36 + if (x_ < x_min) x_min = x_;
  37 + if (y_ > y_max)y_max = y_;
  38 + if (y_ < y_min) y_min = y_;
  39 + }
  40 + }
  41 + x = (x_min + x_max) / 2;
  42 + y = (y_min + y_max) / 2;
  43 + return true;
  44 + }
  45 + bool clsStruct::GetCenter(double & x, double & y, MLINE* pMLine)
  46 + {
  47 + int nLine = pMLine->nLine;
  48 + clsStruct::LINE* pLine = pMLine->p;
  49 + double x_max, x_min, y_max, y_min;
  50 + double x_, y_;
  51 + for (int i = 0; i < nLine; i++)
  52 + {
  53 + int nPoint = (pLine + i)->nPoint;
  54 + clsStruct::POINT* pPoint = (pLine + i)->p;
  55 + for (int j = 0; j < nPoint; j++)
  56 + {
  57 + x_ = pPoint[j].x;
  58 + y_ = pPoint[j].y;
  59 + if (i == 0 && j == 0)
  60 + {
  61 + x_max = x_min = x_;
  62 + y_max = y_min = y_;
  63 + }
  64 + else
  65 + {
  66 + if (x_ > x_max)x_max = x_;
  67 + if (x_ < x_min) x_min = x_;
  68 + if (y_ > y_max)y_max = y_;
  69 + if (y_ < y_min) y_min = y_;
  70 + }
  71 + }
  72 + }
  73 + x = (x_min + x_max) / 2;
  74 + y = (y_min + y_max) / 2;
  75 + return true;
  76 + }
  77 + bool clsStruct::GetCenter(double& x, double& y, POLYGON* pPolygon)
  78 + {
  79 + return true;
  80 + }
  81 + bool clsStruct::GetCenter(double& x, double &y, MPOLYGON* pMPolygon)
  82 + {
  83 + double x_max = 0, x_min = 0, y_max = 0, y_min = 0;
  84 + double x_ = 0, y_ = 0;
  85 + int nPolygon = pMPolygon->nPolygon;
  86 + for (int i = 0; i < nPolygon; i++)
  87 + {
  88 + POLYGON* pPolygon = pMPolygon->p + i;
  89 + int nRing = pPolygon->nRing;
  90 + for (int j = 0; j < nRing; j++)
  91 + {
  92 + LINE* pRing = pPolygon->p + j;
  93 + int nPoint = pRing->nPoint;
  94 + for (int k = 0; k < nPoint; k++)
  95 + {
  96 + POINT* pPoint = pRing->p + k;
  97 + x_ = pPoint->x;
  98 + y_ = pPoint->y;
  99 + if (i == 0 && j == 0 && k == 0)
  100 + {
  101 + x_min = x_max = x_;
  102 + y_min = y_max = y_;
  103 + }
  104 + else
  105 + {
  106 + if (x_ > x_max)x_max = x_;
  107 + if (x_ < x_min) x_min = x_;
  108 + if (y_ > y_max)y_max = y_;
  109 + if (y_ < y_min) y_min = y_;
  110 + }
  111 + }
  112 + }
  113 + }
  114 + x = (x_max + x_min) / 2;
  115 + y = (y_max + y_min) / 2;
  116 + return true;
  117 + }
  118 + bool clsStruct::GetGravity(double& x, double&y, LINE* pLine)
  119 + {
  120 + double dLength = clsStruct::GetLength(pLine);
  121 +
  122 + double dHalf = dLength / 2;
  123 +
  124 + int nPoint = pLine->nPoint;
  125 + POINT* pPoint = pLine->p;
  126 + POINT* pp = pPoint;
  127 +
  128 + double x1, x2, y1, y2;
  129 + x2 = pp->x;
  130 + y2 = pp->y;
  131 + pp++;
  132 +
  133 + double len_now = 0;
  134 + int i = 1;
  135 + for (; i < nPoint; i++, pp++)
  136 + {
  137 + x1 = x2; y1 = y2;
  138 + x2 = pp->x;
  139 + y2 = pp->y;
  140 +
  141 + double dL = sqrt((x1 - x2)*(x1 - x2) + (y1 - y2)*(y1 - y2));
  142 + len_now += dL;
  143 + if (len_now > dHalf)
  144 + break;
  145 + }
  146 +
  147 + double dDelta_ = (len_now - dHalf) / (sqrt((x2 - x1)*(x2 - x1) + (y2 - y1)*(y2 - y1)));
  148 + x = x2 - (x2 - x1)*dDelta_;
  149 + y = y2 - (y2 - y1)*dDelta_;
  150 + return true;
  151 + }
  152 + bool clsStruct::GetGravity(double&x, double&y, int& iIndex, LINE*pLine)
  153 + {
  154 + double dLength = clsStruct::GetLength(pLine);
  155 +
  156 + double dHalf = dLength / 2;
  157 +
  158 + int nPoint = pLine->nPoint;
  159 + POINT* pPoint = pLine->p;
  160 + POINT* pp = pPoint;
  161 +
  162 + double x1, x2, y1, y2;
  163 + x2 = pp->x;
  164 + y2 = pp->y;
  165 + pp++;
  166 +
  167 + double len_now = 0;
  168 + int i = 1;
  169 + for (; i < nPoint; i++, pp++)
  170 + {
  171 + x1 = x2; y1 = y2;
  172 + x2 = pp->x;
  173 + y2 = pp->y;
  174 +
  175 + double dL = sqrt((x1 - x2)*(x1 - x2) + (y1 - y2)*(y1 - y2));
  176 + len_now += dL;
  177 + if (len_now > dHalf)
  178 + break;
  179 + }
  180 +
  181 + double dDelta_ = (len_now - dHalf) / (sqrt((x2 - x1)*(x2 - x1) + (y2 - y1)*(y2 - y1)));
  182 + x = x2 - (x2 - x1)*dDelta_;
  183 + y = y2 - (y2 - y1)*dDelta_;
  184 + iIndex = i - 1;
  185 + return true;
  186 + }
  187 + bool clsStruct::GetGravity(double& x, double&y, MLINE* pMLine)
  188 + {
  189 + return clsStruct::GetGravity(x, y, pMLine->p);
  190 + }
  191 + bool clsStruct::GetGravity(double& x, double&y, int& iIndex, MLINE* pMLine)
  192 + {
  193 + return clsStruct::GetGravity(x, y, iIndex, pMLine->p);
  194 + }
  195 +
  196 +
  197 + bool clsStruct::GetGravity(double& x, double&y, POLYGON* pPolygon)
  198 + {
  199 + return true;
  200 + }
  201 +
  202 +
  203 + bool clsStruct::GetGravity(double& x, double&y, MPOLYGON* pMPolygon)
  204 + {
  205 + //不能认为是第一个环的重心,需要找出面积最大的环
  206 +
  207 + int iPolygonIndex, iRingIndex;
  208 + int iMaxPolygonIndex, iMaxRingIndex;
  209 + double area, dMaxArea;
  210 +
  211 + int nPolygon = pMPolygon->nPolygon;
  212 + POLYGON* pPolygon = pMPolygon->p;
  213 +
  214 + for (iPolygonIndex = 0; iPolygonIndex < nPolygon; iPolygonIndex++)
  215 + {
  216 +
  217 + int nRing = (pPolygon + iPolygonIndex)->nRing;
  218 + LINE* pRing = (pPolygon + iPolygonIndex)->p;
  219 +
  220 + for (iRingIndex = 0; iRingIndex < nRing; iRingIndex++)
  221 + {
  222 + area = 0;
  223 + int nPoint = (pRing + iRingIndex)->nPoint;
  224 + POINT* pPoint = (pRing + iRingIndex)->p;
  225 +
  226 + double x1, y1, x2, y2;
  227 + for (int i = 0; i < nPoint - 1; i++)
  228 + {
  229 + x1 = (pPoint + i)->x; y1 = (pPoint + i)->y;
  230 + x2 = (pPoint + i + 1)->x; y2 = (pPoint + i + 1)->y;
  231 +
  232 + area += (x1 * y2 - x2 * y1) / 2;
  233 + }
  234 +
  235 + x1 = (pPoint + nPoint - 1)->x;
  236 + y1 = (pPoint + nPoint - 1)->y;
  237 + x2 = pPoint->x;
  238 + y2 = pPoint->y;
  239 + area += (x1 * y2 - x2 * y1) / 2;
  240 + area = fabs(area);
  241 +
  242 + if (iPolygonIndex == 0 && iRingIndex == 0)
  243 + {
  244 + dMaxArea = area;
  245 + iMaxPolygonIndex = iPolygonIndex;
  246 + iMaxRingIndex = iRingIndex;
  247 + }
  248 + else
  249 + {
  250 + if (dMaxArea < area)
  251 + {
  252 + dMaxArea = area;
  253 + iMaxPolygonIndex = iPolygonIndex;
  254 + iMaxRingIndex = iRingIndex;
  255 + }
  256 + }
  257 + }
  258 + }
  259 +
  260 + LINE* pRing = (pMPolygon->p + iMaxPolygonIndex)->p + iMaxRingIndex;
  261 +
  262 + int nPoint = pRing->nPoint;
  263 + POINT* p = pRing->p;
  264 +
  265 + double x1, y1, x2, y2;
  266 + x = 0; y = 0;
  267 + for (int i = 0; i < nPoint - 1; i++)
  268 + {
  269 + x1 = (p + i)->x;
  270 + x2 = (p + i + 1)->x;
  271 + y1 = (p + i)->y;
  272 + y2 = (p + i + 1)->y;
  273 +
  274 + x += (x1*y2 - x2*y1)*(x1 + x2);
  275 + y += (x1 * y2 - x2*y1)* (y1 + y2);
  276 + }
  277 +
  278 + x1 = (p + nPoint - 1)->x; y1 = (p + nPoint - 1)->y;
  279 + x2 = p->x; y2 = p->y;
  280 +
  281 + x += (x1*y2 - x2*y1)*(x1 + x2);
  282 + y += (x1 * y2 - x2*y1)* (y1 + y2);
  283 +
  284 + x /= 6 * dMaxArea;
  285 + y /= 6 * dMaxArea;
  286 + return true;
  287 + }
  288 +
  289 + bool clsStruct::GetRingGravity(double& x, double & y, LINE* pRing)
  290 + {
  291 + double area = 0;
  292 + x = 0; y = 0;
  293 +
  294 + int nPoint = pRing->nPoint;
  295 + POINT* p = pRing->p;
  296 + double x1, y1, x2, y2;
  297 +
  298 + for (int i = 0; i < nPoint; i++)
  299 + {
  300 + x1 = (p + i)->x; y1 = (p + i)->y;
  301 + if (i == nPoint - 1)
  302 + {
  303 + x2 = p->x; y2 = p->y;
  304 + }
  305 + else
  306 + {
  307 + x2 = (p + i + 1)->x;
  308 + y2 = (p + i + 1)->y;
  309 + }
  310 +
  311 + area += (x1*y2 - x2*y1) / 2;
  312 + x += (x1*y2 - x2*y1)*(x1 + x2);
  313 + y += (x1 * y2 - x2*y1)* (y1 + y2);
  314 + }
  315 +
  316 + x /= 6 * area;
  317 + y /= 6 * area;
  318 + return true;
  319 + }
  320 +
  321 + bool clsStruct::GetStart(MLINE*pMLine, double& x1, double&y1, double&x2, double&y2)
  322 + {
  323 + LINE* pLine = pMLine->p;
  324 + POINT* pPoint1 = pLine->p;
  325 + POINT* pPoint2 = pLine->p + 1;
  326 + x1 = pPoint1->x;
  327 + y1 = pPoint1->y;
  328 + x2 = pPoint2->x;
  329 + y2 = pPoint2->y;
  330 + return true;
  331 + }
  332 + bool clsStruct::GetEnd(MLINE* pMLine, double&x1, double&y1, double&x2, double&y2)
  333 + {
  334 + LINE* pLine = pMLine->p;
  335 + int nPoint = pLine->nPoint;
  336 + POINT* pPoint1 = pLine->p + nPoint - 1;
  337 + POINT* pPoint2 = pLine->p + nPoint - 2;
  338 + x1 = pPoint1->x;
  339 + y1 = pPoint1->y;
  340 + x2 = pPoint2->x;
  341 + y2 = pPoint2->y;
  342 + return true;
  343 + }
  344 + bool clsStruct::GetCenter(MLINE* pMLine, double &x1__, double&y1__, double&x2__, double&y2__)
  345 + {
  346 +
  347 + LINE* pLine = pMLine->p;
  348 + int nPoint = pLine->nPoint;
  349 + double dLength = 0;
  350 + //计算总长
  351 +
  352 + double x1, x2, y1, y2;
  353 + x2 = pLine->p->x;
  354 + y2 = pLine->p->y;
  355 +
  356 + POINT* pp = pLine->p;
  357 + pp++;
  358 + int i;
  359 + for (i = 1; i < nPoint; i++, pp++)
  360 + {
  361 + x1 = x2; y1 = y2;
  362 + x2 = pp->x;
  363 + y2 = pp->y;
  364 + double dL = sqrt((x1 - x2)*(x1 - x2) + (y1 - y2)*(y1 - y2));
  365 + dLength += dL;
  366 + }
  367 +
  368 +
  369 +
  370 + //找出中心点所在线段索引
  371 + x2 = pLine->p->x;
  372 + y2 = pLine->p->y;
  373 + pp = pLine->p; pp++;
  374 + double dHalf = dLength / 2;
  375 + double dNow = 0;
  376 + for (i = 1; i < nPoint; i++, pp++)
  377 + {
  378 + x1 = x2; y1 = y2;
  379 + x2 = pp->x;
  380 + y2 = pp->y;
  381 + double dL = sqrt((x1 - x2)*(x1 - x2) + (y1 - y2)*(y1 - y2));
  382 + dNow += dL;
  383 + if (dNow >= dHalf)
  384 + break;
  385 + }
  386 + //中心点所在线段的第二个顶点索引为当前 i
  387 +
  388 + //赋值
  389 + x2__ = pp->x;
  390 + y2__ = pp->y;
  391 + pp--;
  392 + x1__ = pp->x;
  393 + y1__ = pp->y;
  394 +
  395 +
  396 + return true;
  397 + }
  398 +
  399 + double clsStruct::GetLength(LINE* pLine)
  400 + {
  401 + POINT* pPoint = pLine->p;
  402 + int nPoint = pLine->nPoint;
  403 +
  404 + double dLength = 0;
  405 +
  406 + double x1, x2, y1, y2;
  407 +
  408 + POINT* pp = pPoint;
  409 + x2 = pp->x;
  410 + y2 = pp->y;
  411 + pp++;
  412 +
  413 + for (int i = 1; i < nPoint; i++, pp++)
  414 + {
  415 + x1 = x2; y1 = y2;
  416 + x2 = pp->x;
  417 + y2 = pp->y;
  418 + double dL = sqrt((x1 - x2)*(x1 - x2) + (y1 - y2)*(y1 - y2));
  419 + dLength += dL;
  420 + }
  421 +
  422 + return dLength;
  423 + }
  424 +
  425 + double clsStruct::GetLength5(LINE* pLine, int & iPointIndex, double &beginX, double &beginY, double& dRadia, int w, int h, double dw)
  426 + {
  427 + POINT* pPoint = pLine->p;
  428 + int nPoint = pLine->nPoint;
  429 +
  430 + double dLength = 0;
  431 +
  432 + double x1=0, x2=0, y1=0, y2=0;
  433 +
  434 + POINT* pp = pPoint;
  435 + int i = 0;
  436 +
  437 + for (; i < nPoint; i += 1, pp += 1)
  438 + {
  439 + if (pp->x >0 && pp->x<w && pp->y>0 && pp->y<h)
  440 + {
  441 + x2 = pp->x;
  442 + y2 = pp->y;
  443 + break;
  444 + }
  445 + }
  446 +
  447 + while (i < nPoint)
  448 + {
  449 + beginX = pp->x;
  450 + beginY = pp->y;
  451 + iPointIndex = i;
  452 + x1 = 0;
  453 + y1 = 0;
  454 + double px = 0;
  455 + double py = 0;
  456 +
  457 + double dr = 0;
  458 + dLength = 0;
  459 +
  460 +
  461 + for (i += 1, pp += 1; i < nPoint; i += 1, pp += 1)
  462 + {
  463 + if (pp->x >0 && pp->x<w && pp->y>0 && pp->y<h && pp->x != beginX)
  464 + {
  465 + x1 = x2; y1 = y2;
  466 + x2 = pp->x;
  467 + y2 = pp->y;
  468 +
  469 +
  470 + if (px == 0 && py == 0)
  471 + {
  472 + px = x2 - x1;
  473 + py = y2 - x1;
  474 + dr = atan((y2 - beginY)/(x2 - beginX));
  475 +
  476 + }
  477 + else
  478 + {
  479 + double d0 = atan((y2 - beginY)/(x2 - beginX));
  480 +
  481 + if (fabs(d0-dr)> 0.05)
  482 + {
  483 + if (dLength > dw*2)
  484 + {
  485 + dRadia = atan((y1 - beginY) / (x1 - beginX));
  486 + if (beginX > x1)
  487 + {
  488 + beginX = x1;
  489 + beginY = y1 + 3;
  490 + }
  491 + else
  492 + {
  493 + beginY += 3;
  494 + }
  495 +
  496 + }
  497 + break;
  498 + }
  499 + }
  500 + double dL = sqrt((x1 - x2)*(x1 - x2) + (y1 - y2)*(y1 - y2));
  501 + dLength += dL;
  502 + }
  503 + else
  504 + {
  505 + break;
  506 + }
  507 + }
  508 +
  509 + if ((dLength > 2 * dw || i == nPoint) && x2 - beginX>1)
  510 + {
  511 + double d0 = atan((y2 - beginY) / (x2 - beginX));
  512 + dRadia = atan((y1 - beginY) / (x1 - beginX));
  513 + if (beginX > x1)
  514 + {
  515 + beginX = x1;
  516 + beginY = y1 + 3;
  517 + }
  518 + else
  519 + {
  520 + beginY += 3;
  521 + }
  522 + return dLength;
  523 + }
  524 + }
  525 +
  526 + //if (i == nPoint && dLength > dw)
  527 + //{
  528 + // double d0 = atan((y2 - beginY) / (x2 - beginX));
  529 + // dRadia = atan((y1 - beginY) / (x1 - beginX));
  530 + // if (abs(d0) < 0.62)
  531 + // {
  532 + // //dRadia
  533 +
  534 + // if (x1 < beginX)
  535 + // {
  536 + // beginX = x1;
  537 + // beginY = y1;
  538 + // }
  539 +
  540 + // /* beginX = (x1 ) / 2;
  541 + // beginY = (y1 + beginY) / 2 + 3;*/
  542 + // return dLength;
  543 + // }
  544 + //}
  545 +
  546 + return 0;
  547 + }
  548 +
  549 + double clsStruct::GetMaxRing(MPOLYGON* pMPolygon, int& iPolygonIndex, int& iRingIndex)
  550 + {
  551 + int nPolygon = pMPolygon->nPolygon;
  552 + POLYGON* pPolygon = pMPolygon->p;
  553 + nPolygon = nPolygon;
  554 + double dMaxArea;
  555 +
  556 + for (int i = 0; i < nPolygon; i++)
  557 + {
  558 + int nRing = (pPolygon + i)->nRing;
  559 + LINE* pRing = (pPolygon + i)->p;
  560 +
  561 + for (int j = 0; j < nRing; j++)
  562 + {
  563 + LINE* pp = pRing + j;
  564 + int nPoint = (pRing + j)->nPoint;
  565 + POINT* pPoint = (pRing + j)->p;
  566 +
  567 + double x1, y1, x2, y2, area = 0;
  568 + for (int k = 0; k < nPoint - 1; k++)
  569 + {
  570 + x1 = (pPoint + k)->x; y1 = (pPoint + k)->y;
  571 + x2 = (pPoint + k + 1)->x; y2 = (pPoint + k + 1)->y;
  572 +
  573 + area += (x1*y2 - x2*y1) / 2;
  574 + area = area;
  575 + }
  576 + x1 = (pPoint + nPoint - 1)->x;
  577 + y1 = (pPoint + nPoint - 1)->y;
  578 + x2 = pPoint->x;
  579 + y2 = pPoint->y;
  580 + area += (x1 * y2 - x2 * y1) / 2;
  581 + area = fabs(area);
  582 +
  583 +
  584 + if (i == 0 && j == 0)
  585 + {
  586 + dMaxArea = area;
  587 + iPolygonIndex = i;
  588 + iRingIndex = j;
  589 + }
  590 + else
  591 + {
  592 + if (dMaxArea < area)
  593 + {
  594 + dMaxArea = area;
  595 + iPolygonIndex = i;
  596 + iRingIndex = j;
  597 + }
  598 + }
  599 + }
  600 + }
  601 +
  602 + return dMaxArea;
  603 + }
  604 +
  605 + bool clsStruct::GetConvexRing(clsStruct::LINE* pRing, std::vector<double>&vX, std::vector<double>& vY)
  606 + {
  607 + //使用卷包裹法
  608 +
  609 + vX.clear(); vY.clear();
  610 +
  611 + int nPoint = pRing->nPoint; clsStruct::POINT* pPoint = pRing->p;
  612 +
  613 + double y_min = pPoint->y; int iYMinIndex = 0;
  614 +
  615 + //找出最低点
  616 +
  617 + for (int i = 1; i < nPoint; i++)
  618 + {
  619 + double y = (pPoint + i)->y;
  620 + if (y < y_min)
  621 + {
  622 + y_min = y;
  623 + iYMinIndex = i;
  624 + }
  625 + else if (y == y_min && ((pPoint + i)->x < (pPoint + iYMinIndex)->x))
  626 + iYMinIndex = i;
  627 + }
  628 +
  629 +
  630 + double x, y;
  631 +
  632 + int iIndexNow, iIndexLast;
  633 +
  634 + iIndexNow = iYMinIndex;
  635 + /*x = (pPoint + iIndexNow)->x; y = (pPoint + iIndexNow)->y;
  636 + vX.push_back(x); vY.push_back(y);*/
  637 +
  638 + iIndexNow = clsStruct::GetNextConvexPointMin(pRing, iIndexNow);
  639 + iIndexLast = iYMinIndex;
  640 + x = (pPoint + iIndexNow)->x; y = (pPoint + iIndexNow)->y;
  641 + vX.push_back(x); vY.push_back(y);
  642 +
  643 + while (iIndexNow != iYMinIndex)
  644 + {
  645 + int iIndexTemp = clsStruct::GetNextConvexPointRotate(pRing, iIndexNow, iIndexLast);
  646 + iIndexLast = iIndexNow; iIndexNow = iIndexTemp;
  647 + x = (pPoint + iIndexNow)->x; y = (pPoint + iIndexNow)->y;
  648 + vX.push_back(x); vY.push_back(y);
  649 + }
  650 +
  651 + return true;
  652 + }
  653 +
  654 + int clsStruct::GetNextConvexPointMin(LINE* pRing, int iPointIndexNow)
  655 + {
  656 + //返回下一个凸点的索引
  657 +
  658 + int nPoint = pRing->nPoint;
  659 + clsStruct::POINT* pPoint = pRing->p;
  660 +
  661 + double x1, y1, x2, y2;
  662 + x1 = (pPoint + iPointIndexNow)->x;
  663 + y1 = (pPoint + iPointIndexNow)->y;
  664 +
  665 + double dAngleMin = 2 * M_PI, dAngle;
  666 + int iAngleMinIndex;
  667 +
  668 + for (int i = 0; i < nPoint; i++)
  669 + {
  670 + x2 = (pPoint + i)->x;
  671 + y2 = (pPoint + i)->y;
  672 +
  673 + if ((x1 == x2) && (y1 == y2))
  674 + continue; //重合的点不考虑
  675 + if (y1 == y2)
  676 + {
  677 + if (x1 < x2)
  678 + dAngle = M_PI / 2;
  679 + else
  680 + dAngle = 3 * M_PI / 2;
  681 + }
  682 + else
  683 + {
  684 + dAngle = atan((y2 - y1) / (x2 - x1));
  685 +
  686 + if (x1>x2)
  687 + dAngle += M_PI;
  688 + if (dAngle < 0)
  689 + dAngle += 2 * M_PI;
  690 + }
  691 +
  692 + if (dAngle < dAngleMin)
  693 + {
  694 + dAngleMin = dAngle;
  695 + iAngleMinIndex = i;
  696 + }
  697 + }
  698 +
  699 +
  700 + return iAngleMinIndex;
  701 + }
  702 +
  703 + int clsStruct::GetNextConvexPointRotate(LINE* pRing, int iPointIndexNow, int iPointIndexLast)
  704 + {
  705 + //返回下一个凸点的索引
  706 +
  707 + int nPoint = pRing->nPoint;
  708 + clsStruct::POINT* pPoint = pRing->p;
  709 +
  710 + double x1, y1, x2, y2;
  711 + x1 = (pPoint + iPointIndexNow)->x;
  712 + y1 = (pPoint + iPointIndexNow)->y;
  713 + x2 = (pPoint + iPointIndexLast)->x;
  714 + y2 = (pPoint + iPointIndexLast)->y;
  715 +
  716 + double dAngleRotate;
  717 + if (x1 == x2)
  718 + {
  719 + if (y1 > y2)
  720 + dAngleRotate = 3 * M_PI / 2;
  721 + else
  722 + dAngleRotate = M_PI / 2;
  723 + }
  724 + else
  725 + {
  726 + dAngleRotate = atan((y1 - y2) / (x1 - x2));
  727 + if (x1 < x2)
  728 + dAngleRotate += M_PI;
  729 + }
  730 +
  731 +
  732 +
  733 + double dAngleMin = 2 * M_PI, dAngle, x, y, x2_, y2_;
  734 + int iAngleMinIndex;
  735 +
  736 + for (int i = 0; i < nPoint; i++)
  737 + {
  738 + x = (pPoint + i)->x;
  739 + y = (pPoint + i)->y;
  740 + /*
  741 + x0= (x - rx0)*cos(a) - (y - ry0)*sin(a) + rx0 ;
  742 + y0= (x - rx0)*sin(a) + (y - ry0)*cos(a) + ry0 ;
  743 + */
  744 + x2_ = (x - x1)*cos(-dAngleRotate) - (y - y1)*sin(-dAngleRotate) + x1;
  745 + y2_ = (x - x1)*sin(-dAngleRotate) + (y - y1)*cos(-dAngleRotate) + y1;
  746 +
  747 + if ((x1 == x2) && (y1 == y2))
  748 + dAngle = 2 * M_PI; //重合的点不考虑
  749 + else if (y1 == y2_)
  750 + {
  751 + if (x1 < x2_)
  752 + dAngle = M_PI / 2;
  753 + else
  754 + dAngle = 3 * M_PI / 2;
  755 + }
  756 + else
  757 + {
  758 + dAngle = atan((y2_ - y1) / (x2_ - x1));
  759 +
  760 + if (x1>x2_)
  761 + dAngle += M_PI;
  762 + if (dAngle < 0)
  763 + dAngle += 2 * M_PI;
  764 + }
  765 +
  766 + if (dAngle < dAngleMin)
  767 + {
  768 + dAngleMin = dAngle;
  769 + iAngleMinIndex = i;
  770 + }
  771 + }
  772 +
  773 +
  774 +
  775 + return iAngleMinIndex;
  776 + }
  777 +
  778 +
  779 + bool clsStruct::GetIsInRing(LINE* pRing, double x, double y)
  780 + {
  781 + int iCount = 0, nPoint = pRing->nPoint;
  782 + POINT* pPoint = pRing->p;
  783 + double x1, y1, x2, y2;
  784 +
  785 + for (int i = 0; i < nPoint; i++)
  786 + {
  787 + x1 = (pPoint + i)->x;
  788 + y1 = (pPoint + i)->y;
  789 + if (i == nPoint - 1)
  790 + {
  791 + x2 = pPoint->x;
  792 + y2 = pPoint->y;
  793 + }
  794 + else
  795 + {
  796 + x2 = (pPoint + i + 1)->x;
  797 + y2 = (pPoint + i + 1)->y;
  798 + }
  799 +
  800 + if (((x1 > x) && (x2 > x)) && ((y1 > y) && (y2 < y) || ((y1 < y) && (y2 > y))))
  801 + iCount++;
  802 + }
  803 +
  804 +
  805 + return (iCount & 1);
  806 + }
  807 +
  808 +}
\ No newline at end of file
... ...
  1 +#ifndef _clsStruct_H_
  2 +#define _clsStruct_H_
  3 +#include<vector>
  4 +namespace DmapCore_30
  5 +{
  6 + class clsMalloc;
  7 + class Rect;
  8 + class clsStruct
  9 + {
  10 + public:
  11 + clsStruct();
  12 + ~clsStruct();
  13 + enum StructType
  14 + {
  15 + Struct_Point = 0,
  16 + Struct_Line = 1,
  17 + Struct_MLine = 2,
  18 + Struct_Polygon = 3,
  19 + Struct_MPolygon = 4,
  20 + Struct_Heat = 4
  21 + };
  22 + struct POINT
  23 + {
  24 + double x;
  25 + double y;
  26 + };
  27 + struct POLY_STRUCT
  28 + {
  29 + int nPoint;
  30 + POINT* pPoint;
  31 + int nPartCount;
  32 + clsMalloc* pPartStart;
  33 + clsMalloc* pAllFieldName;
  34 + clsMalloc* pAllFields; //除shape之外的所有字段
  35 + };
  36 +
  37 + struct LINE
  38 + {
  39 + int nPoint;
  40 + POINT* p;
  41 + };
  42 + struct MLINE
  43 + {
  44 + int nLine;
  45 + LINE* p;
  46 + };
  47 + struct POLYGON
  48 + {
  49 + int nRing;
  50 + LINE* p;
  51 + };
  52 + struct MPOLYGON
  53 + {
  54 + int nPolygon;
  55 + POLYGON* p;
  56 + };
  57 +
  58 + static bool GetCenter(double& x, double& y, LINE* pLine);
  59 + static bool GetCenter(double & x, double & y, MLINE* pMLine);
  60 + static bool GetCenter(double& x, double& y, POLYGON* pPolygon);
  61 + static bool GetCenter(double& x, double &y, MPOLYGON* pMPolygon);
  62 + static bool GetGravity(double& x, double&y, LINE* pLine);
  63 + static bool GetGravity(double&x, double&y, int& iIndex, LINE*pLine);
  64 + static bool GetGravity(double& x, double&y, MLINE* pMLine);
  65 + static bool GetGravity(double& x, double&y, int& iIndex, MLINE* pMLine);
  66 + static bool GetGravity(double& x, double&y, POLYGON* pPolygon);
  67 + static bool GetGravity(double& x, double&y, MPOLYGON* pMPolygon);
  68 + static bool GetRingGravity(double& x, double & y, LINE* pRing);
  69 +
  70 + //获取起点线段,终点线段,中心点线段
  71 + //不考虑一个multilinestring 有多条line
  72 + static bool GetStart(MLINE*pMLine, double& x1, double&y1, double&x2, double&y2);
  73 + static bool GetEnd(MLINE* pMLine, double&x1, double&y1, double&x2, double&y2);
  74 + static bool GetCenter(MLINE* pMLine, double &x1, double&y1, double&x2, double&y2);
  75 + static double GetLength(LINE* pLine); //计算长度
  76 + static double GetLength5(LINE* pLine, int & iPointIndex, double& beginX, double &beginY, double& dRadia, int w, int h, double dw); //简单计算长度
  77 +
  78 + static double GetMaxRing(MPOLYGON* pMPolygon, int& iPolygonIndex, int& iRingIndex);
  79 + static bool GetConvexRing(LINE* pRing, std::vector<double>&vX, std::vector<double>& vY); //计算多边形凸壳
  80 + static int GetNextConvexPointMin(LINE* pRing, int iPointIndexNow);
  81 + static int GetNextConvexPointRotate(LINE* pRing, int iPointIndexNow, int iPointIndexLast);
  82 +
  83 +
  84 + static bool GetIsInRing(LINE* pRing, double x, double y);
  85 + };
  86 +
  87 +}
  88 +
  89 +#endif
\ No newline at end of file
... ...
  1 +#include "clsUtil.h"
  2 +#include<stdlib.h>
  3 +#include"DataCollection.h"
  4 +#include"clsCrSurf.h"
  5 +#include"Renderer.h"
  6 +#include"clsStruct.h"
  7 +#include"SimpleMarkerSymbol.h"
  8 +#include"SimpleLabelRenderer.h"
  9 +#include"SimpleLineSymbol.h"
  10 +#include"SimplePolygonSymbol.h"
  11 +#include"iconv.h"
  12 +#include"clsMalloc.h"
  13 +#include"clsRect.h"
  14 +#define _USE_MATH_DEFINES
  15 +#include<math.h>
  16 +//#include <io.h>
  17 +#include <iostream>
  18 +
  19 +#include <vector>
  20 +#include <stdarg.h>
  21 +#include <errno.h>
  22 +#include <sys/time.h>
  23 +#include <unistd.h>
  24 +
  25 +namespace DmapCore_30
  26 +{
  27 +
  28 + clsUtil::clsUtil()
  29 + {
  30 + }
  31 +
  32 +
  33 + clsUtil::~clsUtil()
  34 + {
  35 + }
  36 +
  37 +
  38 + unsigned int clsUtil::RandomColor()
  39 + {
  40 + int r = 10 + rand() % 200;
  41 + int g = 10 + rand() % 200;
  42 + int b = 10 + rand() % 200;
  43 + int a = 255;
  44 + //int a = 110 + rand() % 100;
  45 + //unsigned int color = (((int)(r * 255)) << 16) + (((int)(g * 255)) << 8) + (int)(b * 255) + 0xff000000;
  46 + //unsigned int color = (((int)(r * 255)) << 16) + (((int)(g * 255)) << 8) + (int)(b * 255) + (((int)(a*255)) << 24);
  47 + unsigned int color = (r << 16) + (g << 8) + b + (a << 24);
  48 + return color;
  49 + }
  50 +
  51 + bool clsUtil::Exchange4(unsigned char * here)
  52 + {
  53 + unsigned char temp;
  54 + for (int i = 0; i < 2; i++)
  55 + {
  56 + temp = here[i];
  57 + here[i] = here[3 - i];
  58 + here[3 - i] = temp;
  59 + }
  60 + return true;
  61 + }
  62 +
  63 + bool clsUtil::Exchange8(unsigned char * here)
  64 + {
  65 + unsigned char temp;
  66 + for (int i = 0; i < 4; i++)
  67 + {
  68 + temp = here[i];
  69 + here[i] = here[7 - i];
  70 + here[7 - i] = temp;
  71 + }
  72 + return true;
  73 + }
  74 +
  75 + bool clsUtil::ToCairoColor(unsigned int Color, double& r, double& g, double& b)
  76 + {
  77 + r = ((double)(((unsigned char *)(&Color))[2])) / 255.0;
  78 + g = ((double)(((unsigned char *)(&Color))[1])) / 255.0;
  79 + b = ((double)(((unsigned char *)(&Color))[0])) / 255.0;
  80 + r += 0.001;
  81 + g += 0.001;
  82 + b += 0.001;
  83 + return true;
  84 + }
  85 + bool clsUtil::ToCairoColor(unsigned int Color, double &r, double & g, double& b, double&a)
  86 + {
  87 + a = ((double)(((unsigned char *)(&Color))[3])) / 255.0;
  88 + r = ((double)(((unsigned char *)(&Color))[2])) / 255.0;
  89 + g = ((double)(((unsigned char *)(&Color))[1])) / 255.0;
  90 + b = ((double)(((unsigned char *)(&Color))[0])) / 255.0;
  91 + a += 0.001; r += 0.001; g += 0.001; b += 0.001; //这个做法保证令小数转回整数再取整时能不因为double的误差而小1
  92 + return true;
  93 + }
  94 +
  95 + int clsUtil::Hex2int(char c)
  96 + {
  97 + if ((c >= 'A') && (c <= 'Z'))
  98 + {
  99 + return c - 'A' + 10;
  100 + }
  101 + else if ((c >= 'a') && (c <= 'z'))
  102 + {
  103 + return c - 'a' + 10;
  104 + }
  105 + else if ((c >= '0') && (c <= '9'))
  106 + {
  107 + return c - '0';
  108 + }
  109 + }
  110 +
  111 + bool clsUtil::ToCairoColor(string color, double &r, double & g, double& b, double&a)
  112 + {
  113 + if(color.at(0) == '#' && ( color.size()== 7 || color.size()== 9 ))
  114 + {
  115 + int index = 1;
  116 + if(color.size()== 9)
  117 + {a = Hex2int(color.at(index)* 16 + Hex2int(color.at(index+1))) / 255.0; index += 2;}
  118 +
  119 + r = Hex2int(color.at(index)* 16 + Hex2int(color.at(index+1))) / 255.0; index += 2;
  120 + g = Hex2int(color.at(index)* 16 + Hex2int(color.at(index+1))) / 255.0; index += 2;
  121 + b = Hex2int(color.at(index)* 16 + Hex2int(color.at(index+1))) / 255.0; index += 2;
  122 + }
  123 + }
  124 +
  125 + bool clsUtil::ReadHead(unsigned char* & here, int& not_big1, int & shapetype)
  126 + {
  127 + not_big1 = here[0];
  128 + here++; //取not_big
  129 + if (!not_big1)
  130 + clsUtil::Exchange4(here);
  131 + shapetype = ((int*)here)[0];
  132 + here += 4; //取shapetype
  133 + if (shapetype > 1000)
  134 + {
  135 + shapetype %= 16 * 16;
  136 + here += 4;
  137 + }
  138 + return true;
  139 + }
  140 +
  141 + int clsUtil::ReadInt(unsigned char*& here, int not_big1)
  142 + {
  143 + clsMalloc clsM(4);
  144 + unsigned char* mem = (unsigned char*)clsM.mem;
  145 + memcpy(mem, here, 4);
  146 + if (!not_big1)
  147 + clsUtil::Exchange4(mem);
  148 + int num = ((int*)mem)[0];
  149 + here += 4;
  150 + return num;
  151 + }
  152 +
  153 +
  154 +
  155 + int clsUtil::ReadByte(unsigned char*& here)
  156 + {
  157 + if(strcmp((char *)here, "") ==0){
  158 + return 0;
  159 + }
  160 + int num = ((char*)here)[0];
  161 + here++;
  162 + return num;
  163 + }
  164 +
  165 +
  166 +
  167 + double clsUtil::ReadDouble(unsigned char*& here, int not_big)
  168 + {
  169 + clsMalloc clsM(8);
  170 + unsigned char* mem = (unsigned char*)clsM.mem;
  171 + memcpy(mem, here, 8);
  172 + if (!not_big)
  173 + clsUtil::Exchange8(mem);
  174 + double num = ((double*)mem)[0];
  175 + here += 8;
  176 + return num;
  177 + }
  178 +
  179 + char * clsUtil::ConvertEnc(char *encFrom, char *encTo, const char * in, char *bufout, size_t lenout)
  180 + {
  181 + char *sin, *sout;
  182 + int lenin, ret;
  183 + iconv_t c_pt;
  184 +
  185 + if ((c_pt = iconv_open(encTo, encFrom)) == (iconv_t)-1) { return NULL; }
  186 + iconv(c_pt, NULL, NULL, NULL, NULL);
  187 + lenin = strlen(in) + 1;
  188 + sin = (char *)in;
  189 + sout = bufout;
  190 + ret = iconv(c_pt, (char **)&sin, (size_t *)&lenin, &sout, (size_t *)&lenout);
  191 + if (ret == -1)
  192 + {
  193 + return NULL;
  194 + }
  195 + iconv_close(c_pt);
  196 + return bufout;
  197 + }
  198 +
  199 + bool clsUtil::ConvertEncUTF8_GB18030(const char *from, clsMalloc &m)
  200 + {
  201 + int len = strlen(from);
  202 + char* sz = (char*)malloc(len + 1);
  203 + m.mem = sz;
  204 + //strcpy(sz, from); return true;
  205 + clsUtil::ConvertEnc("UTF-8", "GB18030", from, m.mem, len + 1);
  206 +
  207 + return true;
  208 + }
  209 +
  210 + bool clsUtil::ConvertEncGB18030_UTF8(const char* from, clsMalloc &m)
  211 + {
  212 + int len = strlen(from);
  213 + char* sz = (char*)malloc(6 * len + 100);
  214 + m.mem = sz;
  215 +
  216 + clsUtil::ConvertEnc("GB18030", "UTF-8", from, m.mem, 6 * len + 100);
  217 +
  218 + return true;
  219 +
  220 + }
  221 +
  222 + bool clsUtil::DoSetLineType(int LineType, cairo_t* cr)
  223 + {
  224 + switch (LineType)
  225 + {
  226 + case dmapLineTypeSolid:
  227 + {
  228 + double dashes1[] = { 10, 0 };
  229 + int ndash1 = sizeof (dashes1) / sizeof(dashes1[0]);
  230 + double offset1 = 0;
  231 + cairo_set_dash(cr, dashes1, ndash1, offset1);
  232 + break;
  233 + }
  234 + case (dmapLineTypeDash) :
  235 + {
  236 + double dashes1[] = { 50, 10 };
  237 + int ndash1 = sizeof (dashes1) / sizeof(dashes1[0]);
  238 + double offset1 = 0;
  239 + cairo_set_dash(cr, dashes1, ndash1, offset1);
  240 + break;
  241 + }
  242 + case (dmapLineTypeDot) :
  243 + {
  244 + double dashes2[] = { 10, 10 };
  245 + int ndash2 = sizeof (dashes2) / sizeof(dashes2[0]);
  246 + double offset2 = 0;
  247 + cairo_set_dash(cr, dashes2, ndash2, offset2);
  248 + break;
  249 + }
  250 + case (dmapLineTypeDashDot) :
  251 + {
  252 + double dashes3[] = { 50, 10, 10, 10 };
  253 + int ndash3 = sizeof (dashes3) / sizeof(dashes3[0]);
  254 + double offset3 = 0;
  255 + cairo_set_dash(cr, dashes3, ndash3, offset3);
  256 + break;
  257 + }
  258 +
  259 + case (dmapLineTypeDashDotDot) :
  260 + {
  261 + double dashes4[] = { 50, 10, 10, 10, 10, 10 };
  262 + int ndash4 = sizeof (dashes4) / sizeof(dashes4[0]);
  263 + double offset4 = 0;
  264 + cairo_set_dash(cr, dashes4, ndash4, offset4);
  265 + break;
  266 + }
  267 +
  268 + default: //什么也不做, 直接画直线
  269 + break;
  270 + }
  271 + return true;
  272 + }
  273 +
  274 + bool clsUtil::DoSetAntialias(int iAntialias, cairo_t* cr)
  275 + {
  276 + //CAIRO_ANTIALIAS_DEFAULT,
  277 +
  278 + /* method */
  279 + // CAIRO_ANTIALIAS_NONE,
  280 + // CAIRO_ANTIALIAS_GRAY,
  281 + // CAIRO_ANTIALIAS_SUBPIXEL,
  282 +
  283 + /* hints */
  284 + //CAIRO_ANTIALIAS_FAST,
  285 + // CAIRO_ANTIALIAS_GOOD,
  286 + // CAIRO_ANTIALIAS_BEST
  287 + cairo_set_antialias(cr,CAIRO_ANTIALIAS_FAST);
  288 + return true;
  289 + switch (iAntialias)
  290 + {
  291 + case dmapAntialiasingDefault:cairo_set_antialias(cr, CAIRO_ANTIALIAS_DEFAULT); break;
  292 + case dmapAntialiasingNone:cairo_set_antialias(cr, CAIRO_ANTIALIAS_NONE); break;
  293 + case dmapAntialiasingGray:cairo_set_antialias(cr, CAIRO_ANTIALIAS_GRAY); break;
  294 + case dmapAntialiasingSubpixel:cairo_set_antialias(cr, CAIRO_ANTIALIAS_SUBPIXEL); break;
  295 + case dmapAntialiasingTrue:cairo_set_antialias(cr, CAIRO_ANTIALIAS_DEFAULT); break;
  296 + case dmapAntialiasingFalse:cairo_set_antialias(cr, CAIRO_ANTIALIAS_NONE); break;
  297 + case dmapAntialiasingBest:cairo_set_antialias(cr, CAIRO_ANTIALIAS_BEST); break;
  298 + default:
  299 + /*
  300 + 还有一些枚举没用上
  301 + */
  302 + break;
  303 + }
  304 + return true;
  305 + }
  306 +
  307 +
  308 + bool clsUtil::DrawStruct(clsCrSurf* pClsCS, DataCollection* data, int index, Renderer* pSimpleRenderer)
  309 + {
  310 + int renType = pSimpleRenderer->RendererType();
  311 + int structType = data->m_iStructType;
  312 + void * pStruct = data->m_pData;
  313 + vector<vector<string>>* p_VVAllF = &(data->m_vAllField);
  314 + vector<string>* p_V = &(data->m_vFieldName);
  315 +
  316 + switch (structType)
  317 + {
  318 + case clsStruct::Struct_Point:
  319 + {
  320 + clsStruct::POINT* pPoint = ((clsStruct::POINT*)(pStruct)) + index;
  321 + if (renType == dmapSimpleMarkerSymbol)
  322 + {
  323 + SimpleMarkerSymbol* sms = (SimpleMarkerSymbol*)pSimpleRenderer;
  324 + sms->DrawPOINT(pClsCS, pPoint);
  325 + }
  326 + else if (renType == dmapSimpleLabelRenderer)
  327 + {
  328 + SimpleLabelRenderer* slr = (SimpleLabelRenderer*)pSimpleRenderer;
  329 + }
  330 + else
  331 + return false;//安全中断
  332 + break;
  333 + }
  334 + case clsStruct::Struct_Line:
  335 + {
  336 + clsStruct::LINE* pLine = ((clsStruct::LINE*)(pStruct)) + index;
  337 + if (renType == dmapSimpleMarkerSymbol)
  338 + {
  339 + SimpleMarkerSymbol* sms = (SimpleMarkerSymbol*)pSimpleRenderer;
  340 + sms->DrawMPOINT(pClsCS, pLine);
  341 + }
  342 + else if (renType == dmapSimpleLineSymbol)
  343 + {
  344 + SimpleLineSymbol* sls = (SimpleLineSymbol*)pSimpleRenderer;
  345 + sls->DrawLINESimple(pClsCS, pLine); //这里要传 dc 的宽和高
  346 + }
  347 + else if (renType == dmapSimplePolygonSymbol)
  348 + {
  349 + SimplePolygonSymbol* sps = (SimplePolygonSymbol*)pSimpleRenderer;
  350 + sps->DrawRING(pClsCS, pLine);
  351 + }
  352 + break;
  353 + }
  354 + case clsStruct::Struct_MLine:
  355 + {
  356 + clsStruct::MLINE* pMLine = ((clsStruct::MLINE*)(pStruct)) + index;
  357 + if (renType == dmapSimpleLineSymbol)
  358 + {
  359 + SimpleLineSymbol * sls = (SimpleLineSymbol*)pSimpleRenderer;
  360 + sls->DrawMLINESimple(pClsCS, pMLine);
  361 + }
  362 + else if (renType == dmapSimpleLabelRenderer)
  363 + {
  364 + ;
  365 + }
  366 + else
  367 + return false;//安全中断
  368 + break;
  369 + }
  370 + case clsStruct::Struct_Polygon:
  371 + {
  372 + clsStruct::POLYGON* pMPolygon = ((clsStruct::POLYGON*)(pStruct)) + index;
  373 + if (renType == dmapSimplePolygonSymbol)
  374 + {
  375 +
  376 + }
  377 + else return false; // 安全中断
  378 + break;
  379 + }
  380 + case clsStruct::Struct_MPolygon:
  381 + {
  382 + clsStruct::MPOLYGON* pMPolygon = ((clsStruct::MPOLYGON*)(pStruct)) + index;
  383 + if (renType == dmapSimplePolygonSymbol)
  384 + {
  385 + SimplePolygonSymbol* sps = (SimplePolygonSymbol*)pSimpleRenderer;
  386 + sps->DrawMPOLYGON(pClsCS, pMPolygon);
  387 + }
  388 + else if (renType == dmapSimpleLabelRenderer)
  389 + {
  390 + ;
  391 + }
  392 + else
  393 + return false;//安全中断
  394 + break;
  395 + }
  396 + default:
  397 + break;
  398 + }
  399 + return true;
  400 + }
  401 +
  402 + bool clsUtil::ZoomFunction(Rect* extent_from, Rect* extent_to, double& r, double & x_dis, double& y_dis)
  403 + {
  404 + extent_from->Normal(); extent_to->Normal();
  405 + double w_from = extent_from->m_dRight - extent_from->m_dLeft;
  406 + double w_to = extent_to->m_dRight - extent_to->m_dLeft;
  407 + double h_from = extent_from->m_dTop - extent_from->m_dBottom;
  408 + double h_to = extent_to->m_dTop - extent_to->m_dBottom;
  409 +
  410 + double r1 = w_to / w_from;
  411 + double r2 = h_to / h_from;
  412 + r = r1 < r2 ? r1 : r2;
  413 +
  414 + x_dis = (extent_to->m_dLeft + extent_to->m_dRight) / 2 - r*(extent_from->m_dLeft + extent_from->m_dRight) / 2;
  415 + y_dis = (extent_to->m_dTop + extent_to->m_dBottom) / 2 - r*(extent_from->m_dTop + extent_from->m_dBottom) / 2;
  416 +
  417 + return true;
  418 + }
  419 +
  420 + bool clsUtil::PointInRect(double x, double y, double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4)
  421 + {
  422 + //(x1,y1)和(x2,y2)组成一条直线,另外两点组成一条直线
  423 + double k1, b1, k2, b2;
  424 + k1 = (y2 - y1) / (x2 - x1);
  425 + b1 = y1 - k1*x1;
  426 + k2 = (y4 - y3) / (x4 - x3);
  427 + b2 = y3 - k2*x3;
  428 +
  429 + //判断该点是否在两条直线之间
  430 + bool bInLines = clsUtil::PointInLines(x, y, k1, b1, k2, b2);
  431 + if (!bInLines)
  432 + return false;
  433 +
  434 + //(x1,y1)和(x4,y4) 组成一条直线,另外亮点组成一条直线
  435 + k1 = (y1 - y4) / (x1 - x4);
  436 + b1 = y1 - k1*x1;
  437 + k2 = (y3 - y2) / (x3 - x2);
  438 + b2 = y2 - k2*x2;
  439 + //判断该店是否在两条直线之间
  440 + bInLines = clsUtil::PointInLines(x, y, k1, b1, k2, b2);
  441 + if (!bInLines)
  442 + return false;
  443 + return true;
  444 + }
  445 + bool clsUtil::PointInLines(double x, double y, double k1, double b1, double k2, double b2)
  446 + {
  447 + double y1 = k1*x + b1;
  448 + double y2 = k2* x + b2;
  449 + if ((y >= y1) && (y <= y2))
  450 + return true;
  451 + if ((y <= y1) && (y >= y2))
  452 + return true;
  453 +
  454 + return false;
  455 +
  456 + }
  457 +
  458 + double clsUtil::StandardizationAngle(double dAngle)
  459 + {
  460 + while (dAngle > 2 * M_PI)
  461 + dAngle -= 2 * M_PI;
  462 + while (dAngle < 0)
  463 + dAngle += 2 * M_PI;
  464 + return dAngle;
  465 + }
  466 +
  467 + /*
  468 + 此两个函数只处理 被双引号完全包含的字符串
  469 + */
  470 + string clsUtil::TryAddDoubleQuotation(string s)
  471 + {
  472 + //双引号开头的不加
  473 + if ((s.c_str()[0] == '"'))
  474 + return s;
  475 + string ss = "\"" + s + "\"";
  476 + return ss;
  477 + }
  478 + string clsUtil::TryDeleteDoubleQuotation(string s)
  479 + {
  480 + //不是双引号开头不去双引号
  481 + if ((s.c_str()[0]) != '"')
  482 + return s;
  483 + char ss[500]; memset(ss, 0, 500);
  484 + const char* s_ = s.c_str();
  485 + int len = strlen(s_);
  486 +
  487 + memcpy(ss, s_ + 1, len - 2);
  488 +
  489 + return ss;
  490 + }
  491 +
  492 + void clsUtil::GetFiles(string path, string exd, vector<string> & files)
  493 + {
  494 + /************************************************************************/
  495 + /* 获取文件夹下所有文件名
  496 + 输入:
  497 + path : 文件夹路径
  498 + exd : 所要获取的文件名后缀,如jpg、png等;如果希望获取所有
  499 + 文件名, exd = ""
  500 + 输出:
  501 + files : 获取的文件名列表
  502 + */
  503 + /************************************************************************/
  504 +
  505 +
  506 +/*
  507 + //文件句柄
  508 + long hFile = 0;
  509 + //文件信息
  510 + struct _finddata_t fileinfo;
  511 + string pathName, exdName;
  512 +
  513 + if (0 != strcmp(exd.c_str(), ""))
  514 + {
  515 + exdName = "\\*." + exd;
  516 + }
  517 + else
  518 + {
  519 + exdName = "\\*";
  520 + }
  521 +
  522 + if ((hFile = _findfirst(pathName.assign(path).append(exdName).c_str(), &fileinfo)) != -1)
  523 + {
  524 + do
  525 + {
  526 + //如果是文件夹中仍有文件夹,迭代之
  527 + //如果不是,加入列表
  528 + if ((fileinfo.attrib & _A_SUBDIR))
  529 + {
  530 + if (strcmp(fileinfo.name, ".") != 0 && strcmp(fileinfo.name, "..") != 0)
  531 + clsUtil::GetFiles(pathName.assign(path).append("\\").append(fileinfo.name), exd, files);
  532 + }
  533 + else
  534 + {
  535 + if (strcmp(fileinfo.name, ".") != 0 && strcmp(fileinfo.name, "..") != 0)
  536 + files.push_back(pathName.assign(path).append("\\").append(fileinfo.name));
  537 + }
  538 + } while (_findnext(hFile, &fileinfo) == 0);
  539 + _findclose(hFile);
  540 + }*/
  541 + }
  542 +
  543 + int clsUtil::ParseStringTok(char * sz, char toK, char ** szPtr, int maxPtr)
  544 + {
  545 + if (sz == 0)
  546 + {
  547 + return 0;
  548 + }
  549 + int nowCount = 0;
  550 + int i = 0;
  551 + szPtr[nowCount] = sz;
  552 + nowCount++;
  553 + if (nowCount >= maxPtr)return nowCount;
  554 +
  555 + for (;; i++)
  556 + {
  557 + char c = sz[i];
  558 + if (c == 0)return nowCount;
  559 + if (c == toK)
  560 + {
  561 + sz[i] = 0;
  562 + if (sz[i + 1] == 0)return nowCount;
  563 + szPtr[nowCount] = sz + i + 1;
  564 + nowCount++;
  565 + if (nowCount >= maxPtr)return nowCount;
  566 + }
  567 + }
  568 + return nowCount;
  569 + }
  570 +
  571 + void clsUtil::ValueString(string* s, bool* bValue)
  572 + {
  573 + if (*s == "")
  574 + {
  575 + if (*bValue)
  576 + *s = "true";
  577 + return;
  578 + }
  579 +
  580 + string s____ = clsUtil::TryDeleteDoubleQuotation(*s);
  581 + if (s____ == "true")
  582 + *bValue = true;
  583 + else
  584 + *bValue = false;
  585 + }
  586 +
  587 + std::string clsUtil::fmt(char* fmt, ...)
  588 + {
  589 + va_list argptr;
  590 + int cnt;
  591 + char buffer[2000];
  592 + va_start(argptr, fmt);
  593 +
  594 + cnt = vsnprintf(buffer, 1000, fmt, argptr);
  595 +
  596 + va_end(argptr);
  597 +
  598 + return buffer;
  599 + }
  600 +
  601 + std::string clsUtil::fmt(const char* fmt, ...)
  602 + {
  603 + va_list argptr;
  604 + int cnt;
  605 + char buffer[2000];
  606 + va_start(argptr, fmt);
  607 +
  608 + cnt = vsnprintf(buffer, 1000, fmt, argptr);
  609 +
  610 + va_end(argptr);
  611 +
  612 + return buffer;
  613 + }
  614 +
  615 +
  616 +
  617 + void clsUtil::ValueString(string* s, double* dValue)
  618 + {
  619 + if (*s == "")
  620 + {
  621 + //char buf[500];
  622 + string str = clsUtil::fmt("%lf", *dValue);
  623 + *s = str.c_str();
  624 + return;
  625 + }
  626 +
  627 + string s____ = clsUtil::TryDeleteDoubleQuotation(*s);
  628 + *dValue = stod(s____.c_str());
  629 + }
  630 +
  631 +
  632 +
  633 + void clsUtil::ValueString(string* s, long* lValue)
  634 + {
  635 + if (*s == "")
  636 + {
  637 + //char s_[500];
  638 + string str = clsUtil::fmt("%ld", lValue);
  639 + *s = str.c_str();
  640 + return;
  641 + }
  642 + string s____ = clsUtil::TryDeleteDoubleQuotation(*s);
  643 + *lValue = stol(s____.c_str());
  644 + }
  645 +
  646 + void clsUtil::ValueString(string* s, string* sValue)
  647 + {
  648 + if (*s == "")
  649 + {
  650 + string s_ = "";
  651 + s_ += "\"";
  652 + s_ += *sValue;
  653 + s_ += "\"";
  654 + *s = s_;
  655 + return;
  656 + }
  657 + string s____ = clsUtil::TryDeleteDoubleQuotation(*s);
  658 + const char* s_ = s____.c_str();
  659 + int len = strlen(s_);
  660 + clsMalloc clsM(len - 1);
  661 + char* ss = clsM.mem;
  662 + memcpy(ss, s_ + 1, len - 2);
  663 + ss[len - 2] = 0;
  664 + *sValue = ss;
  665 + }
  666 +
  667 + void clsUtil::EnumString(string* s, int* iEnum, string s1, string s2, string s3, string s4, string s5, string s6, string s7, string s8, string s9, string s10, string s11, string s12)
  668 + {
  669 + if (*s == "")
  670 + {
  671 + switch (*iEnum)
  672 + {
  673 + case 0: *s = s1; break;
  674 + case 1: *s = s2; break;
  675 + case 2: *s = s3; break;
  676 + case 3: *s = s4; break;
  677 + case 4: *s = s5; break;
  678 + case 5: *s = s6; break;
  679 + case 6: *s = s7; break;
  680 + case 7: *s = s8; break;
  681 + case 8: *s = s9; break;
  682 + case 9:*s = s10; break;
  683 + case 10:*s = s11; break;
  684 + case 11:*s = s12; break;
  685 + default:
  686 + *s = "";
  687 + break;
  688 + }
  689 + return;
  690 + }
  691 +
  692 + string s_ = clsUtil::TryDeleteDoubleQuotation(*s);
  693 + if (s_ == s1) { *iEnum = 0; return; }
  694 + if (s_ == s2) { *iEnum = 1; return; }
  695 + if (s_ == s3) { *iEnum = 2; return; }
  696 + if (s_ == s4) { *iEnum = 3; return; }
  697 + if (s_ == s5) { *iEnum = 4; return; }
  698 + if (s_ == s6) { *iEnum = 5; return; }
  699 + if (s_ == s7) { *iEnum = 6; return; }
  700 + if (s_ == s8) { *iEnum = 7; return; }
  701 + if (s_ == s9) { *iEnum = 8; return; }
  702 + if (s_ == s10) { *iEnum = 9; return; }
  703 + if (s_ == s11) { *iEnum = 10; return; }
  704 + if (s_ == s12) { *iEnum = 11; return; }
  705 + iEnum = 0; return;
  706 +
  707 + }
  708 +
  709 + void clsUtil::ColorString(string* s, unsigned int* iColor)
  710 + {
  711 + if (*s == "")
  712 + {
  713 + unsigned char r, g, b, a;
  714 + a = ((char*)iColor)[3];
  715 + r = ((char*)iColor)[2];
  716 + g = ((char*)iColor)[1];
  717 + b = ((char*)iColor)[0];
  718 + //char s_[1000];
  719 + string str = clsUtil::fmt("%d,%d,%d,%d", r, g, b, a);
  720 + *s = str.c_str();
  721 + return;
  722 + }
  723 +
  724 + string s____ = clsUtil::TryDeleteDoubleQuotation(*s);
  725 + const char* s_ = s____.c_str();
  726 + int len = strlen(s_);
  727 + char ss[1000];
  728 + memcpy(ss, s_, len + 1);
  729 + char* sRGBA[4];
  730 + clsUtil::ParseStringTok(ss, ',', sRGBA, 4);
  731 + char* sr, *sg, *sb, *sa;
  732 + sr = sRGBA[0]; sg = sRGBA[1]; sb = sRGBA[2]; sa = sRGBA[3];
  733 + int r, g, b, a;
  734 + r = stoi(sr);
  735 + g = stoi(sg);
  736 + b = stoi(sb);
  737 + a = stoi(sa);
  738 + *iColor = (unsigned int)((r << 16) + (g << 8) + b + (a << 24));
  739 + }
  740 +}
\ No newline at end of file
... ...
  1 +#pragma once
  2 +#include <cairo/cairo.h>
  3 +#include<string>
  4 +#include<vector>
  5 +#include "dmap_core.h"
  6 +using namespace std;
  7 +namespace DmapCore_30
  8 +{
  9 + class clsCrSurf;
  10 + class DataCollection;
  11 + class Renderer;
  12 + class Rect;
  13 + class clsMalloc;
  14 +
  15 +#define GetIndexP(index,to) \
  16 + int length = (int)to.size(); \
  17 + if (index<0 || index >= length)return NULL; \
  18 + to[index]->AddRef(); \
  19 + return to[index];
  20 + //Set一个指针时, 必须先AddRef, 由于传入的指针与被替换的指针有可能是同一个, 先Release 内存出错
  21 +#define SetIndexP(index,from,to) \
  22 + if (!from)return false; \
  23 + int length = (int)to.size(); \
  24 + if (index>length)return false; \
  25 + from->AddRef(); \
  26 + if (index < 0 || index == length)to.push_back(from); \
  27 +else { to[index]->Release(); to[index] = from; }\
  28 + return true;
  29 +#define RemoveIndexP(index,to) \
  30 + int length = (int)to.size(); \
  31 + if (index < 0 || index >= length)return false; \
  32 + to[index]->Release(); \
  33 + to.erase(to.begin() + index); \
  34 + return true;
  35 +#define ClearP(to) \
  36 + int length = (int)to.size(); \
  37 + for (int i = 0; i < length; i++)\
  38 + {to[i]->Release(); }to.clear(); return true;
  39 +
  40 +
  41 + class CORE_EXPORT clsUtil
  42 + {
  43 + public:
  44 + clsUtil();
  45 + ~clsUtil();
  46 + static unsigned int RandomColor();
  47 + static bool Exchange4(unsigned char * here);
  48 + static bool Exchange8(unsigned char * here);
  49 + static bool ToCairoColor(unsigned int Color, double& r, double & g, double& b);
  50 + static bool ToCairoColor(unsigned int Color, double &r, double & g, double& b, double&a);
  51 + static bool ToCairoColor(string color, double &r, double & g, double& b, double&a);
  52 + static bool ReadHead(unsigned char* & here, int& not_big1, int & shapetype);
  53 + static int ReadInt(unsigned char*& here, int not_big1);
  54 + static int Hex2int(char c);
  55 + static int ReadByte(unsigned char*& here);
  56 + static double ReadDouble(unsigned char*& here, int not_big);
  57 + static bool DoSetLineType(int LineType, cairo_t* cr);
  58 + static bool DoSetAntialias(int iAntialias, cairo_t* cr);
  59 + static char * ConvertEnc(char *encFrom, char *encTo, const char * in, char *bufout, size_t lenout);
  60 + static bool ConvertEncUTF8_GB18030(const char *from, clsMalloc &m);
  61 + static bool ConvertEncGB18030_UTF8(const char* from, clsMalloc &m);
  62 +
  63 + static bool DrawStruct(clsCrSurf* pClsCS, DataCollection* data, int index, Renderer* pSimpleRenderer);
  64 +
  65 + static bool ZoomFunction(Rect* extent_from, Rect* extent_to, double& r, double & x_dis, double& y_dis);
  66 + static bool PointInRect(double x, double y, double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4); // 判断一个点是否在矩形内(该矩形可旋转)
  67 + static bool PointInLines(double x, double y, double k1, double b1, double k2, double b2); //采用 y = k * x + b; k1,b1等是直线系数
  68 + static double StandardizationAngle(double dAngle);
  69 +
  70 + static string TryAddDoubleQuotation(string s);
  71 + static string TryDeleteDoubleQuotation(string s);
  72 +
  73 +
  74 + static void GetFiles(string path, string exd, vector<string> & files);
  75 + static int ParseStringTok(char * sz, char toK, char ** szPtr, int maxPtr);
  76 +
  77 + static std::string fmt(char *, ...);
  78 + static std::string fmt(const char*, ...);
  79 + static void ValueString(string * s, bool* bValue);
  80 + static void ValueString(string* s, double* dValue);
  81 + static void ValueString(string* s, long* lValue);
  82 + static void ValueString(string* s, string* sValue);
  83 + static void EnumString(string* s, int* iEnum, string s1 = "", string s2 = "", string s3 = "", string s4 = "", string s5 = "", string s6 = "", string s7 = "", string s8 = "", string s9 = "", string s10 = "", string s11 = "", string s12 = "");
  84 + static void ColorString(string* s, unsigned int* iColor);
  85 + };
  86 +
  87 +}
\ No newline at end of file
... ...
  1 +
  2 +#include "clsXML.h"
  3 +#include"clsUtil.h"
  4 +//#include"StringHelp.h"
  5 +#include"SimpleMarkerSymbol.h"
  6 +#include"SimpleLineSymbol.h"
  7 +#include"SimplePolygonSymbol.h"
  8 +#include"SimpleLabelRenderer.h"
  9 +#include"ValueMapRenderer.h"
  10 +//#include"RangeMapRenderer.h"
  11 +#include"GroupRenderer.h"
  12 +//#include"ScaleDependentRenderer.h"
  13 +//#include"HeatMapRenderer.h"
  14 +#include"SimpleRenderer.h"
  15 +#include"TextSymbol.h"
  16 +#include"clsMalloc.h"
  17 +#include"Renderer.h"
  18 +#include"TrueTypeMarkerSymbol.h"
  19 +
  20 +namespace DmapCore_30
  21 +{
  22 +
  23 + clsXML::clsXML(AppendBuffer * f, string name)
  24 + {
  25 + m_pF = NULL;
  26 + if (f)
  27 + {
  28 + m_sName = name;
  29 + m_pF = f;
  30 + f->AppendString("<", 1); f->AppendString(name.c_str(), name.size()); //fprintf(f, "<%s", name.c_str());
  31 + m_bHaveCloseProperties = false;
  32 + }
  33 + }
  34 +
  35 +
  36 + clsXML::~clsXML()
  37 + {
  38 + if (m_pF == 0)return;
  39 + closeProperties();
  40 + m_pF->AppendString("</", 2); m_pF->AppendString(m_sName.c_str(), m_sName.size()); m_pF->AppendString(">", 1);//fprintf(m_pF, "</%s>", m_sName.c_str());
  41 + }
  42 +
  43 + void clsXML::closeProperties()
  44 + {
  45 + if (m_pF == 0)return;
  46 + if (m_bHaveCloseProperties)return;
  47 + m_pF->AppendString(">", 1); //fprintf(m_pF, ">");
  48 + m_bHaveCloseProperties = true;
  49 + return;
  50 + }
  51 + void clsXML::writeText(string s)
  52 + {
  53 + if (m_pF == 0)return;
  54 + if (!m_bHaveCloseProperties)
  55 + this->closeProperties();
  56 + m_pF->AppendString(s.c_str(), s.size());// fprintf(m_pF, "%s", s.c_str());
  57 + return;
  58 + }
  59 +
  60 + bool clsXML::XMLHead(AppendBuffer * f)
  61 + {
  62 + f->AppendString("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");// fprintf(f, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
  63 + return true;
  64 + }
  65 + string clsXML::XMLGetPropByString(boost::property_tree::ptree &pt, const string& find)
  66 + {
  67 + //xml_attribute<char> *attr = node->first_attribute(find.c_str());
  68 + //if (attr == 0)return "";
  69 + //char * s = attr->value();
  70 + string value = pt.get<std::string>("<xmlattr>."+ find,"");
  71 + return value;
  72 + }
  73 + void clsXML::StringReplace(string &strBase, string strSrc, string strDes)
  74 + {
  75 + string::size_type pos = 0;
  76 + string::size_type srcLen = strSrc.size();
  77 + string::size_type desLen = strDes.size();
  78 + pos = strBase.find(strSrc, pos);
  79 + while ((pos != string::npos))
  80 + {
  81 + strBase.replace(pos, srcLen, strDes);
  82 + pos = strBase.find(strSrc, (pos + desLen));
  83 + }
  84 + }
  85 +
  86 + void clsXML::_Append2(AppendBuffer *f, string &a, string &b)
  87 + {
  88 + f->AppendString(" ", 1);
  89 + f->AppendString(a.c_str(), a.size());
  90 + f->AppendString("=\"", 2);
  91 + f->AppendString(b.c_str(), b.size());
  92 + f->AppendString("\"", 1);
  93 + }
  94 + bool clsXML::XMLAttrParse(boost::property_tree::ptree &pt, AppendBuffer * f, string *value, string find)
  95 + {
  96 + //if (node)// 如果有节点,解析节点
  97 + {
  98 + const static std::string s = "";
  99 + *value = s;
  100 + *value = clsXML::XMLGetPropByString(pt, find);
  101 + return true;
  102 + }
  103 + //写到xml
  104 +
  105 +
  106 + return true;
  107 + }
  108 + bool clsXML::XMLAttrParse(boost::property_tree::ptree &pt, AppendBuffer * f, double *value, string find)
  109 + {
  110 + string sz1__ = clsXML::XMLGetPropByString(pt, find);
  111 + if (sz1__ == "error")return false;
  112 + const char* sz1 = sz1__.c_str();
  113 + *value = atof(sz1);
  114 + return true;
  115 +
  116 + return true;
  117 + }
  118 + bool clsXML::XMLAttrParse(boost::property_tree::ptree &pt, AppendBuffer * f, long *value, string find)
  119 + {
  120 +
  121 + *value = 0;
  122 + string sz1__ = clsXML::XMLGetPropByString(pt, find);
  123 + if (sz1__ == "error")return false;
  124 + const char* sz1 = sz1__.c_str();
  125 + *value = atoi(sz1);
  126 + return true;
  127 +
  128 +
  129 + }
  130 + bool clsXML::XMLAttrParse(boost::property_tree::ptree &pt, AppendBuffer * f, float *value, string find)
  131 + {
  132 + *value = 0;
  133 + string sz1__ = clsXML::XMLGetPropByString(pt, find);
  134 + if (sz1__ == "error")return false;
  135 + const char* sz1 = sz1__.c_str();
  136 + *value = (float)atof(sz1);
  137 + return true;
  138 + }
  139 + bool clsXML::XMLAttrParse(boost::property_tree::ptree &pt, AppendBuffer * f, bool *value, string find, bool defaultValue)
  140 + {
  141 + *value = defaultValue;
  142 + string sz1__ = clsXML::XMLGetPropByString(pt, find);
  143 + if (sz1__ == "error")return false;
  144 + const char* sz1 = sz1__.c_str();
  145 + if (strcmp(sz1, "true") == 0){ *value = true; return true; }
  146 + if (strcmp(sz1, "false") == 0){ *value = false; return true; }
  147 + return defaultValue;
  148 + }
  149 + bool clsXML::XMLAttrParseColor(boost::property_tree::ptree &pt, AppendBuffer * f, unsigned int * value, string find1, string find2)
  150 + { *value = 0xff000000;
  151 + string sz1__ = clsXML::XMLGetPropByString(pt, find1);
  152 + if (sz1__ == "error" || sz1__ == "")return false;
  153 + const char* sz1 = sz1__.c_str();
  154 + string sz2 = "1";
  155 + if (find2 != "")
  156 + {
  157 + sz2 = clsXML::XMLGetPropByString(pt, find2);
  158 + }
  159 + int r = 0, g = 0, b = 0; double a = 1;
  160 + sscanf(sz1, "%d,%d,%d", &r, &g, &b);
  161 + const char* sz2__ = sz2.c_str();
  162 + a = atof(sz2__);
  163 + //sscanf(sz2, "%lf", &a);
  164 + a += 0.001;
  165 + *value = (((int)(a * 255)) << 24) + (r << 16) + (g << 8) + b;
  166 + return true;
  167 +
  168 + }
  169 +
  170 +
  171 +
  172 + string clsXML::ParseEnum(int v, string a1, string a2, string a3, string a4, string a5, string a6, string a7, string a8, string a9, string a10, string a11, string a12, string a13, string a14, string a15, string a16)
  173 + {
  174 + switch (v)
  175 + {
  176 + case 0: return a1;
  177 + case 1: return a2;
  178 + case 2: return a3;
  179 + case 3: return a4;
  180 + case 4: return a5;
  181 + case 5: return a6;
  182 + case 6: return a7;
  183 + case 7: return a8;
  184 + case 8: return a9;
  185 + case 9: return a10;
  186 + case 10: return a11;
  187 + case 11: return a12;
  188 + case 12: return a13;
  189 + case 13: return a14;
  190 + case 14: return a15;
  191 + case 15: return a16;
  192 +
  193 + default:
  194 + return a1;
  195 + }
  196 + }
  197 +
  198 + bool clsXML::ParseEnum(string find, boost::property_tree::ptree &pt, AppendBuffer * f, bool *v, string a1, string a2, string a3, string a4, string a5, string a6, string a7, string a8, string a9, string a10, string a11, string a12, string a13, string a14, string a15, string a16)
  199 + {
  200 + string s;
  201 + clsXML::XMLAttrParse(pt, f, &s, find);
  202 + if (clsXML::XMLAttrParse(pt, f, &s, find) == false)return false; //sgq:返回的是GBK的编码
  203 +
  204 + int nowAt = 0;
  205 + if (s == "")return true;
  206 +
  207 + //SGQ:得到Marker的类型
  208 + if (s == a1){ *v = false; return true; };
  209 + if (s == a2){ *v = true; return true; };
  210 +
  211 + return true;
  212 + }
  213 +
  214 + bool clsXML::ParseEnum(string find, boost::property_tree::ptree &pt, AppendBuffer * f, int *v, string a1, string a2, string a3, string a4, string a5, string a6, string a7, string a8, string a9, string a10, string a11, string a12, string a13, string a14, string a15, string a16)
  215 + {
  216 + //if (node)
  217 + {
  218 + string s;
  219 + clsXML::XMLAttrParse(pt, f, &s, find);
  220 + if (clsXML::XMLAttrParse(pt, f, &s, find) == false)return false; //sgq:返回的是GBK的编码
  221 +
  222 + int nowAt = 0;
  223 + if (s == "")return true;
  224 +
  225 + //SGQ:得到Marker的类型
  226 + if (s == a1){ *v = nowAt; return true; }; nowAt++;
  227 + if (s == a2){ *v = nowAt; return true; }; nowAt++;
  228 + if (s == a3){ *v = nowAt; return true; }; nowAt++;
  229 + if (s == a4){ *v = nowAt; return true; }; nowAt++;
  230 + if (s == a5){ *v = nowAt; return true; }; nowAt++;
  231 + if (s == a6){ *v = nowAt; return true; }; nowAt++;
  232 + if (s == a7){ *v = nowAt; return true; }; nowAt++;
  233 + if (s == a8){ *v = nowAt; return true; }; nowAt++;
  234 + if (s == a9){ *v = nowAt; return true; }; nowAt++;
  235 + if (s == a10){ *v = nowAt; return true; }; nowAt++;
  236 + if (s == a11){ *v = nowAt; return true; }; nowAt++;
  237 + if (s == a12){ *v = nowAt; return true; }; nowAt++;
  238 + if (s == a13){ *v = nowAt; return true; }; nowAt++;
  239 + if (s == a14){ *v = nowAt; return true; }; nowAt++;
  240 + if (s == a15){ *v = nowAt; return true; }; nowAt++;
  241 + if (s == a16){ *v = nowAt; return true; }; nowAt++;
  242 + return true;
  243 + }
  244 +
  245 + }
  246 +
  247 +
  248 + bool clsXML::XMLParseString( char* xml, AppendBuffer *f, Renderer** renderer)
  249 + {
  250 + /*xml_document<> doc; // character type defaults to char
  251 + doc.parse<0>(xml);
  252 + xml_node<char> *n = doc.first_node();
  253 + if (n == NULL)
  254 + {
  255 + return false;
  256 + }
  257 + return XMLParse(n, f, renderer);*/
  258 + return false;
  259 + }
  260 +
  261 + bool clsXML::XMLParse(string rendererName, boost::property_tree::ptree &pt, Renderer** renderer)
  262 + {
  263 +
  264 +
  265 +
  266 + //const char *sz = node->name();
  267 + //string ss ;
  268 + bool flag = false;
  269 + //所有的AddRef 在这里加? 调用函数出不再考虑
  270 + if (rendererName == "SIMPLEMARKERSYMBOL")
  271 + {
  272 + SimpleMarkerSymbol *sms = new SimpleMarkerSymbol();
  273 + flag = sms->Parse(pt, nullptr);
  274 + if ((*renderer) != NULL)
  275 + (*renderer)->Release();
  276 + *renderer = sms; /*sms->AddRef(); */
  277 + }
  278 + else if (rendererName == "SIMPLELINESYMBOL")
  279 + {
  280 + SimpleLineSymbol *sls = new SimpleLineSymbol();
  281 + flag = sls->Parse(pt, nullptr);
  282 + if ((*renderer) != NULL)
  283 + (*renderer)->Release();
  284 + *renderer = sls; /*sls->AddRef();*/
  285 + }
  286 + else if (rendererName == "SIMPLEPOLYGONSYMBOL")
  287 + {
  288 + SimplePolygonSymbol *sps = new SimplePolygonSymbol();
  289 + flag = sps->Parse(pt, nullptr);
  290 + if ((*renderer) != NULL)
  291 + (*renderer)->Release();
  292 + *renderer = sps; /*sps->AddRef();*/
  293 + }
  294 + else if (rendererName == "VALUEMAPRENDERER")
  295 + {
  296 + ValueMapRenderer *vmr = new ValueMapRenderer();
  297 + flag = vmr->Parse(pt, nullptr);
  298 + if ((*renderer) != NULL)
  299 + (*renderer)->Release();
  300 + *renderer = vmr; /*vmr->AddRef();*/
  301 + }
  302 + /*else if (rendererName == "RANGEMAPRENDERER")
  303 + {
  304 + RangeMapRenderer *rmr = new RangeMapRenderer();
  305 + flag = rmr->Parse(node, nullptr);
  306 + if ((*renderer) != NULL)
  307 + (*renderer)->Release();
  308 + *renderer = rmr;
  309 + }*/
  310 + else if (rendererName == "GROUPRENDERER")
  311 + {
  312 + GroupRenderer *gr = new GroupRenderer();
  313 + flag = gr->Parse(pt, nullptr);
  314 + if ((*renderer) != NULL)
  315 + (*renderer)->Release();
  316 + *renderer = gr; /*gr->AddRef();*/
  317 + }
  318 + /* else if (rendererName == "SCALEDEPENDENTRENDERER")
  319 + {
  320 + ScaleDependentRenderer *gr = new ScaleDependentRenderer();
  321 + flag = gr->Parse(pt, nullptr);
  322 + if ((*renderer) != NULL)
  323 + (*renderer)->Release();
  324 + *renderer = gr;
  325 + }*/
  326 + else if (rendererName == "SIMPLELABELRENDERER")
  327 + {
  328 + SimpleLabelRenderer *gr = new SimpleLabelRenderer();
  329 + flag = gr->Parse(pt, nullptr);
  330 + if ((*renderer) != NULL)
  331 + (*renderer)->Release();
  332 + *renderer = gr; /*gr->AddRef();*/
  333 + }
  334 + else if (rendererName == "SIMPLERENDERER")
  335 + {
  336 + SimpleRenderer *sr = new SimpleRenderer();
  337 + flag = sr->Parse(pt, nullptr);
  338 + if ((*renderer) != NULL)
  339 + (*renderer)->Release();
  340 + *renderer = sr;
  341 + }
  342 + else if (rendererName == "TEXTSYMBOL")
  343 + {
  344 + TextSymbol *gr = new TextSymbol();
  345 + flag = gr->Parse(pt, nullptr);
  346 + if ((*renderer) != NULL)
  347 + (*renderer)->Release();
  348 + *renderer = gr; /*gr->AddRef();*/
  349 + }
  350 + else if (rendererName == "TRUETYPEMARKERSYMBOL")
  351 + {
  352 + TrueTypeMarkerSymbol *gr = new TrueTypeMarkerSymbol();
  353 + flag = gr->Parse(pt, nullptr);
  354 + if ((*renderer) != NULL)
  355 + (*renderer)->Release();
  356 + *renderer = gr; /*gr->AddRef();*/
  357 + }
  358 + /*else if( rendererName == "HEATSYMBOL")
  359 + {
  360 + HeatMapRenderer *gr = new HeatMapRenderer();
  361 + flag = gr->Parse(pt, nullptr);
  362 + if ((*renderer) != NULL)
  363 + (*renderer)->Release();
  364 + *renderer = gr;
  365 +
  366 + }*/
  367 +
  368 + if (flag == false)
  369 + {
  370 + if ((*renderer) != NULL)
  371 + (*renderer)->Release();
  372 + *renderer = NULL;
  373 + }
  374 +
  375 + return flag;
  376 + }
  377 +
  378 +}
\ No newline at end of file
... ...
  1 +
  2 +#ifndef _clsXML_H_
  3 +#define _clsXML_H_
  4 +#include <boost/property_tree/ptree.hpp>
  5 +#include <boost/property_tree/xml_parser.hpp>
  6 +#include <boost/foreach.hpp>
  7 +#include <string>
  8 +#include "AppendBuffer.h"
  9 +using namespace std;
  10 +namespace DmapCore_30
  11 +{
  12 + class Renderer;
  13 + class clsXML
  14 + {
  15 + public:
  16 + clsXML(AppendBuffer* f, string name);
  17 + ~clsXML();
  18 +
  19 + string m_sName;
  20 + AppendBuffer* m_pF;
  21 + bool m_bHaveCloseProperties;
  22 +
  23 +
  24 + void closeProperties();//关闭属性
  25 + void writeText(string s); //写入文本
  26 + static void _Append2(AppendBuffer *f, string &a, string &b);
  27 + static void StringReplace(string &strBase, string strSrc, string strDes);
  28 + static bool XMLHead(AppendBuffer * f);
  29 + static string XMLGetPropByString(boost::property_tree::ptree &pt,const string& find);
  30 + static bool XMLAttrParse(boost::property_tree::ptree &pt, AppendBuffer * f, string *value, string find);
  31 + static bool XMLAttrParse(boost::property_tree::ptree &pt, AppendBuffer * f, double *value, string find);
  32 + static bool XMLAttrParse(boost::property_tree::ptree &pt, AppendBuffer * f, long *value, string find);
  33 + static bool XMLAttrParse(boost::property_tree::ptree &pt, AppendBuffer * f, float *value, string find);
  34 + static bool XMLAttrParse(boost::property_tree::ptree &pt, AppendBuffer * f, bool *value, string find, bool defaultValue = false);
  35 +
  36 + static bool XMLAttrParseColor(boost::property_tree::ptree &pt, AppendBuffer * f, unsigned int * value, string find1, string find2 = "");//这里处理的 int 类型只有 color
  37 + static bool ParseEnum(string find, boost::property_tree::ptree &pt, AppendBuffer * f, bool *v, string a1 = "", string a2 = "", string a3 = "", string a4 = "", string a5 = "", string a6 = "", string a7 = "", string a8 = "", string a9 = "", string a10 = "", string a11 = "", string a12 = "", string a13 = "", string a14 = "", string a15 = "", string a16 = "");
  38 + static bool ParseEnum(string find, boost::property_tree::ptree &pt, AppendBuffer * f, int *v, string a1 = "", string a2 = "", string a3 = "", string a4 = "", string a5 = "", string a6 = "", string a7 = "", string a8 = "", string a9 = "", string a10 = "", string a11 = "", string a12 = "", string a13 = "", string a14 = "", string a15 = "", string a16 = "");
  39 + static string ParseEnum(int v, string a1 = "", string a2 = "", string a3 = "", string a4 = "", string a5 = "", string a6 = "", string a7 = "", string a8 = "", string a9 = "", string a10 = "", string a11 = "", string a12 = "", string a13 = "", string a14 = "", string a15 = "", string a16 = "");
  40 + static bool XMLParse(string ptreeName, boost::property_tree::ptree &pt, Renderer** renderer);
  41 + static bool XMLParseString( char*, AppendBuffer *f, Renderer** renderer);
  42 + };
  43 +}
  44 +#endif
\ No newline at end of file
... ...
  1 +#include "legendParamater.h"
  2 +
  3 +namespace DmapCore_30
  4 +{
  5 + legendParamater::legendParamater(/* args */)
  6 + {
  7 + index = 0;
  8 +
  9 + rowspacing = 15;
  10 +
  11 + size_x = 30;
  12 +
  13 + size_y = 15;
  14 +
  15 + pixYIndex = 10;
  16 +
  17 + pixXIndex = 20;
  18 +
  19 + fontSize = 10;
  20 +
  21 + current_Col_Index = 0;
  22 +
  23 + max_pixXIndex = 10;
  24 + max_pixYIndex = 10;
  25 + }
  26 +
  27 + legendParamater::~legendParamater()
  28 + {
  29 + }
  30 +
  31 + bool legendParamater::next(char * title)
  32 + {
  33 + if(index/row_maxsize> current_Col_Index)
  34 + {
  35 + current_Col_Index ++;
  36 + pixXIndex = 10 + (current_Col_Index *100);
  37 + pixYIndex = 10;
  38 +
  39 + if(pixXIndex> max_pixXIndex)
  40 + {
  41 + max_pixXIndex = pixXIndex;
  42 + }
  43 +
  44 + }
  45 + if(title == nullptr)
  46 + {
  47 +
  48 + index ++;
  49 + provTitle ="";
  50 +
  51 + pixYIndex += (rowspacing + size_y);
  52 +
  53 + if(pixYIndex> max_pixYIndex)
  54 + {
  55 + max_pixYIndex = pixYIndex;
  56 + }
  57 + return true;
  58 + }
  59 + string str_title = title;
  60 + if(str_title != provTitle)
  61 + {
  62 + index ++;
  63 + provTitle =str_title;
  64 + pixYIndex += (rowspacing + size_y);
  65 + if(pixYIndex> max_pixYIndex)
  66 + {
  67 + max_pixYIndex = pixYIndex;
  68 + }
  69 + return true;
  70 + }
  71 +
  72 + return true;
  73 +
  74 + }
  75 +
  76 +}
\ No newline at end of file
... ...
  1 +/**************************************************************************
  2 +* file: legendParamater.h
  3 +
  4 +* Author: qingxiongf
  5 +* Date: 2021-12-12 23:05:31
  6 +* Email: qingxiongf@chinadci.com
  7 +* copyright: 广州城市信息研究所有限公司
  8 +***************************************************************************/
  9 +
  10 +#ifndef __legendParamater_h__
  11 +#define __legendParamater_h__
  12 +
  13 +#include "dmap_core.h"
  14 +#include <string>
  15 +using namespace std;
  16 +
  17 +namespace DmapCore_30
  18 +{
  19 + class CORE_EXPORT legendParamater
  20 + {
  21 + public:
  22 + /* data */
  23 + int index;
  24 +
  25 + double pixYIndex;
  26 +
  27 + double pixXIndex;
  28 +
  29 + double m_dScaleDenominator;
  30 +
  31 + string provTitle="";
  32 +
  33 + public:
  34 +
  35 + int r=0,g=0,b=0;
  36 +
  37 + int back_r = 255,back_g = 255, back_b = 255;
  38 +
  39 + int back_a = 200;
  40 +
  41 + string title = "图例";
  42 +
  43 + string font = "宋体";
  44 +
  45 + bool isbold = false;
  46 +
  47 + bool showclassification;
  48 +
  49 + int fontSize;
  50 +
  51 + double rowspacing;
  52 +
  53 + double size_x;
  54 +
  55 + double size_y;
  56 +
  57 + int row_maxsize;
  58 +
  59 + int current_Col_Index;
  60 +
  61 + double max_pixXIndex;
  62 + double max_pixYIndex;
  63 +
  64 + public:
  65 + legendParamater(/* args */);
  66 +
  67 + bool next(char * title);
  68 +
  69 + ~legendParamater();
  70 + };
  71 +
  72 +
  73 +
  74 +}
  75 +
  76 +#endif // __legendParamater_h__
  77 +
... ...
1   -/**************************************************************************
2   -* file: dmphttpbase.cpp
3   -
4   -* Author: lijiahuan
5   -* Date: 2021-12-09 17:41:00
6   -* Email: jiahuanl@chinadci.com
7   -* copyright: 广州城市信息研究所有限公司
8   -***************************************************************************/
9   -#include "dmphttpbase.h"
10   -
11   -#define HTTP_JSON_BEGIN ("[")
12   -#define HTTP_JSON_END ("]")
13   -
14   -DmpHttp::DmpHttpBase::DmpHttpBase(){}
15   -DmpHttp::DmpHttpBase::~DmpHttpBase(){}
16   -int DmpHttp::DmpHttpBase::parseUrl(const std::string& url, std::string& out_server,
17   - std::string& out_port, std::string& out_path){
18   -const std::string& http_ = "http://";
19   -const std::string& https_ = "https://";
20   -std::string temp_data = url;
21   -if (temp_data.find(http_) == 0) {
22   - temp_data = temp_data.substr(http_.length());
23   - }
24   - else if (temp_data.find(https_) == 0) {
25   - temp_data = temp_data.substr(https_.length());
26   - }
27   - else {
28   - return HTTP_ERROR_HTTP_HEAD;
29   - }
30   - // 解析域名
31   - std::size_t idx = temp_data.find('/');
32   - // 解析 域名后的page
33   - if (std::string::npos == idx) {
34   - out_path = "/";
35   - idx = temp_data.size();
36   - }
37   - else {
38   - out_path = temp_data.substr(idx);
39   - }
40   - // 解析域名
41   - out_server = temp_data.substr(0, idx);
42   - // 解析端口
43   - idx = out_server.find(':');
44   - if (std::string::npos == idx) {
45   - out_port = "80";
46   - }
47   - else {
48   - out_port = out_server.substr(idx + 1);
49   - out_server = out_server.substr(0, idx);
50   - }
51   - return HTTP_SUCCESS;
52   -}
53   -
54   -int DmpHttp::DmpHttpBase::buildPostRequest(const std::string& server, const std::string& path,
55   - std::ostream& out_request) {
56   - // 分割path中的json数据
57   - std::string temp_path(path), temp_json;
58   - int json_pos_begin = temp_path.find(HTTP_JSON_BEGIN) + 1;
59   - int json_pos_end = temp_path.find(HTTP_JSON_END);
60   - if (json_pos_begin != std::string::npos) {
61   - // 计算json的长度
62   - int temp_json_lenth = std::string::npos;
63   - if (json_pos_end != temp_json_lenth) {
64   - temp_json_lenth = (json_pos_end - json_pos_begin);
65   - }
66   - temp_json = temp_path.substr(json_pos_begin, temp_json_lenth);
67   - temp_path = temp_path.substr(0, (json_pos_begin - 1));
68   - }
69   - out_request << "POST " << temp_path.c_str() << " HTTP/1.0\r\n";
70   - out_request << "Host: " << server.c_str() << "\r\n";
71   - out_request << "Content-Length: " << temp_json.length() << "\r\n";
72   - out_request << "Content-Type: application/x-www-form-urlencoded\r\n";
73   - out_request << "Accept: */*\r\n";
74   - out_request << "Connection: close\r\n\r\n";
75   - out_request << temp_json.c_str();
76   - return HTTP_SUCCESS;
77   -}
78   -
79   -int DmpHttp::DmpHttpBase::buildGetRequest(const std::string& server, const std::string& path,
80   - std::ostream& out_request) {
81   - out_request << "GET " << path.c_str() << " HTTP/1.0\r\n";
82   - out_request << "Host: " << server.c_str() << "\r\n";
83   - out_request << "Accept: */*\r\n";
84   - out_request << "Connection: close\r\n\r\n";
85   - return HTTP_SUCCESS;
86   -}
  1 +/**************************************************************************
  2 +* file: dmphttpbase.cpp
  3 +
  4 +* Author: lijiahuan
  5 +* Date: 2021-12-09 17:41:00
  6 +* Email: jiahuanl@chinadci.com
  7 +* copyright: 广州城市信息研究所有限公司
  8 +***************************************************************************/
  9 +#include "dmphttpbase.h"
  10 +
  11 +#define HTTP_JSON_BEGIN ("[")
  12 +#define HTTP_JSON_END ("]")
  13 +
  14 +DmpHttp::DmpHttpBase::DmpHttpBase(){}
  15 +DmpHttp::DmpHttpBase::~DmpHttpBase(){}
  16 +int DmpHttp::DmpHttpBase::parseUrl(const std::string& url, std::string& out_server,
  17 + std::string& out_port, std::string& out_path){
  18 +const std::string& http_ = "http://";
  19 +const std::string& https_ = "https://";
  20 +std::string temp_data = url;
  21 +if (temp_data.find(http_) == 0) {
  22 + temp_data = temp_data.substr(http_.length());
  23 + }
  24 + else if (temp_data.find(https_) == 0) {
  25 + temp_data = temp_data.substr(https_.length());
  26 + }
  27 + else {
  28 + return HTTP_ERROR_HTTP_HEAD;
  29 + }
  30 + // 解析域名
  31 + std::size_t idx = temp_data.find('/');
  32 + // 解析 域名后的page
  33 + if (std::string::npos == idx) {
  34 + out_path = "/";
  35 + idx = temp_data.size();
  36 + }
  37 + else {
  38 + out_path = temp_data.substr(idx);
  39 + }
  40 + // 解析域名
  41 + out_server = temp_data.substr(0, idx);
  42 + // 解析端口
  43 + idx = out_server.find(':');
  44 + if (std::string::npos == idx) {
  45 + out_port = "80";
  46 + }
  47 + else {
  48 + out_port = out_server.substr(idx + 1);
  49 + out_server = out_server.substr(0, idx);
  50 + }
  51 + return HTTP_SUCCESS;
  52 +}
  53 +
  54 +int DmpHttp::DmpHttpBase::buildPostRequest(const std::string& server, const std::string& path,
  55 + std::ostream& out_request) {
  56 + // 分割path中的json数据
  57 + std::string temp_path(path), temp_json;
  58 + int json_pos_begin = temp_path.find(HTTP_JSON_BEGIN) + 1;
  59 + int json_pos_end = temp_path.find(HTTP_JSON_END);
  60 + if (json_pos_begin != std::string::npos) {
  61 + // 计算json的长度
  62 + int temp_json_lenth = std::string::npos;
  63 + if (json_pos_end != temp_json_lenth) {
  64 + temp_json_lenth = (json_pos_end - json_pos_begin);
  65 + }
  66 + temp_json = temp_path.substr(json_pos_begin, temp_json_lenth);
  67 + temp_path = temp_path.substr(0, (json_pos_begin - 1));
  68 + }
  69 + out_request << "POST " << temp_path.c_str() << " HTTP/1.0\r\n";
  70 + out_request << "Host: " << server.c_str() << "\r\n";
  71 + out_request << "Content-Length: " << temp_json.length() << "\r\n";
  72 + out_request << "Content-Type: application/x-www-form-urlencoded\r\n";
  73 + out_request << "Accept: */*\r\n";
  74 + out_request << "Connection: close\r\n\r\n";
  75 + out_request << temp_json.c_str();
  76 + return HTTP_SUCCESS;
  77 +}
  78 +
  79 +int DmpHttp::DmpHttpBase::buildGetRequest(const std::string& server, const std::string& path,
  80 + std::ostream& out_request) {
  81 + out_request << "GET " << path.c_str() << " HTTP/1.0\r\n";
  82 + out_request << "Host: " << server.c_str() << "\r\n";
  83 + out_request << "Accept: */*\r\n";
  84 + out_request << "Connection: close\r\n\r\n";
  85 + return HTTP_SUCCESS;
  86 +}
... ...
1   -/**************************************************************************
2   -* file: dmphttpbase.h
3   -
4   -* Author: lijiahuan
5   -* Date: 2021-12-09 17:41:00
6   -* Email: jiahuanl@chinadci.com
7   -* copyright: 广州城市信息研究所有限公司
8   -***************************************************************************/
9   -#ifndef __dmphttpbase_h__
10   -#define __dmphttpbase_h__
11   -#include <iostream>
12   -#include <boost/asio.hpp>
13   -namespace DmpHttp
14   -{
15   - #define HTTP_SUCCESS (0) // 操作成功
16   - #define HTTP_ERROR_UNKNOWN (-1) // 未知的错误
17   - #define HTTP_ERROR_NETWORK (-2) // 网络连接失败
18   - #define HTTP_ERROR_HTTP_HEAD (-3) // 未找到协议头 http || https
19   -
20   - #define HTTP_ERROR_SERVICE (-1000) // 服务器请求失败
21   - #define HTTP_ERROR_LOGIN (-1001) // 登录失败
22   - #define HTTP_ERROR_ID (-1002) // 企业ID错误
23   - #define HTTP_ERROR_USER (-1003) // 帐号不存在
24   - #define HTTP_ERROR_PASSWORD (-1004) // 密码错误
25   -
26   - #define HTTP_ERROR_PARAMETER (1) // 参数错误
27   - #define HTTP_ERROR_PHONE (2) // 电话号码错误
28   - #define HTTP_ERROR_MESSAGE (3) // 短信有屏蔽字段
29   - #define HTTP_ERROR_FUNCTION (4) // 当前平台不支持这个功能
30   -
31   - class DmpHttpBase
32   - {
33   - public:
34   - DmpHttpBase();
35   - virtual ~DmpHttpBase();
36   - // Post请求
37   - virtual int post(const std::string& url) = 0;
38   - // get请求
39   - virtual int get(const std::string& url) = 0;
40   - virtual std::string getResponse(void) = 0;
41   -
42   - protected:
43   - typedef int(*pBuildRequest)(const std::string&, const std::string&,std::ostream&);
44   -
45   - static int parseUrl(const std::string& url, std::string& out_server,
46   - std::string& out_port, std::string& out_path);
47   - static int buildPostRequest(const std::string& server, const std::string& path,
48   - std::ostream& out_request);
49   - static int buildGetRequest(const std::string& server, const std::string& path,
50   - std::ostream& out_request);
51   - };
52   -}
53   -
54   -
55   -
56   -
  1 +/**************************************************************************
  2 +* file: dmphttpbase.h
  3 +
  4 +* Author: lijiahuan
  5 +* Date: 2021-12-09 17:41:00
  6 +* Email: jiahuanl@chinadci.com
  7 +* copyright: 广州城市信息研究所有限公司
  8 +***************************************************************************/
  9 +#ifndef __dmphttpbase_h__
  10 +#define __dmphttpbase_h__
  11 +#include <iostream>
  12 +#include <boost/asio.hpp>
  13 +namespace DmpHttp
  14 +{
  15 + #define HTTP_SUCCESS (0) // 操作成功
  16 + #define HTTP_ERROR_UNKNOWN (-1) // 未知的错误
  17 + #define HTTP_ERROR_NETWORK (-2) // 网络连接失败
  18 + #define HTTP_ERROR_HTTP_HEAD (-3) // 未找到协议头 http || https
  19 +
  20 + #define HTTP_ERROR_SERVICE (-1000) // 服务器请求失败
  21 + #define HTTP_ERROR_LOGIN (-1001) // 登录失败
  22 + #define HTTP_ERROR_ID (-1002) // 企业ID错误
  23 + #define HTTP_ERROR_USER (-1003) // 帐号不存在
  24 + #define HTTP_ERROR_PASSWORD (-1004) // 密码错误
  25 +
  26 + #define HTTP_ERROR_PARAMETER (1) // 参数错误
  27 + #define HTTP_ERROR_PHONE (2) // 电话号码错误
  28 + #define HTTP_ERROR_MESSAGE (3) // 短信有屏蔽字段
  29 + #define HTTP_ERROR_FUNCTION (4) // 当前平台不支持这个功能
  30 +
  31 + class DmpHttpBase
  32 + {
  33 + public:
  34 + DmpHttpBase();
  35 + virtual ~DmpHttpBase();
  36 + // Post请求
  37 + virtual int post(const std::string& url) = 0;
  38 + // get请求
  39 + virtual int get(const std::string& url) = 0;
  40 + virtual std::string getResponse(void) = 0;
  41 +
  42 + protected:
  43 + typedef int(*pBuildRequest)(const std::string&, const std::string&,std::ostream&);
  44 +
  45 + static int parseUrl(const std::string& url, std::string& out_server,
  46 + std::string& out_port, std::string& out_path);
  47 + static int buildPostRequest(const std::string& server, const std::string& path,
  48 + std::ostream& out_request);
  49 + static int buildGetRequest(const std::string& server, const std::string& path,
  50 + std::ostream& out_request);
  51 + };
  52 +}
  53 +
  54 +
  55 +
  56 +
57 57 #endif //__dmphttpbase_h__
\ No newline at end of file
... ...
... ... @@ -8,14 +8,14 @@
8 8
9 9 DmpPgsqlUtils::DmpPgsqlUtils()
10 10 {}
11   - DmpPgsqlUtils::DmpPgsqlUtils( const char* strConn_,std::string& Msg_)
  11 + DmpPgsqlUtils::DmpPgsqlUtils( const char* strConn,std::string& Msg)
12 12 {
13 13 //std::string strconn_="hostaddr=172.26.99.160 prot=5432 dbname='DmapServer' user='postgres' password='chinadci'";
14   - conn_=strConn_;
  14 + conn_=strConn;
15 15 basepconn_=PQconnectdb(conn_);
16 16 if(PQstatus(basepconn_)!=CONNECTION_OK)
17 17 {
18   - Msg_= (std::string)PQerrorMessage(basepconn_);
  18 + Msg= (std::string)PQerrorMessage(basepconn_);
19 19 }
20 20 }
21 21 DmpPgsqlUtils::~DmpPgsqlUtils()
... ... @@ -32,9 +32,9 @@
32 32 exit(1);
33 33 }
34 34
35   - bool DmpPgsqlUtils::GetDMapServices(std::map<int,DMapService> &dmapServices_,std::string& Msg_)
  35 + bool DmpPgsqlUtils::GetDMapServices(std::map<int,DMapService> &dmapServices,std::string& Msg)
36 36 {
37   - PGresult *res_;
  37 + PGresult *res;
38 38 const char* strsql="SELECT name, title, state::character, create_time, update_time, description, node::character, overview, type, service_guid, catalog_guid FROM public.dmap_service where type='WMTS'";
39 39 //char* conn_="hostaddr=172.26.60.100 port=5432 dbname=dmap_manager_test user=postgres password=chinadci";
40 40 //PGconn* pconn_=PQconnectdb(conn_);
... ... @@ -44,26 +44,26 @@
44 44 PQfinish(basepconn_);
45 45 return false;
46 46 }
47   - res_ = PQexec(basepconn_,strsql);
48   - int tuple_num=PQntuples(res_);
49   - int field_num=PQnfields(res_);
  47 + res = PQexec(basepconn_,strsql);
  48 + int tuple_num=PQntuples(res);
  49 + int field_num=PQnfields(res);
50 50 if(tuple_num>0)
51 51 {
52 52 for(int i=0;i<tuple_num;i++)
53 53 {
54   - std::string name_=PQgetvalue(res_,i,0);
55   - std::string state_=PQgetvalue(res_,i,2);
56   - std::string createtime_=PQgetvalue(res_,i,3);
57   - std::string type_=PQgetvalue(res_,i,8);
58   - std::string serviceguid_=PQgetvalue(res_,i,9);
  54 + std::string name=PQgetvalue(res,i,0);
  55 + std::string state=PQgetvalue(res,i,2);
  56 + std::string createtime=PQgetvalue(res,i,3);
  57 + std::string type=PQgetvalue(res,i,8);
  58 + std::string serviceguid=PQgetvalue(res,i,9);
59 59 DMapService service{
60   - .name=name_,
61   - .state=state_,
62   - .create_time=createtime_,
63   - .type=type_,
64   - .service_guid=serviceguid_
  60 + .name=name,
  61 + .state=state,
  62 + .create_time=createtime,
  63 + .type=type,
  64 + .service_guid=serviceguid
65 65 };
66   - dmapServices_[i]=service;
  66 + dmapServices[i]=service;
67 67 }
68 68
69 69 }
... ... @@ -71,170 +71,170 @@
71 71 {
72 72 return false;
73 73 }
74   - PQclear(res_);
  74 + PQclear(res);
75 75 return true;
76 76 }
77   - bool DmpPgsqlUtils::GetDMapService(DMapService &dmapService_,const std::string& servicename_,std::string& Msg_)
  77 + bool DmpPgsqlUtils::GetDMapService(DMapService &dmapService,const std::string& servicename,std::string& Msg)
78 78 {
79   - PGresult *res_;
80   - std::string strsql_="SELECT name, title, state::character, create_time, update_time, description, node::character, overview, type, service_guid, catalog_guid FROM public.dmap_service where name='"+servicename_+"'";
81   - const char* csql_=strsql_.c_str();
  79 + PGresult *res;
  80 + std::string strsql="SELECT name, title, state::character, create_time, update_time, description, node::character, overview, type, service_guid, catalog_guid FROM public.dmap_service where name='"+servicename+"'";
  81 + const char* csql=strsql.c_str();
82 82 if(PQstatus(basepconn_)!=CONNECTION_OK)
83 83 {
84   - std::string Msg_= (std::string)PQerrorMessage(basepconn_);
  84 + std::string Msg= (std::string)PQerrorMessage(basepconn_);
85 85 PQfinish(basepconn_);
86 86 return false;
87 87 }
88   - res_ = PQexec(basepconn_,csql_);
89   - int tuple_num=PQntuples(res_);
90   - int field_num=PQnfields(res_);
  88 + res = PQexec(basepconn_,csql);
  89 + int tuple_num=PQntuples(res);
  90 + int field_num=PQnfields(res);
91 91 if(tuple_num==1)
92 92 {
93   - std::string name_=PQgetvalue(res_,0,0);
94   - std::string state_=PQgetvalue(res_,0,2);
95   - std::string createtime_=PQgetvalue(res_,0,3);
96   - std::string type_=PQgetvalue(res_,0,8);
97   - std::string serviceguid_=PQgetvalue(res_,0,9);
  93 + std::string name=PQgetvalue(res,0,0);
  94 + std::string state=PQgetvalue(res,0,2);
  95 + std::string createtime=PQgetvalue(res,0,3);
  96 + std::string type=PQgetvalue(res,0,8);
  97 + std::string serviceguid=PQgetvalue(res,0,9);
98 98 DMapService service{
99   - .name=name_,
100   - .state=state_,
101   - .create_time=createtime_,
102   - .type=type_,
103   - .service_guid=serviceguid_
  99 + .name=name,
  100 + .state=state,
  101 + .create_time=createtime,
  102 + .type=type,
  103 + .service_guid=serviceguid
104 104 };
105   - dmapService_=service;
  105 + dmapService=service;
106 106 }
107 107 else
108 108 {
109 109 return false;
110 110 }
111   - PQclear(res_);
  111 + PQclear(res);
112 112 return true;
113 113 }
114 114
115   - bool DmpPgsqlUtils::GetDMapwmts(const std::string& serviceGuid_,DMapWmtsService& resWmts_,std::string& Msg_)
  115 + bool DmpPgsqlUtils::GetDMapwmts(const std::string& serviceGuid,DMapWmtsService& resWmts,std::string& Msg)
116 116 {
117 117 //char* conn_="hostaddr=172.26.60.100 port=5432 dbname=dmap_manager_test user=postgres password=chinadci";
118   - std::string strsql_="SELECT name, wmts_type, vendor, create_time::character, crs, datasource, metadata_url, scheme_guid FROM public.dmap_wmts where guid='"+serviceGuid_+"'";
119   - const char* csql_=strsql_.c_str();
  118 + std::string strsql="SELECT name, wmts_type, vendor, create_time::character, crs, datasource, metadata_url, scheme_guid FROM public.dmap_wmts where guid='"+serviceGuid+"'";
  119 + const char* csql=strsql.c_str();
120 120
121 121 //PGconn* pconn_=PQconnectdb(conn_);
122 122 if(PQstatus(basepconn_)!=CONNECTION_OK)
123 123 {
124   - std::string Msg_= (std::string)PQerrorMessage(basepconn_);
  124 + std::string Msg= (std::string)PQerrorMessage(basepconn_);
125 125 PQfinish(basepconn_);
126 126 return false;
127 127 }
128   - PGresult *res_;
129   - res_ = PQexec(basepconn_,csql_);
130   - int tuple_num=PQntuples(res_);
131   - int field_num=PQnfields(res_);
  128 + PGresult *res;
  129 + res = PQexec(basepconn_,csql);
  130 + int tuple_num=PQntuples(res);
  131 + int field_num=PQnfields(res);
132 132
133 133 if(tuple_num>0)
134 134 {
135   - resWmts_.name=PQgetvalue(res_,0,0);
136   - resWmts_.type=PQgetvalue(res_,0,1);
137   - std::string v=PQgetvalue(res_,0,2);
138   - resWmts_.vendor=StringToVendor(v);
139   - resWmts_.create_time=PQgetvalue(res_,0,3);
140   - resWmts_.crs=PQgetvalue(res_,0,4);
141   - resWmts_.datasource=PQgetvalue(res_,0,5);
142   - resWmts_.metadata_url=PQgetvalue(res_,0,6);
143   - resWmts_.tile_id= PQgetvalue(res_,0,7);
  135 + resWmts.name=PQgetvalue(res,0,0);
  136 + resWmts.type=PQgetvalue(res,0,1);
  137 + std::string v=PQgetvalue(res,0,2);
  138 + resWmts.vendor=StringToVendor(v);
  139 + resWmts.create_time=PQgetvalue(res,0,3);
  140 + resWmts.crs=PQgetvalue(res,0,4);
  141 + resWmts.datasource=PQgetvalue(res,0,5);
  142 + resWmts.metadata_url=PQgetvalue(res,0,6);
  143 + resWmts.tile_id= PQgetvalue(res,0,7);
144 144 }
145 145 else
146 146 {
147 147 return false;
148 148 }
149   - PQclear(res_);
  149 + PQclear(res);
150 150 return true;
151 151 }
152   - bool DmpPgsqlUtils::GetDMapwmtsFromName(const std::string& serviceName_, DMapWmtsService& resWmts_,std::string& Msg_)
  152 + bool DmpPgsqlUtils::GetDMapwmtsFromName(const std::string& serviceName, DMapWmtsService& resWmts,std::string& Msg)
153 153 {
154   - std::string strsql_="SELECT name, wmts_type, vendor, create_time::character, crs, datasource, metadata_url,layer_name, layer_alias, layer_title, layer_style, layer_format, layer_extent, scheme_guid FROM public.dmap_wmts where name='"+serviceName_+"'";
155   - const char* csql_=strsql_.c_str();
  154 + std::string strsql="SELECT name, wmts_type, vendor, create_time::character, crs, datasource, metadata_url,layer_name, layer_alias, layer_title, layer_style, layer_format, layer_extent, scheme_guid FROM public.dmap_wmts where name='"+serviceName+"'";
  155 + const char* csql=strsql.c_str();
156 156
157 157 //PGconn* pconn_=PQconnectdb(conn_);
158 158 if(PQstatus(basepconn_)!=CONNECTION_OK)
159 159 {
160   - std::string Msg_= (std::string)PQerrorMessage(basepconn_);
  160 + std::string Msg= (std::string)PQerrorMessage(basepconn_);
161 161 PQfinish(basepconn_);
162 162 return false;
163 163 }
164   - PGresult *res_;
165   - res_ = PQexec(basepconn_,csql_);
166   - int tuple_num=PQntuples(res_);
167   - int field_num=PQnfields(res_);
  164 + PGresult *res;
  165 + res = PQexec(basepconn_,csql);
  166 + int tuple_num=PQntuples(res);
  167 + int field_num=PQnfields(res);
168 168
169 169 if(tuple_num>0)
170 170 {
171   - resWmts_.name=PQgetvalue(res_,0,0);
172   - resWmts_.type=PQgetvalue(res_,0,1);
173   - std::string v=PQgetvalue(res_,0,2);
174   - resWmts_.vendor=StringToVendor(v);
175   - resWmts_.create_time=PQgetvalue(res_,0,3);
176   - resWmts_.crs=PQgetvalue(res_,0,4);
177   - resWmts_.datasource=PQgetvalue(res_,0,5);
178   - resWmts_.metadata_url=PQgetvalue(res_,0,6);
179   - resWmts_.layername=PQgetvalue(res_,0,7);
180   - resWmts_.layer_alias=PQgetvalue(res_,0,8);
181   - resWmts_.layer_tile=PQgetvalue(res_,0,9);
182   - resWmts_.layer_style=PQgetvalue(res_,0,10);
183   - resWmts_.layer_format=PQgetvalue(res_,0,11);
184   - resWmts_.layer_extent=PQgetvalue(res_,0,12);
185   - resWmts_.tile_id= PQgetvalue(res_,0,13);
  171 + resWmts.name=PQgetvalue(res,0,0);
  172 + resWmts.type=PQgetvalue(res,0,1);
  173 + std::string v=PQgetvalue(res,0,2);
  174 + resWmts.vendor=StringToVendor(v);
  175 + resWmts.create_time=PQgetvalue(res,0,3);
  176 + resWmts.crs=PQgetvalue(res,0,4);
  177 + resWmts.datasource=PQgetvalue(res,0,5);
  178 + resWmts.metadata_url=PQgetvalue(res,0,6);
  179 + resWmts.layername=PQgetvalue(res,0,7);
  180 + resWmts.layer_alias=PQgetvalue(res,0,8);
  181 + resWmts.layer_tile=PQgetvalue(res,0,9);
  182 + resWmts.layer_style=PQgetvalue(res,0,10);
  183 + resWmts.layer_format=PQgetvalue(res,0,11);
  184 + resWmts.layer_extent=PQgetvalue(res,0,12);
  185 + resWmts.tile_id= PQgetvalue(res,0,13);
186 186 }
187 187 else
188 188 {
189 189 return false;
190 190 }
191   - PQclear(res_);
  191 + PQclear(res);
192 192 return true;
193 193 }
194   - bool DmpPgsqlUtils::GetTileScheme(const std::string& guid_,TileScheme& tileScheme_,std::string& Msg_)
  194 + bool DmpPgsqlUtils::GetTileScheme(const std::string& guid,TileScheme& tileScheme,std::string& Msg)
195 195 {
196   - std::string strsql_="SELECT guid, name, alias, description, crs, crs_wkt, extent, top_left, levels, dpi::character, rows::character, cols::character, update_time, parameter FROM public.dmap_tile_scheme where guid='"+guid_+"'";
197   - const char* csql_=strsql_.c_str();
  196 + std::string strsql="SELECT guid, name, alias, description, crs, crs_wkt, extent, top_left, levels, dpi::character, rows::character, cols::character, update_time, parameter FROM public.dmap_tile_scheme where guid='"+guid+"'";
  197 + const char* csql=strsql.c_str();
198 198
199 199 //PGconn* pconn_=PQconnectdb(conn_);
200 200 if(PQstatus(basepconn_)!=CONNECTION_OK)
201 201 {
202   - std::string Msg_= (std::string)PQerrorMessage(basepconn_);
  202 + std::string Msg= (std::string)PQerrorMessage(basepconn_);
203 203 PQfinish(basepconn_);
204 204 return false;
205 205 }
206   - PGresult *res_;
207   - res_ = PQexec(basepconn_,csql_);
208   - int tuple_num=PQntuples(res_);
209   - int field_num=PQnfields(res_);
  206 + PGresult *res;
  207 + res = PQexec(basepconn_,csql);
  208 + int tuple_num=PQntuples(res);
  209 + int field_num=PQnfields(res);
210 210
211 211 if(tuple_num>0)
212 212 {
213   - tileScheme_.guid=PQgetvalue(res_,0,0);
214   - tileScheme_.name=PQgetvalue(res_,0,1);
215   - tileScheme_.crs=PQgetvalue(res_,0,4);
216   - tileScheme_.wkt=PQgetvalue(res_,0,5);
217   - tileScheme_.layer_extent=PQgetvalue(res_,0,6);
218   - tileScheme_.top_left=PQgetvalue(res_,0,7);
219   - tileScheme_.levels=PQgetvalue(res_,0,8);
220   - tileScheme_.dpi=PQgetvalue(res_,0,9);
221   - tileScheme_.rows=PQgetvalue(res_,0,10);
222   - tileScheme_.cols=PQgetvalue(res_,0,11);
  213 + tileScheme.guid=PQgetvalue(res,0,0);
  214 + tileScheme.name=PQgetvalue(res,0,1);
  215 + tileScheme.crs=PQgetvalue(res,0,4);
  216 + tileScheme.wkt=PQgetvalue(res,0,5);
  217 + tileScheme.layer_extent=PQgetvalue(res,0,6);
  218 + tileScheme.top_left=PQgetvalue(res,0,7);
  219 + tileScheme.levels=PQgetvalue(res,0,8);
  220 + tileScheme.dpi=PQgetvalue(res,0,9);
  221 + tileScheme.rows=PQgetvalue(res,0,10);
  222 + tileScheme.cols=PQgetvalue(res,0,11);
223 223 }
224 224 else
225 225 {
226 226 return false;
227 227 }
228   - PQclear(res_);
  228 + PQclear(res);
229 229 return true;
230 230 }
231   - bool DmpPgsqlUtils::CreatServerPTree(const DMapService &dmapServices_,const DMapWmtsService& resWmts_,boost::property_tree::ptree& pt_root)
  231 + bool DmpPgsqlUtils::CreatServerPTree(const DMapService &dmapServices,const DMapWmtsService& resWmts,boost::property_tree::ptree& pt_root)
232 232 {
233 233 boost::property_tree::ptree pt_properties;
234   - pt_root.add("serviceName",dmapServices_.name);
235   - pt_root.add("mapType",dmapServices_.type);
236   - pt_root.add("state",dmapServices_.state);
237   - pt_root.add("capabilities",dmapServices_.type+"Server");
  234 + pt_root.add("serviceName",dmapServices.name);
  235 + pt_root.add("mapType",dmapServices.type);
  236 + pt_root.add("state",dmapServices.state);
  237 + pt_root.add("capabilities",dmapServices.type+"Server");
238 238 pt_root.add_child("properties",pt_properties);
239 239 pt_properties.add("filePath","postgresql");
240 240 pt_properties.add("maxScale","");
... ... @@ -243,40 +243,40 @@
243 243 //pt_service.add("typeName",atoi(dmpwmtsservices_.type.c_str()));
244 244 pt_service.add("typeName",0);
245 245 pt_service.add("enabled","true");
246   - pt_service.add("properties.tileVersion",resWmts_.vendor);
247   - pt_service.add("properties.tilePath",resWmts_.datasource);
  246 + pt_service.add("properties.tileVersion",resWmts.vendor);
  247 + pt_service.add("properties.tilePath",resWmts.datasource);
248 248 pt_service.add("capabilities","");
249 249 pt_services.push_back(std::make_pair("", pt_service));
250 250 pt_root.put_child("services",pt_services);
251 251 return true;
252 252 }
253   - bool DmpPgsqlUtils::GetDMapServices(DMapService &dmapService_,const std::string serviceName_,std::string& Msg_)
  253 + bool DmpPgsqlUtils::GetDMapServices(DMapService &dmapService,const std::string serviceName,std::string& Msg)
254 254 {
255   - PGresult *res_;
  255 + PGresult *res;
256 256 const char* strsql="SELECT name, title, state::character, create_time, update_time, description, node::character, overview, type, service_guid, catalog_guid FROM public.dmap_service where type='WMTS'";
257 257 //char* conn_="hostaddr=172.26.60.100 port=5432 dbname=dmap_manager_test user=postgres password=chinadci";
258 258 //PGconn* pconn_=PQconnectdb(conn_);
259 259 if(PQstatus(basepconn_)!=CONNECTION_OK)
260 260 {
261   - std::string Msg_= (std::string)PQerrorMessage(basepconn_);
  261 + std::string Msg= (std::string)PQerrorMessage(basepconn_);
262 262 PQfinish(basepconn_);
263 263 return false;
264 264 }
265   - res_ = PQexec(basepconn_,strsql);
266   - int tuple_num=PQntuples(res_);
  265 + res = PQexec(basepconn_,strsql);
  266 + int tuple_num=PQntuples(res);
267 267 if(tuple_num>0)
268 268 {
269   - dmapService_.name=PQgetvalue(res_,0,0);
270   - dmapService_.state=PQgetvalue(res_,0,2);
271   - dmapService_.create_time=PQgetvalue(res_,0,3);
272   - dmapService_.type=PQgetvalue(res_,0,8);
273   - dmapService_.service_guid=PQgetvalue(res_,0,9);
  269 + dmapService.name=PQgetvalue(res,0,0);
  270 + dmapService.state=PQgetvalue(res,0,2);
  271 + dmapService.create_time=PQgetvalue(res,0,3);
  272 + dmapService.type=PQgetvalue(res,0,8);
  273 + dmapService.service_guid=PQgetvalue(res,0,9);
274 274 }
275 275 else
276 276 {
277 277 return false;
278 278 }
279   - PQclear(res_);
  279 + PQclear(res);
280 280 return true;
281 281 }
282 282
... ...
... ... @@ -68,15 +68,15 @@
68 68 DmpPgsqlUtils();
69 69 ~DmpPgsqlUtils();
70 70
71   - void do_exit(PGconn *conn_);
  71 + void do_exit(PGconn *conn);
72 72 //bool ExecuteQuery(const std::string& sqlstr,resMap& resMap_,std::string& Msg_);
73   - bool GetDMapServices(std::map<int,DMapService> &dmapServices_,std::string& Msg_);
74   - bool GetDMapService(DMapService &dmapService_,const std::string& servicename_,std::string& Msg_);
75   - bool GetDMapwmts(const std::string& serviceGuid_, DMapWmtsService& resWmts_,std::string& Msg_);
76   - bool GetDMapwmtsFromName(const std::string& serviceName_, DMapWmtsService& resWmts_,std::string& Msg_);
77   - bool GetTileScheme(const std::string& guid_, TileScheme& tileScheme_,std::string& Msg_);
78   - bool CreatServerPTree(const DMapService &dmapServices_,const DMapWmtsService& resWmts_,boost::property_tree::ptree& pt_root);
79   - bool GetDMapServices(DMapService &dmapService_,const std::string serviceName_,std::string& Msg_);
  73 + bool GetDMapServices(std::map<int,DMapService> &dmapServices,std::string& Msg);
  74 + bool GetDMapService(DMapService &dmapService,const std::string& servicename,std::string& Msg);
  75 + bool GetDMapwmts(const std::string& serviceGuid, DMapWmtsService& resWmts,std::string& Msg);
  76 + bool GetDMapwmtsFromName(const std::string& serviceName, DMapWmtsService& resWmts,std::string& Msg);
  77 + bool GetTileScheme(const std::string& guid, TileScheme& tileScheme,std::string& Msg);
  78 + bool CreatServerPTree(const DMapService &dmapServices,const DMapWmtsService& resWmts,boost::property_tree::ptree& pt_root);
  79 + bool GetDMapServices(DMapService &dmapService,const std::string serviceName,std::string& Msg);
80 80 std::string StringToVendor(const std::string str);
81 81 };
82 82
... ...
... ... @@ -145,11 +145,11 @@ bool DmpServerManager::stopService(const std::string &serverName, const std::str
145 145 }
146 146 bool DmpServerManager::LoadServices()
147 147 {
148   - boost::property_tree::ptree pt_,ptList_;
  148 + boost::property_tree::ptree pt,ptList;
149 149
150   - const std::string url_="http://172.26.60.100:8841/API/Service/TileService/Reload";
151   - std::string strContent_=DmpHttp::get(url_);
152   - if(strContent_.length()==0)
  150 + const std::string url="http://172.26.60.100:8841/API/Service/TileService/Reload";
  151 + std::string strContent=DmpHttp::get(url);
  152 + if(strContent.length()==0)
153 153 {
154 154 return false;
155 155 }
... ... @@ -162,21 +162,21 @@ bool DmpServerManager::LoadServices()
162 162 // }
163 163 //boost::property_tree::read_json("./example.txt", pt_);
164 164
165   - std::stringstream ssData_;
166   - ssData_<<strContent_.c_str();
167   - boost::property_tree::read_json(ssData_, pt_);
168   - int iCount_ = std::atoi(pt_.get<std::string>("data.count").c_str());
169   - if(iCount_>0)
  165 + std::stringstream ssData;
  166 + ssData<<strContent.c_str();
  167 + boost::property_tree::read_json(ssData, pt);
  168 + int iCount = std::atoi(pt.get<std::string>("data.count").c_str());
  169 + if(iCount>0)
170 170 {
171   - ptList_=pt_.get_child("data.list");
172   - for (auto& e : ptList_)
  171 + ptList=pt.get_child("data.list");
  172 + for (auto& e : ptList)
173 173 {
174   - std::string name_=e.second.get<std::string>("name");
175   - std::string title_ = e.second.get<std::string>("title");
176   - std::string type_ = e.second.get<std::string>("type");
177   - int capabilities_ =e.second.get<int>("capabilities");
178   - std::string project_ = e.second.get<std::string>("project");
179   - this->publish(type_,name_,capabilities_,project_);
  174 + std::string name = e.second.get<std::string>("name");
  175 + std::string title = e.second.get<std::string>("title");
  176 + std::string type = e.second.get<std::string>("type");
  177 + int capabilities =e.second.get<int>("capabilities");
  178 + std::string project = e.second.get<std::string>("project");
  179 + this->publish(type,name,capabilities,project);
180 180 }
181 181 }
182 182 return true;
... ...
... ... @@ -177,7 +177,7 @@ void DmpManagerApiHandler::startService(const DmpServerApiContext &context) cons
177 177 }
178 178 default:
179 179 {
180   -
  180 +
181 181 }
182 182 }
183 183 }
... ...
  1 +/**************************************************************************
  2 +* file: dmppgsql.cpp
  3 +
  4 +* Author: qingxiongf
  5 +* Date: 2021-12-11 13:43:42
  6 +* Email: qingxiongf@chinadci.com
  7 +* copyright: 广州城市信息研究所有限公司
  8 +***************************************************************************/
  9 +#include "dmppgsql.h"
  10 +#include <time.h>
  11 +
  12 +namespace mapserver
  13 +{
  14 + DmpPgsql::DmpPgsql()
  15 + {
  16 + pPGconn_ = NULL;
  17 + pPGresult_ = NULL;
  18 + bAutoReconnect_ = true;
  19 + m_iN = 1;
  20 + index_ = 0;
  21 + aliveTime_ = time(nullptr);
  22 + }
  23 +
  24 + DmpPgsql::~DmpPgsql()
  25 + {
  26 + this->FreeResult();
  27 + this->CloseConn();
  28 + }
  29 +
  30 + void DmpPgsql::refreshAliveTime()
  31 + {
  32 + aliveTime_ = time(nullptr);
  33 + }
  34 +
  35 + bool DmpPgsql::Connect(const string& s)
  36 + {
  37 + return this->Connect(s.c_str());
  38 + }
  39 + bool DmpPgsql::Connect(const char * s)
  40 + {
  41 + CloseConn();
  42 + FreeResult();
  43 + pPGconn_ = PQconnectdb(s);
  44 + ConnStatusType t = PQstatus(pPGconn_);
  45 + if (t != CONNECTION_OK)
  46 + return false;
  47 + int re = PQsetClientEncoding(pPGconn_, "UTF-8");
  48 + if (re == -1)
  49 + {
  50 + CloseConn(); return false;
  51 + }
  52 + this->sConnInfo_ = s;
  53 + return true;
  54 + }
  55 +
  56 + bool DmpPgsql::CloseConn()
  57 + {
  58 + if (pPGconn_)
  59 + {
  60 + PQfinish(pPGconn_);
  61 + pPGconn_ = NULL;
  62 + }
  63 + return true;
  64 + }
  65 +
  66 + bool DmpPgsql::FreeResult()
  67 + {
  68 + if (pPGresult_)
  69 + {
  70 + PQclear(pPGresult_);
  71 + pPGresult_ = NULL;
  72 + }
  73 + m_iN = 1;
  74 + index_ = 0;
  75 + rowCount_ = 0;
  76 + return true;
  77 + }
  78 +
  79 + bool DmpPgsql::ExecWait(const string& sql)
  80 + {
  81 + return this->ExecWait(sql.c_str());
  82 + }
  83 +
  84 +
  85 +
  86 + bool DmpPgsql::ExecWait(const char * sql)
  87 + {
  88 + FreeResult();
  89 +
  90 + pPGresult_ = PQexec(pPGconn_, sql);
  91 + char *sz = PQerrorMessage(pPGconn_);
  92 + sError_ = sz;
  93 +
  94 + if (sz &&strlen(sz)>0 && bAutoReconnect_ && pPGresult_== NULL)
  95 + {
  96 + if (this->TryReconn())
  97 + {
  98 + pPGresult_ = PQexecParams(pPGconn_, sql, 0, 0, 0, 0, 0, 1);
  99 + sz = PQerrorMessage(pPGconn_);
  100 + sError_ = sz;
  101 + }
  102 + }
  103 + rowCount_ = PQntuples(pPGresult_);
  104 + index_ = -1;
  105 + return sError_ == "";
  106 + }
  107 +
  108 +
  109 + bool DmpPgsql::ExecWaitBinary(const std::string& sql)
  110 + {
  111 + return this->ExecWaitBinary(sql.c_str());
  112 + }
  113 +
  114 +
  115 + bool DmpPgsql::ExecWaitBinary(const char * sql)
  116 + {
  117 + FreeResult();
  118 + pPGresult_ = PQexecParams(pPGconn_, sql, 0, 0, 0, 0, 0, 1);
  119 + char *sz = PQerrorMessage(pPGconn_);
  120 + sError_ = sz;
  121 +
  122 + if (sz &&strlen(sz)>0 && bAutoReconnect_ && pPGresult_ == NULL)
  123 + {
  124 + if (this->TryReconn())
  125 + {
  126 + pPGresult_ = PQexecParams(pPGconn_, sql, 0, 0, 0, 0, 0, 1);
  127 + sz = PQerrorMessage(pPGconn_);
  128 + sError_ = sz;
  129 + }
  130 +
  131 + }
  132 + rowCount_ = PQntuples(pPGresult_);
  133 + index_ = -1;
  134 + return sError_ == "";
  135 + }
  136 +
  137 + bool DmpPgsql::ExecOnly(const string& sql)
  138 + {
  139 + return this->ExecOnly(sql.c_str());
  140 + }
  141 +
  142 + bool DmpPgsql::ExecOnly(const char * sql)
  143 + {
  144 + PGresult *r = PQexec(pPGconn_, sql);
  145 +
  146 + if (r)
  147 + PQclear(r);
  148 + char* sz = PQerrorMessage(pPGconn_); // 这样对吗??? PQclear对 message 获取会不会有影响??
  149 + sError_ = sz;
  150 +
  151 + if (sz&&bAutoReconnect_)
  152 + this->TryReconn();
  153 + return sError_ == "";
  154 + }
  155 +
  156 + int DmpPgsql::next(void)
  157 + {
  158 + if (rowCount_ == 0)
  159 + {
  160 + rowCount_ = PQntuples(pPGresult_);
  161 + }
  162 + index_++;
  163 +
  164 + if (index_ >= rowCount_)
  165 + {
  166 + return false;
  167 + }
  168 + else
  169 + {
  170 + return true;
  171 + }
  172 +
  173 + //return index_;
  174 + }
  175 +
  176 + bool DmpPgsql::Get(int index, std::string * str)
  177 + {
  178 + *str = PQgetvalue(pPGresult_, index_, index);
  179 + return true;
  180 + }
  181 +
  182 + bool DmpPgsql::Get(int index, double * str)
  183 + {
  184 + *str = atof(PQgetvalue(pPGresult_, index_, index));
  185 + return true;
  186 + }
  187 +
  188 +
  189 + bool DmpPgsql::Get(int index, bool * str)
  190 + {
  191 + char *ss = PQgetvalue(pPGresult_, index_, index);
  192 + if (ss == 0)
  193 + {
  194 + *str = false;
  195 + }
  196 + char c = ss[0];
  197 + if (c == 0 || c == ' ' || c == 'f' || c == 'F')
  198 + {
  199 + *str = false;
  200 + }
  201 + else
  202 + {
  203 + *str = true;
  204 + }
  205 + return true;
  206 + }
  207 +
  208 +
  209 +
  210 + int DmpPgsql::getInt(int index)
  211 + {
  212 + return atoi(PQgetvalue(pPGresult_, index_, index));
  213 + }
  214 +
  215 + double DmpPgsql::getDouble(int index)
  216 + {
  217 + return atof(PQgetvalue(pPGresult_, index_, index));
  218 + }
  219 +
  220 + const char* DmpPgsql::getString(int index)
  221 + {
  222 + if(index_ == -1) index_ = 0;
  223 + // static const char *blankstring="";
  224 + const char *a = PQgetvalue(this->pPGresult_, index_, index);
  225 + if (a == 0)
  226 + {
  227 + return "";
  228 + }
  229 + else
  230 + {
  231 + return a;
  232 + }
  233 + }
  234 +
  235 + bool DmpPgsql::TryReconn()
  236 + {
  237 + if (Connect(this->sConnInfo_.c_str()))return true;
  238 + return false;
  239 + }
  240 +
  241 +}
\ No newline at end of file
... ...
  1 +/**************************************************************************
  2 +* file: dmppgsql.h
  3 +
  4 +* Author: qingxiongf
  5 +* Date: 2021-12-11 13:43:17
  6 +* Email: qingxiongf@chinadci.com
  7 +* copyright: 广州城市信息研究所有限公司
  8 +***************************************************************************/
  9 +
  10 +#ifndef __dmppgsql_h__
  11 +#define __dmppgsql_h__
  12 +#include <string>
  13 +#include <string.h>
  14 +#include <vector>
  15 +#include"libpq-fe.h"
  16 +
  17 +using namespace std;
  18 +namespace mapserver
  19 +{
  20 + enum PGFieldType
  21 + {
  22 + ShapeFieldType,
  23 + ShapeFieldPoint,
  24 + ShapeFieldLine,
  25 + ShapeFieldPolygon,
  26 + IntFieldType,
  27 + DoubleFieldType,
  28 + VarCharFieldType,
  29 + ByteaFieldType,
  30 + ClobFieldType,
  31 + DateFieldType ,
  32 + BigIntFieldType,
  33 + TimestampWithoutTimeZone,
  34 + UnknowFieldType
  35 + };
  36 +
  37 + class DmpPgsql
  38 + {
  39 + public:
  40 +
  41 + DmpPgsql();
  42 + ~DmpPgsql();
  43 +
  44 + bool Connect(const string& conninfo);
  45 + bool Connect(const char* conninfo);
  46 + bool CloseConn();
  47 + bool FreeResult();
  48 + bool ExecWaitBinary(const std::string& sql);
  49 + bool ExecWaitBinary(const char *sql);
  50 + bool ExecWait(const char * sql);
  51 + bool ExecWait(const std::string& sql);
  52 + bool ExecOnly(const char * sql);
  53 + bool ExecOnly(const std::string& sql);
  54 +
  55 + bool ContainTable(string tableName,string schema);
  56 + bool GetTableList(string &result, bool isXml);
  57 + bool GetTableInfo(string tableschema,string tablename, string &shapeType, string &srid);
  58 + bool GetValueList(string& resultMsg,string tableschema,string layername, string fieldname);
  59 +
  60 + bool TryReconn(void);
  61 +
  62 + PGresult* GetPGresult(){ return pPGresult_;}
  63 +
  64 + // int GetRowCount();
  65 + // int GetFieldCount();
  66 + // char *GetFieldName(int index);
  67 + // int GetFieldType(int index);
  68 + public:
  69 +
  70 + //void PrepareFieldhead();
  71 + //void FreeResult(void);
  72 +
  73 + int next(void);
  74 + bool Get(int index, std::string *str);
  75 + bool Get(int index, double *str);
  76 + bool Get(int index, bool *v);
  77 +
  78 + const char *getString(int index);
  79 + double getDouble(int index);
  80 + int getInt(int index);
  81 +
  82 + // bool GetAutoReconnect();
  83 + // bool SetAutoReconnect(bool autoReconnect);
  84 +
  85 +
  86 + // void ToHexLen(const unsigned char * from, int len, char * to);
  87 + // char ToHex1(const int i);
  88 + // void ToUpper(char * sz);
  89 + // void ToLower(char * sz);
  90 + // bool PQescapeStringConnArray(std::vector<std::string> &arr, size_t size);
  91 +
  92 + // string TimeToName(time_t tm);
  93 +
  94 + void refreshAliveTime();
  95 + long aliveTime(){return aliveTime_;}
  96 + std::string error() const{return sError_;}
  97 +
  98 +private:
  99 + bool bAutoReconnect_ = true;
  100 + int index_ = 0;
  101 + int rowCount_ =0;
  102 +
  103 + std::string sConnInfo_;
  104 + long aliveTime_;
  105 +
  106 + void * m_handle;
  107 +
  108 + int m_iN; //对象引用计数
  109 + int fieldCount;
  110 +
  111 + PGconn* pPGconn_;
  112 + PGresult* pPGresult_;
  113 + /*
  114 + 错误信息
  115 + */
  116 + string sError_;
  117 +
  118 + };
  119 +}
  120 +
  121 +
  122 +#endif // __dmppgsql_h__
... ...
  1 +/**************************************************************************
  2 +* file: dmppgsqlpool.cpp
  3 +
  4 +* Author: qingxiongf
  5 +* Date: 2021-12-11 11:53:36
  6 +* Email: qingxiongf@chinadci.com
  7 +* copyright: 广州城市信息研究所有限公司
  8 +***************************************************************************/
  9 +#include <thread>
  10 +#include <functional>
  11 +#include <iostream>
  12 +#include "dmppgsqlpool.h"
  13 +#define MAX_SIZE 40
  14 +namespace mapserver
  15 +{
  16 + DmpPgsqlPool::DmpPgsqlPool()
  17 + {
  18 + waitConnectSize_ = MAX_SIZE;
  19 + connectionTimeout_ = 15000;
  20 + }
  21 +
  22 + DmpPgsqlPool::~DmpPgsqlPool()
  23 + {
  24 + this->Close();
  25 + }
  26 +
  27 + std::shared_ptr<DmpPgsql> DmpPgsqlPool::TestDmpPgsql(void)
  28 + {
  29 +
  30 + unique_lock<mutex> lock(mutex_);
  31 + std::cout << "QCount = " << connectionQue_.size() << endl;
  32 + while (connectionQue_.empty())
  33 + {
  34 + if (cv_status::timeout == cv_.wait_for(lock, std::chrono::milliseconds(20000)))
  35 + {
  36 +
  37 + if (connectionQue_.empty())
  38 + {
  39 + printf("Failed to get connection:got idle connection timeout!\r\n");
  40 + return nullptr;
  41 + }
  42 + else
  43 + {
  44 + printf("Surcce to get connection**!\r\n");
  45 + }
  46 + }
  47 + else
  48 + {
  49 + printf("Surcce to get connection!!!!\r\n");
  50 + }
  51 + }
  52 +
  53 + /*
  54 + * std::shared_ptr智能指针析构时,会把connection资源直接delete掉,
  55 + * 相当于调用connection的析构函数,connection就被close掉了。
  56 + * 这里需要自定义std::shared_ptr的释放资源的方式,把connection直接归还到queue当中*/
  57 + std::shared_ptr<DmpPgsql> sp(connectionQue_.front(),
  58 + [&](DmpPgsql *pcon)
  59 + {
  60 + // 这里是在服务器应用线程中调用的,所以一定要考虑队列的线程安全操作
  61 + unique_lock<mutex> lock(mutex_);
  62 +
  63 + pcon->FreeResult();
  64 + pcon->refreshAliveTime(); //在归还回空闲连接队列之前要记录一下连接开始空闲的时刻
  65 + connectionQue_.push(pcon);
  66 + cv_.notify_one();
  67 + std::cout << "notify_one = " << connectionQue_.size() << endl;
  68 + });
  69 +
  70 + connectionQue_.pop();
  71 +
  72 + // 消费者取出一个连接之后,通知生产者,生产者检查队列,如果为空则生产
  73 +
  74 + return sp;
  75 +
  76 + //std::shared_ptr<CDmpPgsqlPoolZero2> poolZero(new CDmpPgsqlPoolZero2(this,nullptr));
  77 + //return poolZero;
  78 + }
  79 +
  80 +
  81 +
  82 + std::shared_ptr<DmpPgsql> DmpPgsqlPool::GetPgsqlConn(void)
  83 + {
  84 +
  85 + unique_lock<mutex> lock(mutex_);
  86 +
  87 + while (connectionQue_.empty())
  88 + {
  89 +
  90 + if(this->connectSize_ < MAX_SIZE)
  91 + {
  92 + DmpPgsql *p = this->GetConnect();
  93 + p->refreshAliveTime();
  94 + if(p)
  95 + {
  96 + std::shared_ptr<DmpPgsql> sp0(p,
  97 + [&](DmpPgsql *pcon)
  98 + {
  99 + // 这里是在服务器应用线程中调用的,所以一定要考虑队列的线程安全操作
  100 + unique_lock<mutex> lock(mutex_);
  101 +
  102 + pcon->refreshAliveTime(); //在归还回空闲连接队列之前要记录一下连接开始空闲的时刻
  103 + connectionQue_.push(pcon);
  104 + cv_.notify_one();
  105 + });
  106 +
  107 + // 消费者取出一个连接之后,通知生产者,生产者检查队列,如果为空则生产
  108 +
  109 + return sp0;
  110 + }
  111 + }
  112 +
  113 + if (cv_status::timeout == cv_.wait_for(lock, std::chrono::milliseconds(connectionTimeout_)))
  114 + {
  115 +
  116 + if (connectionQue_.empty())
  117 + {
  118 +
  119 + printf("Failed to get postgresql connection: timeout!\r\n");
  120 + return nullptr;
  121 +
  122 + }
  123 + }
  124 + }
  125 +
  126 +
  127 + //printf("wite conn %d\r\n",connectionQue_.size());
  128 +
  129 + /*
  130 + * std::shared_ptr智能指针析构时,会把connection资源直接delete掉,
  131 + * 相当于调用connection的析构函数,connection就被close掉了。
  132 + * 这里需要自定义std::shared_ptr的释放资源的方式,把connection直接归还到queue当中*/
  133 + std::shared_ptr<DmpPgsql> sp(connectionQue_.front(),
  134 + [&](DmpPgsql *pcon)
  135 + {
  136 + // 这里是在服务器应用线程中调用的,所以一定要考虑队列的线程安全操作
  137 + unique_lock<mutex> lock(mutex_);
  138 + pcon->FreeResult();
  139 + pcon->refreshAliveTime(); //在归还回空闲连接队列之前要记录一下连接开始空闲的时刻
  140 + connectionQue_.push(pcon);
  141 + cv_.notify_one();
  142 + });
  143 +
  144 + connectionQue_.pop();
  145 +
  146 + // 消费者取出一个连接之后,通知生产者,生产者检查队列,如果为空则生产
  147 +
  148 + return sp;
  149 +
  150 + //std::shared_ptr<CDmpPgsqlPoolZero2> poolZero(new CDmpPgsqlPoolZero2(this,nullptr));
  151 + //return poolZero;
  152 + }
  153 +
  154 + void DmpPgsqlPool::ScannerConnectionTask()
  155 + {
  156 + for (;;)
  157 + {
  158 + // 通过sleep模拟定时效果
  159 + this_thread::sleep_for(chrono::seconds(300));
  160 + //thread::s
  161 + // 扫描队列,释放多余的连接
  162 +
  163 + if(isClose_) return;
  164 +
  165 + unique_lock<mutex> lock(mutex_);
  166 +
  167 + time_t t =time(NULL);
  168 +
  169 + while (connectionQue_.size() > 2)
  170 + {
  171 + DmpPgsql *p = connectionQue_.front();
  172 + if(!p) continue;
  173 +
  174 + if( t - p->aliveTime() >300)
  175 + {
  176 + connectionQue_.pop();
  177 + this->connectSize_--;
  178 + delete p;
  179 + }
  180 + else
  181 + {
  182 + break; //队头连接没有超时 其他连接肯定没有超时
  183 + }
  184 + }
  185 + }
  186 + }
  187 +
  188 + void DmpPgsqlPool::ReleaseHandle(DmpPgsql *handler)
  189 + {
  190 + connectionQue_.push(handler);
  191 + cv_.notify_all();
  192 + }
  193 +
  194 + void DmpPgsqlPool::Close()
  195 + {
  196 + isClose_ = true;
  197 + if (connectionQue_.size() > 0)
  198 + {
  199 + DmpPgsql *p = connectionQue_.front();
  200 + {
  201 + this->connectSize_--;
  202 + delete p;
  203 + }
  204 + }
  205 + }
  206 +
  207 + bool DmpPgsqlPool::Connect(const char *s)
  208 + {
  209 + this->conninfo_ = s;
  210 + for (int i = 0; i < 2; i++)
  211 + {
  212 + DmpPgsql *pgsqlConn = new DmpPgsql();
  213 + //bool pConnOK = true;
  214 + bool b = pgsqlConn->Connect(conninfo_);
  215 + if (b)
  216 + {
  217 + this->connectSize_++;
  218 + connectionQue_.push(pgsqlConn);
  219 + }
  220 + else
  221 + {
  222 + //printf("%s connect failed: %s \r\n", s, pgsqlConn->sError_.c_str());
  223 + delete pgsqlConn;
  224 + pgsqlConn = NULL;
  225 + return false;
  226 + }
  227 + }
  228 +
  229 + thread scanner(std::bind(&DmpPgsqlPool::ScannerConnectionTask,this));
  230 + scanner.detach();
  231 + return true;
  232 + }
  233 +
  234 + DmpPgsql* DmpPgsqlPool::GetConnect()
  235 + {
  236 + //this->conninfo_ = s;
  237 + DmpPgsql *pgsqlConn = new DmpPgsql();
  238 + //bool pConnOK = true;
  239 + bool b = pgsqlConn->Connect(conninfo_);
  240 + if (b)
  241 + {
  242 + this->connectSize_++;
  243 + //connectionQue_.push(pgsqlConn);
  244 + return pgsqlConn;
  245 + }
  246 + else
  247 + {
  248 + delete pgsqlConn;
  249 + pgsqlConn = NULL;
  250 + }
  251 + return pgsqlConn;
  252 + }
  253 +
  254 +}
\ No newline at end of file
... ...
  1 +/**************************************************************************
  2 +* file: dmppgsqlpool.h
  3 +
  4 +* Author: fanqingxiong
  5 +* Date: 2021-11-19 15:40:28
  6 +* Email: qingxiongf@chinadci.com
  7 +* copyright: 广州城市信息研究所有限公司
  8 +***************************************************************************/
  9 +
  10 +#ifndef __dmppgsqlpool_h__
  11 +#define __dmppgsqlpool_h__
  12 +
  13 +#include <queue>
  14 +#include <memory>
  15 +#include <mutex>
  16 +#include <condition_variable>
  17 +#include "dmppgsql.h"
  18 +
  19 +namespace mapserver
  20 +{
  21 + class DmpPgsqlPool
  22 + {
  23 +public:
  24 + DmpPgsqlPool();
  25 + ~DmpPgsqlPool();
  26 + void ScannerConnectionTask();
  27 + std::shared_ptr<DmpPgsql> TestDmpPgsql(void);
  28 + std::shared_ptr<DmpPgsql> GetPgsqlConn(void);
  29 + void ReleaseHandle(DmpPgsql*);
  30 +
  31 + void Close(void);
  32 + bool Connect(const char * s);
  33 + DmpPgsql* GetConnect();
  34 + std::string guid()const { return guid_;}
  35 + std::string name()const { return name_;}
  36 + std::string alias()const{ return alias_;}
  37 +
  38 +private:
  39 + std::string conninfo_;
  40 + // 存储连接的队列
  41 + queue<DmpPgsql*> connectionQue_;
  42 + int waitConnectSize_;
  43 + int connectSize_ = 0;
  44 + mutex mutex_;
  45 + //连接超时时间
  46 + int connectionTimeout_;
  47 +
  48 + // 设置条件变量,用于连接生产线程和连接消费线程的通信
  49 + condition_variable cv_;
  50 + bool isClose_ = false;
  51 + std::string guid_;
  52 + std::string name_;
  53 + std::string alias_;
  54 + };
  55 +
  56 +}
  57 +
  58 +
  59 +#endif //__dmppgsqlpool_h__
  60 +
... ...
  1 +/**************************************************************************
  2 +* file: dmppgsqlsourcepools.cpp
  3 +
  4 +* Author: qingxiongf
  5 +* Date: 2021-12-11 11:53:36
  6 +* Email: qingxiongf@chinadci.com
  7 +* copyright: 广州城市信息研究所有限公司
  8 +***************************************************************************/
  9 +
  10 +#include "dmppgsqlsourcepools.h"
  11 +#include <iostream>
  12 +//#include "DES.h"
  13 +//#include "StringHelp.h"
  14 +
  15 +namespace mapserver
  16 +{
  17 + DmpPgsqlSourcePools* DmpPgsqlSourcePools::instance_ptr = nullptr;
  18 +
  19 + DmpPgsqlSourcePools* DmpPgsqlSourcePools::get_instance()
  20 + {
  21 + if(instance_ptr==nullptr){
  22 + instance_ptr = new DmpPgsqlSourcePools();
  23 + }
  24 + return instance_ptr;
  25 + }
  26 +
  27 +
  28 + DmpPgsqlSourcePools::DmpPgsqlSourcePools()
  29 + {
  30 +
  31 + }
  32 +
  33 + DmpPgsqlSourcePools::~DmpPgsqlSourcePools()
  34 + {
  35 +
  36 + }
  37 +
  38 + shared_ptr<DmpPgsql> DmpPgsqlSourcePools::GetDefaultPgsqlConn()
  39 + {
  40 + if (defaultPool_ != nullptr)
  41 + {
  42 + return defaultPool_->GetPgsqlConn();
  43 + }
  44 + return nullptr;
  45 + }
  46 +/*
  47 + shared_ptr<DmpPgsql> DmpPgsqlSourcePools::GetPgsqlConn(char* name)
  48 + {
  49 + if(name == 0)
  50 + {
  51 + return GetDefaultPgsqlConn();
  52 + }
  53 + else
  54 + {
  55 + string n = name;
  56 + return GetPgsqlConn(n);
  57 + }
  58 + }
  59 +*/
  60 +
  61 + shared_ptr<DmpPgsql> DmpPgsqlSourcePools::GetPgsqlConn(const string& name)
  62 + {
  63 +
  64 + map<string, shared_ptr<DmpPgsqlPool>>::iterator poolIter = this->pgsqlPool_.find(name);
  65 + if (poolIter != this->pgsqlPool_.end())
  66 + {
  67 + shared_ptr<DmpPgsqlPool> pool = poolIter->second;
  68 + return pool->GetPgsqlConn();
  69 + }
  70 +
  71 +
  72 + unique_lock<mutex> lock(mutex_);
  73 +
  74 + map<string, shared_ptr<DmpPgsqlPool>>::iterator poolIter3 = this->pgsqlPool_.find(name);
  75 + if (poolIter3 != this->pgsqlPool_.end())
  76 + {
  77 + shared_ptr<DmpPgsqlPool> pool = poolIter3->second;
  78 + return pool->GetPgsqlConn();
  79 + }
  80 +
  81 +
  82 + AddDatabasePool("postgis", name, name,name, name);
  83 +
  84 + map<string, shared_ptr<DmpPgsqlPool>>::iterator poolIter2 = this->pgsqlPool_.find(name);
  85 + if (poolIter2 != this->pgsqlPool_.end())
  86 + {
  87 + shared_ptr<DmpPgsqlPool> pool = poolIter2->second;
  88 + return pool->GetPgsqlConn();
  89 + }
  90 +
  91 + return nullptr;
  92 + }
  93 +
  94 +
  95 +
  96 +/*
  97 + shared_ptr<DmpPgsql> DmpPgsqlSourcePools::GetPgsqlConn(string name)
  98 + {
  99 + if(name == "")
  100 + {
  101 + return GetDefaultPgsqlConn();
  102 + }
  103 + unique_lock<mutex> lock(mutex_);
  104 + map<string, shared_ptr<DmpPgsqlPool>>::iterator poolIter = this->pgsqlPool_.find(name);
  105 + if (poolIter != this->pgsqlPool_.end())
  106 + {
  107 + shared_ptr<DmpPgsqlPool> pool = poolIter->second;
  108 + return pool->GetPgsqlConn();
  109 + }
  110 +
  111 + for(poolIter = this->pgsqlPool_.begin(); poolIter != this->pgsqlPool_.end(); poolIter++)
  112 + {
  113 + shared_ptr<DmpPgsqlPool> pool = poolIter->second;
  114 + if(pool->alias() == name)
  115 + {
  116 + return pool->GetPgsqlConn();
  117 + }
  118 + }
  119 + if(!this->updateLock_)
  120 + {
  121 + this->updateLock_ = true;
  122 + UpdateDatabasePool();
  123 + this->updateLock_ = false;
  124 + }
  125 +
  126 +
  127 + map<string, shared_ptr<DmpPgsqlPool>>::iterator poolIter2 = this->pgsqlPool_.find(name);
  128 + if (poolIter2 != this->pgsqlPool_.end())
  129 + {
  130 + shared_ptr<DmpPgsqlPool> pool = poolIter2->second;
  131 + return pool->GetPgsqlConn();
  132 + }
  133 +
  134 + for(poolIter2 = this->pgsqlPool_.begin(); poolIter2 != this->pgsqlPool_.end(); poolIter2++)
  135 + {
  136 + shared_ptr<DmpPgsqlPool> pool = poolIter2->second;
  137 + if(pool->alias() == name)
  138 + {
  139 + return pool->GetPgsqlConn();
  140 + }
  141 + }
  142 +
  143 + return nullptr;
  144 + }
  145 +*/
  146 + string DmpPgsqlSourcePools::GetDbSourceID(string name)
  147 + {
  148 + if(name == "")
  149 + {
  150 + return "";
  151 + }
  152 + map<string, shared_ptr<DmpPgsqlPool>>::iterator poolIter = this->pgsqlPool_.find(name);
  153 + if (poolIter != this->pgsqlPool_.end())
  154 + {
  155 + return name;
  156 + }
  157 +
  158 + for(poolIter = this->pgsqlPool_.begin(); poolIter != this->pgsqlPool_.end(); poolIter++)
  159 + {
  160 + shared_ptr<DmpPgsqlPool> pool = poolIter->second;
  161 + if(pool->alias() == name)
  162 + {
  163 + return pool->guid();
  164 + }
  165 + }
  166 + return "";
  167 + }
  168 +
  169 + bool DmpPgsqlSourcePools::UpdateDatabasePool()
  170 + {
  171 + printf("InitDatabasePool\r\n");
  172 + char sqlBuff[500];
  173 + sprintf(sqlBuff, "SELECT guid, name, alias, sqlalchemy_uri,connectstr FROM %s.%s",DMAP_SCHEMA, DMAP_DMDMS_DATABASE);
  174 +
  175 + shared_ptr<DmpPgsql> pPgsqlConn = this->GetDefaultPgsqlConn();
  176 + if(pPgsqlConn == nullptr)
  177 + {
  178 + return false;
  179 + }
  180 + bool result = pPgsqlConn->ExecWaitBinary(sqlBuff);
  181 + if(result == false)
  182 + {
  183 + std::cout<< "InitDatabasePool error:" << pPgsqlConn->error().c_str();
  184 + return false;
  185 + }
  186 +
  187 + map<string,bool> list;
  188 + for( map<string, shared_ptr<DmpPgsqlPool>>::iterator iter= pgsqlPool_.begin();
  189 + iter != pgsqlPool_.end(); iter++)
  190 + {
  191 + list[iter->first] = false;
  192 + }
  193 +
  194 + while (pPgsqlConn->next())
  195 + {
  196 + string guid = pPgsqlConn->getString(0);
  197 + string name = pPgsqlConn->getString(1);
  198 + string alias = pPgsqlConn->getString(2);
  199 + string uri = pPgsqlConn->getString(3);
  200 + string connectstr = pPgsqlConn->getString(4);
  201 +
  202 +
  203 +
  204 + list[guid] = true;
  205 +
  206 + string pgConnect= "";
  207 + if(connectstr != "")
  208 + {
  209 + char key[] = "Chinadci";
  210 + char decry[500] = { 0 };
  211 + // shared_ptr<clsMalloc> b = DmapDll::StringHelp::base64_decode_rbyte(connectstr);
  212 + // Decrypt((unsigned char*)b->mem, b->GetSize(), (unsigned char*)key, (unsigned char*)decry);
  213 + // string connectstrUrl = decry;
  214 + // printf("");
  215 + // UpdDatabasePool("postgresql", guid, name,alias, connectstrUrl);
  216 + }
  217 + else if(uri != "")
  218 + {
  219 + char key[] = "Chinadci";
  220 + char decry[500] = { 0 };
  221 + // shared_ptr<clsMalloc> b = DmapDll::StringHelp::base64_decode_rbyte(connectstr);
  222 + // Decrypt((unsigned char*)b->mem,b->GetSize(), (unsigned char*)key, (unsigned char*)decry);
  223 + string jdbcConnect = "";
  224 +
  225 + string dbType = "";
  226 +
  227 + if(jdbcConnect != "")
  228 + {
  229 + string username = "";
  230 + string password = "";
  231 + string ip = "";
  232 + string port = "5432";
  233 + string dbname = "";
  234 +
  235 + size_t n =0;
  236 + if ((n = jdbcConnect.find("://")) != string::npos)
  237 + {
  238 + dbType = jdbcConnect.substr(0,n);
  239 + jdbcConnect = jdbcConnect.substr(n+3);
  240 + }
  241 +
  242 + if ((n = jdbcConnect.find(":")) != string::npos)
  243 + {
  244 + username = jdbcConnect.substr(0,n);
  245 + jdbcConnect = jdbcConnect.substr(n+1);
  246 + }
  247 +
  248 + if ((n = jdbcConnect.find_last_of("@")) != string::npos)
  249 + {
  250 + password = jdbcConnect.substr(0,n);
  251 + jdbcConnect = jdbcConnect.substr(n+1);
  252 + }
  253 +
  254 + if ((n = jdbcConnect.find("/")) != string::npos)
  255 + {
  256 + dbname = jdbcConnect.substr(n+1);
  257 + jdbcConnect = jdbcConnect.substr(0,n);
  258 + }
  259 +
  260 + if ((n = jdbcConnect.find(":")) != string::npos)
  261 + {
  262 + ip = jdbcConnect.substr(0,n);
  263 + port = jdbcConnect.substr(n+1);
  264 + }
  265 + else
  266 + {
  267 + ip = jdbcConnect;
  268 + }
  269 +
  270 + sprintf(decry,"hostaddr=%s port=%s dbname='%s' user='%s' password='%s'",
  271 + ip.c_str(),
  272 + port.c_str(),
  273 + dbname.c_str(),
  274 + username.c_str(),
  275 + password.c_str());
  276 +
  277 + pgConnect = decry;
  278 + }
  279 +
  280 +
  281 + //postgresql://postgres:chinadci@172.26.99.156:5433/dmap_data1
  282 + if(pgConnect!="")
  283 + {
  284 + UpdDatabasePool(dbType, guid, name,alias, pgConnect);
  285 + }
  286 +
  287 + }
  288 + }
  289 +
  290 + for( map<string,bool>::iterator iter_list= list.begin();iter_list != list.end(); iter_list++)
  291 + {
  292 + bool b = iter_list->second;
  293 + if(b == false)
  294 + {
  295 + printf("删除 数据库连接 undo\r\n");
  296 + }
  297 + }
  298 + return true;
  299 + }
  300 +
  301 +
  302 + bool DmpPgsqlSourcePools::InitDatabasePool()
  303 + {
  304 + printf("InitDatabasePool\r\n");
  305 +
  306 + char sqlBuff[500];
  307 + sprintf(sqlBuff, "SELECT guid, name, alias, sqlalchemy_uri,connectstr FROM %s.%s",DMAP_SCHEMA, DMAP_DMDMS_DATABASE);
  308 +
  309 + shared_ptr<DmpPgsql> pPgsqlConn = this->GetDefaultPgsqlConn();
  310 + if(pPgsqlConn == nullptr)
  311 + {
  312 + return false;
  313 + }
  314 + pPgsqlConn->ExecWaitBinary(sqlBuff);
  315 + while (pPgsqlConn->next())
  316 + {
  317 + string guid = pPgsqlConn->getString(0);
  318 + string name = pPgsqlConn->getString(1);
  319 + string alias = pPgsqlConn->getString(2);
  320 + string uri = pPgsqlConn->getString(3);
  321 + string connectstr = pPgsqlConn->getString(4);
  322 + /* if(guid == "74c73a18-00c9-11ec-aced-0242ac110002")
  323 + {
  324 + continue;
  325 + }*/
  326 +
  327 +
  328 +
  329 + string pgConnect= "";
  330 + if(connectstr != "")
  331 + {
  332 + char key[] = "Chinadci";
  333 + char decry[500] = { 0 };
  334 + // shared_ptr<clsMalloc> b = DmapDll::StringHelp::base64_decode_rbyte(connectstr);
  335 + // Decrypt((unsigned char*)b->mem, b->GetSize(), (unsigned char*)key, (unsigned char*)decry);
  336 + for(size_t i =0; i< strlen(decry) && i<500; i++)
  337 + {
  338 + if(decry[i]== '\b')
  339 + {
  340 + decry[i]= '\0';
  341 + break;
  342 + }
  343 +
  344 + }
  345 + string connectstrUrl = decry;
  346 + printf("%s %s\r\n",guid.c_str(),connectstrUrl.c_str());
  347 + // if(guid == "53636306-407a-11ec-8237-0242ac110002")
  348 + //{
  349 + // connectstrUrl = "hostaddr=124.71.38.197 port=5432 dbname='dmap' user='root' password='DMap@123'";
  350 + //}
  351 + AddDatabasePool("postgresql", guid, name,alias, connectstrUrl);
  352 + }
  353 + else if(uri != "")
  354 + {
  355 + char key[] = "Chinadci";
  356 + char decry[500] = { 0 };
  357 + // shared_ptr<clsMalloc> b = DmapDll::StringHelp::base64_decode_rbyte(uri);
  358 + // Decrypt((unsigned char*)b->mem,b->GetSize(), (unsigned char*)key, (unsigned char*)decry);
  359 + for(int i = 0;decry[i] >0; i++)
  360 + {
  361 + if(decry[i]=='\b')
  362 + {
  363 + decry[i] =0;
  364 + break;
  365 + }
  366 +
  367 + }
  368 +
  369 + string jdbcConnect = decry;
  370 +
  371 + string dbType = "";
  372 +
  373 + if(jdbcConnect != "")
  374 + {
  375 + string username = "";
  376 + string password = "";
  377 + string ip = "";
  378 + string port = "5432";
  379 + string dbname = "";
  380 +
  381 + size_t n =0;
  382 + if ((n = jdbcConnect.find("://")) != string::npos)
  383 + {
  384 + dbType = jdbcConnect.substr(0,n);
  385 + jdbcConnect = jdbcConnect.substr(n+3);
  386 + }
  387 +
  388 + if ((n = jdbcConnect.find(":")) != string::npos)
  389 + {
  390 + username = jdbcConnect.substr(0,n);
  391 + jdbcConnect = jdbcConnect.substr(n+1);
  392 + }
  393 +
  394 + if ((n = jdbcConnect.find_last_of("@")) != string::npos)
  395 + {
  396 + password = jdbcConnect.substr(0,n);
  397 + jdbcConnect = jdbcConnect.substr(n+1);
  398 + }
  399 +
  400 + if ((n = jdbcConnect.find("/")) != string::npos)
  401 + {
  402 + dbname = jdbcConnect.substr(n+1);
  403 + jdbcConnect = jdbcConnect.substr(0,n);
  404 + }
  405 +
  406 + if ((n = jdbcConnect.find(":")) != string::npos)
  407 + {
  408 + ip = jdbcConnect.substr(0,n);
  409 + // ip = "124.71.38.197";
  410 + port = jdbcConnect.substr(n+1);
  411 + }
  412 + else
  413 + {
  414 + ip = jdbcConnect;
  415 + }
  416 +
  417 + sprintf(decry,"hostaddr=%s port=%s dbname='%s' user='%s' password='%s'",
  418 + ip.c_str(),
  419 + port.c_str(),
  420 + dbname.c_str(),
  421 + username.c_str(),
  422 + password.c_str());
  423 +
  424 + pgConnect = decry;
  425 + }
  426 +
  427 +
  428 + //postgresql://postgres:chinadci@172.26.99.156:5433/dmap_data1
  429 + if(pgConnect!="")
  430 + {
  431 + printf("%s %s\r\n",guid.c_str(),pgConnect.c_str());
  432 + AddDatabasePool(dbType, guid, name,alias, pgConnect);
  433 + }
  434 +
  435 + }
  436 + }
  437 + return true;
  438 +
  439 + }
  440 +
  441 + bool DmpPgsqlSourcePools::CreateDefaultDatabasePool(string dataType, string connStr)
  442 + {
  443 + shared_ptr<DmpPgsqlPool> newPool(new DmpPgsqlPool());
  444 + defaultPool_ = newPool;
  445 + bool result = defaultPool_->Connect(connStr.c_str());
  446 +
  447 + return true;
  448 + }
  449 +
  450 + bool DmpPgsqlSourcePools::AddDatabasePool(string dataType,
  451 + string guid,
  452 + string databaseName,
  453 + string alias,
  454 + string connStr)
  455 + {
  456 +
  457 + shared_ptr<DmpPgsqlPool> newPool(new DmpPgsqlPool());
  458 + // newPool->guid() = guid;
  459 + // newPool->m_name = databaseName;
  460 + // newPool->m_alias = alias;
  461 + newPool->Connect(connStr.c_str());
  462 + //newPool->Connect("PostgreSQLConn=hostaddr=172.26.99.173 port=5433 dbname='postgres' user='postgres' password='chinadci'");
  463 + pgsqlPool_[guid] = newPool;
  464 + return true;
  465 + }
  466 +
  467 + bool DmpPgsqlSourcePools::UpdDatabasePool(string dataType, string guid, string databaseName, string alias, string connStr)
  468 + {
  469 + if(pgsqlPool_.find(guid) == pgsqlPool_.end())
  470 + {
  471 + shared_ptr<DmpPgsqlPool> newPool(new DmpPgsqlPool());
  472 + // newPool->guid() = guid;
  473 + // newPool->m_name = databaseName;
  474 + // newPool->m_alias = alias;
  475 + // newPool->Connect(connStr.c_str());
  476 + // newPool->Connect("PostgreSQLConn=hostaddr=172.26.99.173 port=5433 dbname='postgres' user='postgres' password='chinadci'");
  477 + // pgsqlPool_[guid] = newPool;
  478 + return true;
  479 + }
  480 + return false;
  481 + }
  482 +}
\ No newline at end of file
... ...
  1 +/**************************************************************************
  2 +* file: dmppgsqlsourcepools.h
  3 +
  4 +* Author: fanqingxiong
  5 +* Date: 2021-11-19 15:40:28
  6 +* Email: qingxiongf@chinadci.com
  7 +* copyright: 广州城市信息研究所有限公司
  8 +***************************************************************************/
  9 +
  10 +
  11 +#ifndef __dmppgsqlsourcepools_h__
  12 +#define __dmppgsqlsourcepools_h__
  13 +
  14 +#include <map>
  15 +#include "dmppgsqlpool.h"
  16 +#include <mutex>
  17 +#define DMAP_DMDMS_DATABASE "dmdms_database"
  18 +#define DMAP_SCHEMA "public"
  19 +#define MAXCOUNT 200000
  20 +
  21 +namespace mapserver
  22 +{
  23 + class DmpPgsqlPool;
  24 + class DmpPgsqlSourcePools
  25 + {
  26 + public:
  27 +
  28 + DmpPgsqlSourcePools();
  29 + ~DmpPgsqlSourcePools();
  30 + static DmpPgsqlSourcePools* get_instance();
  31 +
  32 + //获取默认数据库连接
  33 + shared_ptr<DmpPgsql> GetDefaultPgsqlConn();
  34 +
  35 + //获取数据库连接
  36 + shared_ptr<DmpPgsql> GetPgsqlConn(const string& name);
  37 +
  38 + // shared_ptr<DmpPgsql> GetPgsqlConn(char* name);
  39 +
  40 + string GetDbSourceID(string name);
  41 +
  42 + bool InitDatabasePool();
  43 +
  44 + bool UpdateDatabasePool();
  45 + //创建默认数据库连接池
  46 + bool CreateDefaultDatabasePool(string dataType, string connStr);
  47 + // 添加数据库连接池
  48 + bool AddDatabasePool(string dataType, string guid, string databaseName, string alias, string connStr);
  49 + // Update 数据库连接池
  50 + bool UpdDatabasePool(string dataType, string guid, string databaseName, string alias, string connStr);
  51 + private:
  52 + shared_ptr<DmpPgsqlPool> defaultPool_;
  53 + map<string, shared_ptr<DmpPgsqlPool>> pgsqlPool_;
  54 + bool updateLock_ = false;
  55 +
  56 + private:
  57 + mutex mutex_;
  58 + static DmpPgsqlSourcePools* instance_ptr;
  59 + };
  60 +}
  61 +
  62 +
  63 +#endif //__dmppgsqlsourcepools_h__
  64 +
... ...
  1 +/**************************************************************************
  2 +* file: dmprasterbuffer.cpp
  3 +
  4 +* Author: qingxiongf
  5 +* Date: 2021-12-13 09:25:24
  6 +* Email: qingxiongf@chinadci.com
  7 +* copyright: 广州城市信息研究所有限公司
  8 +***************************************************************************/
  9 +#include "dmprasterbuffer.h"
\ No newline at end of file
... ...
  1 +/**************************************************************************
  2 +* file: dmprasterbuffer.h
  3 +
  4 +* Author: qingxiongf
  5 +* Date: 2021-12-13 09:24:09
  6 +* Email: qingxiongf@chinadci.com
  7 +* copyright: 广州城市信息研究所有限公司
  8 +***************************************************************************/
  9 +
  10 +#ifndef __dmprasterbuffer_h__
  11 +#define __dmprasterbuffer_h__
  12 +
  13 +#define MS_SUCCESS 1
  14 +
  15 +
  16 +/* COLOR OBJECT */
  17 +typedef struct {
  18 + int red;
  19 + int green;
  20 + int blue;
  21 + int alpha;
  22 +} colorObj;
  23 +
  24 +enum MS_RASTER_BUFFER_TYPE { MS_BUFFER_NONE=2000, MS_BUFFER_BYTE_RGBA, MS_BUFFER_BYTE_PALETTE };
  25 +
  26 +typedef struct {
  27 + unsigned char *pixels;
  28 + unsigned int pixel_step, row_step;
  29 + unsigned char *a,*r,*g,*b;
  30 +} rgbaArrayObj;
  31 +
  32 +typedef struct {
  33 + unsigned char b,g,r,a;
  34 +} rgbaPixel;
  35 +
  36 +typedef struct {
  37 + unsigned char r,g,b;
  38 +} rgbPixel;
  39 +
  40 +
  41 +typedef struct {
  42 + unsigned char *pixels; /*stores the actual pixel indexes*/
  43 + rgbaPixel *palette; /*rgba palette entries*/
  44 + unsigned int num_entries; /*number of palette entries*/
  45 + unsigned int scaling_maxval;
  46 +} paletteArrayObj;
  47 +
  48 +typedef struct {
  49 + int type;
  50 + unsigned int width,height;
  51 + union {
  52 + rgbaArrayObj rgba;
  53 + paletteArrayObj palette;
  54 + } data;
  55 +} rasterBufferObj;
  56 +
  57 +
  58 +
  59 +/* NOTE: RB_SET_PIXEL() will premultiply by alpha, inputs should not be
  60 + premultiplied */
  61 +
  62 +#define RB_SET_PIXEL(rb,x,y,red,green,blue,alpha) \
  63 + { \
  64 + int _rb_off = (x) * (rb)->data.rgba.pixel_step + (y) * (rb)->data.rgba.row_step; \
  65 + if( !(rb)->data.rgba.a ) { \
  66 + (rb)->data.rgba.r[_rb_off] = red; \
  67 + (rb)->data.rgba.g[_rb_off] = green; \
  68 + (rb)->data.rgba.b[_rb_off] = blue; \
  69 + } else { \
  70 + double a = alpha/255.0; \
  71 + (rb)->data.rgba.r[_rb_off] = red * a; \
  72 + (rb)->data.rgba.g[_rb_off] = green * a; \
  73 + (rb)->data.rgba.b[_rb_off] = blue * a; \
  74 + (rb)->data.rgba.a[_rb_off] = alpha; \
  75 + } \
  76 + }
  77 +
  78 +/* This versions receives an input red/green/blue that is already
  79 + premultiplied with alpha */
  80 +#define RB_SET_PIXEL_PM(rb,x,y,red,green,blue,alpha) \
  81 + { \
  82 + int _rb_off = (x) * (rb)->data.rgba.pixel_step + (y) * (rb)->data.rgba.row_step; \
  83 + (rb)->data.rgba.r[_rb_off] = red; \
  84 + (rb)->data.rgba.g[_rb_off] = green; \
  85 + (rb)->data.rgba.b[_rb_off] = blue; \
  86 + if( rb->data.rgba.a ) { \
  87 + (rb)->data.rgba.a[_rb_off] = alpha; \
  88 + } \
  89 + }
  90 +
  91 +/* NOTE: RB_MIX_PIXEL() will premultiply by alpha, inputs should not be
  92 + premultiplied */
  93 +
  94 +#define RB_MIX_PIXEL(rb,x,y,red,green,blue,alpha) \
  95 + { \
  96 + int _rb_off = (x) * (rb)->data.rgba.pixel_step + (y) * (rb)->data.rgba.row_step; \
  97 + \
  98 + msAlphaBlend( red, green, blue, alpha, \
  99 + (rb)->data.rgba.r + _rb_off, \
  100 + (rb)->data.rgba.g + _rb_off, \
  101 + (rb)->data.rgba.b + _rb_off, \
  102 + ((rb)->data.rgba.a == NULL ) ? NULL : (rb)->data.rgba.a + _rb_off ); \
  103 + }
  104 +
  105 +
  106 +
  107 +struct imageCacheObj {
  108 + int symbol;
  109 + int size;
  110 + colorObj color;
  111 + colorObj outlinecolor;
  112 + colorObj backgroundcolor;
  113 + rasterBufferObj img;
  114 + struct imageCacheObj *next;
  115 +};
  116 +
  117 +#endif // __dmprasterbuffer_h__
... ...
... ... @@ -17,7 +17,8 @@
17 17 #include "dmpserverresponse.h"
18 18 #include "dmpwms.h"
19 19 #include "dmplogger.h"
20   -
  20 +#include "dmpwmsgetcapabilities.h"
  21 +#include "dmpwmsgetmap.h"
21 22 using namespace std;
22 23
23 24 namespace DmpWms
... ... @@ -34,6 +35,33 @@ namespace DmpWms
34 35
35 36 void DmpWMSService::executeRequest(const DmpServerContext &context)
36 37 {
  38 + const DmpWmsParameters params(context.request()->ServerParameters());
  39 + const DmpProject* project = context.project();
  40 + const std::string request = params.Request();
  41 + if (request.empty())
  42 + {
  43 + context.response()->writeHtml("wms,Operation is null");
  44 + }
  45 + else if(boost::iequals(request, "getcapabilities"))
  46 + {
  47 + writeGetCapabilities(context,params, project);
  48 + }
  49 + else if(boost::iequals(request, "getmap"))
  50 + {
  51 + writeGetMap(context,params, project);
  52 + }
  53 + else if(boost::iequals(request,"thumbnail"))
  54 + {
  55 + writeThumbnail(context,params, project);
  56 + }
  57 + else if(boost::iequals(request, "getfeatureinfo"))
  58 + {
  59 +
  60 + }
  61 + else if(request == "getlegendgraphic")
  62 + {
  63 +
  64 + }
37 65 }
38 66 }
39 67
... ...
... ... @@ -11,6 +11,7 @@
11 11 #define __dmpwms_h__
12 12 #include <string>
13 13 #include "dmpservice.h"
  14 +#include "dmpwmsparameters.h"
14 15
15 16 namespace DmpWms
16 17 {
... ...
  1 +/**************************************************************************
  2 +* file: dmpwmsgetcapabilities.cpp
  3 +
  4 +* Author: qingxiongf
  5 +* Date: 2021-12-07 09:00:53
  6 +* Email: qingxiongf@chinadci.com
  7 +* copyright: 广州城市信息研究所有限公司
  8 +***************************************************************************/
  9 +#include "dmpwmsgetcapabilities.h"
  10 +#include "dmpserverresponse.h"
  11 +#include "dmpserverrequest.h"
  12 +
  13 +namespace DmpWms
  14 +{
  15 + void writeGetCapabilities( const DmpServerContext &context, const DmpWmsParameters& params,
  16 + const DmpProject* project, bool projectSettings)
  17 + {
  18 + std::string version = params.Version();
  19 + std::string hrefUrl;
  20 + char char_hrefUrl[1024] = {0};
  21 + std::string domain = context.request()->domain();
  22 + std::string port = context.request()->port();
  23 + if(port == "80" || port =="")
  24 + {
  25 + sprintf(char_hrefUrl, "http://%s%s", domain.c_str(), context.request()->path().c_str());
  26 + }
  27 + else
  28 + {
  29 + sprintf(char_hrefUrl, "http://%s:%s%s", domain.c_str(),port.c_str(), context.request()->path().c_str());
  30 + }
  31 + hrefUrl = char_hrefUrl;
  32 + // hrefUrl = "http://172.26.40.51:8821/?mapService=test";
  33 + std::shared_ptr<boost::property_tree::ptree> doc = getCapabilities(project, version,hrefUrl, projectSettings);
  34 +
  35 + std::stringstream stream;
  36 + write_xml(stream, *doc.get());
  37 + std::string xml;
  38 + xml = stream.str();
  39 +
  40 + // DmpServerResponse* response = context.response();
  41 + context.response()->removeHeader("Content-Type");
  42 + context.response()->setHeader("Content-Type", "text/xml;charset=utf-8");
  43 + context.response()->write(xml);
  44 + }
  45 +
  46 + std::shared_ptr<boost::property_tree::ptree> getCapabilities( const DmpProject* project,
  47 + const std::string &version, const std::string &hrefUrl,
  48 + bool projectSettings )
  49 + {
  50 + std::shared_ptr<boost::property_tree::ptree> xmlRootDoc(new boost::property_tree::ptree());
  51 + boost::property_tree::ptree xmlRoot;
  52 + std::string rootname;
  53 +
  54 + if ( version == "1.1.1" )
  55 + {
  56 + rootname = "WMT_MS_Capabilities";
  57 + xmlRoot.add("<xmlattr>.version", version);
  58 + }
  59 + else // 1.3.0 as default
  60 + {
  61 + rootname = "WMS_Capabilities";
  62 + // xmlRoot.add("<xmlattr>.xmlns:xsi","http://www.w3.org/2001/XMLSchema-instance");
  63 + // xmlRoot.add("<xmlattr>.xmlns","http://www.opengis.net/wms");
  64 + // xmlRoot.add("<xmlattr>.xmlns:sld","http://www.opengis.net/sld");
  65 + // xmlRoot.add("<xmlattr>.xsi:schemaLocation","http://www.opengis.net/wms http://schemas.opengis.net/wms/1.3.0/capabilities_1_3_0.xsd http://www.opengis.net/sld http://schemas.opengis.net/sld/1.1.0/sld_capabilities.xsd");
  66 + xmlRoot.add("<xmlattr>.version", version);
  67 + }
  68 +
  69 + boost::property_tree::ptree ptService;
  70 + ptService.add("Name", project->name());
  71 + ptService.add("Title", project->title()==""? project->name(): project->title());
  72 + ptService.add("Abstract", "dmap wms service");
  73 + ptService.add("Keywords", "WMS,DMAP," + project->name());
  74 + ptService.add("OnlineResource", hrefUrl);
  75 + ptService.add("Fees","none");
  76 + ptService.add("AccessConstraints","none");
  77 + xmlRoot.add_child("Service",ptService);
  78 +
  79 + boost::property_tree::ptree ptCapability;
  80 +
  81 + addCapabilitiesRequest(ptCapability,hrefUrl);
  82 + boost::property_tree::ptree format;
  83 + format.add("Format", "XML");
  84 + ptCapability.add_child("Exception",format);
  85 + addCapabilitiesLayers(ptCapability,project);
  86 +
  87 + xmlRoot.add_child("Capability",ptCapability);
  88 + xmlRootDoc->add_child(rootname,xmlRoot);
  89 + return xmlRootDoc;
  90 +
  91 + }
  92 +
  93 +
  94 + void addCapabilitiesRequestNode(boost::property_tree::ptree &pt, const std::string &hrefUrl, const char* request,const std::vector<const char*>& formatList)
  95 + {
  96 + boost::property_tree::ptree pt_request;
  97 + boost::property_tree::ptree pt_dcpType;
  98 + boost::property_tree::ptree pt_http;
  99 + boost::property_tree::ptree pt_method;
  100 + boost::property_tree::ptree pt_onlineRes;
  101 +
  102 + for(int i =0; i< formatList.size(); i++)
  103 + {
  104 + const char* format = formatList.at(i);
  105 + pt_request.add("Format",format);
  106 + }
  107 +
  108 + pt_onlineRes.add("<xmlattr>.xmlns:xlink","http://www.w3.org/1999/xlink");
  109 + pt_onlineRes.add("<xmlattr>.xmlns:type","simple");
  110 + pt_onlineRes.add("<xmlattr>.xmlns:href",hrefUrl);
  111 +
  112 + pt_method.add_child("OnlineResource",pt_onlineRes);
  113 + pt_http.add_child("Get",pt_method);
  114 + pt_dcpType.add_child("HTTP",pt_http);
  115 + pt_request.add_child("DCPType",pt_dcpType);
  116 + pt.add_child(request,pt_request);
  117 +
  118 + }
  119 +
  120 +
  121 + void addCapabilitiesRequest(boost::property_tree::ptree &pt, const std::string &hrefUrl)
  122 + {
  123 + boost::property_tree::ptree pt_request;
  124 + std::vector<const char*> formatList;
  125 +
  126 + formatList.push_back("text/xml");
  127 + addCapabilitiesRequestNode(pt_request,hrefUrl,"GetCapabilities",formatList);
  128 +
  129 + formatList.clear();
  130 + formatList.push_back("png");
  131 + formatList.push_back("jpeg");
  132 + formatList.push_back("image/jpeg");
  133 + formatList.push_back("image/png");
  134 + addCapabilitiesRequestNode(pt_request,hrefUrl,"GetMap",formatList);
  135 +
  136 + formatList.clear();
  137 + formatList.push_back("text/json");
  138 + formatList.push_back("text/xml");
  139 + addCapabilitiesRequestNode(pt_request,hrefUrl,"GetFeatureInfo",formatList);
  140 +
  141 + pt.add_child("Request", pt_request);
  142 + return;
  143 + }
  144 +
  145 + void addCapabilitiesLayers(boost::property_tree::ptree &pt,const DmpProject* project)
  146 + {
  147 + std::string srs = "EPSG:" + std::__cxx11::to_string(project->crs().srid());
  148 +
  149 + boost::property_tree::ptree ptProject;
  150 + // ptProject.add("<xmlattr>.queryable","1");
  151 + ptProject.add("Name", project->name());
  152 + ptProject.add("Title", project->title()==""? project->name(): project->title());
  153 + ptProject.add("CRS", srs);
  154 +
  155 +
  156 + double minx,miny,maxx,maxy;
  157 + int i =0;
  158 + std::map<std::string, DmpMapLayer*> mapLayers = project->mapLayers();
  159 + for (std::map<std::string, DmpMapLayer*>::iterator iter = mapLayers.begin();iter != mapLayers.end(); iter++)
  160 + {
  161 + DmpMapLayer* layer = iter->second;
  162 + if(i ==0)
  163 + {
  164 + minx = layer->extent().xmin();
  165 + miny = layer->extent().ymin();
  166 + maxx = layer->extent().xmax();
  167 + maxy = layer->extent().ymax();
  168 + }
  169 + else
  170 + {
  171 + if(minx > layer->extent().xmin()) minx = layer->extent().xmin();
  172 + if(miny > layer->extent().ymin()) miny = layer->extent().ymin();
  173 + if(maxx < layer->extent().xmax()) maxx = layer->extent().xmax();
  174 + if(maxy < layer->extent().ymax()) maxy = layer->extent().ymax();
  175 + }
  176 + i++;
  177 + }
  178 +
  179 + boost::property_tree::ptree ptGeographicBoundingbox;
  180 + ptGeographicBoundingbox.add("westBoundLongitude", minx);
  181 + ptGeographicBoundingbox.add("eastBoundLongitude", maxx);
  182 + ptGeographicBoundingbox.add("southBoundLatitude", miny);
  183 + ptGeographicBoundingbox.add("northBoundLatitude", maxy);
  184 + ptProject.add_child("EX_GeographicBoundingBox",ptGeographicBoundingbox);
  185 +
  186 + boost::property_tree::ptree ptBoundingbox;
  187 + ptBoundingbox.add("<xmlattr>.CRS", srs);
  188 + if (boost::iequals(srs, "CRS:84")|| boost::iequals(srs, "EPSG:4326"))
  189 + {
  190 + ptBoundingbox.add("<xmlattr>.miny", minx);
  191 + ptBoundingbox.add("<xmlattr>.maxy", maxx);
  192 + ptBoundingbox.add("<xmlattr>.minx", miny);
  193 + ptBoundingbox.add("<xmlattr>.maxx", maxy);
  194 + }
  195 + else
  196 + {
  197 + ptBoundingbox.add("<xmlattr>.minx", minx);
  198 + ptBoundingbox.add("<xmlattr>.maxx", maxx);
  199 + ptBoundingbox.add("<xmlattr>.miny", miny);
  200 + ptBoundingbox.add("<xmlattr>.maxy", maxy);
  201 + }
  202 + ptProject.add_child("BoundingBox",ptBoundingbox);
  203 +
  204 + for (std::map<std::string, DmpMapLayer*>::iterator iter= mapLayers.begin();iter != mapLayers.end(); iter++)
  205 + {
  206 + DmpMapLayer* layer = iter->second;
  207 + addCapabilitiesLayer(ptProject, layer,srs);
  208 + }
  209 + pt.add_child("Layer", ptProject);
  210 + }
  211 +
  212 + void addCapabilitiesLayer(boost::property_tree::ptree &pt, DmpMapLayer* layer, const std::string& srs)
  213 + {
  214 + boost::property_tree::ptree ptLayer;
  215 + ptLayer.add("<xmlattr>.queryable","1");
  216 + ptLayer.add("Name", layer->name());
  217 + ptLayer.add("Title", layer->title());
  218 + ptLayer.add("CRS", srs);
  219 +
  220 + boost::property_tree::ptree ptGeographicBoundingbox;
  221 + ptGeographicBoundingbox.add("westBoundLongitude", layer->extent().xmin());
  222 + ptGeographicBoundingbox.add("eastBoundLongitude", layer->extent().xmax());
  223 + ptGeographicBoundingbox.add("southBoundLatitude", layer->extent().ymin());
  224 + ptGeographicBoundingbox.add("northBoundLatitude", layer->extent().ymax());
  225 + ptLayer.add_child("EX_GeographicBoundingBox",ptGeographicBoundingbox);
  226 +
  227 + boost::property_tree::ptree ptBoundingbox;
  228 + ptBoundingbox.add("<xmlattr>.CRS", srs);
  229 + if (boost::iequals(srs, "CRS:84")|| boost::iequals(srs, "EPSG:4326"))
  230 + {
  231 + ptBoundingbox.add("<xmlattr>.miny", layer->extent().xmin());
  232 + ptBoundingbox.add("<xmlattr>.maxy", layer->extent().xmax());
  233 + ptBoundingbox.add("<xmlattr>.minx", layer->extent().ymin());
  234 + ptBoundingbox.add("<xmlattr>.maxx", layer->extent().ymax());
  235 + }
  236 + else
  237 + {
  238 + ptBoundingbox.add("<xmlattr>.minx", layer->extent().xmin());
  239 + ptBoundingbox.add("<xmlattr>.maxx", layer->extent().xmax());
  240 + ptBoundingbox.add("<xmlattr>.miny", layer->extent().ymin());
  241 + ptBoundingbox.add("<xmlattr>.maxy", layer->extent().ymax());
  242 + }
  243 +
  244 +
  245 + ptLayer.add_child("BoundingBox",ptBoundingbox);
  246 +
  247 + pt.add_child("Layer", ptLayer);
  248 + }
  249 +
  250 + void coordInvert(double& x1,double& y1,double& x2, double& y2)
  251 + {
  252 + double temp1 = x1; x1 = y1; y1 = temp1;
  253 + double temp2 = x2; x2 = y2; y2= temp2;
  254 + }
  255 +
  256 +
  257 +} // namespace QgsWms
... ...
  1 +/**************************************************************************
  2 +* file: dmpwmsgetcapabilities.h
  3 +
  4 +* Author: fanqingxiong
  5 +* Date: 2021-11-19 15:40:28
  6 +* Email: qingxiongf@chinadci.com
  7 +* copyright: 广州城市信息研究所有限公司
  8 +***************************************************************************/
  9 +
  10 +#ifndef __dmpwmsgetcapabilities_h__
  11 +#define __dmpwmsgetcapabilities_h__
  12 +
  13 +#include <boost/property_tree/ptree.hpp>
  14 +#include <boost/property_tree/xml_parser.hpp>
  15 +#include <boost/typeof/typeof.hpp>
  16 +#include <memory>
  17 +#include <vector>
  18 +#include "dmpproject.h"
  19 +#include "dmpwmsparameters.h"
  20 +#include "dmpservercontext.h"
  21 +
  22 +namespace DmpWms
  23 +{
  24 +
  25 + /**
  26 + * Output GetCapabilities response
  27 + */
  28 + void writeGetCapabilities( const DmpServerContext &context,const DmpWmsParameters& params,
  29 + const DmpProject* project,
  30 + bool projectSettings = false);
  31 +
  32 + /**
  33 + * Creates the WMS GetCapabilities XML document.
  34 + * \param serverIface Interface for plugins
  35 + * \param project Project
  36 + * \param version WMS version
  37 + * \param request WMS request
  38 + * \param projectSettings If TRUE, adds extended project information (does not validate against WMS schema)
  39 + * \returns GetCapabilities XML document
  40 + */
  41 + std::shared_ptr<boost::property_tree::ptree> getCapabilities( const DmpProject* project,
  42 + const std::string &version, const std::string &hrefUrl,
  43 + bool projectSettings );
  44 +
  45 + void addCapabilitiesRequest(boost::property_tree::ptree &pt, const std::string &hrefUrl);
  46 +
  47 + void addCapabilitiesRequestNode(boost::property_tree::ptree &pt, const std::string &hrefUrl,
  48 + const char* request,const std::vector<const char*>& formatList);
  49 +
  50 + void addCapabilitiesLayers(boost::property_tree::ptree &pt,const DmpProject* project);
  51 +
  52 + void addCapabilitiesLayer(boost::property_tree::ptree &pt,DmpMapLayer* layer,const std::string& srs);
  53 +
  54 + void coordInvert(double& x1,double& y1,double& x2, double& y2);
  55 +} // namespace DmpWms
  56 +
  57 +#endif
... ...
  1 +/**************************************************************************
  2 +* file: dmpwmsgetmap.cpp
  3 +
  4 +* Author: qingxiongf
  5 +* Date: 2021-12-11 11:53:36
  6 +* Email: qingxiongf@chinadci.com
  7 +* copyright: 广州城市信息研究所有限公司
  8 +***************************************************************************/
  9 +#include "dmpwmsgetmap.h"
  10 +#include "dmpwmsrenderer.h"
  11 +#include "dmpserverresponse.h"
  12 +#include "dmpserverrequest.h"
  13 +#include <map>
  14 +#include <memory>
  15 +namespace DmpWms
  16 +{
  17 +
  18 + void writeGetMap(const DmpServerContext &context,const DmpWmsParameters& params,
  19 + const DmpProject* project,
  20 + bool projectSettings )
  21 + {
  22 + string exception = WmsGetMap(context,params, project,projectSettings);
  23 + if(exception.length() >0)
  24 + {
  25 +
  26 + }
  27 + }
  28 +
  29 +
  30 + std::string WmsGetMap(const DmpServerContext &context, const DmpWmsParameters& params,
  31 + const DmpProject* project, bool projectSettings)
  32 + {
  33 + try
  34 + {
  35 +
  36 + double boxX1, boxY1, boxX2, boxY2;
  37 + std::string srs = params.Srs();
  38 + std::string recbox = params.BBox();
  39 +
  40 + int width = params.Width();
  41 + int height = params.Height();
  42 + std::string layerDefs = params.layerDefs();
  43 + std::string regionDefs = params.regionDefs();
  44 + std::map<std::string, std::string> mapLayerDefs;
  45 + std::map<std::string, std::string> mapRegionDefs;
  46 + StrDefs2Map(mapLayerDefs,layerDefs);
  47 + StrDefs2Map(mapRegionDefs,regionDefs);
  48 +
  49 + if (boost::iequals(srs, "CRS:84")|| boost::iequals(srs, "EPSG:4326"))
  50 + {
  51 + sscanf(recbox.c_str(), "%lf,%lf,%lf,%lf", &boxY1, &boxX1, &boxY2, &boxX2);
  52 + }
  53 + else
  54 + {
  55 + sscanf(recbox.c_str(), "%lf,%lf,%lf,%lf", &boxX1, &boxY1, &boxX2, &boxY2);
  56 + }
  57 +
  58 +
  59 + //stbstb:应该检查大量地方的 width和height不为零 ,char* regionDefs
  60 + if (width <= 0 || height <= 0) return "width和height 参数错误";
  61 + if (width > 8000 || height > 6000) return "参数错误,图片大小 宽不能大于8000像素 高大于6000像素";
  62 +
  63 + DmpWms::DmpWmsRenderer mapRenderer(height, width);
  64 +
  65 + std::string layers = params.Layers();
  66 + if (layers !="")
  67 + {
  68 + mapRenderer.AddWmsMapLayers(project);
  69 + }
  70 + else
  71 + {
  72 + char strlayers[1000] = {0};
  73 + strcpy(strlayers,(char *)layers.c_str());
  74 + mapRenderer.AddWmsMapLayers(project, strlayers);
  75 + }
  76 +
  77 +
  78 + shared_ptr<Rect> rect (new Rect(boxY2, boxX2, boxY1, boxX1));
  79 + mapRenderer.SetExtent(rect);
  80 + mapRenderer.GetMap(&mapLayerDefs,&mapRegionDefs);
  81 + string responseData;
  82 + mapRenderer.ToStream(responseData);
  83 + context.response()->removeHeader("Content-Type");
  84 + context.response()->setHeader("Content-Type", "image/png");
  85 + context.response()->write(responseData);
  86 + return "";
  87 + }
  88 + catch (const std::exception &e)
  89 + {
  90 + std::cerr << " GetMap " << e.what() << '\n';
  91 + return e.what();
  92 + }
  93 + }
  94 +
  95 + void writeThumbnail(const DmpServerContext &context,const DmpWmsParameters& params,
  96 + const DmpProject* project,bool projectSettings = false)
  97 + {
  98 + try
  99 + {
  100 +
  101 + double boxX1, boxY1, boxX2, boxY2;
  102 + // int width = params.Width();
  103 + // int height = params.Height();
  104 + DmpWms::DmpWmsRenderer mapRenderer(231,256);
  105 + double boxX1 = rect_service->m_dLeft;
  106 + double boxY1 = rect_service->m_dBottom;
  107 + double boxX2 = rect_service->m_dRight;
  108 + double boxY2 = rect_service->m_dTop;
  109 +
  110 + double dx = (boxX2 - boxX1) *0.1;
  111 + double dy = (boxY2 - boxY1) *0.1;
  112 +
  113 + shared_ptr<Rect> rect (new Rect(boxY2, boxX2, boxY1, boxX1));
  114 + mapRenderer.SetExtent(rect);
  115 + mapRenderer.GetMap(&mapLayerDefs,&mapRegionDefs);
  116 + string responseData;
  117 + mapRenderer.ToStream(responseData);
  118 + context.response()->removeHeader("Content-Type");
  119 + context.response()->setHeader("Content-Type", "image/png");
  120 + context.response()->write(responseData);
  121 + return "";
  122 + }
  123 + catch (const std::exception &e)
  124 + {
  125 + std::cerr << " GetMap " << e.what() << '\n';
  126 + return e.what();
  127 + }
  128 + }
  129 +
  130 +
  131 +
  132 + int StrDefs2Map(std::map<std::string,std::string>& mapDefs,std::string& strDefs)
  133 + {
  134 + char layerDefs[2000] = {0};
  135 + strcpy( layerDefs,(char*) strDefs.c_str());
  136 +
  137 + if (layerDefs && strlen(layerDefs) > 0)
  138 + {
  139 + int i = 0;
  140 + int len = strlen(layerDefs);
  141 +
  142 + for (; i < len; i++)
  143 + {
  144 + if (layerDefs[i] == '{')
  145 + {
  146 + break;
  147 + }
  148 + }
  149 +
  150 + while (i<len && layerDefs[i] != '}')
  151 + {
  152 + while (i < len && layerDefs[i] != '}' && layerDefs[i] != ',')
  153 + {
  154 + std::string layername;
  155 + std::string expression;
  156 +
  157 + char *p;
  158 + while (i < len && layerDefs[i] != '}' && layerDefs[i] != ',' && layerDefs[i] != '\"'){ i++; }
  159 + i++;
  160 + p = &layerDefs[i];
  161 + while (i < len && layerDefs[i] != '}' && layerDefs[i] != ',' && layerDefs[i] != '\"'){ i++; }
  162 + layerDefs[i] = 0;
  163 + layername = p;
  164 +
  165 +
  166 + while (i < len && layerDefs[i] != '}' && layerDefs[i] != ',' && layerDefs[i] != '\"'){ i++; }
  167 + i++;
  168 + p = &layerDefs[i];
  169 + char*p1 = &layerDefs[i - 2];
  170 + *p1 = '\"';
  171 + int leftKh =0;
  172 + //p1++;
  173 + while (i < len && layerDefs[i] != '}' && layerDefs[i] != ',' &&
  174 + layerDefs[i] != '\"' && (layerDefs[i] != ' ') && layerDefs[i] != '>' &&
  175 + layerDefs[i] != '<' && layerDefs[i] != '=' && layerDefs[i] != '!')
  176 + {
  177 +
  178 + layerDefs[i - 1] = layerDefs[i];
  179 + i++;
  180 + }
  181 + layerDefs[i - 1] = '\"';
  182 + while (i < len && layerDefs[i] != '}' && (( layerDefs[i] != ',' && layerDefs[i] != '\"')|| leftKh> 0))
  183 + {
  184 + if(layerDefs[i] == '(')
  185 + {
  186 + leftKh ++;
  187 + }
  188 + if(layerDefs[i] == ')')
  189 + {
  190 + leftKh --;
  191 + }
  192 + i++;
  193 + }
  194 + layerDefs[i] = 0;
  195 + expression = p1;
  196 + i++;
  197 + mapDefs[layername] = expression;
  198 + }
  199 + if (layerDefs[i] == '}' || layerDefs[i] == ',')i++;
  200 + //i++;
  201 + }
  202 +
  203 + }
  204 + return mapDefs.size();
  205 + }
  206 +}
\ No newline at end of file
... ...
  1 +/**************************************************************************
  2 +* file: dmpwmsgetmap.h
  3 +
  4 +* Author: fanqingxiong
  5 +* Date: 2021-11-19 15:40:28
  6 +* Email: qingxiongf@chinadci.com
  7 +* copyright: 广州城市信息研究所有限公司
  8 +***************************************************************************/
  9 +
  10 +
  11 +#ifndef __dmpwmsgetmap_h__
  12 +#define __dmpwmsgetmap_h__
  13 +#include <boost/property_tree/ptree.hpp>
  14 +#include <boost/property_tree/xml_parser.hpp>
  15 +#include <boost/typeof/typeof.hpp>
  16 +#include <memory>
  17 +#include <vector>
  18 +#include "dmpproject.h"
  19 +#include "dmpwmsparameters.h"
  20 +#include "dmpservercontext.h"
  21 +
  22 +namespace DmpWms
  23 +{
  24 + void writeGetMap(const DmpServerContext &context,const DmpWmsParameters& params,
  25 + const DmpProject* project,
  26 + bool projectSettings = false );
  27 + std::string WmsGetMap(const DmpServerContext &context,const DmpWmsParameters& params,
  28 + const DmpProject* project,
  29 + bool projectSettings = false );
  30 +
  31 + void writeThumbnail(const DmpServerContext &context,const DmpWmsParameters& params,
  32 + const DmpProject* project,bool projectSettings = false);
  33 +
  34 + int StrDefs2Map(std::map<std::string,std::string>& mapDefs,std::string& strDefs);
  35 +
  36 +}
  37 +
  38 +#endif //__dmpwmsgetmap_h__
  39 +
... ...
  1 +/**************************************************************************
  2 +* file: dmpwmsparameters.cpp
  3 +
  4 +* Author: qingxiongf
  5 +* Date: 2021-12-07 09:00:53
  6 +* Email: qingxiongf@chinadci.com
  7 +* copyright: 广州城市信息研究所有限公司
  8 +***************************************************************************/
  9 +#include <iostream>
  10 +#include "dmpwmsparameters.h"
  11 +#include <boost/lexical_cast.hpp>
  12 +#include <boost/algorithm/string.hpp>
  13 +#include "dmplogger.h"
  14 +#include "dmpserverutils.h"
  15 +
  16 +namespace DmpWms
  17 +{
  18 + DmpWmsParameters::DmpWmsParameters()
  19 + : DmpServerParameters()
  20 + {
  21 + }
  22 +
  23 + DmpWmsParameters::DmpWmsParameters(const DmpServerParameters &params)
  24 + {
  25 + params_ = params.Parameters();
  26 + }
  27 +
  28 + bool DmpWmsParameters::GetStringParameter(const char* key, std::string &value) const
  29 + {
  30 + std::map<std::string, std::string>::const_iterator iter;
  31 + iter = params_.find(key);
  32 + if (iter != params_.end())
  33 + {
  34 + try
  35 + {
  36 + value = boost::lexical_cast<std::string>(iter->second);
  37 + return true;
  38 + }
  39 + catch (boost::bad_lexical_cast &e)
  40 + {
  41 + LOGGER_ERROR(e.what());
  42 + }
  43 + }
  44 + return false;
  45 + }
  46 +
  47 + bool DmpWmsParameters::GetIntParameter(const char* key, int& value) const
  48 + {
  49 + std::map<std::string, std::string>::const_iterator iter;
  50 + iter = params_.find(key);
  51 + if (iter != params_.end())
  52 + {
  53 + try
  54 + {
  55 + value= boost::lexical_cast<int>(iter->second);
  56 + return true;
  57 + }
  58 + catch (boost::bad_lexical_cast &e)
  59 + {
  60 + LOGGER_ERROR(e.what());
  61 + }
  62 + }
  63 + return false;
  64 + }
  65 +
  66 +
  67 + std::string DmpWmsParameters::Service() const
  68 + {
  69 + std::string value = "WMS";
  70 + this->GetStringParameter("SERVICE", value);
  71 + return value;
  72 + }
  73 +
  74 + //必须 值为GetMap GetCapabilities GetFeatureInfo GetFeatureInfo GetLegendGraphic
  75 + std::string DmpWmsParameters::Request() const
  76 + {
  77 + std::string value = "";
  78 + GetStringParameter("REQUEST",value);
  79 + return value;
  80 + }
  81 +
  82 + //必须 默认全部, 要在地图上显示的图层。值是以逗号分隔的图层名称列表。
  83 + std::string DmpWmsParameters::Layers() const
  84 + {
  85 + std::string value = "";
  86 + GetStringParameter("LAYERS",value);
  87 + return value;
  88 + }
  89 +
  90 +
  91 + //必须 服务版本, 值为 1.0.0, 1.1.0, 1.1.1, 1.3
  92 + std::string DmpWmsParameters::Version() const
  93 + {
  94 + std::string value = "";
  95 + GetStringParameter("VERSION",value);
  96 + return value;
  97 + }
  98 +
  99 +
  100 +
  101 + //GetMap 必须 坐标系 地图输出的空间参考系统。值的格式为EPSG:4490. crs是WMS 1.3.0中使用的参数键
  102 + std::string DmpWmsParameters::Srs() const
  103 + {
  104 + std::string value = "";
  105 + if(GetStringParameter("SRS",value))
  106 + {
  107 + return value;
  108 + }
  109 +
  110 + GetStringParameter("CRS",value);
  111 + return value;
  112 + }
  113 +
  114 + std::string DmpWmsParameters::BBox() const
  115 + {
  116 + std::string value = "";
  117 + GetStringParameter("BBOX",value);
  118 + return value;
  119 + }
  120 +
  121 + int DmpWmsParameters::Width() const
  122 + {
  123 + int value = 0;
  124 + GetIntParameter("WIDTH",value);
  125 + return value;
  126 + }
  127 +
  128 + int DmpWmsParameters::Height() const
  129 + {
  130 + int value = 0;
  131 + GetIntParameter("HEIGHT",value);
  132 + return value;
  133 + }
  134 +
  135 + bool DmpWmsParameters::Transparent() const
  136 + {
  137 + return true;
  138 + }
  139 +
  140 + // Value is in the form RRGGBB. Default is FFFFFF (white).
  141 + std::string DmpWmsParameters::BgColor() const
  142 + {
  143 + return "";
  144 + }
  145 +
  146 +
  147 + //报告异常的格式。默认值为application/vnd.ogc.se_xml。
  148 + std::string DmpWmsParameters::Exceptions() const
  149 + {
  150 + return "application/vnd.ogc.se_xml";
  151 + }
  152 +
  153 + std::string DmpWmsParameters::sld_body() const
  154 + {
  155 + return "";
  156 + }
  157 +
  158 + std::string DmpWmsParameters::layerDefs() const
  159 + {
  160 + std::string value = "";
  161 + GetStringParameter("LAYERDDEFS",value);
  162 + return value;
  163 + }
  164 +
  165 + std::string DmpWmsParameters::regionDefs() const
  166 + {
  167 + std::string value = "";
  168 + GetStringParameter("REGIONDEFS",value);
  169 + return value;
  170 + }
  171 +
  172 +
  173 +
  174 + DmpWmsParameters::Format DmpWmsParameters::ResFormat() const
  175 + {
  176 + std::string frm;
  177 + std::map<std::string, std::string>::const_iterator iter;
  178 + iter = params_.find("format");
  179 + if (iter != params_.end())
  180 + {
  181 + frm = iter->second;
  182 + if (frm.empty()) {
  183 + return DmpWmsParameters::Format::NONE;
  184 + }
  185 + Format f = Format::PNG;
  186 + boost::to_lower(frm);
  187 + if (frm.compare("jpg") == 0 || frm.compare("jpeg") == 0 || frm.compare("image/jpeg") == 0 ) {
  188 + f = DmpWmsParameters::Format::JPG;
  189 + }
  190 + return f;
  191 + }
  192 + return DmpWmsParameters::Format::NONE;
  193 + }
  194 +} // namespace DmpWms
\ No newline at end of file
... ...
  1 +/**************************************************************************
  2 +* file: dmpwmsparameters.h
  3 +
  4 +* Author: qingxiongf
  5 +* Date: 2021-12-19 15:40:28
  6 +* Email: qingxiongf@chinadci.com
  7 +* copyright: 广州城市信息研究所有限公司
  8 +***************************************************************************/
  9 +
  10 +#ifndef __dmpwmsparameters_h__
  11 +#define __dmpwmsparameters_h__
  12 +#include "dmpserverparameters.h"
  13 +
  14 +namespace DmpWms
  15 +{
  16 + class DmpWmsParameters : public DmpServerParameters
  17 + {
  18 + public:
  19 + enum class Format
  20 + {
  21 + NONE,
  22 + JPG,
  23 + PNG,
  24 + TEXT,
  25 + XML,
  26 + HTML,
  27 + GML,
  28 + GeoJson
  29 + };
  30 + DmpWmsParameters(const DmpServerParameters &parameters);
  31 + DmpWmsParameters();
  32 + virtual ~DmpWmsParameters() = default;
  33 + std::string Service() const; //必须 值为WMS
  34 + std::string Request() const; //必须 值为GetMap GetCapabilities GetFeatureInfo GetFeatureInfo GetLegendGraphic
  35 +
  36 + std::string Layers() const; //必须 默认全部, 要在地图上显示的图层。值是以逗号分隔的图层名称列表。
  37 + std::string Version() const; //必须 服务版本, 值为 1.0.0, 1.1.0, 1.1.1, 1.3
  38 +
  39 + //GetMap
  40 + std::string Srs() const; //必须 坐标系 地图输出的空间参考系统。值的格式为EPSG:4490. crs是WMS 1.3.0中使用的参数键
  41 + std::string BBox() const; //必须
  42 + int Width() const; //必须
  43 + int Height() const; //必须
  44 +
  45 + bool Transparent() const; //地图背景是否应该是透明的。值是真是假。默认值为true
  46 + // bool Time() const;
  47 + std::string BgColor() const;// Value is in the form RRGGBB. Default is FFFFFF (white).
  48 + std::string Exceptions() const; //报告异常的格式。默认值为application/vnd.ogc.se_xml。
  49 + std::string sld_body() const; //URL编码的StyledLayerDescriptor XML文档,用于控制或增强地图图层和样式
  50 +
  51 + std::string layerDefs() const;
  52 + std::string regionDefs() const;
  53 +
  54 + // GetFeatureInfo
  55 + std::string QueryLayers() const; //查询图层
  56 + std::string FeatureCount() const; //查询记录数量
  57 + int X() const; //地图上查询点的X坐标,以像素为单位。0是左侧。i是WMS 1.3.0中使用的参数键。
  58 + int Y() const; //地图上查询点的Y坐标,以像素为单位。0是左侧。j是WMS 1.3.0中使用的参数键。
  59 +
  60 + DmpWmsParameters::Format ResFormat() const; //GetMap URL为Format GetFeatureInfo url为:info_format
  61 + private:
  62 + bool GetStringParameter(const char* key, std::string &value) const;
  63 + bool GetIntParameter(const char* key, int& value) const;
  64 +
  65 +
  66 +
  67 + };
  68 +} // namespace DmpWmts
  69 +#endif //__dmpwmsparameters_h__
... ...
  1 +/**************************************************************************
  2 +* file: dmpwmsrenderer.cpp
  3 +
  4 +* Author: qingxiongf
  5 +* Date: 2021-12-12 21:55:38
  6 +* Email: qingxiongf@chinadci.com
  7 +* copyright: 广州城市信息研究所有限公司
  8 +***************************************************************************/
  9 +#include "dmpwmsrenderer.h"
  10 +#include <sstream>
  11 +#include <stdarg.h>
  12 +#include <set>
  13 +#include <png.h>
  14 +#include <math.h>
  15 +namespace DmpWms
  16 +{
  17 + static cairo_status_t cairo_write_func(void *pbuff, const unsigned char *data, unsigned int length)
  18 + {
  19 + std::string* responseData = (std::string*)pbuff;
  20 + responseData->append((char*)data,length);
  21 + return CAIRO_STATUS_SUCCESS;
  22 + }
  23 +
  24 + static void png_write_data_to_buffer(png_structp png_ptr, png_bytep data, png_size_t length)
  25 + {
  26 +
  27 + std::string* responseData = (std::string*)png_get_io_ptr(png_ptr);
  28 + responseData->append((char*)data,length);
  29 + }
  30 +
  31 + static void png_flush_data(png_structp png_ptr)
  32 + {
  33 +
  34 + }
  35 +
  36 + DmpWmsRenderer::DmpWmsRenderer(double height, double width)
  37 + {
  38 + rasterBufferObj* rb = (rasterBufferObj*)malloc(sizeof(rasterBufferObj));
  39 + initializeRasterBufferCairo(rb, width, height);
  40 +
  41 + pRasterBufferObj = rb;
  42 +
  43 + oneInchInLayoutUnits = 0.0254;
  44 +
  45 + m_dHeight = height;
  46 + m_dWidth = width;
  47 + m_vLayers = {};
  48 + m_WMSServers = {};
  49 + m_iN = 1;
  50 + m_iBackColor = 0xffffffff; //背景默认白色
  51 + cairo_surface_t *surface = cairo_image_surface_create_for_data(rb->data.rgba.pixels,
  52 + CAIRO_FORMAT_ARGB32, (int)m_dWidth, (int)m_dHeight,rb->data.rgba.row_step); //cairo_win32_surface_create(hdc);
  53 + m_pClsSurfDC = new clsCrSurf(surface);
  54 + cairo_surface_t *surfaceBuffer = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, (int)m_dWidth, (int)m_dHeight);
  55 + m_pClsSurfBuff = new clsCrSurf(surfaceBuffer);
  56 + cairo_surface_t *maxSurfaceBuffer = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, (int)m_dWidth, (int)m_dHeight);
  57 + m_pClsMaxSurfBuffer = new clsCrSurf(maxSurfaceBuffer);
  58 +
  59 + m_pExtent = shared_ptr<Rect>(new Rect(0, 0, 0, 0));
  60 + }
  61 +
  62 + int DmpWmsRenderer::initializeRasterBufferCairo(rasterBufferObj *rb, int width, int height)
  63 + {
  64 + rb->type = MS_BUFFER_BYTE_RGBA;
  65 + rb->width = width;
  66 + rb->height = height;
  67 + rb->data.rgba.pixel_step = 4;
  68 + rb->data.rgba.row_step = width * 4;
  69 + rb->data.rgba.pixels = (unsigned char*)calloc(width*height*4,sizeof(unsigned char));
  70 + rb->data.rgba.r = &(rb->data.rgba.pixels[2]);
  71 + rb->data.rgba.g = &(rb->data.rgba.pixels[1]);
  72 + rb->data.rgba.b = &(rb->data.rgba.pixels[0]);
  73 + rb->data.rgba.a = &(rb->data.rgba.pixels[3]);
  74 + return MS_SUCCESS;
  75 + }
  76 +
  77 + DmpWmsRenderer::~DmpWmsRenderer()
  78 + {
  79 + m_vLayers.clear();
  80 + if(this->pRasterBufferObj)
  81 + {
  82 + cairo_surface_finish(m_pClsSurfDC->m_pSurf);
  83 + if( this->pRasterBufferObj->data.rgba.pixels)
  84 + {
  85 + free(this->pRasterBufferObj->data.rgba.pixels);
  86 + this->pRasterBufferObj->data.rgba.pixels = nullptr;
  87 + }
  88 + free(this->pRasterBufferObj);
  89 + this->pRasterBufferObj = nullptr;
  90 + }
  91 +
  92 + if (m_pClsMaxSurfBuffer)
  93 + {
  94 + delete m_pClsMaxSurfBuffer;
  95 + m_pClsMaxSurfBuffer = nullptr;
  96 + }
  97 + if (m_pClsSurfDC)
  98 + {
  99 + delete m_pClsSurfDC;
  100 + m_pClsSurfDC = nullptr;
  101 + }
  102 +
  103 + if (m_pClsSurfBuff)
  104 + {
  105 + delete m_pClsSurfBuff;
  106 + m_pClsSurfBuff = nullptr;
  107 + }
  108 + }
  109 +
  110 + std::string DmpWmsRenderer::format(const char *fmt, ...)
  111 + {
  112 + va_list argptr;
  113 + int cnt;
  114 + char buffer[10000];
  115 + va_start(argptr, fmt);
  116 +
  117 + cnt = vsnprintf(buffer, 2000, fmt, argptr);
  118 +
  119 + va_end(argptr);
  120 +
  121 + return buffer;
  122 + }
  123 +
  124 +
  125 +
  126 + string DmpWmsRenderer::GetDrawSQL(DmpVectorLayer* layer, Rect *pRect, const char *layerdef)
  127 + {
  128 + if (layer == 0 || layer->geom().size() == 0)
  129 + return "";
  130 +
  131 + //char sql[6000];
  132 + string ss = "SELECT \"%s\" "; //这个 %s 是表示 shape 字段
  133 +
  134 + shared_ptr<Renderer> renderer = layer->GetRenderer30();
  135 +
  136 + // int renType = renderer->RendererType();
  137 + vector<string> vFieldName;
  138 + renderer->TryAddField(vFieldName);
  139 +
  140 + int length = (int)(vFieldName.size());
  141 + for (int i = 0; i < length; i++)
  142 + {
  143 + string filename = vFieldName[i];
  144 + ss += ",\"" + (filename) + "\"::varchar ";
  145 + }
  146 +
  147 + string tableName = layer->name(); //layer->name();
  148 + string shapeName = layer->geom();
  149 + shared_ptr<DmpVectorThinLayer> pVectorThinLayer = layer->GetCurrentScaleTable(1 / this->m_dR);
  150 +
  151 + if (pVectorThinLayer != nullptr)
  152 + {
  153 + tableName = pVectorThinLayer->tableName();
  154 + }
  155 +
  156 + ss += " FROM \"%s\".\"%s\" "; // 这个 %s 是tableName
  157 + ss += " WHERE \"%s\" && \'BOX3D(%lf %lf,%lf %lf)\'::box3d";
  158 + if (layer->wherestr().length() > 0)
  159 + {
  160 + ss += " and ";
  161 + ss += layer->wherestr();
  162 + }
  163 +
  164 + if (layerdef != nullptr && strcmp(layerdef, "") != 0)
  165 + {
  166 + ss += " and ";
  167 + ss += layerdef;
  168 + }
  169 + ss += format(" limit %d ",MAXCOUNT);
  170 + //ss += " limit 40000 ";
  171 +
  172 + double t = pRect->m_dTop, r = pRect->m_dRight, b = pRect->m_dBottom, l = pRect->m_dLeft;
  173 + std::string sql = format(ss.c_str(), shapeName.c_str(), layer->schema().c_str(), tableName.c_str(), shapeName.c_str(), l, b, r, t);
  174 + //printf("%s\r\n",sql.c_str());
  175 + return sql;
  176 + }
  177 +
  178 +
  179 +
  180 + string DmpWmsRenderer::GetRegionQuerySQL(DmpVectorLayer* layer,Rect *pRect,string srid, const char *regionDef,const char *layerdef)
  181 + {
  182 + if (layer == 0 || layer->geom().size() == 0)
  183 + return "";
  184 + string sql = "";
  185 + shared_ptr<DmpPgsql> pPgsqlConn = DmpPgsqlSourcePools::get_instance()->GetPgsqlConn(layer->source());
  186 + if (pPgsqlConn != nullptr)
  187 + {
  188 + double t = pRect->m_dTop, r = pRect->m_dRight, b = pRect->m_dBottom, l = pRect->m_dLeft;
  189 + // if(pPgsqlConn->ExecWait(sql.c_str()) && pPgsqlConn->next())
  190 + {
  191 + // const char * polygon = pPgsqlConn->getString(0);
  192 + string ss = "SELECT \"%s\" "; //这个 %s 是表示 shape 字段
  193 +
  194 + shared_ptr<Renderer> renderer = layer->GetRenderer30();
  195 +
  196 + // int renType = renderer->RendererType();
  197 + vector<string> vFieldName;
  198 + renderer->TryAddField(vFieldName);
  199 +
  200 + int length = (int)(vFieldName.size());
  201 + for (int i = 0; i < length; i++)
  202 + {
  203 + string filename = vFieldName[i];
  204 + ss += ",\"" + (filename) + "\"::varchar ";
  205 + }
  206 +
  207 + string tableName = layer->name(); //layer->name();
  208 + string shapeName = layer->geom();
  209 + shared_ptr<DmpVectorThinLayer> pVectorThinLayer = layer->GetCurrentScaleTable(1 / this->m_dR);
  210 +
  211 + if (pVectorThinLayer != nullptr)
  212 + {
  213 + tableName = pVectorThinLayer->tableName();
  214 + }
  215 +
  216 + ss += " FROM \"%s\".\"%s\" "; // 这个 %s 是tableName
  217 + ss += " WHERE ST_Intersects( (select (ST_Intersection(ST_GeometryFromText('POLYGON((%f %f, %f %f, %f %f, %f %f, %f %f))',%s),'%s'::Geometry)) ),\"%s\" )";
  218 + if (layer->wherestr().length() > 0)
  219 + {
  220 + ss += " and ";
  221 + ss += layer->wherestr();
  222 + }
  223 +
  224 + if (layerdef != nullptr && strcmp(layerdef, "") != 0)
  225 + {
  226 + ss += " and ";
  227 + ss += layerdef;
  228 + }
  229 + ss += format(" limit %d ",MAXCOUNT);
  230 + // ss += " limit 40000 ";
  231 + //size_t size = strlen(regionDef);
  232 + std::string sql1 = format(ss.c_str(), shapeName.c_str(), layer->schema().c_str(),
  233 + tableName.c_str(),l,t, r,t, r, b, l, b ,l, t,srid.c_str(), regionDef,shapeName.c_str() );
  234 +
  235 + // printf("%s\r\n",sql1.c_str());
  236 +
  237 + return sql1;
  238 + }
  239 + // else
  240 + {
  241 + return "";
  242 + }
  243 +
  244 +
  245 + }
  246 + return "";
  247 + }
  248 +
  249 +
  250 +
  251 + string DmpWmsRenderer::GetRegionQuerySQL(DmpVectorLayer* layer,Rect *pRect,string srid, const string &regionLayerName,const string &regionDef,const char *layerdef)
  252 + {
  253 + if (layer == 0 || layer->geom().size() == 0)
  254 + return "";
  255 + string sql = "";
  256 + //shared_ptr<DmpPgsql> pPgsqlConn = DmpPgsqlSourcePools::get_instance()->GetDefaultWorkspace();
  257 + //if (pPgsqlConn != nullptr)
  258 + {
  259 + double t = pRect->m_dTop, r = pRect->m_dRight, b = pRect->m_dBottom, l = pRect->m_dLeft;
  260 + size_t pos = regionDef.find("not in");
  261 + if(pos == string::npos)
  262 + {
  263 + sql = format( "select ST_Intersection( \
  264 +ST_GeometryFromText('POLYGON((%f %f, %f %f, %f %f, %f %f, %f %f))',%s),\
  265 +(select st_union(geom) from \"%s\" where %s))",
  266 + l,t, r,t, r, b, l, b ,l, t, srid.c_str(),regionLayerName.c_str(),regionDef.c_str());
  267 + }
  268 + else
  269 + {
  270 + string field = regionDef.substr(0, pos);
  271 + string exp = regionDef.substr(pos+6);
  272 + sql = format( "select (ST_Difference( \
  273 +ST_GeometryFromText('POLYGON((%f %f, %f %f, %f %f, %f %f, %f %f))',%s),\
  274 +(select st_union(geom) from \"%s\" where %s in %s)))",
  275 + l,t, r,t, r, b, l, b ,l, t, srid.c_str(), regionLayerName.c_str(),field.c_str(),exp.c_str());
  276 +
  277 + //regionDef = StringHelp::
  278 + }
  279 +
  280 +
  281 +
  282 +
  283 + // if(pPgsqlConn->ExecWait(sql.c_str()) && pPgsqlConn->next())
  284 + {
  285 + // const char * polygon = pPgsqlConn->getString(0);
  286 + string ss = "SELECT \"%s\" "; //这个 %s 是表示 shape 字段
  287 +
  288 + shared_ptr<Renderer> renderer = layer->GetRenderer30();
  289 +
  290 + // int renType = renderer->RendererType();
  291 + vector<string> vFieldName;
  292 + renderer->TryAddField(vFieldName);
  293 +
  294 + int length = (int)(vFieldName.size());
  295 + for (int i = 0; i < length; i++)
  296 + {
  297 + string filename = vFieldName[i];
  298 + ss += ",\"" + (filename) + "\"::varchar ";
  299 + }
  300 +
  301 + string tableName = layer->name(); //layer->name();
  302 + string shapeName = layer->geom();
  303 + shared_ptr<DmpVectorThinLayer> pVectorThinLayer = layer->GetCurrentScaleTable(1 / this->m_dR);
  304 +
  305 + if (pVectorThinLayer != nullptr)
  306 + {
  307 + tableName = pVectorThinLayer->tableName();
  308 + }
  309 +
  310 + ss += " FROM \"%s\".\"%s\" "; // 这个 %s 是tableName
  311 + ss += " WHERE \"%s\" && \'BOX3D(%lf %lf,%lf %lf)\'::box3d and ST_Intersects( (%s),\"%s\" )"; //'%s'::Geometry
  312 + if (layer->wherestr().length() > 0)
  313 + {
  314 + ss += " and ";
  315 + ss += layer->wherestr();
  316 + }
  317 +
  318 + if (layerdef != nullptr && strcmp(layerdef, "") != 0)
  319 + {
  320 + ss += " and ";
  321 + ss += layerdef;
  322 + }
  323 +
  324 + ss += format(" limit %d ",MAXCOUNT);
  325 +
  326 + std::string sql1 = format(ss.c_str(), shapeName.c_str(), layer->schema().c_str(),
  327 + tableName.c_str(), shapeName.c_str(), l, b, r, t, sql.c_str(),shapeName.c_str() );
  328 +
  329 + //printf("%s\r\n",sql1.c_str());
  330 +
  331 + return sql1;
  332 + }
  333 + //else
  334 + {
  335 + return "";
  336 + }
  337 +
  338 +
  339 + }
  340 + return "";
  341 + }
  342 +
  343 +
  344 + string DmpWmsRenderer::GetDrawSQLAll_Catch(DmpVectorLayer* layer, shared_ptr<DmpVectorThinLayer> pVectorThinLayer)
  345 + {
  346 + if (layer == 0 || layer->geom().size() == 0)
  347 + return "";
  348 +
  349 + //char sql[6000];
  350 + string ss = "SELECT \"%s\" "; //这个 %s 是表示 shape 字段
  351 +
  352 + shared_ptr<Renderer> renderer = layer->GetRenderer30();
  353 +
  354 + // int renType = renderer->RendererType();
  355 + vector<string> vFieldName;
  356 + renderer->TryAddField(vFieldName);
  357 +
  358 + int length = (int)(vFieldName.size());
  359 + for (int i = 0; i < length; i++)
  360 + {
  361 + string filename = vFieldName[i];
  362 + //StringHelp::ToLower(filename); layer->GetFieldName
  363 + ss += ",\"" + (filename) + "\"::varchar ";
  364 + }
  365 +
  366 + ss += " FROM \"%s\".\"%s\" "; // 这个 %s 是tableName
  367 +
  368 + if (layer->wherestr().length() > 0)
  369 + {
  370 + ss += " where ";
  371 + ss += layer->wherestr();
  372 + }
  373 +
  374 + string tableName = layer->name();
  375 + if (pVectorThinLayer != nullptr)
  376 + {
  377 + tableName = pVectorThinLayer->tableName();
  378 + }
  379 +
  380 + string shapeName = layer->geom();
  381 + std::string sql = format(ss.c_str(), shapeName.c_str(), layer->schema().c_str(), tableName.c_str(), shapeName.c_str());
  382 +
  383 + return sql;
  384 + }
  385 +
  386 + string DmpWmsRenderer::GetDrawSQLAll(DmpVectorLayer* layer)
  387 + {
  388 + if (layer == 0 || layer->geom().size() == 0)
  389 + return "";
  390 +
  391 + //char sql[6000];
  392 + string ss = "SELECT \"%s\" "; //这个 %s 是表示 shape 字段
  393 +
  394 + shared_ptr<Renderer> renderer = layer->GetRenderer30();
  395 +
  396 + // int renType = renderer->RendererType();
  397 + vector<string> vFieldName;
  398 + renderer->TryAddField(vFieldName);
  399 +
  400 + int length = (int)(vFieldName.size());
  401 + for (int i = 0; i < length; i++)
  402 + {
  403 + string filename = vFieldName[i];
  404 + //StringHelp::ToLower(filename); layer->GetFieldName
  405 + ss += ",\"" + (filename) + "\"::varchar ";
  406 + }
  407 +
  408 + ss += " FROM \"%s\".\"%s\" "; // 这个 %s 是tableName
  409 +
  410 + if (layer->wherestr().length() > 0)
  411 + {
  412 + ss += " where ";
  413 + ss += layer->wherestr();
  414 + }
  415 +
  416 + string tableName = layer->name();
  417 + string shapeName = layer->geom();
  418 +
  419 + std::string sql = format(ss.c_str(), shapeName.c_str(), layer->schema().c_str(), tableName.c_str(), shapeName.c_str());
  420 +
  421 + return sql;
  422 + }
  423 +
  424 + string DmpWmsRenderer::GetDrawSQLAllOrderby(DmpVectorLayer* layer)
  425 + {
  426 + if (layer == 0 || layer->geom().size() == 0)
  427 + return "";
  428 +
  429 + //char sql[6000];
  430 + string ss = "SELECT \"%s\" "; //这个 %s 是表示 shape 字段
  431 +
  432 + shared_ptr<Renderer> renderer = layer->GetRenderer30();
  433 +
  434 + // int renType = renderer->RendererType();
  435 + vector<string> vFieldName;
  436 + renderer->TryAddField(vFieldName);
  437 +
  438 + int length = (int)(vFieldName.size());
  439 + for (int i = 0; i < length; i++)
  440 + {
  441 + string filename = vFieldName[i];
  442 + //StringHelp::ToLower(filename);layer->GetFieldName
  443 + ss += ",\"" + (filename) + "\"::varchar ";
  444 + }
  445 +
  446 + ss += " FROM \"%s\".\"%s\" "; // 这个 %s 是tableName
  447 +
  448 + if (layer->wherestr().length() > 0)
  449 + {
  450 + ss += " where ";
  451 + ss += layer->wherestr();
  452 + }
  453 +
  454 + ss += format(" limit %d ",MAXCOUNT);
  455 +
  456 + string tableName = layer->name();
  457 + string shapeName = layer->geom();
  458 +
  459 + std::string sql = format(ss.c_str(), shapeName.c_str(), layer->schema().c_str(), tableName.c_str(), shapeName.c_str());
  460 + //StringHelp::ToLower(sql);
  461 + return sql;
  462 + }
  463 +
  464 + string DmpWmsRenderer::GetCountSQL(DmpVectorLayer* layer)
  465 + {
  466 + if (layer == 0 || layer->geom().size() == 0)
  467 + return "";
  468 +
  469 + //char sql[6000];
  470 + string ss = "SELECT count(*) "; //这个 %s 是表示 shape 字段
  471 + ss += " FROM \"%s\".\"%s\" "; // 这个 %s 是tableName
  472 +
  473 + if (layer->wherestr().length() > 0)
  474 + {
  475 + ss += " where ";
  476 + ss += layer->wherestr();
  477 + }
  478 +
  479 + string tableName = layer->name();
  480 + string shapeName = layer->geom();
  481 +
  482 + if (layer->thinLayers().size() > 0)
  483 + {
  484 + tableName = layer->thinLayers()[0]->tableName();
  485 + }
  486 +
  487 + std::string sql = format(ss.c_str(), layer->schema().c_str(), tableName.c_str());
  488 + return sql;
  489 + }
  490 +
  491 + string DmpWmsRenderer::GetFeatureInfoSQL(DmpVectorLayer* layer, double x, double y, double dis,int feature_count)
  492 + {
  493 + if (layer == 0 || layer->geom().size() == 0)
  494 + return "";
  495 +
  496 +
  497 +
  498 + string ss = "SELECT "; //这个 %s 是表示 shape 字段
  499 +
  500 + string fields_str = "";
  501 +
  502 + shared_ptr<DmpPgsql> pPgsqlConn = DmpPgsqlSourcePools::get_instance()->GetPgsqlConn(layer->source());
  503 + if (pPgsqlConn != nullptr)
  504 + {
  505 +
  506 + char tablesql_buff[300];
  507 + sprintf(tablesql_buff, "select column_name,data_type from information_schema.columns where table_schema = '%s' and table_name = '%s'",
  508 + layer->schema().c_str(),
  509 + layer->name().c_str());
  510 +
  511 + int returnResult = pPgsqlConn->ExecWait(tablesql_buff);
  512 + if (!returnResult)
  513 + {
  514 + string fields_str = " * ";
  515 + }
  516 + else
  517 + {
  518 +
  519 + for (int i = 0; pPgsqlConn->next(); i++)
  520 + {
  521 + if (i > 0 && fields_str.length() >0 && fields_str[fields_str.length() -1]!=',')
  522 + {
  523 + fields_str += ",";
  524 + }
  525 + string fieldname = pPgsqlConn->getString(0);
  526 + string typeString = pPgsqlConn->getString(1);
  527 + int typeInt = PGFieldType::VarCharFieldType;
  528 + if (layer->geom() == fieldname || typeString == "geometry")
  529 + {
  530 + typeString = "geometry";
  531 + typeInt = PGFieldType::ShapeFieldType;
  532 + fields_str += " st_asgeojson(\"" + (fieldname) + "\") as geometry_as_geojson";
  533 + }
  534 + else if (typeString == "integer")
  535 + {
  536 + typeInt = PGFieldType::BigIntFieldType;
  537 + fields_str += " \"" + (fieldname) + "\" ";
  538 + }
  539 + else if (typeString == "bigint")
  540 + {
  541 + typeInt = PGFieldType::BigIntFieldType;
  542 + fields_str += " \"" + (fieldname) + "\"::varchar ";
  543 + }
  544 + else if (typeString == "double precision" || typeString == "real" || typeString == "numeric")
  545 + {
  546 + typeInt = PGFieldType::DoubleFieldType;
  547 + fields_str += " \"" + (fieldname) + "\" ";
  548 + }
  549 + else if (typeString == "character varying" || typeString == "text")
  550 + {
  551 + typeInt = PGFieldType::VarCharFieldType;
  552 + fields_str += " \"" + (fieldname) + "\" ";
  553 + }
  554 + else if (typeString == "bytea")
  555 + {
  556 + continue;
  557 + }
  558 + else if (typeString == "timestamp without time zone")
  559 + {
  560 + fields_str += " \"" + (fieldname) + "\"::varchar ";
  561 + }
  562 + }
  563 + }
  564 + }
  565 + else
  566 + {
  567 + fields_str = " * ";
  568 + }
  569 +
  570 + ss += fields_str;
  571 + ss += " FROM \"%s\".\"%s\" "; // 这个 %s 是tableName
  572 +
  573 + if (layer->wherestr().length() > 0)
  574 + {
  575 + ss += format("where %s and ", layer->wherestr().c_str() );
  576 +
  577 + }
  578 + else
  579 + {
  580 + ss += " where ";
  581 + }
  582 +
  583 + string tableName = layer->name();
  584 + std::string sql = format(ss.c_str(), layer->schema().c_str(), tableName.c_str());
  585 +
  586 + string shapeName = layer->geom();
  587 + sql += format(" ST_DWithin(\"%s\", ST_GeometryFromText('POINT(%f %f)',%s), %f) limit %d ",
  588 + shapeName.c_str(),x, y , layer->crs().srid(), dis, feature_count);
  589 + //cout<<sql.c_str() <<endl;
  590 + return sql;
  591 + }
  592 +
  593 +
  594 + bool DmpWmsRenderer::AddWmsMapLayers(const DmpProject* project) //插入型加入
  595 + {
  596 + std::map<std::string, DmpMapLayer*> mapLayers = project->mapLayers();
  597 + for(std::map<std::string, DmpMapLayer*>::iterator iter= mapLayers.begin();
  598 + iter != mapLayers.end(); iter++)
  599 + {
  600 + this->AddMapLayer(-1, (DmpVectorLayer *)iter->second);
  601 + }
  602 + return true;
  603 + }
  604 +
  605 + bool DmpWmsRenderer::AddWmsMapLayers(const DmpProject* project, char *layer) //插入型加入
  606 + {
  607 + bool layerIndex = true;
  608 + for (size_t i = 0; layer[i] != 0; i++)
  609 + {
  610 + if (!(layer[i] >= '0' && layer[i] <= '9') && layer[i] != ',')
  611 + {
  612 + layerIndex = false;
  613 + break;
  614 + }
  615 + }
  616 + if (!layerIndex)
  617 + {
  618 + set<string> set_layer;
  619 + int i = 0;
  620 + char *pl = layer;
  621 + while (true)
  622 + {
  623 + if (layer[i] == ',')
  624 + {
  625 + layer[i] = 0;
  626 + set_layer.insert(pl);
  627 + pl = &layer[i + 1];
  628 + }
  629 + else if (layer[i] == 0)
  630 + {
  631 + set_layer.insert(pl);
  632 + break;
  633 + }
  634 + i++;
  635 + }
  636 +
  637 + std::map<std::string, DmpMapLayer*> mapLayers = project->mapLayers();
  638 + for (std::map<std::string, DmpMapLayer*>::iterator iter= mapLayers.begin();
  639 + iter != mapLayers.end(); iter++)
  640 + {
  641 + if (set_layer.find(iter->first) != set_layer.end())
  642 + {
  643 + this->AddMapLayer(-1, (DmpVectorLayer *)iter->second);
  644 + }
  645 + }
  646 +
  647 + /*for (size_t i = 0; i < pWmsServer->layers.size(); i++)
  648 + {
  649 + shared_ptr<MapLayer> layer = pWmsServer->layers.at(i);
  650 + if (set_layer.find(layer->m_layerName) != set_layer.end())
  651 + {
  652 + this->AddMapLayer(-1, layer);
  653 + }
  654 + }*/
  655 + }
  656 + else
  657 + {
  658 + try
  659 + {
  660 + set<int> set_layer;
  661 + int i = 0;
  662 + char *pl = layer;
  663 + while (true)
  664 + {
  665 + if (layer[i] == ',')
  666 + {
  667 + layer[i] = 0;
  668 + set_layer.insert(atoi(pl));
  669 + pl = &layer[i + 1];
  670 + }
  671 + else if (layer[i] == 0)
  672 + {
  673 + set_layer.insert(atoi(pl));
  674 + break;
  675 + }
  676 + i++;
  677 + }
  678 +
  679 + /*for (size_t i = 0; i < pWmsServer->layers.size(); i++)
  680 + {
  681 + if (set_layer.find(i) != set_layer.end())
  682 + {
  683 + shared_ptr<MapLayer> layer = pWmsServer->layers.at(i);
  684 + this->AddMapLayer(-1, layer);
  685 + }
  686 + }*/
  687 + }
  688 + catch (...)
  689 + {
  690 + }
  691 + }
  692 + //pWmsServer->layers.clear();
  693 + return true;
  694 + }
  695 +
  696 +
  697 + bool DmpWmsRenderer::AddMapLayer(int index, DmpVectorLayer* layer)
  698 + {
  699 + if (!layer)
  700 + return false;
  701 + int length = (int)m_vLayers.size();
  702 + if (index > length)
  703 + return false;
  704 +
  705 + if (index < 0 || index == length)
  706 + {
  707 + m_vLayers.push_back(layer);
  708 + }
  709 + else
  710 + {
  711 + m_vLayers.insert(m_vLayers.begin() + index, layer);
  712 + }
  713 +
  714 + return true;
  715 + }
  716 +
  717 + bool DmpWmsRenderer::SetExtent(shared_ptr<Rect> rect)
  718 + {
  719 + m_pExtent = rect;
  720 + bool flag = this->RecalculateScale();
  721 + return flag;
  722 + }
  723 +
  724 + bool DmpWmsRenderer::GetParameters(double *pR, double *pXdis, double *pYdis)
  725 + {
  726 + *pR = m_dR / ((resolution / oneInchInLayoutUnits));
  727 + *pXdis = m_dXdis / ((resolution / oneInchInLayoutUnits));
  728 + *pYdis = m_dYdis / ((resolution / oneInchInLayoutUnits));
  729 + return true;
  730 + }
  731 + bool DmpWmsRenderer::SetParameters(double r, double xdis, double ydis)
  732 + {
  733 + m_dR = r * ((resolution / oneInchInLayoutUnits));
  734 + m_dXdis = xdis * ((resolution / oneInchInLayoutUnits));
  735 + m_dYdis = ydis * ((resolution / oneInchInLayoutUnits));
  736 + return true;
  737 + }
  738 +
  739 + bool DmpWmsRenderer::RecalculateScale()
  740 + {
  741 + double w = m_pExtent->m_dRight - m_pExtent->m_dLeft;
  742 + double h = m_pExtent->m_dTop - m_pExtent->m_dBottom;
  743 + if ((w > pow(10, 12)) || (w < pow(10, -12)))
  744 + return false;
  745 + if ((h > pow(10, 12)) || (h < pow(10, -12)))
  746 + return false;
  747 +
  748 + long double R1 = m_dWidth / w;
  749 + long double R2 = m_dHeight / h;
  750 + double r = R1 < R2 ? R1 : R2;
  751 + if ((r > std::pow(10, 12)) || (r < std::pow(10, -12)))
  752 + return false;
  753 +
  754 +
  755 + //m_dR = R1 < R2 ? R1 : R2;
  756 + m_dR = r;
  757 + m_dXdis = m_dWidth / 2.0 - m_dR * (m_pExtent->m_dRight + m_pExtent->m_dLeft) / 2.0;
  758 + m_dYdis = m_dHeight / 2.0 + m_dR * (m_pExtent->m_dTop + m_pExtent->m_dBottom) / 2.0;
  759 +
  760 + if(R1 < R2)
  761 + {
  762 + double top = (m_pExtent->m_dTop + m_pExtent->m_dBottom) / 2.0 + m_dHeight/(m_dR * 2);
  763 + double bottom = (m_pExtent->m_dTop + m_pExtent->m_dBottom) / 2.0 - m_dHeight/( m_dR * 2) ;
  764 + m_pExtent->m_dTop = top;
  765 + m_pExtent->m_dBottom = bottom;
  766 + }
  767 + else
  768 + {
  769 + double right= (m_pExtent->m_dRight + m_pExtent->m_dLeft) / 2.0 + m_dWidth/(2 * m_dR);
  770 + double left = (m_pExtent->m_dRight + m_pExtent->m_dLeft) / 2.0 - m_dWidth/(2 * m_dR) ;
  771 + m_pExtent->m_dRight = right;
  772 + m_pExtent->m_dLeft = left;
  773 + }
  774 +
  775 + bool isWGS84 = m_pExtent->m_dLeft <= 180 && m_pExtent->m_dRight < 180 &&
  776 + m_pExtent->m_dLeft >= -180 && m_pExtent->m_dRight >= -180 &&
  777 + m_pExtent->m_dTop < 90 && m_pExtent->m_dBottom < 90;
  778 +
  779 + if (isWGS84)
  780 + {
  781 + m_dScaleDenominator = (this->resolution / oneInchInLayoutUnits) * (1 / r) * 111000;
  782 + //m_dR = r *(96 / 0.0254) *111000 ;//111000 为赤道1经度等于 111000米
  783 + }
  784 + else
  785 + {
  786 + m_dScaleDenominator = (this->resolution / oneInchInLayoutUnits) * 1 / r;
  787 + }
  788 +
  789 + return true;
  790 + }
  791 +
  792 + //所有的绘图都是调用这里
  793 + /*
  794 +1. 在 dc 上绘图时,传入 类变量 m_pClsSurfImage
  795 +2. 切图时,给定额外的surface
  796 +3. DrawShape是, 传入 类变量 m_pClsSurfBuffer
  797 +4. 好像不会传 NULL
  798 +*/
  799 + bool DmpWmsRenderer::DrawSimpleData(DataCollection *data, Renderer *renderer, clsCrSurf *pClsCS)
  800 + {
  801 + /*
  802 + 一次绘图只创建一次 cairo
  803 + */
  804 + int iPartCount = data->m_iPartCount;
  805 + if (iPartCount > 0 && data->m_pData)
  806 + {
  807 + renderer->DrawData(pClsCS, data, true);
  808 + return true;
  809 + }
  810 + if (iPartCount == 0)
  811 + return false;
  812 + else
  813 + {
  814 + return false;
  815 + }
  816 + return true;
  817 + }
  818 +/*
  819 + bool DmpWmsRenderer::DrawData(DataCollection *data, Renderer *renderer, clsCrSurf *pClsCS)
  820 + {
  821 +
  822 + int iPartCount = data->m_iPartCount;
  823 + if (iPartCount > 0 && data->m_pData)
  824 + {
  825 + renderer->DrawData(pClsCS, data, false);
  826 + return true;
  827 + }
  828 + if (iPartCount == 0)
  829 + return false;
  830 + else
  831 + {
  832 + return false;
  833 + }
  834 +
  835 + return true;
  836 + }
  837 +*/
  838 + bool DmpWmsRenderer::ResetDrawShapeBuffer()
  839 + {
  840 + int iW = (int)m_dWidth;
  841 + int iH = (int)m_dHeight;
  842 + unsigned char *buffer = cairo_image_surface_get_data(m_pClsSurfBuff->m_pSurf);
  843 + memset(buffer, 0, iW * iH * 4);
  844 + return true;
  845 + }
  846 + bool DmpWmsRenderer::ResetMaxBuffer()
  847 + {
  848 + int iW = m_pClsMaxSurfBuffer->m_iW;
  849 + int iH = m_pClsMaxSurfBuffer->m_iH;
  850 + unsigned char *buffer = cairo_image_surface_get_data(m_pClsMaxSurfBuffer->m_pSurf);
  851 + memset(buffer, 0, iW * iH * 4);
  852 + return true;
  853 + }
  854 +
  855 +
  856 + bool DmpWmsRenderer::BufferCopy(clsCrSurf *pClsCSFrom, clsCrSurf *pClsCSTo)
  857 + {
  858 + if (pClsCSFrom == NULL)
  859 + pClsCSFrom = m_pClsSurfBuff;
  860 + if (pClsCSTo == NULL)
  861 + pClsCSTo = m_pClsSurfDC;
  862 +
  863 + cairo_t *cr = pClsCSTo->m_pCr;
  864 + cairo_set_source_surface(cr, pClsCSFrom->m_pSurf, 0, 0);
  865 + cairo_paint(cr);
  866 + return true;
  867 + }
  868 +
  869 + //不需要传参,map 只有一份surface
  870 + bool DmpWmsRenderer::DoSetBackGround(clsCrSurf *pClsCS, int iColor)
  871 + {
  872 + cairo_surface_t *surface = pClsCS->m_pSurf;
  873 + cairo_t *cr = pClsCS->m_pCr;
  874 + int surf_w = cairo_image_surface_get_width(surface);
  875 + int surf_h = cairo_image_surface_get_height(surface);
  876 + //画一个矩形背景
  877 + cairo_rectangle(cr, 0, 0, surf_w, surf_h);
  878 + double r, g, b, a;
  879 + clsUtil::ToCairoColor(iColor, r, g, b, a);
  880 + cairo_set_source_rgba(cr, r, g, b, 0);
  881 + cairo_fill(cr);
  882 + return true;
  883 + }
  884 +
  885 +
  886 + //在DC上绘制时是否使用一个临时的 image_surface, 然后拷上去,这样具体的细节处理就没有区别了
  887 + bool DmpWmsRenderer::GetMap(map<string, string> *map_layerDefs,map<string, string> * map_regionDefs, clsCrSurf *pClsCS, bool isThumbnail,
  888 + shared_ptr<Rect> pRect, double r__, double x_dis__, double y_dis__)
  889 + {
  890 + /*确定参数*/
  891 + clsCrSurf *pClsSurfThis;
  892 + if (pClsCS == NULL)
  893 + {
  894 + pClsSurfThis = m_pClsSurfBuff; //refresh画图在 buff 中
  895 + this->DoSetBackGround(pClsSurfThis, m_iBackColor);
  896 + }
  897 + else
  898 + {
  899 + pClsSurfThis = pClsCS;
  900 + this->DoSetBackGround(pClsSurfThis, 0xffffffff);
  901 + }
  902 +
  903 + shared_ptr<Rect> pExtent;
  904 + if (pRect == NULL)
  905 + pExtent = m_pExtent;
  906 + else
  907 + pExtent = pRect;
  908 + double r, x_dis, y_dis;
  909 + if (r__ == -1)
  910 + {
  911 + r = m_dR;
  912 + x_dis = m_dXdis;
  913 + y_dis = m_dYdis;
  914 + }
  915 + else
  916 + {
  917 + r = r__;
  918 + x_dis = x_dis__;
  919 + y_dis = y_dis__;
  920 + }
  921 +
  922 + /*
  923 + * 重置文字避让
  924 + */
  925 + //文字避让是否写成局部??
  926 + pClsSurfThis->InitFlag(); //已初始化文字避让数组,在 pClsSurfThis中
  927 + //char* pFlag = pClsSurfThis->m_pFlag;
  928 + this->ResetMaxBuffer();
  929 +
  930 + bool has_regionDefs = false;
  931 + string strRegionColDefs = "";
  932 + string strRegionLayerNameDefs = "";
  933 +
  934 + if(map_regionDefs)
  935 + {
  936 + map<string, string>::iterator iter_regionDef = map_regionDefs->begin();
  937 + if (iter_regionDef != map_regionDefs->end())
  938 + {
  939 + strRegionColDefs = iter_regionDef->second.c_str();
  940 + strRegionLayerNameDefs = iter_regionDef->first.c_str();
  941 + has_regionDefs = true;
  942 + }
  943 + }
  944 +
  945 +
  946 + map<DmpVectorLayer*, shared_ptr<DataCollection>> map_DataCollection;
  947 +
  948 + for (int i = 0; i < (int)(m_vLayers.size()); i++)
  949 + {
  950 + DmpVectorLayer* layer = m_vLayers[i];
  951 +
  952 +
  953 + double r1 = layer->maxScale(); // *
  954 + double r2 = layer->minScale(); // *
  955 + bool has_layerDef = false;
  956 + const char *strLayerDef = nullptr;
  957 +
  958 + //if ((this->m_dScaleDenominator > r1 || this->m_dScaleDenominator < r2 || layer->GetRenderer30() == nullptr) && isThumbnail == false)
  959 + // continue;
  960 +
  961 + if (map_layerDefs)
  962 + {
  963 + map<string, string>::iterator iter_layerDef = map_layerDefs->find(layer->name());
  964 + if (iter_layerDef != map_layerDefs->end())
  965 + {
  966 + has_layerDef = true;
  967 + strLayerDef = iter_layerDef->second.c_str();
  968 + }
  969 + }
  970 +
  971 + //bool isbuffQuery = false;
  972 + // double width_scale = abs((layer->m_pDataset->maxx - layer->m_pDataset->minx) / (pExtent->m_dRight - pExtent->m_dLeft));
  973 + {
  974 + //std::printf("db \r\n ");
  975 + double start = clock();
  976 + double cost, cost2;
  977 +
  978 + string sql ="";
  979 + shared_ptr<DmpVectorThinLayer> pVectorThinLayer = nullptr;
  980 +
  981 + bool renderHeat = false;
  982 + shared_ptr<DataCollection> data(new DataCollection());
  983 +
  984 + if(!has_regionDefs)
  985 + {
  986 + sql = GetDrawSQL(layer, pExtent.get(), strLayerDef);
  987 + }
  988 + else
  989 + {
  990 + sql = GetRegionQuerySQL(layer, pExtent.get(), format("%d",layer->crs().srid()), strRegionLayerNameDefs,strRegionColDefs, strLayerDef);
  991 + }
  992 +
  993 + pVectorThinLayer = layer->GetCurrentScaleTable(1 / this->m_dR);
  994 +
  995 + // printf( "%s\r\n", sql.c_str());
  996 + // this->GetDrawSQL(layer, pExtent.get(), strLayerDef); //sql语句中使用 ::box
  997 + if (sql == "")
  998 + continue;
  999 +
  1000 + string tableName = layer->name();
  1001 +
  1002 +
  1003 + if (pVectorThinLayer != nullptr)
  1004 + {
  1005 + tableName = pVectorThinLayer->tableName();
  1006 + }
  1007 +
  1008 + if(tableName.length() > 32)
  1009 + {
  1010 + tableName = tableName.substr(32);
  1011 + }
  1012 +
  1013 +
  1014 + const char *ss__ = "";
  1015 + const char **pmsg = &ss__;
  1016 + try
  1017 + {
  1018 +
  1019 + shared_ptr<DmpPgsql> pPgsqlConn = nullptr;
  1020 + if(pVectorThinLayer == nullptr)
  1021 + {
  1022 + pPgsqlConn = DmpPgsqlSourcePools::get_instance()->GetPgsqlConn(layer->source());
  1023 + }
  1024 + else
  1025 + {
  1026 + pPgsqlConn = DmpPgsqlSourcePools::get_instance()->GetDefaultPgsqlConn();
  1027 + }
  1028 +
  1029 + if (pPgsqlConn == nullptr)
  1030 + break;
  1031 + if (pPgsqlConn->ExecWaitBinary(sql))
  1032 + {
  1033 + PGresult *res = pPgsqlConn->GetPGresult();
  1034 + if (PQntuples(res) == 0)
  1035 + continue;
  1036 +
  1037 + int shapeType = layer->GeometryType();
  1038 + shared_ptr<DataCollection> data(new DataCollection());
  1039 + data->InitDataCollection(res, shapeType, this->m_dWidth, this->m_dHeight, 0, m_dR, m_dScaleDenominator, x_dis, y_dis);
  1040 +
  1041 + //data->InitDataCollection(res, shapeType, this->m_dWidth, this->m_dHeight, (int)layer->subset, m_dR, m_dScaleDenominator, x_dis, y_dis);
  1042 + map_DataCollection[layer] = data;
  1043 + //data_ptr = data;
  1044 + auto endTime_data = chrono::steady_clock::now();
  1045 +
  1046 + allDataCount += PQntuples(res);
  1047 + this->DrawSimpleData(data.get(), layer->GetRenderer30().get(), pClsSurfThis);
  1048 + // DrawText(StringHelp::fmt("data %.0fm",(endTime_data - startTime).count()/1000000.0)
  1049 + // ,pClsSurfThis,10,50);
  1050 +
  1051 + /*
  1052 + DrawText(tableName ,pClsSurfThis,10,100);
  1053 +
  1054 + char ptext[100] = {0};
  1055 + sprintf(ptext, "count = %d",allDataCount);
  1056 + DrawText2(ptext ,pClsSurfThis,10,140);
  1057 +
  1058 + */
  1059 + }
  1060 + else if(pVectorThinLayer != nullptr)
  1061 + {
  1062 + shared_ptr<DmpPgsql> pPgsqlConn1 = DmpPgsqlSourcePools::get_instance()->GetPgsqlConn(layer->source());
  1063 +
  1064 + if (pPgsqlConn1 == nullptr)
  1065 + break;
  1066 + if (pPgsqlConn1->ExecWaitBinary(sql))
  1067 + {
  1068 + PGresult *res = pPgsqlConn1->GetPGresult();
  1069 + if (PQntuples(res) == 0)
  1070 + continue;
  1071 +
  1072 + int shapeType = layer->GeometryType();
  1073 + shared_ptr<DataCollection> data(new DataCollection());
  1074 + if(!renderHeat)
  1075 + {
  1076 + data->InitDataCollection(res, shapeType, this->m_dWidth, this->m_dHeight, 0, m_dR, m_dScaleDenominator, x_dis, y_dis);
  1077 + }
  1078 + else
  1079 + {
  1080 + data->InitHeatCollection(res, shapeType, this->m_dWidth, this->m_dHeight,
  1081 + pExtent->m_dLeft, pExtent->m_dRight, pExtent->m_dBottom, pExtent->m_dTop, 0, m_dR, m_dScaleDenominator, x_dis, y_dis);
  1082 + }
  1083 +
  1084 + map_DataCollection[layer] = data;
  1085 +
  1086 + //auto endTime_data = chrono::steady_clock::now();
  1087 + //data_ptr = data;
  1088 +
  1089 + allDataCount += PQntuples(res);
  1090 + this->DrawSimpleData(data.get(), layer->GetRenderer30().get(), pClsSurfThis);
  1091 +
  1092 + }
  1093 + else
  1094 + {
  1095 + //DrawText2("获取数据失败,找不到图层" ,pClsSurfThis,10,10);
  1096 + }
  1097 + }
  1098 +
  1099 + }
  1100 + catch (const std::exception &e)
  1101 + {
  1102 + std::cerr << "#DrawSimpleData " << e.what() << '\n';
  1103 + }
  1104 + }
  1105 + }
  1106 +
  1107 +
  1108 + map_DataCollection.clear();
  1109 +
  1110 + //return true;
  1111 + if (pClsCS == NULL) //这个时候证明是在 buffer 上绘图,直接拷到 dc上
  1112 + {
  1113 + this->BufferCopy(m_pClsSurfBuff, m_pClsMaxSurfBuffer);
  1114 + this->BufferCopy(m_pClsSurfBuff, m_pClsSurfDC);
  1115 + }
  1116 + return true;
  1117 + }
  1118 +
  1119 +
  1120 + bool DmpWmsRenderer::ToStream(std::string& responseData)
  1121 + {
  1122 + responseData.reserve(10240);
  1123 + if(this->pRasterBufferObj == nullptr)
  1124 + {
  1125 + cairo_surface_write_to_png_stream(m_pClsSurfDC->m_pSurf, cairo_write_func, &responseData);
  1126 + return true;
  1127 + }
  1128 + else
  1129 + {
  1130 + return ToPngStream(this->pRasterBufferObj, responseData);
  1131 + }
  1132 + }
  1133 +
  1134 +
  1135 +bool DmpWmsRenderer::ToPngStream(rasterBufferObj *rb,std::string& responseData)
  1136 +{
  1137 + png_infop info_ptr;
  1138 + int color_type;
  1139 + int row;
  1140 + unsigned int *rowdata;
  1141 + int compression = 9;
  1142 + png_structp png_ptr = png_create_write_struct(
  1143 + PNG_LIBPNG_VER_STRING, NULL,NULL,NULL);
  1144 +
  1145 + if (!png_ptr)
  1146 + return (false);
  1147 +
  1148 + png_set_compression_level(png_ptr, compression);
  1149 + png_set_filter (png_ptr,0, PNG_FILTER_NONE);
  1150 +
  1151 + info_ptr = png_create_info_struct(png_ptr);
  1152 + if (!info_ptr) {
  1153 + png_destroy_write_struct(&png_ptr,
  1154 + (png_infopp)NULL);
  1155 + return (false);
  1156 + }
  1157 +
  1158 + if (setjmp(png_jmpbuf(png_ptr))) {
  1159 + png_destroy_write_struct(&png_ptr, &info_ptr);
  1160 + return (false);
  1161 + }
  1162 + //if(info->fp)
  1163 + // png_set_write_fn(png_ptr,info, png_write_data_to_stream, png_flush_data);
  1164 + //else
  1165 + png_set_write_fn(png_ptr,&responseData, png_write_data_to_buffer, png_flush_data);
  1166 +
  1167 + if(rb->data.rgba.a)
  1168 + color_type = PNG_COLOR_TYPE_RGB_ALPHA;
  1169 + else
  1170 + color_type = PNG_COLOR_TYPE_RGB;
  1171 +
  1172 + png_set_IHDR(png_ptr, info_ptr, rb->width, rb->height,
  1173 + 8, color_type, PNG_INTERLACE_NONE,
  1174 + PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT);
  1175 +
  1176 + png_write_info(png_ptr, info_ptr);
  1177 +
  1178 + if(!rb->data.rgba.a && rb->data.rgba.pixel_step==4)
  1179 + png_set_filler(png_ptr, 0, PNG_FILLER_AFTER);
  1180 +
  1181 + rowdata = (unsigned int*)malloc(rb->width*sizeof(unsigned int));
  1182 + for(row=0; row<rb->height; row++) {
  1183 + unsigned int *pixptr = rowdata;
  1184 + int col;
  1185 + unsigned char *a,*r,*g,*b;
  1186 + r=rb->data.rgba.r+row*rb->data.rgba.row_step;
  1187 + g=rb->data.rgba.g+row*rb->data.rgba.row_step;
  1188 + b=rb->data.rgba.b+row*rb->data.rgba.row_step;
  1189 + if(rb->data.rgba.a) {
  1190 + a=rb->data.rgba.a+row*rb->data.rgba.row_step;
  1191 + for(col=0; col<rb->width; col++) {
  1192 + if(*a) {
  1193 + double da = *a/255.0;
  1194 + unsigned char *pix = (unsigned char*)pixptr;
  1195 + pix[0] = *r/da;
  1196 + pix[1] = *g/da;
  1197 + pix[2] = *b/da;
  1198 + pix[3] = *a;
  1199 + } else {
  1200 + *pixptr=0;
  1201 + }
  1202 + pixptr++;
  1203 + a+=rb->data.rgba.pixel_step;
  1204 + r+=rb->data.rgba.pixel_step;
  1205 + g+=rb->data.rgba.pixel_step;
  1206 + b+=rb->data.rgba.pixel_step;
  1207 + }
  1208 + } else {
  1209 + for(col=0; col<rb->width; col++) {
  1210 + unsigned char *pix = (unsigned char*)pixptr;
  1211 + pix[0] = *r;
  1212 + pix[1] = *g;
  1213 + pix[2] = *b;
  1214 + pixptr++;
  1215 + r+=rb->data.rgba.pixel_step;
  1216 + g+=rb->data.rgba.pixel_step;
  1217 + b+=rb->data.rgba.pixel_step;
  1218 + }
  1219 + }
  1220 +
  1221 + png_write_row(png_ptr,(png_bytep)rowdata);
  1222 +
  1223 + }
  1224 + png_write_end(png_ptr, info_ptr);
  1225 + free(rowdata);
  1226 + png_destroy_write_struct(&png_ptr, &info_ptr);
  1227 + return MS_SUCCESS;
  1228 +}
  1229 +
  1230 +
  1231 +}
... ...
  1 +/**************************************************************************
  2 +* file: dmpwmsrenderer.h
  3 +
  4 +* Author: qingxiongf
  5 +* Date: 2021-12-12 21:55:51
  6 +* Email: qingxiongf@chinadci.com
  7 +* copyright: 广州城市信息研究所有限公司
  8 +***************************************************************************/
  9 +
  10 +#ifndef __dmpwmsrenderer_h__
  11 +#define __dmpwmsrenderer_h__
  12 +#include <iostream>
  13 +#include <string>
  14 +#include <map>
  15 +#include <boost/dll/alias.hpp> // for BOOST_DLL_ALIAS
  16 +#include <boost/filesystem.hpp>
  17 +#include <boost/function.hpp>
  18 +#include <boost/make_shared.hpp>
  19 +#include "legendParamater.h"
  20 +#include "clsCrSurf.h"
  21 +#include "clsRect.h"
  22 +#include "clsUtil.h"
  23 +#include "DataCollection.h"
  24 +#include "dmpvectorlayer.h"
  25 +#include "dmpvectorthinlayer.h"
  26 +#include "dmprasterbuffer.h"
  27 +#include "dmpproject.h"
  28 +#include "dmppgsqlsourcepools.h"
  29 +
  30 +using namespace std;
  31 +using namespace DmapCore_30;
  32 +using namespace mapserver;
  33 +namespace DmpWms
  34 +{
  35 +
  36 +
  37 + class DmpWmsRenderer
  38 + {
  39 + public:
  40 + DmpWmsRenderer(double height, double width);
  41 + ~DmpWmsRenderer();
  42 +
  43 + int initializeRasterBufferCairo(rasterBufferObj *rb, int width, int height);
  44 +
  45 + bool GetMapLog(std::stringstream& outputStream, map<string,string>* map_layerDefs = NULL,map<string,string>* map_regionDefs = NULL, shared_ptr<Rect> pRect = nullptr, double r__ = -1, double x_dis__ = 0, double y_dis__ = 0);
  46 + bool GetMap(map<string,string>* map_layerDefs = NULL,map<string,string>* map_regionDefs = NULL, clsCrSurf* pClsSurf = NULL,bool isThumbnail = false, shared_ptr<Rect> pRect = nullptr, double r__ = -1, double x_dis__ = 0, double y_dis__ = 0);
  47 + bool GetFeatureInfo(std::stringstream& ab, int gmlVersion, int x, int y, int feature_count);
  48 +
  49 + bool GetMapLegend( std::stringstream& ab, shared_ptr<legendParamater> pLegendParamater);
  50 + bool GetMapLegend( shared_ptr<legendParamater> pLegendParamater, clsCrSurf* pClsSurf);
  51 +
  52 + string GetDrawSQLAll_Catch(DmpVectorLayer* layer,shared_ptr<DmpVectorThinLayer> pMapLayerThinning);
  53 + string GetDrawSQL(DmpVectorLayer* layer, Rect* pRect,const char* layerdef = nullptr);
  54 + string GetDrawSQLAll(DmpVectorLayer* layer);
  55 + string GetDrawSQLAllOrderby(DmpVectorLayer* layer);
  56 + string GetRegionQuerySQL(DmpVectorLayer* layer,Rect *pRect,string srid,const char *regionDef,const char *layerdef);
  57 + string GetRegionQuerySQL(DmpVectorLayer* layer,Rect *pRect,string srid, const string &regionLayerName,const string &regionDef,const char *layerdef);
  58 + string GetCountSQL(DmpVectorLayer* layer);
  59 + string GetFeatureInfoSQL(DmpVectorLayer* layer,double x, double y, double dis, int feature_count);
  60 + std::string format(const char*, ...);
  61 +
  62 + void TryAddField1(vector<string>&pvField, string str);
  63 + bool AddMapLayer(int index, DmpVectorLayer* layer); //插入型加入
  64 + bool AddWmsMapLayers(const DmpProject*); //插入型加入
  65 + bool AddWmsMapLayers(const DmpProject*, char *); //插入型加入
  66 + bool EnableToServer();
  67 + bool ResetMaxBuffer();
  68 + bool ResetDrawShapeBuffer();
  69 +
  70 + int SaveWmsMapLayers(); //插入型加入
  71 + bool DrawSimpleData(DataCollection* data, Renderer* renderer, clsCrSurf* pClsSurf);
  72 +
  73 + //shared_ptr<Rect> GetFullExtent(bool bRecalculate); //加一个bool值,如果为false , 无需计算
  74 + //shared_ptr<Rect> GetExtent();
  75 + bool SetExtent(shared_ptr<Rect> rect);
  76 + bool GetParameters(double* pR, double* pXdis, double* pYdis);
  77 + bool SetParameters(double r = -1, double xdis = 0, double ydis = 0);
  78 + bool ToRealCoord(double x, double y, double* realX, double* realY);
  79 + bool BufferCopy(clsCrSurf* clsSufFrom = NULL, clsCrSurf* clsSurfTo = NULL);
  80 +
  81 +
  82 + bool ToStream(string &responseData);
  83 + bool ToPngStream(rasterBufferObj *rb,string &responseData); //streamInfo *info
  84 +
  85 + //int GetLayerCount();
  86 + //bool RemoveMapLayer(int index);
  87 + //shared_ptr<DmpVectorLayer> GetMapLayer(int index);
  88 + bool SetMapLayer(int index, shared_ptr<DmpVectorLayer> layer);
  89 + bool ClearLayers();
  90 +
  91 + bool SetBackGround(int color);
  92 + int GetBackGround();
  93 + bool SortByID(); //使用 layer 中的ID 号, 将 map 中的所有layer 重新排序
  94 +
  95 + clsCrSurf* GetSurfDC();
  96 + /*
  97 + 合成一个函数, map为 NULL 时, 读取,map 不为NULL , 写入
  98 + 真的有必要?
  99 + */
  100 +
  101 +
  102 +
  103 + clsCrSurf* m_pClsSurfDC; // 此surface使用 DC 构造
  104 + //clsSurface* m_pClsSurfImage; //这个按 DC大小构造的 image_surface, 绘图都在这上面完成
  105 + clsCrSurf* m_pClsSurfBuff; //这个也是 image_surface,大小也与dc一致
  106 +
  107 + int resolution = 96;
  108 + double oneInchInLayoutUnits = 0.0254;
  109 +
  110 + double m_dR;
  111 + double m_dScaleDenominator;
  112 + double m_dXdis;
  113 + double m_dYdis;
  114 + double m_dHeight; //HDC 高;
  115 + double m_dWidth; //HDC 宽
  116 + shared_ptr<Rect> m_pExtent; //绘图范围
  117 +
  118 + vector<string> m_vWKS_name;
  119 + vector<string> m_vWKS_conn;
  120 +
  121 + int allDataCount =0;
  122 +
  123 + rasterBufferObj* pRasterBufferObj = nullptr;;
  124 + clsCrSurf* m_pClsMaxSurfBuffer;
  125 +
  126 + private:
  127 + int m_iN;
  128 + public:
  129 + vector<DmpVectorLayer* > m_vLayers;
  130 + vector<DmpProject*> m_WMSServers;
  131 +
  132 + private:
  133 + int m_iBackColor;
  134 + shared_ptr<Rect> m_pFullExtent;
  135 + bool DoSetBackGround(clsCrSurf* pClsSurf, int iColor); //设置背景色
  136 + bool RecalculateScale();
  137 + private:
  138 +
  139 + //string CutMap(Rect* rect, double rule, const char* path, FILE* f);
  140 + //bool GetCutMapData(Rect* rect, double r, double x_dis, double y_dis);
  141 + //string CutMapOnce(clsCrSurf* pClsSurf, double x0, double y0, double r, double x_dis, double y_dis, const char* path, FILE*f);
  142 + bool CreateCutMapXML(double x, double y, double width, double height, vector<double>* pvDouble, const char* path);
  143 + bool CollectRules(const char* sRules);
  144 + bool CollectRules2(const char* sRules);
  145 +
  146 + //void FormatWFSJsonCAll(shared_ptr<Workspace> pWorkspace, AppendBuffer *ab, char *layerNAMEc,int gmlVersion,char *srsOut);
  147 + //void FormatWFSXMLCAll(shared_ptr<Workspace> pWorkspace, AppendBuffer *ab, char *layerNAMEc, int gmlVersion,char *srsOut);
  148 + };
  149 +}
  150 +
  151 +#endif // __dmpwmsrenderer_h__
... ...
  1 +
  2 +URL 路径:
  3 +http://localhost:8088/DMap/Services/广州地址/MapServer/WMSService?Service=WMS
  4 +
  5 +/DMap/Services/?([\\w./]*)/MapServer/([\\w]+)
  6 +
... ...
... ... @@ -35,38 +35,38 @@ namespace DmpTms
35 35
36 36 if(context.request()->isRestful())
37 37 {
38   - std::string path_=context.request()->path();
39   - std::vector<std::string> vec_;
40   - boost::split(vec_,context.request()->path(),boost::is_any_of("/"),boost::token_compress_on);
41   - int isize_=vec_.size();
42   - if(isize_<4)
  38 + std::string path=context.request()->path();
  39 + std::vector<std::string> vec;
  40 + boost::split(vec,context.request()->path(),boost::is_any_of("/"),boost::token_compress_on);
  41 + int isize=vec.size();
  42 + if(isize<4)
43 43 {
44 44 context.response()->write("Tms,Operation is null");
45 45 return;
46 46 }
47   - std::string::size_type idx0_,idx1_;
48   - idx0_=vec_[isize_-1].find("png");
49   - idx1_=vec_[isize_-1].find("jpg");
  47 + std::string::size_type idx0,idx1;
  48 + idx0=vec[isize-1].find("png");
  49 + idx1=vec[isize-1].find("jpg");
50 50
51   - if((idx0_!=std::string::npos)||(idx1_!=std::string::npos))
  51 + if((idx0!=std::string::npos)||(idx1!=std::string::npos))
52 52 {
53   - std::vector<std::string> vec0_;
54   - boost::split(vec0_,vec_[isize_-1],boost::is_any_of("."),boost::token_compress_on);
55   - int tileCol_=atoi(vec0_[0].c_str());
56   - int tileRow_=atoi(vec_[isize_-2].c_str());
57   - int tileMatrix_=atoi(vec_[isize_-3].c_str());
  53 + std::vector<std::string> vec0;
  54 + boost::split(vec0,vec[isize-1],boost::is_any_of("."),boost::token_compress_on);
  55 + int tileCol=atoi(vec0[0].c_str());
  56 + int tileRow=atoi(vec[isize-2].c_str());
  57 + int tileMatrix=atoi(vec[isize-3].c_str());
58 58 const DmpProject *project = context.project();
59   - DmpTileLayer *tileLayer = static_cast<DmpTileLayer *>(project->getLayer("layer"));
60   - std::string format_=vec0_[1].c_str();
61   - std::string filePath_=tileLayer->getDataSource();
62   - if(filePath_.empty())
  59 + DmpTileLayer *tileLayer = static_cast<DmpTileLayer *>(project->getLayer());
  60 + std::string format=vec0[1].c_str();
  61 + std::string filePath=tileLayer->getDataSource();
  62 + if(filePath.empty())
63 63 {
64 64 context.response()->write("Tms,Operation is null");
65 65 }
66 66 else
67 67 {
68   - DmpTmsTileProvider provider_=DmpTmsTileProvider(filePath_);
69   - provider_.WriteTile(tileRow_, tileCol_, tileMatrix_, format_, *context.response());
  68 + DmpTmsTileProvider provider_=DmpTmsTileProvider(filePath);
  69 + provider_.WriteTile(tileRow, tileCol, tileMatrix, format, *context.response());
70 70 }
71 71 }
72 72 else
... ...
... ... @@ -52,56 +52,56 @@ namespace DmpWmts
52 52 return;
53 53 }
54 54 }
55   - void DmpCapabiliTilesOperation::WriteCapabilities(boost::property_tree::ptree& pt_,const std::string& host_,const std::string& servicename,DmpServerResponse& response)
  55 + void DmpCapabiliTilesOperation::WriteCapabilities(boost::property_tree::ptree& pt,const std::string& host,const std::string& servicename,DmpServerResponse& response)
56 56 {
57 57 //构建能力文档
58   - boost::property_tree::ptree pt_root_,pt_TileMatrix_;
59   - CreateGetCapabilitiesDocument(host_,servicename,pt_root_);
60   - pt_root_.add("Capabilities.Contents.Layer.ows:Title",pt_.get<std::string>("Layer.ows:Title"));
61   - pt_root_.add("Capabilities.Contents.Layer.ows:Abstract",pt_.get<std::string>("Layer.ows:Abstract"));
62   - pt_root_.add("Capabilities.Contents.Layer.ows:Identifier",pt_.get<std::string>("Layer.ows:Identifier"));
  58 + boost::property_tree::ptree pt_root,pt_TileMatrix;
  59 + CreateGetCapabilitiesDocument(host,servicename,pt_root);
  60 + pt_root.add("Capabilities.Contents.Layer.ows:Title",pt.get<std::string>("Layer.ows:Title"));
  61 + pt_root.add("Capabilities.Contents.Layer.ows:Abstract",pt.get<std::string>("Layer.ows:Abstract"));
  62 + pt_root.add("Capabilities.Contents.Layer.ows:Identifier",pt.get<std::string>("Layer.ows:Identifier"));
63 63 //pt_root_.add("Capabilities.Contents.Layer.Style.<xmlattr>.isDefault",pt_.get<std::string>("Layer.Style.<xmlattr>.isDefault"));
64   - pt_root_.add("Capabilities.Contents.Layer.Style",pt_.get<std::string>("Layer.Style"));
65   - pt_root_.add("Capabilities.Contents.Layer.Format",pt_.get<std::string>("Layer.Format"));
66   - pt_root_.add("Capabilities.Contents.Layer.TileMatrixSetLink.TileMatrixSet",pt_.get<std::string>("Layer.TileMatrixSetLink.TileMatrixSet"));
  64 + pt_root.add("Capabilities.Contents.Layer.Style",pt.get<std::string>("Layer.Style"));
  65 + pt_root.add("Capabilities.Contents.Layer.Format",pt.get<std::string>("Layer.Format"));
  66 + pt_root.add("Capabilities.Contents.Layer.TileMatrixSetLink.TileMatrixSet",pt.get<std::string>("Layer.TileMatrixSetLink.TileMatrixSet"));
67 67
68   - boost::property_tree::ptree pt_TileMatrixSet_;
69   - pt_TileMatrixSet_.add("ows:Identifier",pt_.get<std::string>("TileMatrixSet.ows:Identifier"));
70   - pt_TileMatrixSet_.add("ows:SupportedCRS",pt_.get<std::string>("TileMatrixSet.ows:SupportedCRS"));
71   - pt_TileMatrixSet_.add("TileWidth",pt_.get<std::string>("TileMatrixSet.TileWidth"));
72   - pt_TileMatrixSet_.add("TileHeight",pt_.get<std::string>("TileMatrixSet.TileHeight"));
73   - pt_TileMatrixSet_.add("TopLeftCorner",pt_.get<std::string>("TileMatrixSet.TopLeftCorner"));
74   - pt_TileMatrixSet_.add("Dpi",pt_.get<std::string>("TileMatrixSet.DPI"));
  68 + boost::property_tree::ptree pt_TileMatrixSet;
  69 + pt_TileMatrixSet.add("ows:Identifier",pt.get<std::string>("TileMatrixSet.ows:Identifier"));
  70 + pt_TileMatrixSet.add("ows:SupportedCRS",pt.get<std::string>("TileMatrixSet.ows:SupportedCRS"));
  71 + pt_TileMatrixSet.add("TileWidth",pt.get<std::string>("TileMatrixSet.TileWidth"));
  72 + pt_TileMatrixSet.add("TileHeight",pt.get<std::string>("TileMatrixSet.TileHeight"));
  73 + pt_TileMatrixSet.add("TopLeftCorner",pt.get<std::string>("TileMatrixSet.TopLeftCorner"));
  74 + pt_TileMatrixSet.add("Dpi",pt.get<std::string>("TileMatrixSet.DPI"));
75 75
76 76 //pt_TileMatrix_=pt_.get_child("TileMatrixSet.TileMatrix");
77   - pt_TileMatrix_=pt_.get_child("TileMatrixSet.Levels");
78   - int i=pt_TileMatrix_.size();
79   - boost::property_tree::ptree::iterator pos_ = pt_TileMatrix_.begin();
80   - for (; pos_ != pt_TileMatrix_.end(); ++pos_ )
  77 + pt_TileMatrix=pt.get_child("TileMatrixSet.Levels");
  78 + int i=pt_TileMatrix.size();
  79 + boost::property_tree::ptree::iterator pos = pt_TileMatrix.begin();
  80 + for (; pos != pt_TileMatrix.end(); ++pos )
81 81 {
82   - boost::property_tree::ptree pt_level_;
83   - boost::property_tree::ptree ptTile_ = pos_->second;
84   - std::string level_=ptTile_.get<std::string>("level");
85   - std::string scale_=ptTile_.get<std::string>("scale");
86   - std::string resolution_=ptTile_.get<std::string>("resolution");
87   - pt_level_.add("ows:Identifier",level_);
88   - pt_level_.add("ows:ScaleDenominator",scale_);
89   - pt_level_.add("ows:Resolution",resolution_);
  82 + boost::property_tree::ptree pt_level;
  83 + boost::property_tree::ptree ptTile = pos->second;
  84 + std::string level=ptTile.get<std::string>("level");
  85 + std::string scale=ptTile.get<std::string>("scale");
  86 + std::string resolution=ptTile.get<std::string>("resolution");
  87 + pt_level.add("ows:Identifier",level);
  88 + pt_level.add("ows:ScaleDenominator",scale);
  89 + pt_level.add("ows:Resolution",resolution);
90 90
91   - pt_TileMatrixSet_.add_child("TileMatrix",pt_level_);
  91 + pt_TileMatrixSet.add_child("TileMatrix",pt_level);
92 92 }
93   - pt_root_.add_child("Capabilities.Contents.TileMatrixSet",pt_TileMatrixSet_);
  93 + pt_root.add_child("Capabilities.Contents.TileMatrixSet",pt_TileMatrixSet);
94 94 //pt_root_.add("Capabilities.Contents.TileMatrixSet.TileMatrix.ows:Identifier",pt_.get<std::string>("TileMatrixSet.TileMatrix.ows:Identifier"));
95 95 //pt_root_.add("Capabilities.Contents.TileMatrixSet.TileMatrix.TopLeftCorner",pt_.get<std::string>("TileMatrixSet.TileMatrix.TopLeftCorner"));
96   - std::string http_cap0_="http://"+host_+"/DMap/Services/"+servicename+"/TileServer/WMTSService/1.0.0/WMTSCapabilities.xml";
97   - pt_root_.add("Capabilities.ServiceMetadataURL.<xmlattr>.xlink:href",http_cap0_);
  96 + std::string http_cap0="http://"+host+"/DMap/Services/"+servicename+"/TileServer/WMTSService/1.0.0/WMTSCapabilities.xml";
  97 + pt_root.add("Capabilities.ServiceMetadataURL.<xmlattr>.xlink:href",http_cap0);
98 98
99 99 //写入流
100 100 std::stringstream ss;
101   - boost::property_tree::write_xml(ss,pt_root_);
102   - std::string strExtent_=ss.str();
  101 + boost::property_tree::write_xml(ss,pt_root);
  102 + std::string strExtent=ss.str();
103 103 response.setHeader("Content-Type", "application/xml;charset=utf-8");
104   - response.write(strExtent_);
  104 + response.write(strExtent);
105 105 return;
106 106 /*
107 107 //文件流代换写入
... ... @@ -138,7 +138,7 @@ namespace DmpWmts
138 138 void DmpCapabiliTilesOperation::GetCapabilitiesDocument(DmpServerResponse& response)
139 139 {
140 140 }
141   - void DmpCapabiliTilesOperation::CreateGetCapabilitiesDocument(const std::string& host_,const std::string& servicename,boost::property_tree::ptree& pt)
  141 + void DmpCapabiliTilesOperation::CreateGetCapabilitiesDocument(const std::string& host,const std::string& servicename,boost::property_tree::ptree& pt)
142 142 {
143 143 pt.add("Capabilities.<xmlattr>.xmlns",WMTS_NAMESPACE);
144 144 pt.add("Capabilities.<xmlattr>.xmlns:gml",GML_NAMESPACE);
... ... @@ -153,7 +153,7 @@ namespace DmpWmts
153 153 pt.add_child("Capabilities.ows:ServiceIdentification",pt_Identification);
154 154 GetServiceProviderElement(pt_Provider);
155 155 pt.add_child("Capabilities.ows:ServiceProvider",pt_Provider);
156   - GetServiceMetadataElement(host_,servicename,pt_Metadata);
  156 + GetServiceMetadataElement(host,servicename,pt_Metadata);
157 157 pt.add_child("Capabilities.ows:OperationsMetadata",pt_Metadata);
158 158 //pt.add("Capabilities.Contents.Layer",servicename);
159 159
... ... @@ -178,38 +178,38 @@ namespace DmpWmts
178 178 pt.add("ows:ServiceContact.ows:ContactInfo.ows:Phone","020-87578877");
179 179 }
180 180
181   - void DmpCapabiliTilesOperation:: GetServiceMetadataElement(const std::string& host_,const std::string& servicename,boost::property_tree::ptree& pt)
  181 + void DmpCapabiliTilesOperation:: GetServiceMetadataElement(const std::string& host,const std::string& servicename,boost::property_tree::ptree& pt)
182 182 {
183 183 //localhost:8080/DMap/Services/GDWMTS/MapServer/WMTSServer?request=GetCapabilities
184   - std::string http_cap0_="http://"+host_+"/DMap/Services/"+servicename+"/TileServer/WMTSService/1.0.0/WMTSCapabilities.xml";
185   - std::string http_cap1_="http://"+host_+"/DMap/Services/"+servicename+"/TileServer/WMTSService?";
186   - std::string http_cap2_="http://"+host_+"/DMap/Services/"+servicename+"/TileServer/WMTSService/1.0.0/";
187   - boost::property_tree::ptree pt_child0_,pt_child1_;
  184 + std::string http_cap0="http://"+host+"/DMap/Services/"+servicename+"/TileServer/WMTSService/1.0.0/WMTSCapabilities.xml";
  185 + std::string http_cap1="http://"+host+"/DMap/Services/"+servicename+"/TileServer/WMTSService?";
  186 + std::string http_cap2="http://"+host+"/DMap/Services/"+servicename+"/TileServer/WMTSService/1.0.0/";
  187 + boost::property_tree::ptree pt_child0,pt_child1;
188 188
189   - pt_child0_.add("<xmlattr>.name","GetCapabilities");
190   - boost::property_tree::ptree pt_child00_,pt_child01_;
191   - pt_child00_.add("ows:HTTP.ows:Get.<xmlattr>.xlink:href",http_cap0_);
192   - pt_child00_.add("ows:HTTP.ows:Get.ows:Constraint.<xmlattr>.name","GetEncoding");
193   - pt_child00_.add("ows:HTTP.ows:Get.ows:Constraint.ows:AllowedValues.ows:Value","RESTful");
194   - pt_child0_.add_child("ows:DCP",pt_child00_);
  189 + pt_child0.add("<xmlattr>.name","GetCapabilities");
  190 + boost::property_tree::ptree pt_child00,pt_child01;
  191 + pt_child00.add("ows:HTTP.ows:Get.<xmlattr>.xlink:href",http_cap0);
  192 + pt_child00.add("ows:HTTP.ows:Get.ows:Constraint.<xmlattr>.name","GetEncoding");
  193 + pt_child00.add("ows:HTTP.ows:Get.ows:Constraint.ows:AllowedValues.ows:Value","RESTful");
  194 + pt_child0.add_child("ows:DCP",pt_child00);
195 195
196   - pt_child01_.add("ows:HTTP.ows:Get.<xmlattr>.xlink:href",http_cap1_);
197   - pt_child01_.add("ows:HTTP.ows:Get.ows:Constraint.<xmlattr>.name","GetEncoding");
198   - pt_child01_.add("ows:HTTP.ows:Get.ows:Constraint.ows:AllowedValues.ows:Value","KVP");
199   - pt_child0_.add_child("ows:DCP",pt_child01_);
200   - pt.add_child("ows:Operation",pt_child0_);
  196 + pt_child01.add("ows:HTTP.ows:Get.<xmlattr>.xlink:href",http_cap1);
  197 + pt_child01.add("ows:HTTP.ows:Get.ows:Constraint.<xmlattr>.name","GetEncoding");
  198 + pt_child01.add("ows:HTTP.ows:Get.ows:Constraint.ows:AllowedValues.ows:Value","KVP");
  199 + pt_child0.add_child("ows:DCP",pt_child01);
  200 + pt.add_child("ows:Operation",pt_child0);
201 201
202   - pt_child1_.add("<xmlattr>.name","GetTile");
203   - boost::property_tree::ptree pt_child10_,pt_child11_;
204   - pt_child10_.add("ows:HTTP.ows:Get.<xmlattr>.xlink:href",http_cap2_);
205   - pt_child10_.add("ows:HTTP.ows:Get.ows:Constraint.<xmlattr>.name","GetEncoding");
206   - pt_child10_.add("ows:HTTP.ows:Get.ows:Constraint.ows:AllowedValues.ows:Value","RESTful");
207   - pt_child1_.add_child("ows:DCP",pt_child10_);
208   - pt_child11_.add("ows:HTTP.ows:Get.<xmlattr>.xlink:href",http_cap1_);
209   - pt_child11_.add("ows:HTTP.ows:Get.ows:Constraint.<xmlattr>.name","GetEncoding");
210   - pt_child11_.add("ows:HTTP.ows:Get.ows:Constraint.ows:AllowedValues.ows:Value","KVP");
211   - pt_child1_.add_child("ows:DCP",pt_child11_);
212   - pt.add_child("ows:Operation",pt_child1_);
  202 + pt_child1.add("<xmlattr>.name","GetTile");
  203 + boost::property_tree::ptree pt_child10,pt_child11;
  204 + pt_child10.add("ows:HTTP.ows:Get.<xmlattr>.xlink:href",http_cap2);
  205 + pt_child10.add("ows:HTTP.ows:Get.ows:Constraint.<xmlattr>.name","GetEncoding");
  206 + pt_child10.add("ows:HTTP.ows:Get.ows:Constraint.ows:AllowedValues.ows:Value","RESTful");
  207 + pt_child1.add_child("ows:DCP",pt_child10);
  208 + pt_child11.add("ows:HTTP.ows:Get.<xmlattr>.xlink:href",http_cap1);
  209 + pt_child11.add("ows:HTTP.ows:Get.ows:Constraint.<xmlattr>.name","GetEncoding");
  210 + pt_child11.add("ows:HTTP.ows:Get.ows:Constraint.ows:AllowedValues.ows:Value","KVP");
  211 + pt_child1.add_child("ows:DCP",pt_child11);
  212 + pt.add_child("ows:Operation",pt_child1);
213 213 }
214 214 void GetServiceTileMatrixSetElement(const std::string& servicename,boost::property_tree::ptree& pt)
215 215 {
... ...
... ... @@ -30,21 +30,22 @@ namespace DmpWmts
30 30 try
31 31 {
32 32 std::string tileVersion= dmpTileLayer->getVendor();
33   - std::string tilePath_=dmpTileLayer->getDataSource();
  33 + std::string tilePath=dmpTileLayer->getDataSource();
34 34 //std::string tilePath_ = "/mnt/d/Code/tiles/gdmap/_alllayers";
35 35 //std::string tileVersion_ = "ESRI_V1";
36   - int iver=StringToVector(tileVersion);
  36 + int iver=StringToVector(tileVersion);
37 37 Vendor version = (Vendor)boost::lexical_cast<int>(iver);
38 38 switch(version)
39 39 {
40 40 case Vendor::ESRI_V0:
41   - provider = std::make_shared<DmpEsriTileProvider>(tilePath_);
  41 + provider = std::make_shared<DmpEsriTileProvider>(tilePath);
42 42 break;
43 43 case Vendor::ESRI_V1:
44   - provider = std::make_shared<DmpEsriBundleV1Provider>(tilePath_);
  44 + provider = std::make_shared<DmpEsriBundleV1Provider>(tilePath);
45 45 break;
46 46 case Vendor::ESRI_V2:
47   - provider = std::make_shared<DmpEsriBundleV2Provider>(tilePath_);
  47 + provider = std::make_shared<DmpEsriBundleV2Provider>(tilePath);
  48 +
48 49 break;
49 50 default:
50 51 provider = nullptr;
... ... @@ -60,24 +61,24 @@ namespace DmpWmts
60 61 }
61 62 int TileProviderFactory::StringToVector(std::string& strVector)
62 63 {
63   - int iVector_=-1;
  64 + int iVector=-1;
64 65 if(std::strcmp(strVector.c_str(),"ESRI_V0")==0)
65 66 {
66   - iVector_=0;
  67 + iVector=0;
67 68 }
68 69 else if(std::strcmp(strVector.c_str(),"ESRI_V1")==0)
69 70 {
70   - iVector_=1;
  71 + iVector=1;
71 72 }
72 73 else if(std::strcmp(strVector.c_str(),"ESRI_V2")==0)
73 74 {
74   - iVector_=2;
  75 + iVector=2;
75 76 }
76 77 else
77 78 {
78   - iVector_=3;
  79 + iVector=3;
79 80 }
80   - return iVector_;
  81 + return iVector;
81 82 }
82 83 // CapabiliTileProviderFactory::CapabiliTileProviderFactory()
83 84 // {
... ...
... ... @@ -82,8 +82,8 @@ namespace DmpWmts
82 82 }
83 83 else if (boost::iequals(req, "GetCapabilities"))
84 84 {
85   - const std::string host_=context.request()->domain()+":"+context.request()->port();;
86   - const std::string servicename_=context.request()->serviceName();
  85 + const std::string host=context.request()->domain()+":"+context.request()->port();;
  86 + const std::string servicename=context.request()->serviceName();
87 87
88 88 boost::property_tree::ptree pt;
89 89 pt.add("Layer.ows:Title",tileLayer->title());
... ... @@ -100,18 +100,18 @@ namespace DmpWmts
100 100 {
101 101 pt.add("Layer.TileMatrixSetLink.TileMatrixSet",(*iter)->id());
102 102
103   - boost::property_tree::ptree ptLevels_;
104   - std::vector<TileLevel*> tileLevels_=(*iter)->tileLevels();
105   - for(auto leviter=tileLevels_.cbegin();leviter!=tileLevels_.cend();leviter++)
  103 + boost::property_tree::ptree ptLevels;
  104 + std::vector<TileLevel*> tileLevels=(*iter)->tileLevels();
  105 + for(auto leviter=tileLevels.cbegin();leviter!=tileLevels.cend();leviter++)
106 106 {
107   - boost::property_tree::ptree pt_level_;
  107 + boost::property_tree::ptree pt_level;
108 108
109   - pt_level_.add("level",(*leviter)->id);
110   - pt_level_.add("scale",(*leviter)->scaleDenominator);
111   - pt_level_.add("resolution",(*leviter)->resolution);
112   - ptLevels_.add_child("TileMatrix",pt_level_);
  109 + pt_level.add("level",(*leviter)->id);
  110 + pt_level.add("scale",(*leviter)->scaleDenominator);
  111 + pt_level.add("resolution",(*leviter)->resolution);
  112 + ptLevels.add_child("TileMatrix",pt_level);
113 113 }
114   - pt.add_child("TileMatrixSet.Levels",ptLevels_);
  114 + pt.add_child("TileMatrixSet.Levels",ptLevels);
115 115 pt.add("TileMatrixSet.ows:Identifier",(*iter)->id());
116 116 pt.add("TileMatrixSet.ows:SupportedCRS",(*iter)->crs());
117 117 pt.add("TileMatrixSet.TileWidth",(*iter)->tileCols());
... ... @@ -122,7 +122,7 @@ namespace DmpWmts
122 122 //boost::property_tree::write_json("/mnt/d/json.txt",pt);
123 123
124 124 DmpCapabiliTilesOperation capOper;
125   - capOper.WriteCapabilities(pt,host_,servicename_,*context.response());
  125 + capOper.WriteCapabilities(pt,host,servicename,*context.response());
126 126
127 127 }
128 128 }
... ...
注册登录 后发表评论