~mortenoh/+junk/dhis2-detailed-import-export

« back to all changes in this revision

Viewing changes to gis/dhis-gis-geostat/mfbase/openlayers/tests/Layer/SphericalMercator.html

  • Committer: larshelge at gmail
  • Date: 2009-03-03 16:46:36 UTC
  • Revision ID: larshelge@gmail.com-20090303164636-2sjlrquo7ib1gf7r
Initial check-in

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<html>
 
2
<head>
 
3
    <script src="../../lib/OpenLayers.js"></script>
 
4
    <script type="text/javascript">
 
5
    function test_SphericalMercator_forwardMercator(t) {
 
6
        t.plan(12);
 
7
        var arctic = OpenLayers.Layer.SphericalMercator.forwardMercator(0, 85);
 
8
        var antarctic = OpenLayers.Layer.SphericalMercator.forwardMercator(0, -85);
 
9
        var hawaii = OpenLayers.Layer.SphericalMercator.forwardMercator(-180, 0);
 
10
        var phillipines = OpenLayers.Layer.SphericalMercator.forwardMercator(180, 0);
 
11
        var ne = OpenLayers.Layer.SphericalMercator.forwardMercator(180, 90);
 
12
        var sw = OpenLayers.Layer.SphericalMercator.forwardMercator(-180, -90);
 
13
        
 
14
        t.eq(arctic.lon, 0, "Arctic longitude is correct");
 
15
        t.eq(Math.round(arctic.lat), 19971869, "Arctic latitude is correct");
 
16
        
 
17
        t.eq(antarctic.lon, 0, "Antarctic longitude is correct");
 
18
        t.eq(Math.round(antarctic.lat), -19971869, "Antarctic latitude is correct");
 
19
        
 
20
        t.eq(Math.round(hawaii.lat), 0, "Hawaiian lat is correct");
 
21
        t.eq(hawaii.lon, -20037508.34, "Hawaiian lon is correct");
 
22
        
 
23
        t.eq(Math.round(phillipines.lat), 0, "Phillipines lat is correct");
 
24
        t.eq(phillipines.lon, 20037508.340, "Phillipines lon is correct");
 
25
       
 
26
        // Rounding errors make this not infinity 
 
27
        t.ok(ne.lat > 50000000, "NE lat is correct");
 
28
        t.eq(ne.lon, 20037508.34, "NE lon is correct");
 
29
        
 
30
        t.eq(sw.lat, -Infinity, "SW lat is correct");
 
31
        t.eq(sw.lon, -20037508.34, "SW lon is correct");
 
32
    } 
 
33
    
 
34
    function test_sphericalMercator_inverseMercator(t) {
 
35
        t.plan(4);
 
36
        var sw =  OpenLayers.Layer.SphericalMercator.inverseMercator(-20037508.34,  -20037508.34);
 
37
        var ne =  OpenLayers.Layer.SphericalMercator.inverseMercator(20037508.34,  20037508.34);
 
38
        t.eq(sw.lon, -180, "Southwest lon correct");
 
39
        t.eq(ne.lon, 180, "Northeast lon correct");
 
40
        
 
41
        t.eq(sw.lat, -85.05112877980659, "Southwest lat correct");
 
42
        t.eq(ne.lat, 85.05112877980660, "Northeast lat correct");
 
43
    }
 
44
 
 
45
    function strToFixed(str, dig) { 
 
46
        if(dig == undefined) { 
 
47
            dig = 5; 
 
48
        } 
 
49
        return str.replace(/(\d+\.\d+)/g, function(match) { 
 
50
            return parseFloat(match).toFixed(dig); 
 
51
        }); 
 
52
    } 
 
53
 
 
54
    function test_SphericalMercator_projectForward(t) { 
 
55
        t.plan(1);
 
56
        var point = new OpenLayers.Geometry.Point(10, 20); 
 
57
        OpenLayers.Layer.SphericalMercator.projectForward(point); 
 
58
 
 
59
        t.eq(strToFixed(point.toString()), 
 
60
             strToFixed("POINT(1113194.9077777779 2273030.9266712805)"), 
 
61
             "point transforms from EPSG:4326 to Spherical Mercator"); 
 
62
    } 
 
63
         
 
64
    function test_SphericalMercator_to4326(t) { 
 
65
        t.plan(1);
 
66
        var point = new OpenLayers.Geometry.Point(1113195, 2273031); 
 
67
 
 
68
        OpenLayers.Layer.SphericalMercator.projectInverse(point); 
 
69
         
 
70
        t.eq(strToFixed(point.toString()), 
 
71
             strToFixed("POINT(10.000000828446318 20.000000618997227)"), 
 
72
             "point transforms from EPSG:4326 to Spherical Mercator"); 
 
73
    }
 
74
    
 
75
    function test_SphericalMercator_addTransform(t) {
 
76
        // this class should add two methods to the
 
77
        // OpenLayers.Projection.transforms object
 
78
        t.plan(4);
 
79
        var wgs84 = OpenLayers.Projection.transforms["EPSG:4326"];
 
80
        t.ok(wgs84 instanceof Object, "EPSG:4326 exists in table");
 
81
        
 
82
        var smerc = OpenLayers.Projection.transforms["EPSG:900913"];
 
83
        t.ok(smerc instanceof Object, "EPSG:900913 exists in table");
 
84
        
 
85
        t.ok(wgs84["EPSG:900913"] === OpenLayers.Layer.SphericalMercator.projectForward,
 
86
             "from EPSG:4326 to EPSG:900913 correctly defined");
 
87
        t.ok(smerc["EPSG:4326"] === OpenLayers.Layer.SphericalMercator.projectInverse,
 
88
             "from EPSG:900913 to EPSG:4326 correctly defined");
 
89
    }
 
90
    
 
91
  </script> 
 
92
</head>
 
93
<body>
 
94
</body>
 
95
</html>