📄 svg_interactive_map.cpp
字号:
m_sSVGCode.Append(wxT("</g>\n"));
}
m_sSVGCode.Append(wxT("<g font-family=\"sans-serif\" fill=\"dimgray\" font-size=\"15px\" pointer-events=\"none\">\n"));
iRow = 1;
for (i = 0; i < pMap->Get_Count(); i++)
{
y = iRow * 30 + 6;
if (i % 2)
{
x = 212;
iRow++;
}
else
{
x = 12;
}
m_sSVGCode.Append(wxT("<text "));
_AddAttribute(wxT("x"), x);
_AddAttribute(wxT("y"), y);
m_sSVGCode.Append(wxT(">"));
m_sSVGCode.Append(pMap->Get_Layer(i)->Get_Layer()->Get_Object()->Get_Name());
m_sSVGCode.Append(wxT("</text>\n"));
}
m_sSVGCode.Append(wxT("</g>\n"));
m_sSVGCode.Append(_Get_Code_2());
}
///////////////////////////////////////////////////////////
// //
// //
// //
///////////////////////////////////////////////////////////
//---------------------------------------------------------
const wxChar * CSVG_Interactive_Map::_Get_Code_1(void)
{
return( SG_STR_MBTOSG(
"<g>\n"
" <g font-family=\"sans-serif\" fill=\"dimgray\" font-size=\"15px\" pointer-events=\"none\">"
" <text id=\"coordX\" x=\"745\" y=\"145\">X:</text>\n"
" <text id=\"coordY\" x=\"845\" y=\"145\">Y:</text>\n"
" </g>\n"
" <g>"
" <!-- vertical line, displays current height of map extent -->\n"
" <line stroke=\"dimgray\" stroke-width=\"1.5\" marker-start=\"url(#myStartArrow)\" marker-end=\"url(#myEndArrow)\" x1=\"561\" y1=\"15\" x2=\"561\" y2=\"715\"/>\n"
" <rect fill=\"aliceblue\" x=\"555\" y=\"330\" width=\"12\" height=\"70\"/>\n"
" <text id=\"myScaleTextH\" font-family=\"sans-serif\" fill=\"dimgray\" font-size=\"15px\" text-anchor=\"middle\" transform=\"translate(556,365),rotate(90)\" pointer-events=\"none\">-</text>\n"
" <!-- horizontal line, displays current width of map extent -->\n"
" <line stroke=\"dimgray\" stroke-width=\"1.5\" marker-start=\"url(#myStartArrow)\" marker-end=\"url(#myEndArrow)\" x1=\"0\" y1=\"723\" x2=\"553.1\" y2=\"723\"/>\n"
" <rect fill=\"aliceblue\" x=\"242\" y=\"717\" width=\"70\" height=\"12\"/>\n"
" <text id=\"myScaleTextW\" font-family=\"sans-serif\" fill=\"dimgray\" font-size=\"15px\" text-anchor=\"middle\" transform=\"translate(277,728)\" pointer-events=\"none\">-</text>\n"
" <!-- small rectangle in lower right corner, onclick displays current map extent in real world coordinates -->\n"
" <rect fill=\"dimgray\" x=\"558.5\" y=\"720.5\" width=\"5\" height=\"5\" onclick=\"showExtent()\" />\n"
" </g>\n"
" <g transform=\"translate(590 225)\">\n"
" <text font-family=\"sans-serif\" fill=\"dimgray\" font-size=\"18px\" font-weight=\"bold\" x=\"-10\" y=\"0\" pointer-events=\"none\">"
));
}
//---------------------------------------------------------
const wxChar * CSVG_Interactive_Map::_Get_Code_2(void)
{
return( SG_STR_MBTOSG(
"</g>\n"
" <g text-rendering=\"optimizeLegibility\" font-family=\"sans-serif\" fill=\"dimgray\" font-size=\"12px\">\n"
" <!-- text with this id is required to show help texts -->\n"
" <text id=\"statusText\" x=\"745\" y=\"125\">Statusbar: Your Status Text</text>\n"
" </g>\n"
"</g>\n"
"<svg id=\"referenceMap\" x=\"580\" y=\"45\" "
));
}
//---------------------------------------------------------
const wxChar * CSVG_Interactive_Map::_Get_Code_3(void)
{
return( SG_STR_MBTOSG(
"width=\"118.52\" height=\"150\" onmousedown=\"myMapApp.refMapDragger.handleEvent(evt)\" onmousemove=\"myMapApp.refMapDragger.handleEvent(evt)\" onmouseup=\"myMapApp.refMapDragger.handleEvent(evt)\" onmouseout=\"myMapApp.refMapDragger.handleEvent(evt)\" cursor=\"crosshair\">\n"
" <g transform=\"scale(1,-1)\"\n>"
));
}
//---------------------------------------------------------
const wxChar * CSVG_Interactive_Map::_Get_Code_4(void)
{
return( SG_STR_MBTOSG(
" </g>\n"
" <rect id=\"dragRectForRefMap\" fill=\"lightskyblue\" fill-opacity=\"0.4\" "
));
}
//---------------------------------------------------------
const wxChar * CSVG_Interactive_Map::_Get_Code_5(void)
{
return( SG_STR_MBTOSG(
" pointer-events=\"none\" />\n "
" <use id=\"myDragCross\" x=\"0\" y=\"0\" xlink:href=\"#myDragCrossSymbol\" visibility=\"hidden\" />\n"
" </svg>\n"
));
}
//---------------------------------------------------------
const wxChar * CSVG_Interactive_Map::_Get_Code_Closing_1(void)
{
return( SG_STR_MBTOSG(
" <g>\n"
" <!-- empty group where zoomSlider is later appended -->\n"
" <g id=\"mapZoomSlider\"/>\n"
" <!-- button for zoom-in, above slider -->\n"
" <g id=\"zoomIn\" cursor=\"pointer\" />\n"
" <!-- button for zoom-out, below slider -->\n"
" <g id=\"zoomOut\" cursor=\"pointer\" />\n"
" <!-- info button -->\n"
" <g id=\"infoButton\" cursor=\"pointer\" />\n"
" <!-- button for full view (f) -->\n"
" <g id=\"zoomFull\" cursor=\"pointer\" />\n"
" <!-- button for manual zoom (rectangle) -->\n"
" <g id=\"zoomManual\" cursor=\"pointer\" />\n"
" <!-- button for manual pan -->\n"
" <g id=\"panManual\" cursor=\"pointer\" />\n"
" <!-- button for redefining map center -->\n"
" <g id=\"recenterMap\" cursor=\"pointer\" />\n"
" <!-- button for backwarding map extent (extent history) -->\n"
" <g id=\"backwardExtent\" cursor=\"pointer\" />\n"
" <!-- button for forwarding map extent (extent history) -->\n"
" <g id=\"forwardExtent\" cursor=\"pointer\" />\n"
" </g>\n"
));
}
///////////////////////////////////////////////////////////
// //
// //
// //
///////////////////////////////////////////////////////////
//---------------------------------------------------------
const wxChar * CSVG_Interactive_Map::_Get_Code_CheckBox(void)
{
return( SG_STR_MBTOSG(
"function checkBoxScript(evt,myLayer) { //checkBox for toggling layers an contextMenue\n"
" var myLayerObj = document.getElementById(myLayer);\n"
" var myCheckCrossObj = document.getElementById(\"checkCross\"+myLayer);\n"
" var myCheckCrossVisibility = myCheckCrossObj.getAttributeNS(null,\"visibility\"));\n"
" if (evt.type == \"click\" && evt.detail == 1) {\n"
" if (myCheckCrossVisibility == \"visible\")) {\n"
" myLayerObj.setAttributeNS(null,\"visibility\"),\"hidden\"));\n"
" myCheckCrossObj.setAttributeNS(null,\"visibility\"),\"hidden\"));\n"
" //you can do if/else or switch statements to set different actions on activating a checkbox here\n"
" //myLayer holds the currentLayer name\n"
" }\n"
" else {\n"
" myLayerObj.setAttributeNS(null,\"visibility\"),\"visible\"));\n"
" myCheckCrossObj.setAttributeNS(null,\"visibility\"),\"visible\"));\n"
" }\n"
" }\n"
"}\n"
"\n"
));
}
//---------------------------------------------------------
const wxChar * CSVG_Interactive_Map::_Get_Code_MapApp(void)
{
return( SG_STR_MBTOSG(
"//holds data on window size\n"
"function mapApp() {\n"
" if (!document.documentElement.getScreenCTM) {\n"
" this.resetFactors();\n"
" //add resize event to document element\n"
" document.documentElement.addEventListener(\"SVGResize\"),this,false);\n"
" }\n"
"}\n"
"\n"
"mapApp.prototype.handleEvent = function(evt) {\n"
" if (evt.type == \"SVGResize\")) {\n"
" this.resetFactors();\n"
" }\n"
"}\n"
"\n"
"mapApp.prototype.resetFactors = function() {\n"
" if (!document.documentElement.getScreenCTM) {\n"
" //case for viewers that don't support .getScreenCTM, such as ASV3\n"
" //calculate ratio and offset values of app window\n"
" var viewBoxArray = document.documentElement.getAttributeNS(null,\"viewBox\")).split(\" \"));\n"
" var myRatio = viewBoxArray[2]/viewBoxArray[3];\n"
" if ((window.innerWidth/window.innerHeight) > myRatio) { //case window is more wide than myRatio\n"
" this.scaleFactor = viewBoxArray[3] / window.innerHeight;\n"
" }\n"
" else { //case window is more tall than myRatio\n"
" this.scaleFactor = viewBoxArray[2] / window.innerWidth;\n"
" }\n"
" this.offsetX = (window.innerWidth - viewBoxArray[2] * 1 / this.scaleFactor) / 2;\n"
" this.offsetY = (window.innerHeight - viewBoxArray[3] * 1 / this.scaleFactor) / 2;\n"
" }\n"
"}\n"
"\n"
"mapApp.prototype.calcCoord = function(evt,ctmNode) {\n"
" var svgPoint = document.documentElement.createSVGPoint();\n"
" svgPoint.x = evt.clientX;\n"
" svgPoint.y = evt.clientY;\n"
" if (!document.documentElement.getScreenCTM) {\n"
" //case ASV3 a. Corel\n"
" svgPoint.x = (svgPoint.x - this.offsetX) * this.scaleFactor;\n"
" svgPoint.y = (svgPoint.y - this.offsetY) * this.scaleFactor;\n"
" //undo the effect of transformations\n"
" if (ctmNode) {\n"
" var ctm = getTransformToRootElement(ctmNode).inverse();\n"
" }\n"
" else {\n"
" var ctm = getTransformToRootElement(evt.target).inverse();\n"
" }\n"
" svgPoint = svgPoint.matrixTransform(ctm);\n"
"\n"
" }\n"
" else {\n"
" if (ctmNode) {\n"
" var matrix = ctmNode.getScreenCTM();\n"
" }\n"
" else {\n"
" var matrix = evt.target.getScreenCTM();\n"
" }\n"
" svgPoint = svgPoint.matrixTransform(matrix.inverse());\n"
" }\n"
" return svgPoint;\n"
"}\n"
"\n"
));
}
//---------------------------------------------------------
const wxChar * CSVG_Interactive_Map::_Get_Code_Timer(void)
{
return( SG_STR_MBTOSG(
"// source/credits: \"Algorithm\": http://www.codingforums.com/showthread.php?s=&threadid=10531\n"
"// The constructor should be called with\n"
"// the parent object (optional, defaults to window).\n"
"\n"
"function Timer(){\n"
" this.obj = (arguments.length)?arguments[0]:window;\n"
" return this;\n"
"}\n"
"\n"
"// The set functions should be called with:\n"
"// - The name of the object method (as a string) (required)\n"
"// - The millisecond delay (required)\n"
"// - Any number of extra arguments, which will all be\n"
"// passed to the method when it is evaluated.\n"
"\n"
"Timer.prototype.setInterval = function(func, msec){\n"
" var i = Timer.getNew();\n"
" var t = Timer.buildCall(this.obj, i, arguments);\n"
" Timer.set[i].timer = window.setInterval(t,msec);\n"
" return i;\n"
"}\n"
"Timer.prototype.setTimeout = function(func, msec){\n"
" var i = Timer.getNew();\n"
" Timer.buildCall(this.obj, i, arguments);\n"
" Timer.set[i].timer = window.setTimeout(\"Timer.callOnce(\"+i+\"));\"),msec);\n"
" return i;\n"
"}\n"
"\n"
"// The clear functions should be called with\n"
"// the return value from the equivalent set function.\n"
"\n"
"Timer.prototype.clearInterval = function(i){\n"
" if(!Timer.set[i]) return;\n"
" window.clearInterval(Timer.set[i].timer);\n"
" Timer.set[i] = null;\n"
"}\n"
"Timer.prototype.clearTimeout = function(i){\n"
" if(!Timer.set[i]) return;\n"
" window.clearTimeout(Timer.set[i].timer);\n"
" Timer.set[i] = null;\n"
"}\n"
"\n"
"// Private data\n"
"\n"
"Timer.set = new Array();\n"
"Timer.buildCall = function(obj, i, args){\n"
" var t = \"\");\n"
" Timer.set[i] = new Array();\n"
" if(obj != window){\n"
" Timer.set[i].obj = obj;\n"
" t = \"Timer.set[\"+i+\"].obj.\");\n"
" }\n"
" t += args[0]+\"(\");\n"
" if(args.length > 2){\n"
" Timer.set[i][0] = args[2];\n"
" t += \"Timer.set[\"+i+\"][0]\");\n"
" for(var j=1; (j+2)<args.length; j++){\n"
" Timer.set[i][j] = args[j+2];\n"
" t += \"), Timer.set[\"+i+\"][\"+j+\"]\");\n"
" }}\n"
" t += \"));\");\n"
" Timer.set[i].call = t;\n"
" return t;\n"
"}\n"
"Timer.callOnce = function(i){\n"
" if(!Timer.set[i]) return;\n"
" eval(Timer.set[i].call);\n"
" Timer.set[i] = null;\n"
"}\n"
"Timer.getNew = function(){\n"
" var i = 0;\n"
" while(Timer.set[i]) i++;\n"
" return i;\n"
"}\n"
"\n"
));
}
//---------------------------------------------------------
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -