📄 svg_interactive_map.cpp
字号:
" <circle fill=\"dimgray\" cx=\"0\" cy=\"0\" r=\"1\" pointer-events=\"none\"/>\n"
" <g fill=\"none\" stroke=\"dimgray\" stroke-width=\"1.5\" pointer-events=\"none\">\n"
" <line x1=\"-7\" y1=\"-7\" x2=\"-3\" y2=\"-3\"/>\n"
" <line x1=\"7\" y1=\"7\" x2=\"3\" y2=\"3\"/>\n"
" <line x1=\"-7\" y1=\"7\" x2=\"-3\" y2=\"3\"/>\n"
" <line x1=\"7\" y1=\"-7\" x2=\"3\" y2=\"-3\"/>\n"
" </g>\n"
" </symbol>\n"
" <!-- Symbol for Slider -->\n"
" <symbol id=\"sliderSymbol\" overflow=\"visible\" pointer-events=\"none\">\n"
" <line x1=\"0\" y1=\"-5\" x2=\"0\" y2=\"5\" fill=\"none\" stroke=\"dimgray\" stroke-width=\"5\"/>\n"
" </symbol>\n"
" <!-- Symbol for Dragging if zoomed in far -->\n"
" <symbol id=\"myDragCrossSymbol\" overflow=\"visible\" stroke-width=\"2000\" fill=\"none\" stroke=\"darkblue\" pointer-events=\"none\">\n"
" <line x1=\"-7000\" y1=\"0\" x2=\"-2500\" y2=\"0\"/>\n"
" <line x1=\"7000\" y1=\"0\" x2=\"2500\" y2=\"0\"/>\n"
" <line x1=\"0\" y1=\"-3300\" x2=\"0\" y2=\"-7800\"/>\n"
" <line x1=\"0\" y1=\"3300\" x2=\"0\" y2=\"7800\"/>\n"
" </symbol>\n"
" <!-- Marker for Extent-Arrows -->\n"
" <marker id=\"myStartArrow\" overflow=\"visible\" orient=\"auto\">\n"
" <polyline fill=\"dimgray\" points=\"-0.5,0 8,-2 8,2\"/>\n"
" </marker>\n"
" <marker id=\"myEndArrow\" overflow=\"visible\" orient=\"auto\">\n"
" <polyline fill=\"dimgray\" points=\"0.5,0 -8,-2 -8,2\"/>\n"
" </marker>\n"
" </defs>\n"
" <rect x=\"-500\" y=\"-500\" width=\"3000\" height=\"3000\" stroke=\"none\" fill=\"aliceblue\" />\n"
" <!-- Main Map Frame -->\n"
" <svg id=\"mainMap\" x=\"0\" y=\"15\" width=\"550\" height=\"700\" cursor=\"crosshair\" "
));
}
///////////////////////////////////////////////////////////
// //
// //
// //
///////////////////////////////////////////////////////////
//---------------------------------------------------------
void CSVG_Interactive_Map::_Add_ReferenceMap(CSG_Shapes *pIndexLayer, CSG_Rect r)
{
int i;
CSG_String sViewBox;
double Line_Width, Point_Width;
double Width, Height;
double OffsetX, OffsetY;
CSG_Shape *pShape;
if (r.Get_XRange() / r.Get_YRange() > MAP_WINDOW_WIDTH / MAP_WINDOW_HEIGHT)
{
Width = r.Get_XRange();
Height = r.Get_XRange() * MAP_WINDOW_HEIGHT / MAP_WINDOW_WIDTH;
}
else
{
Height = r.Get_YRange();
Width = r.Get_YRange() / MAP_WINDOW_HEIGHT * MAP_WINDOW_WIDTH;
}
OffsetX = (Width - r.Get_XRange()) / 2.;
OffsetY = (Height - r.Get_YRange()) / 2.;
sViewBox.Append(SG_Get_String(r.Get_XMin() - OffsetX,2));
sViewBox.Append(wxT(" "));
sViewBox.Append(SG_Get_String(- r.Get_YMax() - OffsetY,2));
sViewBox.Append(wxT(" "));
sViewBox.Append(SG_Get_String(Width,2));
sViewBox.Append(wxT(" "));
sViewBox.Append(SG_Get_String(Height,2));
_AddAttribute(wxT("viewBox"), sViewBox);
m_sSVGCode.Append(_Get_Code_3());
if (pIndexLayer)
{
m_sSVGCode.Append(wxT("<g id=\"index\">\n"));
for (i = 0; i < pIndexLayer->Get_Count(); i++)
{
pShape = pIndexLayer->Get_Shape(i);
Line_Width = Point_Width = m_dWidth / MAP_WINDOW_WIDTH;
Point_Width *= 5;
_Add_Shape(pShape, 0, 0, Line_Width, Point_Width);
}
m_sSVGCode.Append(wxT("</g>\n"));
}
m_sSVGCode.Append(_Get_Code_4());
_AddAttribute(wxT("x"), r.Get_XMin() - OffsetX);
_AddAttribute(wxT("y"), - r.Get_YMax() - OffsetY);
_AddAttribute(wxT("width"), Width);
_AddAttribute(wxT("height"), Height);
m_sSVGCode.Append(_Get_Code_5());
}
//---------------------------------------------------------
void CSVG_Interactive_Map::_Add_Grid(CWKSP_Grid *pLayer)
{
wxString Filename;
wxBitmap BMP;
if( pLayer->Get_Image_Grid(BMP) )
{
Filename = SG_File_Make_Path(m_Directory.c_str(), pLayer->Get_Object()->Get_Name(), wxT("jpg"));
BMP.SaveFile(Filename, wxBITMAP_TYPE_JPEG);
m_sSVGCode.Append(wxT("<image "));
_AddAttribute(wxT("id") , pLayer->Get_Object()->Get_Name());
_AddAttribute(wxT("x") , ((CSG_Grid *)pLayer->Get_Object())->Get_XMin());
_AddAttribute(wxT("y") ,-((CSG_Grid *)pLayer->Get_Object())->Get_YMax());
_AddAttribute(wxT("width") , ((CSG_Grid *)pLayer->Get_Object())->Get_XRange());
_AddAttribute(wxT("height") , ((CSG_Grid *)pLayer->Get_Object())->Get_YRange());
_AddAttribute(wxT("xlink:href") , SG_File_Get_Name(Filename, true));
m_sSVGCode.Append(wxT("/>"));
}
}
//---------------------------------------------------------
void CSVG_Interactive_Map::_Add_Shapes(CWKSP_Shapes *pLayer)
{
int i;
int iColorField;
int Line_Color, Fill_Color;
double Line_Width, Point_Width;
double dSize;
CSG_Shape *pShape;
CSG_String sLabel;
m_sSVGCode.Append(wxT("<g id=\""));
m_sSVGCode.Append(pLayer->Get_Object()->Get_Name());
m_sSVGCode.Append(wxT("\" >\n"));
iColorField = pLayer->Get_Color_Field();
m_sSVGCode.Append(wxT("<g transform=\"scale(1,-1)\">\n"));
for (i = 0; i < ((CSG_Shapes*)pLayer->Get_Object())->Get_Count(); i++)
{
pShape = pLayer->Get_Shapes()->Get_Shape(i);
Line_Color = Fill_Color = pLayer->Get_Classifier()->Get_Class_Color_byValue(pShape->Get_Record()->asDouble(iColorField));
Line_Width = Point_Width = m_dWidth / MAP_WINDOW_WIDTH;
Point_Width *= 5;
_Add_Shape(pShape, Fill_Color, Line_Color, Line_Width, Point_Width);
}
if (pLayer->Get_Label_Field() >= 0)
{
m_sSVGCode.Append(wxT("<g transform=\"scale(0.01,-0.01)\"\n>"));
for (i = 0; i < ((CSG_Shapes*)pLayer->Get_Object())->Get_Count(); i++)
{
pShape = pLayer->Get_Shapes()->Get_Shape(i);
Line_Width = Point_Width = m_dWidth / MAP_WINDOW_WIDTH;
sLabel = (pShape)->Get_Record()->asString(pLayer->Get_Label_Field());
switch( pLayer->Get_Parameters()->Get_Parameter(wxT("LABEL_ATTRIB_SIZE_TYPE"))->asInt() )
{
case 0: default:
dSize = Line_Width * pLayer->Get_Parameters()->Get_Parameter(wxT("LABEL_ATTRIB_FONT"))->asFont()->GetPointSize();
_Add_Label(sLabel, pShape, dSize, wxT("%"));
break;
case 1:
dSize = pLayer->Get_Parameters()->Get_Parameter(wxT("LABEL_ATTRIB_SIZE"))->asDouble();
_Add_Label(sLabel, pShape, dSize, wxT(""));
break;
}
}
m_sSVGCode.Append(wxT("</g>\n"));
}
m_sSVGCode.Append(wxT("</g>\n</g>\n"));
}
//---------------------------------------------------------
void CSVG_Interactive_Map::_Add_Label(const wxChar* Label, CSG_Shape *pShape, double dSize, const wxChar* Unit)
{
int iPoint, iPart;
TSG_Point Point;
switch( pShape->Get_Type() )
{
case SHAPE_TYPE_Point:
case SHAPE_TYPE_Points:
for(iPoint=0; iPoint < pShape->Get_Point_Count(0); iPoint++)
{
Point = pShape->Get_Point(iPoint);
Draw_Text(100 * Point.x, -100 * Point.y, Label, 0, wxT("Verdana"), 100 * dSize, Unit);
}
break;
case SHAPE_TYPE_Line:
///************///
break;
case SHAPE_TYPE_Polygon:
for (iPart = 0; iPart < pShape->Get_Part_Count(); iPart++)
{
if(! ((CSG_Shape_Polygon *)pShape)->is_Lake(iPart) )
{
Point = ((CSG_Shape_Polygon *)pShape)->Get_Centroid(iPart);
Draw_Text(100 * Point.x, -100 * Point.y, Label, 0, wxT("Verdana"), 100 * dSize, Unit);
}
}
break;
}
}
//---------------------------------------------------------
bool CSVG_Interactive_Map::_Add_Shape(CSG_Shape *pShape, int Fill_Color, int Line_Color, double Line_Width, double Point_Width)
{
if( pShape && pShape->is_Valid() )
{
int iPart, iPoint;
TSG_Point Point;
CSG_Points Points;
for(iPart=0; iPart<pShape->Get_Part_Count(); iPart++)
{
Points.Clear();
for(iPoint=0; iPoint<pShape->Get_Point_Count(iPart); iPoint++)
{
Point = pShape->Get_Point(iPoint, iPart);
Points.Add(Point.x, Point.y);
}
switch( pShape->Get_Type() )
{
case SHAPE_TYPE_Point:
case SHAPE_TYPE_Points:
for(iPoint=0; iPoint<Points.Get_Count(); iPoint++)
{
Draw_Circle(Points[iPoint].x, Points[iPoint].y, Point_Width, Fill_Color, 0, Line_Width, wxT(""));
}
break;
case SHAPE_TYPE_Line:
Draw_Line(Points, Line_Width, wxT(""), Line_Color);
break;
case SHAPE_TYPE_Polygon:
if( ((CSG_Shape_Polygon *)pShape)->is_Lake(iPart) )
{
Draw_Polygon(Points, -1, 0, 0.01, wxT("%"));
}
else
{
Draw_Polygon(Points, Fill_Color, 0, 0.01, wxT("%"));
}
break;
}
}
return( true );
}
return( false );
}
//---------------------------------------------------------
void CSVG_Interactive_Map::_Add_CheckBoxes(CWKSP_Map *pMap)
{
int i;
CSG_String s;
int x,y;
int iRow = 1;
m_sSVGCode.Append(_Get_Code_1()); // 2* <g> open
m_sSVGCode.Append(LNG("Layers"));
m_sSVGCode.Append(wxT("</text>\n"));
for (i = 0; i < pMap->Get_Count(); i++)
{
y = iRow * 30;
if (i % 2)
{
x = 200;
iRow++;
}
else
{
x = 0;
}
m_sSVGCode.Append(wxT("<g "));
s = wxT("translate(");
s.Append(SG_Get_String(x,0));
s.Append(wxT(" "));
s.Append(SG_Get_String(y,0));
s.Append(wxT("))"));
_AddAttribute(wxT("transform"), s);
m_sSVGCode.Append(wxT(">\n"));
m_sSVGCode.Append(wxT("<use "));
s = wxT("checkBox");
s.Append(pMap->Get_Layer(i)->Get_Layer()->Get_Object()->Get_Name());
_AddAttribute(wxT("id"), s);
_AddAttribute(wxT("xlink:href"), wxT("#checkBoxRect"));
s = wxT("checkBoxScript(evt,'");
s.Append(pMap->Get_Layer(i)->Get_Layer()->Get_Object()->Get_Name());
s.Append(wxT("');"));
_AddAttribute(wxT("onclick"), s);
m_sSVGCode.Append(wxT("/>\n"));
m_sSVGCode.Append(wxT("<use "));
s = wxT("checkCross");
s.Append(pMap->Get_Layer(i)->Get_Layer()->Get_Object()->Get_Name());
_AddAttribute(wxT("id"), s);
_AddAttribute(wxT("xlink:href"), wxT("#checkBoxCross"));
_AddAttribute(wxT("visibility"), wxT("visible"));
m_sSVGCode.Append(wxT("/>\n"));
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -