⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 svg_interactive_map.cpp

📁 这是一个GPS相关的程序
💻 CPP
📖 第 1 页 / 共 5 页
字号:
const wxChar * CSVG_Interactive_Map::_Get_Code_Slider(void)
{
	return( SG_STR_MBTOSG(
		"//slider properties\n"
		"function slider(x1,y1,value1,x2,y2,value2,startVal,sliderGroupId,sliderColor,visSliderWidth,invisSliderWidth,sliderSymb,functionToCall,mouseMoveBool) {\n"
		"	this.x1 = x1;\n"
		"	this.y1 = y1;\n"
		"	this.value1 = value1;\n"
		"	this.x2 = x2;\n"
		"	this.y2 = y2;\n"
		"	this.value2 = value2;\n"
		"	this.startVal = startVal;\n"
		"	this.value = startVal;\n"
		"	this.sliderGroupId = sliderGroupId;\n"
		"	this.sliderGroup = document.getElementById(this.sliderGroupId);\n"
		"	this.sliderColor = sliderColor;\n"
		"	this.visSliderWidth = visSliderWidth;\n"
		"	this.invisSliderWidth = invisSliderWidth;\n"
		"	this.sliderSymb = sliderSymb;\n"
		"	this.functionToCall = functionToCall;\n"
		"	this.mouseMoveBool = mouseMoveBool;\n"
		"	this.length = toPolarDist((this.x2 - this.x1),(this.y2 - this.y1));\n"
		"	this.direction = toPolarDir((this.x2 - this.x1),(this.y2 - this.y1));\n"
		"	this.sliderLine = null;\n"
		"	this.createSlider();\n"
		"	this.slideStatus = 0;\n"
		"}\n"
		"\n"
		"//create slider\n"
		"slider.prototype.createSlider = function() {\n"
		"	this.sliderLine = document.createElementNS(svgNS,\"line\"));\n"
		"	this.sliderLine.setAttributeNS(null,\"x1\"),this.x1);\n"
		"	this.sliderLine.setAttributeNS(null,\"y1\"),this.y1);\n"
		"	this.sliderLine.setAttributeNS(null,\"x2\"),this.x2);\n"
		"	this.sliderLine.setAttributeNS(null,\"y2\"),this.y2);\n"
		"	this.sliderLine.setAttributeNS(null,\"stroke\"),this.sliderColor);\n"
		"	this.sliderLine.setAttributeNS(null,\"stroke-width\"),this.invisSliderWidth);\n"
		"	this.sliderLine.setAttributeNS(null,\"opacity\"),\"0\"));\n"
		"	this.sliderLine.setAttributeNS(null,\"stroke-linecap\"),\"square\"));\n"
		"	this.sliderLine.setAttributeNS(null,\"id\"),this.sliderGroupId+\"_invisibleSliderLine\"));\n"
		"	this.sliderLine.addEventListener(\"mousedown\"),this,false);\n"
		"	this.sliderGroup.appendChild(this.sliderLine);\n"
		"	var mySliderLine = document.createElementNS(svgNS,\"line\"));\n"
		"	mySliderLine.setAttributeNS(null,\"x1\"),this.x1);\n"
		"	mySliderLine.setAttributeNS(null,\"y1\"),this.y1);\n"
		"	mySliderLine.setAttributeNS(null,\"x2\"),this.x2);\n"
		"	mySliderLine.setAttributeNS(null,\"y2\"),this.y2);\n"
		"	mySliderLine.setAttributeNS(null,\"stroke\"),this.sliderColor);\n"
		"	mySliderLine.setAttributeNS(null,\"stroke-width\"),this.visSliderWidth);\n"
		"	mySliderLine.setAttributeNS(null,\"id\"),this.sliderGroupId+\"_visibleSliderLine\"));\n"
		"	mySliderLine.setAttributeNS(null,\"pointer-events\"),\"none\"));\n"
		"	this.sliderGroup.appendChild(mySliderLine);\n"
		"	mySliderSymb = document.createElementNS(svgNS,\"use\"));\n"
		"	mySliderSymb.setAttributeNS(xlinkNS,\"xlink:href\"),\"#\"+this.sliderSymb);\n"
		"	var myStartDistance = this.length - ((this.value2 - this.startVal) / (this.value2 - this.value1)) * this.length;\n"
		"	var myPosX = this.x1 + toRectX(this.direction,myStartDistance);\n"
		"	var myPosY = this.y1 + toRectY(this.direction,myStartDistance);\n"
		"	var myTransformString = \"translate(\"+myPosX+\"),\"+myPosY+\")) rotate(\" + Math.round(this.direction / Math.PI * 180) + \"))\");\n"
		"	mySliderSymb.setAttributeNS(null,\"transform\"),myTransformString);\n"
		"	mySliderSymb.setAttributeNS(null,\"id\"),this.sliderGroupId+\"_sliderSymbol\"));\n"
		"	this.sliderGroup.appendChild(mySliderSymb);\n"
		"}\n"
		"\n"
		"//remove all slider elements\n"
		"slider.prototype.removeSlider = function() {\n"
		"	var mySliderSymb = document.getElementById(this.sliderGroup+\"_sliderSymbol\"));\n"
		"	this.sliderGroup.removeChild(mySliderSymb);\n"
		"	var mySliderLine = document.getElementById(this.sliderGroup+\"_visibleSliderLine\"));\n"
		"	this.sliderGroup.removeChild(mySliderLine);\n"
		"	var mySliderLine = document.getElementById(this.sliderGroup+\"_invisibleSliderLine\"));\n"
		"	this.sliderGroup.removeChild(mySliderLine);\n"
		"}\n"
		"\n"
		"//handle events\n"
		"slider.prototype.handleEvent = function(evt) {\n"
		"	this.drag(evt);\n"
		"}\n"
		"\n"
		"//drag slider\n"
		"slider.prototype.drag = function(evt) {\n"
		"	if (evt.type == \"mousedown\" || (evt.type == \"mousemove\" && this.slideStatus == 1)) {\n"
		"	//get coordinate in slider coordinate system\n"
		"	var coordPoint = myMapApp.calcCoord(evt,this.sliderLine);\n"
		"	//draw normal line for first vertex\n"
		"	var ax = this.x2 - this.x1;\n"
		"	var ay = this.y2 - this.y1;\n"
		"	//normal vector 1\n"
		"	var px1 = parseFloat(this.x1) + ay * -1;\n"
		"	var py1 = parseFloat(this.y1) + ax;\n"
		"	//normal vector 2\n"
		"	var px2 = parseFloat(this.x2) + ay * -1;\n"
		"	var py2 = parseFloat(this.y2) + ax;\n"
		"		\n"
		"	if (leftOfTest(coordPoint.x,coordPoint.y,this.x1,this.y1,px1,py1) == 0 && leftOfTest(coordPoint.x,coordPoint.y,this.x2,this.y2,px2,py2) == 1) {\n"
		"		if (evt.type == \"mousedown\" && evt.detail == 1) {\n"
		"		this.slideStatus = 1;\n"
		"		document.documentElement.addEventListener(\"mousemove\"),this,false);\n"
		"		document.documentElement.addEventListener(\"mouseup\"),this,false);\n"
		"		}\n"
		"		myNewPos = intersect2lines(this.x1,this.y1,this.x2,this.y2,coordPoint.x,coordPoint.y,coordPoint.x + ay * -1,coordPoint.y + ax);\n"
		"		var myPercentage = toPolarDist(myNewPos['x'] - this.x1,myNewPos['y'] - this.y1) / this.length;\n"
		"		this.value = this.value1 + myPercentage * (this.value2 - this.value1);\n"
		"	}\n"
		"	else {\n"
		"		var myNewPos = new Array();\n"
		"		if (leftOfTest(coordPoint.x,coordPoint.y,this.x1,this.y1,px1,py1) == 0 && leftOfTest(coordPoint.x,coordPoint.y,this.x2,this.y2,px2,py2) == 0) {\n"
		"		//more than max\n"
		"		this.value = this.value2;\n"
		"		myNewPos['x'] = this.x2;\n"
		"		myNewPos['y'] = this.y2;\n"
		"		}\n"
		"		if (leftOfTest(coordPoint.x,coordPoint.y,this.x1,this.y1,px1,py1) == 1 && leftOfTest(coordPoint.x,coordPoint.y,this.x2,this.y2,px2,py2) == 1) {\n"
		"		//less than min\n"
		"		this.value = this.value1;\n"
		"		myNewPos['x'] = this.x1;\n"
		"		myNewPos['y'] = this.y1;\n"
		"		}\n"
		"	}\n"
		"	var myTransformString = \"translate(\"+myNewPos['x']+\"),\"+myNewPos['y']+\")) rotate(\" + Math.round(this.direction / Math.PI * 180) + \"))\");\n"
		"	document.getElementById(this.sliderGroupId+\"_sliderSymbol\")).setAttributeNS(null,\"transform\"),myTransformString);\n"
		"	this.getValue();\n"
		"	}\n"
		"	if (evt.type == \"mouseup\" && evt.detail == 1) {\n"
		"	if (this.slideStatus == 1) {\n"
		"		this.slideStatus = 2;\n"
		"		document.documentElement.removeEventListener(\"mousemove\"),this,false);\n"
		"		document.documentElement.removeEventListener(\"mouseup\"),this,false);\n"
		"		this.getValue();\n"
		"	}\n"
		"	this.slideStatus = 0;\n"
		"	}\n"
		"}\n"
		"\n"
		"//this code is executed, after the slider is released\n"
		"//you can use switch/if to detect which slider was used (use this.sliderGroup) for that\n"
		"slider.prototype.getValue = function() {\n"
		"	if (this.slideStatus == 1 && this.mouseMoveBool == true) {\n"
		"	if (typeof(this.functionToCall) == \"function\")) {\n"
		"		this.functionToCall(\"change\"),this.sliderGroupId,this.value);\n"
		"	}\n"
		"	if (typeof(this.functionToCall) == \"object\")) {\n"
		"		this.functionToCall.getSliderVal(\"change\"),this.sliderGroupId,this.value);\n"
		"	}\n"
		"	if (typeof(this.functionToCall) == \"string\")) {\n"
		"		eval(this.functionToCall+\"('change','\"+this.sliderGroupId+\"',\"+this.value+\"))\"));\n"
		"	}\n"
		"	}\n"
		"	if (this.slideStatus == 2) {\n"
		"	if (typeof(this.functionToCall) == \"function\")) {\n"
		"		this.functionToCall(\"release\"),this.sliderGroupId,this.value);\n"
		"	}\n"
		"	if (typeof(this.functionToCall) == \"object\")) {\n"
		"		this.functionToCall.getSliderVal(\"release\"),this.sliderGroupId,this.value);\n"
		"	}\n"
		"	if (typeof(this.functionToCall) == \"string\")) {\n"
		"		eval(this.functionToCall+\"('release','\"+this.sliderGroupId+\"',\"+this.value+\"))\"));\n"
		"	}\n"
		"	}\n"
		"}	\n"
		"\n"
		"//this is to set the value from other scripts\n"
		"slider.prototype.setValue = function(value) {\n"
		"	var myPercAlLine = (value - this.value1) / (this.value2 - this.value1);\n"
		"	this.value = myPercAlLine;\n"
		"	var myPosX = this.x1 + toRectX(this.direction,this.length * myPercAlLine);\n"
		"	var myPosY = this.y1 + toRectY(this.direction,this.length * myPercAlLine);\n"
		"	var myTransformString = \"translate(\"+myPosX+\"),\"+myPosY+\")) rotate(\" + Math.round(this.direction / Math.PI * 180) + \"))\");\n"
		"	document.getElementById(this.sliderGroupId+\"_sliderSymbol\")).setAttributeNS(null,\"transform\"),myTransformString);\n"
		"}\n"
		"\n"
	));
}

//---------------------------------------------------------
const wxChar * CSVG_Interactive_Map::_Get_Code_Helper(void)
{
	return( SG_STR_MBTOSG(
		"/*\n"
		"ECMAScript helper functions\n"
		"Copyright (C) <2004>	<Andreas Neumann>\n"
		"Version 1.1, 2004-11-18\n"
		"neumann@karto.baug.ethz.ch\n"
		"http://www.carto.net/\n"
		"http://www.carto.net/neumann/\n"
		"\n"
		"Credits: numerous people on svgdevelopers@yahoogroups.com\n"
		"\n"
		"This ECMA script library is free software; you can redistribute it and/or\n"
		"modify it under the terms of the GNU Lesser General Public\n"
		"License as published by the Free Software Foundation; either\n"
		"version 2.1 of the License, or (at your option) any later version.\n"
		"\n"
		"This library is distributed in the hope that it will be useful,\n"
		"but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
		"MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.	See the GNU\n"
		"Lesser General Public License for more details.\n"
		"\n"
		"You should have received a copy of the GNU Lesser General Public\n"
		"License along with this library (http://www.carto.net/papers/svg/resources/lesser_gpl.txt); if not, write to the Free Software\n"
		"Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA	02111-1307	USA\n"
		"\n"
		"----\n"
		"\n"
		"original document site: http://www.carto.net/papers/svg/resources/helper_functions.js\n"
		"Please contact the author in case you want to use code or ideas commercially.\n"
		"If you use this code, please include this copyright header, the included full\n"
		"LGPL 2.1 text and read the terms provided in the LGPL 2.1 license\n"
		"(http://www.gnu.org/copyleft/lesser.txt)\n"
		"\n"
		"-------------------------------\n"
		"\n"
		"Please report bugs and send improvements to neumann@karto.baug.ethz.ch\n"
		"If you use these scripts, please link to the original (http://www.carto.net/papers/svg/navigationTools/)\n"
		"somewhere in the source-code-comment or the \"about\" of your project and give credits, thanks!\n"
		"\n"
		"*/\n"
		"\n"
		"//global variables necessary to create elements in these namespaces, do not delete them!!!!\n"
		"var svgNS = \"http://www.w3.org/2000/svg\");\n"
		"var xlinkNS = \"http://www.w3.org/1999/xlink\");\n"
		"var cartoNS = \"http://www.carto.net/attrib\");\n"
		"var attribNS = \"http://www.carto.net/attrib\");\n"
		"var batikNS = \"http://xml.apache.org/batik/ext\");\n"
		"\n"
		"/* ----------------------- helper functions to calculate stuff ---------------- */\n"
		"/* ---------------------------------------------------------------------------- */\n"
		"function toPolarDir(xdiff,ydiff) { // Subroutine for calculating polar Coordinates\n"
		"	direction = (Math.atan2(ydiff,xdiff));\n"
		"	//result is angle in radian\n"
		"	return(direction);\n"
		"}\n"
		"\n"
		"function toPolarDist(xdiff,ydiff) { // Subroutine for calculating polar Coordinates\n"
		"	distance = Math.sqrt(xdiff * xdiff + ydiff * ydiff);\n"
		"	return(distance);\n"
		"}\n"
		"\n"
		"function toRectX(direction,distance) { // Subroutine for calculating cartesic coordinates\n"
		"	x = distance * Math.cos(direction);\n"
		"	y = distance * Math.sin(direction);\n"
		"	return(x);\n"
		"}\n"
		"\n"
		"function toRectY(direction,distance) { // Subroutine for calculating cartesic coordinates\n"
		"	x = distance * Math.cos(direction);\n"
		"	y = distance * Math.sin(direction);\n"
		"	return(y);\n"
		"}\n"
		"\n"
		"//Converts degrees to radians.\n"
		"function DegToRad(deg) {\n"
		"	return (deg / 180.0 * Math.PI);\n"
		"}\n"
		"\n"
		"//Converts radians to degrees.\n"
		"function RadToDeg(rad) {\n"
		"	return (rad / Math.PI * 180.0);\n"
		"}\n"
		"\n"
		"//converts decimal degrees to degree/minutes/seconds\n"
		"function dd2dms(dd) {\n"
		"	var minutes = (dd - Math.floor(dd)) * 60;\n"
		"	var seconds = (minutes - Math.floor(minutes)) * 60;\n"
		"	var minutes = Math.floor(minutes);\n"
		"	var degrees = Math.floor(dd);\n"
		"	return {deg:degrees,min:minutes,sec:seconds};\n"
		"}\n"
		"\n"
		"//converts degree/minutes/seconds to decimal degrees\n"
		"function dms2dd(deg,min,sec) {\n"
		"	return deg + (min / 60) + (sec / 3600);\n"
		"}\n"
		"\n"
		"//log functions that do not exist in Math object\n"
		"function log(x,b) {\n"
		"	if(b==null) b=Math.E;\n"
		"	return Math.log(x)/Math.log(b);\n"
		"}\n"
		"\n"
		"//gets 4 z-values (4 corners), a position, delta x and delty and a cellsize as input and returns interpolated z-value\n"
		"function intBilinear(za,zb,zc,zd,xpos,ypos,ax,ay,cellsize) { //bilinear interpolation function\n"
		"	e = (xpos - ax) / cellsize;\n"
		"	f = (ypos - ay) / cellsize;\n"
		"\n"
		"	//calculation of weights\n"
		"	wa = (1 - e) * (1 - f);\n"
		"	wb = e * (1 - f);\n"
		"	wc = e * f;\n"
		"	wd = f * (1 - e);\n"
		"\n"
		"	height_interpol = wa * zc + wb * zd + wc * za + wd * zb;\n"
		"\n"
		"	return (height_interpol);	\n"
		"}\n"
		"\n"
		"//test if point is left of or right of, result is 1 (leftof) or 0 (rightof)\n"
		"function leftOfTest(pointx,pointy,linex1,liney1,linex2,liney2) {\n"
		"	result = (liney1 - pointy) * (linex2 - linex1) - (linex1 - pointx) * (liney2 - liney1);\n"
		"	if (result < 0) {\n"
		"	leftof = 1; //case left of\n"
		"	}\n"
		"	else {\n"
		"	leftof = 0; //case left of	\n"
		"	}\n"
		"	return(leftof);\n"
		"}\n"
		"\n"
		"//input is point coordinate, and 2 line coordinates\n"
		"function distFromLine(xpoint,ypoint,linex1,liney1,linex2,liney2) {\n"
		"	dx = linex2 - linex1;\n"
		"	dy = liney2 - liney1;\n"
		"	distance = (dy * (xpoint - linex1) - dx * (ypoint - liney1)) / Math.sqrt(Math.pow(dx,2) + Math.pow(dy,2));\n"
		"	return(distance);\n"
		"}\n"
		"\n"
		"//converts radian value to degrees\n"
		"function radian2deg(radian) {\n"
		"	deg = radian / Math.PI * 180;\n"
		"	return(deg);\n"
		"}\n"
		"\n"
		"//input is two vectors (a1,a2 is vector a, b1,b2 is vector b), output is angle in radian\n"
		"//Formula: Acos from	Scalaproduct of the two vectors divided by ( norm (deutsch Betrag) vector 1 by norm vector 2\n"

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -