/
runtests.js
executable file
·86 lines (79 loc) · 2.97 KB
/
runtests.js
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
/* Loop through the test points and create a Proj object for each
*/
var src, dest;
function runTests() {
//src = new Proj4js.Proj(Proj4js.defs["WKT0"],cb2);
/*
src = new Proj4js.Proj("EPSG:900913",cb1);
var testPt = new Proj4js.Point([1113194.9079327357, 6800125.454397307]);
var testRes = Proj4js.transform(src, dest, testPt);
alert(testRes.toString());
*/
for (var i=0; i < Proj4js.testPoints.length; ++i) {
var test = Proj4js.testPoints[i];
var proj = new Proj4js.Proj(test.code, Proj4js.bind(showResults, this, test));
}
}
function cb1() {
dest = new Proj4js.Proj("EPSG:2303X",cb2);
}
function cb2(arg1) {
//alert('all set');
}
/* a callback function to run the test for this test point since we are using
the dynamic load capabilities in the test page
*/
function showResults(test, proj) {
//var test = proj.testPoint;
var xyEPSLN = 1.0e-2;
var llEPSLN = 1.0e-6;
var row = document.createElement('tr');
var td = document.createElement('td');
td.innerHTML = test.code;
row.appendChild(td);
var td = document.createElement('td');
td.innerHTML = proj.projName;
row.appendChild(td);
//transform from lon/lat to projected x/y and cmopare
var xyResult = Proj4js.transform(Proj4js.WGS84, proj, new Proj4js.Point(test.ll));
if (xyResult) {
var deltaX = Math.abs(xyResult.x - test.xy[0]);
var deltaY = Math.abs(xyResult.y - test.xy[1]);
td = document.createElement('td');
td.innerHTML = "in:"+test.ll[0]+","+test.ll[1];
row.appendChild(td);
td = document.createElement('td');
td.innerHTML = "out:"+xyResult.x+","+xyResult.y;
row.appendChild(td);
td = document.createElement('td');
td.innerHTML = "dx:"+deltaX+ " dy:"+deltaY;
if ( deltaX>xyEPSLN || deltaY>xyEPSLN ) td.style.backgroundColor='red';
row.appendChild(td);
} else {
td = document.createElement('td');
td.innerHTML = "proj undefined";
row.appendChild(td);
}
//transform from map x/y to lon/lat and compare
var llResult = Proj4js.transform(proj, Proj4js.WGS84, new Proj4js.Point(test.xy));
if (llResult) {
var deltaX = Math.abs(llResult.x - test.ll[0]);
var deltaY = Math.abs(llResult.y - test.ll[1]);
td = document.createElement('td');
td.innerHTML = "in:"+test.xy[0]+","+test.xy[1];
row.appendChild(td);
td = document.createElement('td');
td.innerHTML = "out:"+llResult.x+","+llResult.y;
row.appendChild(td);
td = document.createElement('td');
td.innerHTML = "dx:"+deltaX+ " dy:"+deltaY;
if ( deltaX>llEPSLN || deltaY>llEPSLN ) td.style.backgroundColor='red';
row.appendChild(td);
} else {
td = document.createElement('td');
td.innerHTML = "proj undefined";
row.appendChild(td);
}
var testTable = document.getElementById('testResult');
testTable.tBodies[0].appendChild(row);
};