SimpleLabelRenderer.h 11.2 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 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 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469
#pragma once
#ifndef _SimpleLabelRenderer_H_
#define _SimpleLabelRenderer_H_
#include<string>
#include<vector>
using namespace std;
#include"Renderer.h"
#include"TextSymbol.h"
#include"clsStruct.h"
#define LLPSZ 10     //dmapLineLabelPosition__Size

namespace DmapCore_30
{
	class CORE_EXPORT SimpleLabelRenderer :public Renderer
	{
	public:
		SimpleLabelRenderer();
		~SimpleLabelRenderer();
		int RendererType();
		virtual bool Parse(boost::property_tree::ptree &pt, AppendBuffer *f);
		virtual bool ParsePtree( boost::property_tree::ptree &pt);
		virtual void ToJson(AppendBuffer *ab);
		//virtual bool RendererString(Renderer** ppRen, const char** psXML);
		virtual bool DrawData(clsCrSurf* pClsCS, DataCollection* data, bool drawSimpleData, char* pFlag = NULL);
		virtual bool DrawData(clsCrSurf* pClsCS, DataCollection* data, int dataIndex, char* pFlag = NULL);
		virtual bool DrawLegend(clsCrSurf* pClsCS, shared_ptr<legendParamater> pLegendParamater,int layerType, char* pFlag= NULL);
		string m_sField;
		TextSymbol* m_pTextSymbol;


		string m_sLabelPriorities;
		string m_sRotationAngles;
		//int m_iRotateMethod;
		string m_sRotationAngleField;
		bool m_bIsVerticalToAngle;

		/*
		LineLabelPosition分成3属性
		*/
		int m_iLineLabelPositionDirection;
		int m_iLineLabelPositionStartOrEnd;
		string m_sLineLabelPositionPlaces;
		int m_LineLabelPositionPlaces[3];


		int m_iPolygonLabelPositionDirection;
		bool m_bLabelInPolygon;




		bool DoSetLineLabelPositionPlaces();

		void TryAddField(vector<string>&pvField);
		bool TryFindHeatRenderer(){ return false; }
		


		static SimpleLabelRenderer* CreateNew();
		const char*  GetField();
		bool    SetField(const char* sField);
		const char*  GetLabelPriorities();
		bool    SetLabelPriorities(const char* sLableLabelPriorities);
		TextSymbol* GetTextSymbol();
		bool    SetTextSymbol(TextSymbol* ts);
		const char* GetRotationAngles();
		bool    SetRotationAngles(const char* sRotationalAngles);
		const char*GetRotationAngleField();
		bool    SetRotationAngleField(const char* sAngleField);
		//int     GetRotateMethod();                //只对点有效
		//bool    SetRotateMethod(int iRotateMethod);
		int     GetLineLabelPositionDirection();
		bool    SetLineLabelPositionDirection(int iLineLabelPositionDirection);
		const char*GetLineLabelPositionPlace();
		bool    SetLineLabelPositionPlace(const char* iLineLabelPositionPlace);
		int     GetLineLabelPositionStartOrEnd();
		bool    SetLineLabelPositionStartOrEnd(int iLineLabelPositionStartOrEnd);
		int     GetPolygonLabelPositionDirection();
		bool    SetPolygonLabelPositionDirection(int iPolygonLabelPositionDirection);
		bool    GetLabelInPolygon();
		bool    SetLabelInPolygon(bool bLabelInPolygon);
		bool    GetIsVerticalToAngle();
		bool    SetIsVerticalToAngle(bool bIsVerticalToAngle);



	private:

		/*
		点样式类型使用规定
		1.优先使用 m_sLabelPriorities , m_sLabelPriorities 可以赋值3种,第一种,确定各标签位优先级的8个数字,第二种,使用 DMap_PlaceOnTopHorizontal, 在点之上
		第三种,使用8个0,则使用旋转角度书写文本
		2. 优先使用AngleField,但每次设置旋转角度时,将AngleField重置为""
		3. 使用旋转角度
		*/
		 enum PointLabelPositionType
		{
			dmapPointLabelPositionOnTopHorizontal = 0,
			dmapPointLabelPositionAngleNumber = 1,
			dmapPointLabelPositionAngleField = 2,
			dmapPointLabelPositionPeriphery = 3,
			dmapPointLabelPositionError,
		};
		PointLabelPositionType m_plpt;
		SimpleLabelRenderer::PointLabelPositionType DoSetPointLabelPositionType();   //每次调用此函数,维护位置的类型 m_lpt



	private:

		vector<double> m_vdAngles;
		int m_i8[8];    // 


		bool CalculatePrioritiesNumber();     //处理 字符串,按8个标签的优先级排序1-8
		bool CalculateAngles();               //处理 m_sRotationalAngles,存到 m_dAngles
		bool TrackPriorityString(const char* sPriority);           //判断 m_sPriorities 字符串是否是8个数字
		bool TrackRotationAngles(const char* sRotationalAngles);





		/*
		Draw部分
		*/
	public:
		bool DrawStruct(clsCrSurf* pClsCS, DataCollection* data, int index);

		/*
		Point
		*/
		bool DrawPoint(clsCrSurf* pClsCS, DataCollection* data, int index, char* sUTF8);

		/*
		MLine
		*/
		bool DrawMLine(clsCrSurf* pClsCS, clsStruct::MLINE* pStrMLine, char* sUTF8);
		bool DrawMLineLevel(clsCrSurf* pClsCS, clsStruct::MLINE* pStrMLine, char* sUTF8);    //水平放置
		bool DrawMLineParallel(clsCrSurf* pClsCS, clsStruct::MLINE* pStrMLine, char* sUTF8); //平行放置
		bool DrawMLineCurve(clsCrSurf* pClsCS, clsStruct::MLINE* pStrMLine, char* sUTF8);      //弯曲
		bool DrawMLineVertical(clsCrSurf* pClsCS, clsStruct::MLINE* pStrMLine, char* sUTF8); //垂直

		double CalculateRadianRight(clsStruct::LINE* pStrLine, double dTextWidth, int iIndex, double x, double y, double&x_show, double&y_show);
		double CalculateRadianLeft(clsStruct::LINE* pStrLine, double dTextWidth, int iIndex, double x, double y, double&x_show, double& y_show);

		bool DrawMLineCurve2(clsCrSurf* pClsCS, clsStruct::MLINE* pStrMLine, char* sUTF8);    //弯曲
		double CalculateRadianRight2(clsStruct::LINE* pStrLine, double dTextWidth, int& iIndex, double x_show, double y_show, double &x_show_next, double&y_show_next);
		double CalculateRadianLeft2(clsStruct::LINE* pStrLine, double dTextWidth, int& iIndex, double x_show, double y_show, double&x_show_next, double&y_show_next);
		void CalculateIntersection(double dWidth, double x_from, double y_from, double x1, double y1, double x2, double y2, double&x_to, double&y_to);

		bool DrawMLineCurve3(clsCrSurf* pClsCS, clsStruct::MLINE* pStrMLine, char* sUTF8);
		// DrawMLineCurve4(clsCrSurf* pClsCS, clsStruct::MLINE* pStrMLine, char* sUTF8);
		bool LineToSmooth(clsStruct::LINE* pStrLine, vector<double>& vX, vector<double>& vY);     //线条平滑处理
		bool Douglas_Peucker_algorithm(vector<double> &vX, vector<double>& vY);

		bool CalculateShowBegin(vector<double> vX, vector<double> vY, double dW, double& x_show_begin, double& y_show_begin, int & iPointIndex);
		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);


		bool DrawMLineCurve4(clsCrSurf* pClsCS, clsStruct::MLINE* pStrMLine, char* sUTF8);
		bool DrawMLineCurve5(clsCrSurf* pClsCS, clsStruct::MLINE* pStrMLine, char* sUTF8);

		double CalculateDistance(double x0, double y0, double x1, double y1, double x2, double y2);
		bool CalculateShowBegin(clsStruct::LINE* pLine, double dW, double& x_show_begin, double& y_show_begin, int & iPointIndex);
		bool CalculateShowBegin5(clsStruct::LINE* pLine, double dW, double& x_show_begin, double& y_show_begin, int & iPointIndex, double& dRadia, int width, int height);
		double CalculateRadianRight4(clsStruct::LINE* pLine, double dTextWidth, int & iIndex, double x_show, double y_show, double &x_show_next, double& y_show_next);
		int SplitUTF8(char* sUTF8, string* pStr, int iStrCount);




		bool DrawMPolygon(clsCrSurf* pClsCS, clsStruct::MPOLYGON* pStrMPolygon, char* sUTF8);
		bool DrawMPolygonParallel(clsCrSurf* pClsCS, clsStruct::MPOLYGON* pStrMPolygon, char* sUTF8);  //平行放置
		bool DrawMPolygonStraight(clsCrSurf* pClsCS, clsStruct::MPOLYGON* pStrMPolygon, char* sUTF8);  //平直
		bool DrawMPolygonParallelAndStraight(clsCrSurf* pClsCS, clsStruct::MPOLYGON* pStrMPolygon, char* sUTF8); // 先水平,其次平直


		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);
		double OBB_GetMBR(std::vector<double> vX, std::vector<double> vY, int i, clsCrSurf* pClsCS);
		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);



	};



}
#endif

















































































































































































//#pragma once
//#include<string>
//using namespace std;
//#include"Renderer.h"
//#include"clsStruct.h"
//class TextSymbol;
//class clsCrSurf;
//class DataCollection;
//class SimpleLabelRenderer:public Renderer
//{
//public:
//	SimpleLabelRenderer();
//	~SimpleLabelRenderer();
//	int RendererType();
//	virtual bool  Parse(rapidxml::xml_node<char>* node, AppendBuffer *f);
//	virtual bool DrawData(clsCrSurf* pClsCS, DataCollection* data, char* pFlag);
//
//	string m_sField;
//	string m_sLabelPriorities;
//	TextSymbol* m_pTextSymbol;
//	int m_iFeatureWeight;
//	int m_iLabelWeight;
//	int m_iHowmanyLabels;
//	double m_dLabelBufferRatio;
//	int m_iLineLabelPosition;
//	string m_sRotationalAngles;
//	
//
//
//	static SimpleLabelRenderer* CreateNew();
//	const char*  GetField();
//	bool    SetField(const char* sField);
//	const char*  GetLabelPriorities();
//	bool    SetLabelPriorities(const char* sLableLabelPriorities);
//	TextSymbol* GetTextSymbol();
//	bool    SetTextSymbol(TextSymbol* ts);
//	int     GetFeatureWeight();
//	bool    SetFeatureWeight(int iFeatureWeight);
//	int     GetLabelWeight();
//	bool    SetLabelWeight(int iLabelWeight);
//	int     GetHowmanyLabels();
//	bool    SetHowmanyLabels(int iHowmanyLabels);
//	double  GetLabelBufferRatio();
//	bool    SetLabelBufferRatio(double dLabelBufferRatio);
//	int     GetLineLabelPosition();
//	bool    SetLineLabelPosition(int iLineLabelPosition);
//	const char* GetRotationalAngles();
//	bool    SetRotationalAngles(const char* sRotationalAngles);
//
//
//	void TryAddField(vector<string>&pvField);
//	bool DrawStruct(clsCrSurf* pClsCS, DataCollection* data, int index, char* pFlag, int dcW, int dcH);
//
//
//	bool DrawPOINT(clsCrSurf* clsCS, clsStruct::POINT* pPoint, const char* sText);
//	bool DrawMPOINT(clsCrSurf* clsCr, clsStruct::LINE* pLine);
//
//	bool DrawAText(clsCrSurf* clsCS, double x, double y,double dAngle, const char* sUTF8);
//
//
//	//bool DrawPOINT(clsCairo* clsCr, clsStruct::POINT* pPoint);
//
//private:
//
//	/*
//	1. labelPriorities优先,只在 labelPriorities 为"0,0,0,0,0,0,0,0"时,考虑 rotationalangles 属性
//	2. labelPriorities 可以赋值为 "LE_PlaceOnTopHorizontal" ,在点之上放置,或者面内部,或者在线上
//	3. rotationalAngles可以被赋值为 "45,30,60" 或者"objectid"两种方式
//	*/
//	
//	
//
//	bool TrackPriorityString(const char* sPriority);
//	bool SetPriority();
//	bool TrackRotationalAngles(const char* sRotationalAngles);
//	
//
//	/*
//	标签位置部分
//	*/
//	static enum LabelPositionType
//	{
//		dmapLabelPositionOnTopHorizontal = 0,  //在点上,或者面上
//		dmapLabelPositionAngleNumber = 1,      //使用数字弧度(固定值)
//		dmapLabelPositionAngleField = 2,       //使用指定字段作为弧度
//		dmapLabelPositionPeriphery = 3,        //使用周边的8个标签位 水平放置
//	};
//	LabelPositionType m_lpt;
//	vector<double> m_vdAngles;
//	int m_i8[8];    // 这是从LabelPriorities直接分割出来的数字
//	int m_iLabelPriorities[8];  //这是经过处理后,依次优先的标签位置的顺序
//
//	SimpleLabelRenderer::LabelPositionType GetLabelPositionType();
//	bool CalculatePrioritiesNumber();     //处理 m_i8,得出 m_iLabelPriorities
//	bool CalculateAngles();               //处理 m_sRotationalAngles,存到 m_dAngles
//
//
//
//
//	
//};
//