Commit dedacdb5 authored by Michael Adair's avatar Michael Adair
Browse files

closes #68: adding support fro MGRS encoding through Proj4js.util.MGRS

parent ee351d04
Loading
Loading
Loading
Loading

lib/util/MGRS.js

0 → 100644
+950 −0

File added.

Preview size limit exceeded, changes collapsed.

+5 −1
Original line number Diff line number Diff line
@@ -5,6 +5,7 @@
  <title>Proj4js Test Page</title>
  <script src="../lib/proj4js.js"></script>
  <script src="../lib/defs/EPSG42304.js"></script>
  <script src="../lib/util/MGRS.js"></script>
  <script src="testdata.js"></script>
  <script src="runtests.js"></script>
</head>
@@ -20,6 +21,7 @@
    <a href="http://communitymapbuilder.org/">MapBuilder</a> | 
    <a href="http://openlayers.org/">OpenLayers</a> | 
  </div>
  <h2>Core tests</h2>
  <table id="testResult" border="1">
      <tr>
        <th>projection</th>
@@ -28,5 +30,7 @@
        <th colspan="3">inverse (dd)</th>
      </tr>
  </table>
  <h2>Utility tests</h2>
  <script type="text/javascript" src="mgrs.js"></script>
</body>
</html>

test/mgrs.js

0 → 100644
+28 −0
Original line number Diff line number Diff line
(function() {
    assert(typeof Proj4js.util.MGRS, "object", "MGRS available in the Proj4js.util namespace");
    assert(typeof Proj4js.Point.fromMGRS, "function", "fromMGRS method added to Proj4js.Point prototype");
    assert(typeof Proj4js.Point.prototype.toMGRS, "function", "toMGRS method added to Proj4js.Point prototype");

    // Conversions cross-tested with http://geographiclib.sourceforge.net/cgi-bin/GeoConvert
    var mgrs, point;
    mgrs = "33UXP04";
    point = Proj4js.Point.fromMGRS(mgrs);
    assert(point.x.toPrecision(7), "16.41450", "Longitude of point from MGRS correct.");
    assert(point.y.toPrecision(7), "48.24949", "Latitude of point from MGRS correct.");
    assert(point.toMGRS(), "33UXP0500444998", "MGRS reference with highest accuracy correct.");
    assert(point.toMGRS(1), mgrs, "MGRS reference with 1-digit accuracy correct.");
    mgrs = "24XWT783908"; // near UTM zone border, so there are two ways to reference this
    point = Proj4js.Point.fromMGRS(mgrs);
    assert(point.x.toPrecision(7), "-32.66433", "Longitude of point from MGRS correct.");
    assert(point.y.toPrecision(7), "83.62778", "Latitude of point from MGRS correct.");
    assert(point.toMGRS(3), "25XEN041865", "MGRS reference with 3-digit accuracy correct.");


    function assert(got, expected, msg) {
        if (got == expected) {
            document.write('<div>' + msg + '</div>');
        } else {
            document.write('<div style="background-color:red">' + msg + ' - got ' + got + ', but expected ' + expected + '</div>');
        }
    }
})();
+3 −39
Original line number Diff line number Diff line
@@ -10,7 +10,7 @@ Proj4js.defs["EPSG:2958"] = "+proj=utm +zone=17 +ellps=GRS80 +units=m +no_defs";
Proj4js.defs["EPSG:102018"] = "+proj=gnom +lat_0=90 +lon_0=0 +x_0=6300000 +y_0=6300000 +ellps=WGS84 +datum=WGS84 +units=m +no_defs";
Proj4js.defs["ESRI:102026"] = "+proj=eqdc +lat_0=0 +lon_0=0 +lat_1=15 +lat_2=65 +x_0=0 +y_0=0 +ellps=WGS84 +datum=WGS84 +units=m +no_defs";
Proj4js.defs["EPSG:26986"] = "+proj=lcc +lat_1=42.68333333333333 +lat_2=41.71666666666667 +lat_0=41 +lon_0=-71.5 +x_0=200000 +y_0=750000 +ellps=GRS80 +datum=NAD83 +units=m +no_defs";

Proj4js.defs["EPSG:102067"] = "+title=Krovak +proj=krovak +lat_0=49.5 +lon_0=42.5 +alpha=30.28813972222222 +k=0.9999 +x_0=0 +y_0=0 +ellps=bessel +pm=ferro +units=m +towgs84=570.8,85.7,462.8,4.998,1.587,5.261,3.56 +czech +no_defs";
//need test points for these

/*
@@ -26,7 +26,7 @@ Proj4js.testPoints = [
  {code: 'EPSG:26986',
    xy: [ 231394.84,902621.11],
    ll: [-71.11881762742996,42.37346263960867]
  }/*,
  },
  {code: 'ESRI:102026',
    xy: [3257939.781874, 5459865.918947],
    ll: [45.17578125, 41.923828125]
@@ -38,43 +38,7 @@ Proj4js.testPoints = [
  {code: 'EPSG:102018',
    xy: [350577.5930806119, 4705857.070634324],
    ll: [-75,46]
  },
  {code: 'EPSG:102067',
    xy: [756073.155,  982411.63],
    ll: [14.118903130690995, 50.61057704668722]
  },
  {code: 'EPSG:102067',
    xy: [756073.155,  982411.63],
    ll: [14.118903130690995, 50.61057704668722]
  },
  {code: 'EPSG:102067',
    xy: [756073.155,  982411.63],
    ll: [14.118903130690995, 50.61057704668722]
  },
  {code: 'EPSG:102067',
    xy: [756073.155,  982411.63],
    ll: [14.118903130690995, 50.61057704668722]
  },
  {code: 'EPSG:102067',
    xy: [756073.155,  982411.63],
    ll: [14.118903130690995, 50.61057704668722]
  },
  {code: 'EPSG:102067',
    xy: [756073.155,  982411.63],
    ll: [14.118903130690995, 50.61057704668722]
  },
  {code: 'EPSG:102067',
    xy: [756073.155,  982411.63],
    ll: [14.118903130690995, 50.61057704668722]
  },
  {code: 'EPSG:102067',
    xy: [756073.155,  982411.63],
    ll: [14.118903130690995, 50.61057704668722]
  },
  {code: 'EPSG:102067',
    xy: [756073.155,  982411.63],
    ll: [14.118903130690995, 50.61057704668722]
  },
  }/*,
  {code: 'EPSG:2958',
    xy: [411461.807497, 4700123.744402],
    ll: [-82.07666015625, 42.448388671875]