Subversion Repositories public

Rev

Rev 275 | Rev 277 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 275 Rev 276
Line 40... Line 40...
40
#define CON_POLYGONPATTERNSYMBOLIZER	107
40
#define CON_POLYGONPATTERNSYMBOLIZER	107
41
#define CON_LAYER		108
41
#define CON_LAYER		108
42
#define CON_DATASOURCE		109
42
#define CON_DATASOURCE		109
43
#define CON_SHIELDSYMBOLIZER	110
43
#define CON_SHIELDSYMBOLIZER	110
44
#define CON_LINEPATTERNSYMBOLIZER	111
44
#define CON_LINEPATTERNSYMBOLIZER	111
-
 
45
#define CON_ELSEFILTER		112
45
 
46
 
46
#define FLD_FILTER		200
47
#define FLD_FILTER		200
47
#define FLD_CSSPARAMETER	201
48
#define FLD_CSSPARAMETER	201
48
#define FLD_MINSCALE		202
49
#define FLD_MINSCALE		202
49
#define FLD_MAXSCALE		203
50
#define FLD_MAXSCALE		203
Line 66... Line 67...
66
#define ATT_PLACEMENT		313
67
#define ATT_PLACEMENT		313
67
#define ATT_ALLOWOVERLAP	314
68
#define ATT_ALLOWOVERLAP	314
68
#define ATT_STATUS		315
69
#define ATT_STATUS		315
69
#define ATT_SRS			316
70
#define ATT_SRS			316
70
#define ATT_DX			317
71
#define ATT_DX			317
-
 
72
#define ATT_ALIGNMENT		318
71
 
73
 
72
#define FIRST_CON		100
74
#define FIRST_CON		100
73
#define LAST_CON		111
75
#define LAST_CON		112
74
 
76
 
75
#define FIRST_FLD		200
77
#define FIRST_FLD		200
76
#define LAST_FLD		205
78
#define LAST_FLD		205
77
 
79
 
78
#define FIRST_ATT		300
80
#define FIRST_ATT		300
79
#define LAST_ATT		317
81
#define LAST_ATT		318
80
 
82
 
81
using std::cout;
83
using std::cout;
82
using std::cerr;
84
using std::cerr;
83
using std::clog;
85
using std::clog;
84
using std::endl;
86
using std::endl;
Line 95... Line 97...
95
	{ CON_POLYGONPATTERNSYMBOLIZER,	in_polygonpatternsymbolizer,	QString("PolygonPatternSymbolizer") },
97
	{ CON_POLYGONPATTERNSYMBOLIZER,	in_polygonpatternsymbolizer,	QString("PolygonPatternSymbolizer") },
96
	{ CON_LAYER,			in_layer,		QString("Layer") },
98
	{ CON_LAYER,			in_layer,		QString("Layer") },
97
	{ CON_DATASOURCE,		in_datasource,		QString("Datasource") },
99
	{ CON_DATASOURCE,		in_datasource,		QString("Datasource") },
98
	{ CON_SHIELDSYMBOLIZER,		in_shieldsymbolizer,	QString("ShieldSymbolizer") },
100
	{ CON_SHIELDSYMBOLIZER,		in_shieldsymbolizer,	QString("ShieldSymbolizer") },
99
	{ CON_LINEPATTERNSYMBOLIZER,	in_linepatternsymbolizer, QString("LinePatternSymbolizer") },
101
	{ CON_LINEPATTERNSYMBOLIZER,	in_linepatternsymbolizer, QString("LinePatternSymbolizer") },
-
 
102
	{ CON_ELSEFILTER,		in_rule,		QString("ElseFilter") },
100
	// Fields
103
	// Fields
101
	{ FLD_FILTER,			in_rule,		QString("Filter") },
104
	{ FLD_FILTER,			in_rule,		QString("Filter") },
102
	{ FLD_CSSPARAMETER,		in_symbolizer,		QString("CSSParameter") },
105
	{ FLD_CSSPARAMETER,		in_symbolizer,		QString("CSSParameter") },
103
	{ FLD_MINSCALE,			in_rule,		QString("MinScaleDenominator") },
106
	{ FLD_MINSCALE,			in_rule,		QString("MinScaleDenominator") },
104
	{ FLD_MAXSCALE,			in_rule,		QString("MaxScaleDenominator") },
107
	{ FLD_MAXSCALE,			in_rule,		QString("MaxScaleDenominator") },
Line 121... Line 124...
121
	{ ATT_MAXDISTANCE,		in_symbolizer,		QString("max_distance") },
124
	{ ATT_MAXDISTANCE,		in_symbolizer,		QString("max_distance") },
122
	{ ATT_PLACEMENT,		in_symbolizer,		QString("placement") },
125
	{ ATT_PLACEMENT,		in_symbolizer,		QString("placement") },
123
	{ ATT_ALLOWOVERLAP,		in_symbolizer,		QString("allow_overlap") },
126
	{ ATT_ALLOWOVERLAP,		in_symbolizer,		QString("allow_overlap") },
124
	{ ATT_STATUS,			in_layer,		QString("status") },
127
	{ ATT_STATUS,			in_layer,		QString("status") },
125
	{ ATT_SRS,			in_layer,		QString("srs") },
128
	{ ATT_SRS,			in_layer,		QString("srs") },
-
 
129
	{ ATT_ALIGNMENT,		in_symbolizer,		QString("alignment") },
126
	{ 0,				in_root,		QString::null }
130
	{ 0,				in_root,		QString::null }
127
};
131
};
128
 
132
 
129
SRender::SRender()
133
SRender::SRender()
130
{
134
{
Line 141... Line 145...
141
	PolygonPatternSymbolizer = 0;
145
	PolygonPatternSymbolizer = 0;
142
	ShieldSymbolizer = 0;
146
	ShieldSymbolizer = 0;
143
	LinePatternSymbolizer = 0;
147
	LinePatternSymbolizer = 0;
144
	_lx = _ly = 180.0;
148
	_lx = _ly = 180.0;
145
	_rx = _ry = -180.0;
149
	_rx = _ry = -180.0;
-
 
150
	__map_type = MAP_SHAPE;		// The default map type
146
	// This is true, when a XML file was parsed successfully
151
	// This is true, when a XML file was parsed successfully
147
	ControlSet = false;
152
	ControlSet = false;
148
 
153
 
149
	// Read settings from config file
154
	// Read settings from config file
150
	KConfig cfg (QString("sportwatcher.rc"), KConfig::SimpleConfig);
155
	KConfig cfg (QString("sportwatcher.rc"), KConfig::SimpleConfig);
Line 405... Line 410...
405
		    else
410
		    else
406
		    {
411
		    {
407
		       Rule->next = allocRule();
412
		       Rule->next = allocRule();
408
		       Rule = Rule->next;
413
		       Rule = Rule->next;
409
		    }
414
		    }
-
 
415
 
-
 
416
		    if ((index = att.index(QString("name"))) != -1)
-
 
417
		    {
-
 
418
		       Rule->name = att.value(index);
-
 
419
		       Rule->rl.set_name(Rule->name.toAscii().data());
-
 
420
		    }
-
 
421
 
-
 
422
		    if ((index = att.index(QString("title"))) != -1)
-
 
423
		    {
-
 
424
		       Rule->title = att.value(index);
-
 
425
		       Rule->rl.set_title(Rule->title.toAscii().data());
-
 
426
		    }
-
 
427
		 break;
-
 
428
 
-
 
429
		 case CON_ELSEFILTER:
-
 
430
		    Container = in_elsefilter;
-
 
431
 
-
 
432
		    if (!Rule)
-
 
433
		    {
-
 
434
		       KMessageBox::error(0, i18n("Error parsing %1, line %2: Open ELSEFILTER outside of a RULE!").arg(XmlPath).arg(XmlLine));
-
 
435
		       return false;
-
 
436
		    }
410
		 break;
437
		 break;
411
 
438
 
412
		 case CON_LAYER:
439
		 case CON_LAYER:
413
		    Container = in_layer;
440
		    Container = in_layer;
414
 
441
 
Line 436... Line 463...
436
		    if ((index = att.index(QString("minzoom"))) != -1)
463
		    if ((index = att.index(QString("minzoom"))) != -1)
437
		       Lay->minzoom = att.value(index).toDouble();
464
		       Lay->minzoom = att.value(index).toDouble();
438
 
465
 
439
		    if ((index = att.index(QString("maxzoom"))) != -1)
466
		    if ((index = att.index(QString("maxzoom"))) != -1)
440
		       Lay->maxzoom = att.value(index).toDouble();
467
		       Lay->maxzoom = att.value(index).toDouble();
-
 
468
 
-
 
469
		    if ((index = att.index(QString("queryable"))) != -1)
-
 
470
		       Lay->queryable = getBool(att.value(index));
-
 
471
 
-
 
472
		    if ((index = att.index(QString("title"))) != -1)
-
 
473
		       Lay->title = att.value(index);
-
 
474
 
-
 
475
		    if ((index = att.index(QString("abstract"))) != -1)
-
 
476
		       Lay->abstract = att.value(index);
-
 
477
 
-
 
478
		    if ((index = att.index(QString("clear_label_cache"))) != -1)
-
 
479
		       Lay->clear_label = getBool(att.value(index));
441
		 break;
480
		 break;
442
 
481
 
443
		 case CON_DATASOURCE:
482
		 case CON_DATASOURCE:
444
		    Container = in_datasource;
483
		    Container = in_datasource;
445
		 break;
484
		 break;
Line 477... Line 516...
477
 
516
 
478
		    if ((index = att.index(QString("height"))) != -1)
517
		    if ((index = att.index(QString("height"))) != -1)
479
		       PointSymbolizer->height = att.value(index).toDouble();
518
		       PointSymbolizer->height = att.value(index).toDouble();
480
 
519
 
481
		    if ((index = att.index(QString("allow_overlap"))) != -1)
520
		    if ((index = att.index(QString("allow_overlap"))) != -1)
482
		    {
-
 
483
		       if (att.value(index).toLower() == QString("true"))
-
 
484
			  PointSymbolizer->allow_overlap = true;
-
 
485
		       else
-
 
486
			  PointSymbolizer->allow_overlap = false;
521
		       PointSymbolizer->allow_overlap = getBool(att.value(index));
487
		    }
-
 
488
		 break;
522
		 break;
489
 
523
 
490
		 break;
524
		 break;
491
 
525
 
492
		 case CON_LINESYMBOLIZER:
526
		 case CON_LINESYMBOLIZER:
Line 561... Line 595...
561
		       TextSymbolizer->name = att.value(index);
595
		       TextSymbolizer->name = att.value(index);
562
 
596
 
563
		    if ((index = att.index(QString("face_name"))) != -1)
597
		    if ((index = att.index(QString("face_name"))) != -1)
564
		       TextSymbolizer->face_name = att.value(index);
598
		       TextSymbolizer->face_name = att.value(index);
565
 
599
 
-
 
600
		    if ((index = att.index(QString("placement"))) != -1)
-
 
601
		       TextSymbolizer->placement = att.value(index);
-
 
602
 
566
		    if ((index = att.index(QString("size"))) != -1)
603
		    if ((index = att.index(QString("size"))) != -1)
567
		       TextSymbolizer->size = att.value(index).toDouble();
604
		       TextSymbolizer->size = att.value(index).toDouble();
568
 
605
 
569
		    if ((index = att.index(QString("fill"))) != -1)
606
		    if ((index = att.index(QString("fill"))) != -1)
570
		       TextSymbolizer->fill = colorToUInt(att.value(index));
607
		       TextSymbolizer->fill = colorToUInt(att.value(index));
Line 573... Line 610...
573
		       TextSymbolizer->halo_radius = att.value(index).toDouble();
610
		       TextSymbolizer->halo_radius = att.value(index).toDouble();
574
 
611
 
575
		    if ((index = att.index(QString("wrap_width"))) != -1)
612
		    if ((index = att.index(QString("wrap_width"))) != -1)
576
		       TextSymbolizer->wrap_width = att.value(index).toDouble();
613
		       TextSymbolizer->wrap_width = att.value(index).toDouble();
577
 
614
 
-
 
615
		    if ((index = att.index(QString("alignment"))) != -1)
-
 
616
		       TextSymbolizer->alignment = att.value(index);
-
 
617
 
578
		    if ((index = att.index(QString("dx"))) != -1)
618
		    if ((index = att.index(QString("dx"))) != -1)
579
		       TextSymbolizer->dx = att.value(index).toDouble();
619
		       TextSymbolizer->dx = att.value(index).toDouble();
580
 
620
 
581
		    if ((index = att.index(QString("dy"))) != -1)
621
		    if ((index = att.index(QString("dy"))) != -1)
582
		       TextSymbolizer->dy = att.value(index).toDouble();
622
		       TextSymbolizer->dy = att.value(index).toDouble();
Line 807... Line 847...
807
			     Names = table;
847
			     Names = table;
808
			  else if (att.value(index).toLower() == QString("estimate_extent"))
848
			  else if (att.value(index).toLower() == QString("estimate_extent"))
809
			     Names = estimate_extent;
849
			     Names = estimate_extent;
810
			  else if (att.value(index).toLower() == QString("extent"))
850
			  else if (att.value(index).toLower() == QString("extent"))
811
			     Names = extent;
851
			     Names = extent;
-
 
852
			  else if (att.value(index).toLower() == QString("parser"))
-
 
853
			     Names = parser__;
-
 
854
			  else if (att.value(index).toLower() == QString("url"))
-
 
855
			     Names = url;
-
 
856
			  else if (att.value(index).toLower() == QString("bbox"))
-
 
857
			     Names = bbox;
812
		       }
858
		       }
813
		       else
859
		       else
814
		       {
860
		       {
815
			  KMessageBox::error(0, i18n("Error parsing %1, line %2: Required attribute NAME is missing in PARAMETER inside DATASOURCE!").arg(XmlPath).arg(XmlLine));
861
			  KMessageBox::error(0, i18n("Error parsing %1, line %2: Required attribute NAME is missing in PARAMETER inside DATASOURCE!").arg(XmlPath).arg(XmlLine));
816
			  return false;
862
			  return false;
Line 849... Line 895...
849
		    Names = empty;
895
		    Names = empty;
850
		 break;
896
		 break;
851
		 case in_linepatternsymbolizer:
897
		 case in_linepatternsymbolizer:
852
		    Names = empty;
898
		    Names = empty;
853
		 break;
899
		 break;
-
 
900
		 case in_elsefilter:
-
 
901
		    Names = empty;
-
 
902
		 break;
854
	      }
903
	      }
855
	   }
904
	   }
856
 
905
 
857
	   i++;
906
	   i++;
858
	}
907
	}
Line 870... Line 919...
870
	else if (qName.toLower() == QString("layer"))
919
	else if (qName.toLower() == QString("layer"))
871
	{
920
	{
872
	   parameters p;
921
	   parameters p;
873
	   Container = in_map;
922
	   Container = in_map;
874
 
923
 
875
	   if (Lay->Datasource.type.toLower() == QString("shape"))
924
	   if (Lay->Datasource.type.toLower() == QString("shape") && __map_type == MAP_SHAPE)
876
	   {
925
	   {
-
 
926
	   QFileInfo qdi(Lay->Datasource.file);
-
 
927
	   QString hv0;
-
 
928
 
-
 
929
	      hv0 = qdi.fileName();
-
 
930
 
-
 
931
	      if (shapePath.right(1) == QChar('/'))
-
 
932
		 hv0 = shapePath + hv0;
-
 
933
	      else
-
 
934
		 hv0 = shapePath + "/" + hv0;
-
 
935
 
877
	      p["type"] = "shape";
936
	      p["type"] = "shape";
878
	      p["file"] = Lay->Datasource.file.toAscii().constData();
937
	      p["file"] = hv0.toAscii().data();
879
	   }
938
	   }
880
	   else if (Lay->Datasource.type.toLower() == QString("postgis"))
939
	   else if (Lay->Datasource.type.toLower() == QString("postgis") && __map_type == MAP_GIS)
881
	   {
940
	   {
882
	      p["type"] = "postgis";
941
	      p["type"] = "postgis";
883
	      p["host"] = Lay->Datasource.host.toAscii().constData();
942
	      p["host"] = Lay->Datasource.host.toAscii().data();
884
	      p["user"] = Lay->Datasource.user.toAscii().constData();
943
	      p["user"] = Lay->Datasource.user.toAscii().data();
885
	      p["dbname"] = Lay->Datasource.dbname.toAscii().constData();
944
	      p["dbname"] = Lay->Datasource.dbname.toAscii().data();
886
	      p["table"] = Lay->Datasource.table.toAscii().constData();
945
	      p["table"] = Lay->Datasource.table.toAscii().data();
887
	      p["estimate_extent"] = (Lay->Datasource.estimate_extent) ? "true" : "false";
946
	      p["estimate_extent"] = (Lay->Datasource.estimate_extent) ? "true" : "false";
888
	      p["extent"] = QString("%1,%2,%3,%4").arg(Lay->Datasource.ext_lx).arg(Lay->Datasource.ext_ly).arg(Lay->Datasource.ext_rx).arg(Lay->Datasource.ext_ry).toAscii().data();
947
	      p["extent"] = QString("%1,%2,%3,%4").arg(Lay->Datasource.ext_lx).arg(Lay->Datasource.ext_ly).arg(Lay->Datasource.ext_rx).arg(Lay->Datasource.ext_ry).toAscii().data();
889
	   }
948
	   }
-
 
949
	   else if (Lay->Datasource.type.toAscii() == QString("osm") && __map_type == MAP_OSM)
-
 
950
	   {
-
 
951
	      p["type"] = "osm";
-
 
952
 
-
 
953
	      if (Lay->Datasource.parser.length() <= 0)
-
 
954
		 p["parser"] = "libxml2";
-
 
955
	      else
-
 
956
		 p["parser"] = Lay->Datasource.parser.toAscii().data();
-
 
957
 
-
 
958
	      if (!Lay->Datasource.url.isEmpty() && !Lay->Datasource.bbox.isEmpty())
-
 
959
	      {
-
 
960
		 p["url"] = Lay->Datasource.url.toAscii().data();
-
 
961
		 p["bbox"] = Lay->Datasource.bbox.toAscii().data();
-
 
962
	      }
-
 
963
	      else
-
 
964
		 p["file"] = shapePath.toAscii().data();
-
 
965
	   }
890
	   else
966
	   else
891
	   {
967
	   {
892
	      cerr << "Warning file " << XmlPath.toAscii().data() << ", line " << XmlLine << ": Layer with no source! Ingnoring!" << endl;
968
	      cerr << "Warning file " << XmlPath.toAscii().data() << ", line " << XmlLine << ": Layer with no source! Ingnoring!" << endl;
893
	      return true;
969
	      return true;
894
	   }
970
	   }
895
 
971
 
896
	   Layer lyr(Lay->name.toAscii().data());
972
	   Layer lyr(Lay->name.toAscii().data());
-
 
973
 
-
 
974
	   if (!Lay->title.isEmpty())
897
	   lyr.set_title(Lay->name.toAscii().data());
975
	      lyr.set_title(Lay->title.toAscii().data());
-
 
976
 
-
 
977
	   if (!Lay->abstract.isEmpty())
-
 
978
	      lyr.set_abstract(Lay->abstract.toAscii().data());
-
 
979
 
898
	   lyr.set_datasource(datasource_cache::instance()->create(p));
980
	   lyr.set_datasource(datasource_cache::instance()->create(p));
899
 
981
 
-
 
982
	   if (!Lay->srs.isEmpty())
-
 
983
	      lyr.set_srs(Lay->srs.toAscii().data());
-
 
984
 
900
	   if (Lay->minzoom > 0.0)
985
	   if (Lay->minzoom > 0.0)
901
	      lyr.setMinZoom(Lay->minzoom);
986
	      lyr.setMinZoom(Lay->minzoom);
902
 
987
 
903
	   if (Lay->maxzoom > 0.0)
988
	   if (Lay->maxzoom > 0.0)
904
	      lyr.setMaxZoom(Lay->maxzoom);
989
	      lyr.setMaxZoom(Lay->maxzoom);
905
 
990
 
906
	   if (!Lay->srs.isEmpty())
-
 
907
	      lyr.set_srs(Lay->srs.toAscii().constData());
991
	   lyr.set_clear_label_cache(Lay->clear_label);
908
 
992
 
909
	   // Add the styles
993
	   // Add the styles
910
	   for (int i = 0; i < Lay->Styles.size(); i++)
994
	   for (int i = 0; i < Lay->Styles.size(); i++)
911
	   {
995
	   {
912
	      if (findStyle (Lay->Styles.at(i)) != 0)
996
	      if (findStyle (Lay->Styles.at(i)) != 0)
913
		 lyr.add_style(Lay->Styles.at(i).toAscii().constData());
997
		 lyr.add_style(Lay->Styles.at(i).toAscii().data());
914
	      else
998
	      else
915
		 cerr << "Warning file " << XmlPath.toAscii().data() << ", line " << XmlLine << ": Style \"" << Lay->Styles.at(i).toAscii().data() << "\" does not exist!" << endl;
999
		 cerr << "Warning file " << XmlPath.toAscii().data() << ", line " << XmlLine << ": Style \"" << Lay->Styles.at(i).toAscii().data() << "\" does not exist!" << endl;
916
	   }
1000
	   }
917
 
1001
 
918
	   lyr.setActive(Lay->status);
1002
	   lyr.setActive(Lay->status);
-
 
1003
	   lyr.setQueryable(true);
919
	   m.addLayer(lyr);
1004
	   m.addLayer(lyr);
920
	   Envelope <double>le(lyr.envelope());
1005
	   Envelope <double>le(lyr.envelope());
921
	   setMaxExtent(le.minx(), le.miny(), le.maxx(), le.maxy());
1006
	   setMaxExtent(le.minx(), le.miny(), le.maxx(), le.maxy());
922
	}
1007
	}
923
	else if (qName.toLower() == QString("map"))
1008
	else if (qName.toLower() == QString("map"))
Line 941... Line 1026...
941
	      point_symbolizer psym;
1026
	      point_symbolizer psym;
942
	      Rule->rl.append(psym);
1027
	      Rule->rl.append(psym);
943
	   }
1028
	   }
944
	   else
1029
	   else
945
	   {
1030
	   {
946
	      point_symbolizer ps(PointSymbolizer->file.toAscii().data(), getTypeText(PointSymbolizer->type), PointSymbolizer->width, PointSymbolizer->height);
1031
	      point_symbolizer ps(findIcon(PointSymbolizer->file).toAscii().data(), getTypeText(PointSymbolizer->type), PointSymbolizer->width, PointSymbolizer->height);
947
	      ps.set_allow_overlap (PointSymbolizer->allow_overlap);
1032
	      ps.set_allow_overlap (PointSymbolizer->allow_overlap);
948
	      Rule->rl.append(ps);
1033
	      Rule->rl.append(ps);
949
	   }
1034
	   }
950
	}
1035
	}
951
	else if (qName.toLower() == QString("linesymbolizer"))
1036
	else if (qName.toLower() == QString("linesymbolizer"))
Line 1033... Line 1118...
1033
	   }
1118
	   }
1034
 
1119
 
1035
	   color col;
1120
	   color col;
1036
	   col.set_bgr(TextSymbolizer->fill);
1121
	   col.set_bgr(TextSymbolizer->fill);
1037
 
1122
 
-
 
1123
	   if (TextSymbolizer->name.length() <= 0 || TextSymbolizer->face_name.length() <= 0 || TextSymbolizer->size <= 0)
-
 
1124
	      cerr << "Error parsing " << XmlPath.toAscii().data() << ", line " << XmlLine << ": Empty TEXTSYMBOLIZER found --> ignoring!" << endl;
-
 
1125
	   else
-
 
1126
	   {
1038
	   text_symbolizer ts(TextSymbolizer->name.toAscii().data(), TextSymbolizer->face_name.toAscii().data(), TextSymbolizer->size, col);
1127
	      text_symbolizer ts(TextSymbolizer->name.toAscii().data(), TextSymbolizer->face_name.toAscii().data(), TextSymbolizer->size, col);
-
 
1128
 
-
 
1129
	      if (TextSymbolizer->halo_radius != 0.0)
-
 
1130
		 ts.set_halo_radius((unsigned int)TextSymbolizer->halo_radius);
1039
 
1131
 
1040
	   if (TextSymbolizer->halo_radius != 0.0)
1132
	      if (TextSymbolizer->wrap_width != 0.0)
1041
	      ts.set_halo_radius((unsigned int)TextSymbolizer->halo_radius);
1133
		 ts.set_wrap_width((unsigned int)TextSymbolizer->wrap_width);
1042
 
1134
 
1043
	   if (TextSymbolizer->wrap_width != 0.0)
1135
	      if (TextSymbolizer->mindistance != 0)
1044
	      ts.set_wrap_width((unsigned int)TextSymbolizer->wrap_width);
1136
		 ts.set_label_spacing(TextSymbolizer->mindistance);
-
 
1137
 
-
 
1138
	      if (!TextSymbolizer->placement.isEmpty())
-
 
1139
	      {
-
 
1140
		 if (TextSymbolizer->placement.toLower() == QString("point"))
-
 
1141
		    ts.set_label_placement(mapnik::POINT_PLACEMENT);
-
 
1142
		 else if (TextSymbolizer->placement.toLower() == QString("line"))
-
 
1143
		    ts.set_label_placement(mapnik::LINE_PLACEMENT);
-
 
1144
		 else
-
 
1145
		    cerr << "Error parsing " << XmlPath.toAscii().data() << ", line " << XmlLine << ": Unknown >>label placement<< \"" << TextSymbolizer->placement.toAscii().data() << "\" --> ignoring!" << endl;
-
 
1146
	      }
1045
 
1147
 
1046
	   if (TextSymbolizer->mindistance != 0)
1148
	      if (!TextSymbolizer->alignment.isEmpty())
-
 
1149
	      {
-
 
1150
		 if (TextSymbolizer->alignment.toLower() == QString("top"))
-
 
1151
		    ts.set_vertical_alignment(mapnik::TOP);
-
 
1152
		 else if (TextSymbolizer->alignment.toLower() == QString("middle"))
-
 
1153
		    ts.set_vertical_alignment(mapnik::MIDDLE);
-
 
1154
		 else if (TextSymbolizer->alignment.toLower() == QString("bottom"))
1047
	      ts.set_label_spacing(TextSymbolizer->mindistance);
1155
		    ts.set_vertical_alignment(mapnik::BOTTOM);
-
 
1156
		 else
-
 
1157
		    cerr << "Error parsing " << XmlPath.toAscii().data() << ", line " << XmlLine << ": Unknown >>vertical placement<< \"" << TextSymbolizer->alignment.toAscii().data() << "\" --> ignoring!" << endl;
-
 
1158
	      }
1048
 
1159
 
1049
	   if (TextSymbolizer->dx != 0 || TextSymbolizer->dy != 0)
1160
	      if (TextSymbolizer->dx != 0 || TextSymbolizer->dy != 0)
1050
	      ts.set_displacement(TextSymbolizer->dx, TextSymbolizer->dy);
1161
		 ts.set_displacement(TextSymbolizer->dx, TextSymbolizer->dy);
1051
 
1162
 
1052
	   Rule->rl.append(ts);
1163
	      Rule->rl.append(ts);
-
 
1164
	   }
1053
	}
1165
	}
1054
	else if (qName.toLower() == QString("polygonpatternsymbolizer"))
1166
	else if (qName.toLower() == QString("polygonpatternsymbolizer"))
1055
	{
1167
	{
1056
	   Container = in_rule;
1168
	   Container = in_rule;
1057
 
1169
 
Line 1059... Line 1171...
1059
	   {
1171
	   {
1060
	      KMessageBox::error(0, i18n("Error parsing %1, line %2: Endin of POLYGONPATTERNSYMBOLIZER without start, or outside of a RULE detected!").arg(XmlPath).arg(XmlLine));
1172
	      KMessageBox::error(0, i18n("Error parsing %1, line %2: Endin of POLYGONPATTERNSYMBOLIZER without start, or outside of a RULE detected!").arg(XmlPath).arg(XmlLine));
1061
	      return false;
1173
	      return false;
1062
	   }
1174
	   }
1063
 
1175
 
-
 
1176
	   if (PolygonPatternSymbolizer->file.length() <= 0)
-
 
1177
	      cerr << "Error parsing " << XmlPath.toAscii().data() << ", line " << XmlLine << ": Incomplete POLYGONPATTERNSYMBOLIZER --> ignoring!" << endl;
-
 
1178
	   else
-
 
1179
	   {
1064
	   Rule->rl.append(polygon_pattern_symbolizer(findIcon(PolygonPatternSymbolizer->file).toAscii().data(),
1180
	      Rule->rl.append(polygon_pattern_symbolizer(findIcon(PolygonPatternSymbolizer->file).toAscii().data(),
1065
						getTypeText(PolygonPatternSymbolizer->type),
1181
						getTypeText(PolygonPatternSymbolizer->type),
1066
						PolygonPatternSymbolizer->width,
1182
						PolygonPatternSymbolizer->width,
1067
						PolygonPatternSymbolizer->height));
1183
						PolygonPatternSymbolizer->height));
1068
	   PolygonPatternSymbolizer = PolygonPatternSymbolizer->next;
-
 
-
 
1184
	   }
1069
	}
1185
	}
1070
	else if (qName.toLower() == QString("shieldsymbolizer"))
1186
	else if (qName.toLower() == QString("shieldsymbolizer"))
1071
	{
1187
	{
1072
	   Container = in_rule;
1188
	   Container = in_rule;
1073
 
1189
 
Line 1116... Line 1232...
1116
		 qName.toLower() == QString("maxscaledenominator") ||
1232
		 qName.toLower() == QString("maxscaledenominator") ||
1117
		 qName.toLower() == QString("minscaledenominator"))
1233
		 qName.toLower() == QString("minscaledenominator"))
1118
	   Container = in_rule;
1234
	   Container = in_rule;
1119
	else if (qName.toLower() == QString("rule"))
1235
	else if (qName.toLower() == QString("rule"))
1120
	   Container = in_style;
1236
	   Container = in_style;
-
 
1237
	else if (qName.toLower() == QString("elsefilter"))
-
 
1238
	{
-
 
1239
	   Container = in_rule;
-
 
1240
 
-
 
1241
	   if (!Rule)
-
 
1242
	   {
-
 
1243
	      KMessageBox::error(0, i18n("Error parsing %1, line %2: Ending of ELSEFILTER outside of a RULE detected!").arg(XmlPath).arg(XmlLine));
-
 
1244
	      return false;
-
 
1245
	   }
-
 
1246
 
-
 
1247
	   Rule->rl.set_else(true);
-
 
1248
	}
1121
	else if (qName.toLower() == QString("style"))
1249
	else if (qName.toLower() == QString("style"))
1122
	{
1250
	{
1123
	   Container = in_map;
1251
	   Container = in_map;
1124
	   feature_type_style style;
1252
	   feature_type_style style;
1125
 
1253
 
Line 1145... Line 1273...
1145
 * The reader calls this function when it has parsed a chunk of character data
1273
 * The reader calls this function when it has parsed a chunk of character data
1146
 * - either normal character data or character data inside a CDATA section.
1274
 * - either normal character data or character data inside a CDATA section.
1147
 */
1275
 */
1148
bool SRender::characters (const QString& chraw)
1276
bool SRender::characters (const QString& chraw)
1149
{
1277
{
1150
	QString ch = chraw.trimmed();
-
 
1151
 
-
 
1152
	if (ch.length() == 0)
-
 
1153
	   return true;
-
 
1154
 
-
 
1155
	if (ch.at(0) == QChar('\n'))
1278
	if (chraw.at(0) == QChar('\n'))
1156
	{
1279
	{
1157
	   XmlLine++;
1280
	   XmlLine++;
1158
	   return true;
1281
	   return true;
1159
	}
1282
	}
1160
 
1283
 
-
 
1284
	QString ch = chraw.trimmed();
-
 
1285
 
-
 
1286
	if (ch.length() == 0)
-
 
1287
	   return true;
-
 
1288
 
1161
	if (Container == in_rule && Rule)
1289
	if (Container == in_rule && Rule)
1162
	{
1290
	{
1163
	   if (Field == FLD_FILTER)
1291
	   if (Field == FLD_FILTER)
1164
	   {
1292
	   {
1165
	      Rule->filter = ch;
1293
	      Rule->filter = ch;
1166
 
1294
 
1167
	      if (!Rule->filter.isEmpty())
1295
	      if (!Rule->filter.isEmpty())
1168
		 Rule->rl.set_filter(create_filter(Rule->filter.toAscii().data()));
1296
		 Rule->rl.set_filter(create_filter(Rule->filter.toLatin1().data(), "latin1"));
1169
	      else
1297
	      else
1170
		 cerr << "Warning in file " << XmlPath.toAscii().data() << " at line " << XmlLine << ": Ignoring empty filter!" << endl;
1298
		 cerr << "Warning in file " << XmlPath.toAscii().data() << " at line " << XmlLine << ": Ignoring empty filter!" << endl;
1171
	   }
1299
	   }
1172
	   else if (Field == FLD_MAXSCALE)
1300
	   else if (Field == FLD_MAXSCALE)
1173
	   {
1301
	   {
Line 1239... Line 1367...
1239
 
1367
 
1240
		 if (hv0.right(1) != QString("/"))
1368
		 if (hv0.right(1) != QString("/"))
1241
		    hv0 += "/";
1369
		    hv0 += "/";
1242
 
1370
 
1243
		 hv0 += qf.fileName();
1371
		 hv0 += qf.fileName();
-
 
1372
 
-
 
1373
		 if (__map_type == MAP_SHAPE)
1244
		 qf.setFile (hv0 + ".shp");
1374
		    qf.setFile (hv0 + ".shp");
-
 
1375
		 else if (__map_type == MAP_OSM)
-
 
1376
		    qf.setFile (hv0 + ".osm");
1245
 
1377
 
1246
		 if (!qf.exists())
1378
		 if (!qf.exists())
1247
		 {
1379
		 {
-
 
1380
		    if (__map_type == MAP_SHAPE)
1248
		    KMessageBox::error(0, i18n("The shape file \"%1\" at line %2 does not exist!").arg(hv0+".shp").arg(XmlLine));
1381
		       KMessageBox::error(0, i18n("The shape file \"%1\" at line %2 does not exist!").arg(hv0+".shp").arg(XmlLine));
-
 
1382
		    else if (__map_type == MAP_OSM)
-
 
1383
		       KMessageBox::error(0, i18n("The OSM file \"%1\" at line %2 does not exist!").arg(hv0+".osm").arg(XmlLine));
-
 
1384
 
1249
		    return false;
1385
		    return false;
1250
		 }
1386
		 }
1251
 
1387
 
1252
		 Lay->Datasource.file = hv0;
1388
		 Lay->Datasource.file = hv0;
1253
	      }
1389
	      }
-
 
1390
	      else if (Names == parser__)
-
 
1391
		 Lay->Datasource.parser = ch;
-
 
1392
	      else if (Names == url)
-
 
1393
		 Lay->Datasource.url = ch;
-
 
1394
	      else if (Names == bbox)
-
 
1395
		 Lay->Datasource.bbox = ch;
1254
	      else if (Names == host)
1396
	      else if (Names == host)
1255
		 Lay->Datasource.host = ch;
1397
		 Lay->Datasource.host = ch;
1256
	      else if (Names == user)
1398
	      else if (Names == user)
1257
		 Lay->Datasource.user = ch;
1399
		 Lay->Datasource.user = ch;
1258
	      else if (Names == dbname)
1400
	      else if (Names == dbname)
Line 1377... Line 1519...
1377
 
1519
 
1378
	m.setWidth(width);
1520
	m.setWidth(width);
1379
	m.setHeight(height);
1521
	m.setHeight(height);
1380
//	load_map(m, XmlPath.toAscii().data());
1522
//	load_map(m, XmlPath.toAscii().data());
1381
 
1523
 
1382
	if (!ControlSet)	// Initialize the map?
1524
	try
1383
	{
1525
	{
-
 
1526
	   if (!ControlSet)	// Initialize the map?
-
 
1527
	   {
1384
	   QXmlInputSource source (&file);
1528
	      QXmlInputSource source (&file);
1385
	   reader.setContentHandler (this);
1529
	      reader.setContentHandler (this);
1386
	   reader.parse (source);
1530
	      reader.parse (source);
1387
	}
1531
	   }
1388
 
1532
 
1389
	save_map(m, "/home/andreas/.sportwatcher/spw.xml");
1533
	   save_map(m, "/home/andreas/.sportwatcher/spw.xml");
1390
//	save_map(m, "/home/andreas/.sportwatcher/spw1.xml");
1534
//	   save_map(m, "/home/andreas/.sportwatcher/spw1.xml");
1391
	plx = lx;
1535
	   plx = lx;
1392
	ply = ly;
1536
	   ply = ly;
1393
	prx = rx;
1537
	   prx = rx;
1394
	pry = ry;
1538
	   pry = ry;
1395
	projection pj(m.srs());
1539
	   projection pj(m.srs());
1396
 
1540
 
1397
	if (pj.is_geographic())
1541
	   if (pj.is_geographic())
1398
	{
1542
	   {
1399
	   pj.inverse(plx, ply);
1543
	      pj.inverse(plx, ply);
1400
	   pj.inverse(prx, pry);
1544
	      pj.inverse(prx, pry);
1401
cout << "Geographic! Inverse projection." << endl;
1545
cout << "Geographic! Inverse projection." << endl;
1402
	}
1546
	   }
1403
	else
1547
	   else
1404
	{
1548
	   {
1405
//	   pj.forward(plx, ply);
1549
//	      pj.forward(plx, ply);
1406
//	   pj.forward(prx, pry);
1550
//	      pj.forward(prx, pry);
1407
cout << "NOT geographic!" << endl;
1551
cout << "NOT geographic!" << endl;
1408
	}
1552
	   }
1409
 
1553
 
1410
for (unsigned i = 0; i < m.layerCount(); i++)
1554
for (unsigned i = 0; i < m.layerCount(); i++)
1411
{
1555
{
1412
   bool vis = m.getLayer(i).isVisible(m.scale_denominator());
1556
   bool vis = m.getLayer(i).isVisible(m.scale_denominator());
-
 
1557
//   bool vis = m.getLayer(i).isVisible(m.scale());
1413
   cout << "Layer " << i << ": " << m.getLayer(i).name();
1558
   cout << "Layer " << i << ": " << m.getLayer(i).name();
1414
   cout << ", Visible: " << vis;
1559
   cout << ", Visible: " << vis;
-
 
1560
   cout << ", Active: " << m.getLayer(i).isActive();
1415
   Envelope <double>e(m.getLayer(i).envelope());
1561
   Envelope <double>e(m.getLayer(i).envelope());
1416
   cout << ", Extent: " << e.minx() << ", " << e.miny() << ", " << e.maxx() << ", " << e.maxy() << endl;
1562
   cout << ", Extent: " << e.minx() << ", " << e.miny() << ", " << e.maxx() << ", " << e.maxy() << endl;
1417
}
1563
}
1418
 
1564
 
1419
	// First we use Mapnik to create the map
1565
	   // First we use Mapnik to create the map
1420
	m.zoomToBox(Envelope<double>(plx, ply, prx, pry));
1566
	   m.zoomToBox(Envelope<double>(plx, ply, prx, pry));
1421
 
1567
 
1422
Envelope <double>e(m.getCurrentExtent());
1568
Envelope <double>e(m.getCurrentExtent());
1423
cout << std::setprecision(16) << "Parameter envelope: " << lx << ", " << ly << ", " << rx << ", " << ry << endl;
1569
cout << std::setprecision(16) << "Parameter envelope: " << lx << ", " << ly << ", " << rx << ", " << ry << endl;
1424
cout << std::setprecision(16) << "Converted envelope: " << plx << ", " << ply << ", " << prx << ", " << pry << endl;
1570
cout << std::setprecision(16) << "Converted envelope: " << plx << ", " << ply << ", " << prx << ", " << pry << endl;
1425
cout << std::setprecision(16) << "Current extent:     " << e.minx() << ", " << e.miny() << ", " << e.maxx() << ", " << e.maxy() << endl;
1571
cout << std::setprecision(16) << "Current extent:     " << e.minx() << ", " << e.miny() << ", " << e.maxx() << ", " << e.maxy() << endl;
-
 
1572
Envelope <double>x(m.get_buffered_extent());
-
 
1573
cout << std::setprecision(16) << "Current buf.extent: " << x.minx() << ", " << x.miny() << ", " << x.maxx() << ", " << x.maxy() << endl;
1426
cout << "SRS: " << m.srs() << endl;
1574
cout << "SRS: " << m.srs() << endl;
1427
cout << std::setprecision(16) << "Scale: " << m.scale() << ", scale denominator: " << m.scale_denominator() << endl;
1575
cout << std::setprecision(16) << "Scale: " << m.scale() << ", scale denominator: " << m.scale_denominator() << endl;
1428
cout << "width=" << m.getWidth() << ", height=" << m.getHeight() << endl;
1576
cout << "width=" << m.getWidth() << ", height=" << m.getHeight() << endl;
1429
 
1577
 
1430
	Image32 buf(m.getWidth(), m.getHeight());
1578
	   Image32 buf(m.getWidth(), m.getHeight());
1431
	agg_renderer<Image32> ren(m, buf);
1579
	   agg_renderer<Image32> ren(m, buf);
1432
	ren.apply();
1580
	   ren.apply();
-
 
1581
 
1433
	// Put the image into a Qt object
1582
	   // Put the image into a Qt object
1434
	QImage image((uchar*)buf.raw_data(), m.getWidth(), m.getHeight(), QImage::Format_ARGB32);
1583
	   QImage image((uchar*)buf.raw_data(), m.getWidth(), m.getHeight(), QImage::Format_ARGB32);
1435
	label->setPixmap(QPixmap::fromImage(image.rgbSwapped()));
1584
	   label->setPixmap(QPixmap::fromImage(image.rgbSwapped()));
1436
	// Create a unique file name
1585
	   // Create a unique file name
1437
//	pid = getpid();
1586
//	   pid = getpid();
1438
//	OutBuf.sprintf("/var/tmp/SportWatcher_%d.png", pid);
1587
//	   OutBuf.sprintf("/var/tmp/SportWatcher_%d.png", pid);
1439
//	save_to_file<ImageData32>(buf.data(), OutBuf.toAscii().data(), "png");
1588
//	   save_to_file<ImageData32>(buf.data(), OutBuf.toAscii().data(), "png");
-
 
1589
	}
-
 
1590
 
-
 
1591
	catch (const mapnik::config_error &ex)
-
 
1592
	{
-
 
1593
	   KMessageBox::error(0, i18n("Configuration error: %1").arg(ex.what()));
-
 
1594
	   return false;
-
 
1595
	}
-
 
1596
 
-
 
1597
	catch (const std::exception &ex)
-
 
1598
	{
-
 
1599
	   KMessageBox::error(0, i18n("Exception at file %1: %2").arg(XmlPath).arg(ex.what()));
-
 
1600
	   return false;
-
 
1601
	}
-
 
1602
 
-
 
1603
	catch (...)
-
 
1604
	{
-
 
1605
	   KMessageBox::error(0, i18n("Unknown exception occured!"));
-
 
1606
	   return false;
-
 
1607
	}
1440
 
1608
 
1441
	return true;
1609
	return true;
1442
}
1610
}
1443
 
1611
 
1444
void SRender::setMaxExtent(double lx, double ly, double rx, double ry)
1612
void SRender::setMaxExtent(double lx, double ly, double rx, double ry)
Line 1639... Line 1807...
1639
 
1807
 
1640
RULE *SRender::allocRule()
1808
RULE *SRender::allocRule()
1641
{
1809
{
1642
RULE *Ru = new RULE;
1810
RULE *Ru = new RULE;
1643
 
1811
 
-
 
1812
	Ru->name.clear();
-
 
1813
	Ru->title.clear();
1644
	Ru->maxscale = 0;
1814
	Ru->maxscale = 0;
1645
	Ru->minscale = 0;
1815
	Ru->minscale = 0;
-
 
1816
	Ru->elsefilter = false;
1646
	Ru->filter.clear();
1817
	Ru->filter.clear();
1647
	Ru->LineSymbolizer = 0;
1818
	Ru->LineSymbolizer = 0;
1648
	Ru->PolygonSymbolizer = 0;
1819
	Ru->PolygonSymbolizer = 0;
1649
	Ru->TextSymbolizer = 0;
1820
	Ru->TextSymbolizer = 0;
1650
	Ru->PointSymbolizer = 0;
1821
	Ru->PointSymbolizer = 0;
Line 1658... Line 1829...
1658
LAYER *SRender::allocLayer()
1829
LAYER *SRender::allocLayer()
1659
{
1830
{
1660
LAYER *La = new LAYER;
1831
LAYER *La = new LAYER;
1661
 
1832
 
1662
	La->name.clear();	// The unique name
1833
	La->name.clear();	// The unique name
-
 
1834
	La->title.clear();
-
 
1835
	La->abstract.clear();
1663
	La->status = false;	// Is it active?
1836
	La->status = false;	// Is it active?
-
 
1837
	La->clear_label = false;
1664
	La->srs.clear();	// Projection
1838
	La->srs.clear();	// Projection
1665
	La->minzoom = 0.0;
1839
	La->minzoom = 0.0;
1666
	La->maxzoom = 0.0;
1840
	La->maxzoom = 0.0;
-
 
1841
	La->queryable = false;
1667
	La->Datasource.type.clear();
1842
	La->Datasource.type.clear();
1668
	La->Datasource.file.clear();
1843
	La->Datasource.file.clear();
-
 
1844
	La->Datasource.parser.clear();
-
 
1845
	La->Datasource.url.clear();
-
 
1846
	La->Datasource.bbox.clear();
1669
	La->Datasource.host.clear();
1847
	La->Datasource.host.clear();
1670
	La->Datasource.user.clear();
1848
	La->Datasource.user.clear();
1671
	La->Datasource.dbname.clear();
1849
	La->Datasource.dbname.clear();
1672
	La->Datasource.table.clear();
1850
	La->Datasource.table.clear();
1673
	La->Datasource.estimate_extent = false;
1851
	La->Datasource.estimate_extent = false;
Line 1742... Line 1920...
1742
{
1920
{
1743
TEXTSYMBOLIZER *ts = new TEXTSYMBOLIZER;
1921
TEXTSYMBOLIZER *ts = new TEXTSYMBOLIZER;
1744
 
1922
 
1745
	ts->name.clear();
1923
	ts->name.clear();
1746
	ts->face_name.clear();
1924
	ts->face_name.clear();
-
 
1925
	ts->placement.clear();
-
 
1926
	ts->alignment.clear();
1747
	ts->size = 0;
1927
	ts->size = 0;
1748
	ts->fill = 0;			// Color
1928
	ts->fill = 0;			// Color
1749
	ts->halo_radius = 0;
1929
	ts->halo_radius = 0;
1750
	ts->wrap_width = 0;
1930
	ts->wrap_width = 0;
1751
	ts->dx = 0.0;
1931
	ts->dx = 0.0;