proj5 0.1.7

Pure Rust, type-safe alternative to PROJ.4
Documentation
<!DOCTYPE html>
<html>
<head>
    <title>PROJ5 WASM example</title>
</head>
<body>
    <h1>PROJ5 WASM coordinate calculator example</h1>
    <p>
        This tool uses the PROJ5 Rust library, compiled to a 56KB WASM file in order
        to transform a buffer of coordinates between longitude/latitude, UTM and
        Web Mercator (EPSG 3857).
    </p>
    <p>
        Enter your source coordinates into the field below and click convert.<br/>
        Coordinates are seperated by comma, with 2 entries per row, like this:
    </p>

    <code>
    8.40404, 45.28383<br/>
    5.12345, 13.58589
    </code>
    <br/>
    <br/>

    <strong>
        Note: Coordinates are always X, then Y: (Longitude, Latitude) instead of (Latitude, Longitude)
        and (Easting, Northing) instead of (Northing, Easting) like usual.<br/>
        False easting (+ 500.000 m inside of UTM zone) and false northing
        (+ 10.000.000 m for values above the equator) are accounted for automatically.
    </strong>

    <p>The output order will correspond to your input order.</p>
    <label for="input_coordinate_type">From:</label>
    <select id="input_coordinate_type">
      <option value="lonlat" selected="selected">(Longitude, Latitude)</option>
      <option value="utm">UTM (Easting, Northing)</option>
      <option value="mercator">Mercator (Easting, Northing)</option>
    </select>
    <br/>


    <label for="output_coordinate_type">To:&nbsp;&nbsp;&nbsp;&nbsp;</label>
    <select id="output_coordinate_type">
      <option value="lonlat">(Longitude, Latitude)</option>
      <option value="utm" selected="selected">UTM (Easting, Northing)</option>
      <option value="mercator">Mercator (Easting, Northing)</option>
    </select>
    <label for="input_utm_zone">UTM zone:</label>
    <input type="number" name="input_utm_zone" placeholder="UTM zone" value="0" cols="4"/>
    <br/>
    <br/>

    <label for="input_coordinates">Input coordinates:</label><br/>
    <textarea name="input_coordinates" rows="8" cols="80"></textarea>
    <br/>
    <br/>

    <button id="convert">Convert!</button>

    <p>Output:</p>
    <textarea id="output_coordinates" rows="8" cols="80"></textarea>
</body>

<script type="text/javascript">

/// Fetch and load WASM
const memory = new WebAssembly.Memory({ initial: 256, maximum: 256 });
const proj5Wasm = {
    env: {
        abortStackOverflow: () => { throw new Error('overflow'); },
        table: new WebAssembly.Table({ initial: 0, maximum: 0, element: 'anyfunc' }),
        tableBase: 0,
        memory: memory,
        memoryBase: 1024,
        STACKTOP: 0,
        STACK_MAX: memory.buffer.byteLength,
    }
};

// var importObject = new WebAssembly.Instance(new WebAssembly.Module(getBinary()), info);

// NOTE: .instantiateStreaming requires the source to have 'application/wasm'
// MIME type, which can't be set on GitHub. So we can't use 'instantiateStreaming'.
//
// fetch() with arrayBuffer also doesn't work, since it can't
// WebAssembly.instantiateStreaming(fetch('https://raw.githubusercontent.com/fschutt/proj5/master/examples/wasm_usage_example/proj5.wasm'), importObject)
// .then(_ => document.getElementById("convert").addEventListener("click", convert_coordinates));

function load_wasm_file(filename) {
    fetch(filename, {
        'mode': 'no-cors'
    })
    .then((response) => {
        console.log(response);
        return response.arrayBuffer();
    })
    .then((bytes) => {
        console.log(bytes);
        return WebAssembly.compile(bytes);
    })
    .then((mod) => {
        // Create the imports for the module, including the
        // standard dynamic library imports
        const memory = new WebAssembly.Memory({ initial: 256 });
        const proj5Wasm = {
            env: {
                abortStackOverflow: () => { throw new Error('Stack overflow'); },
                table: new WebAssembly.Table({ initial: 0, maximum: 0, element: 'anyfunc' }),
                tableBase: 0,
                memory: memory,
                memoryBase: 0, // 1024? Not sure.
                STACKTOP: 0,
                STACK_MAX: memory.buffer.byteLength,
            }
        };

        // Create the instance.
        return new WebAssembly.instantiate(mod, proj5Wasm);
    });
}

//load_wasm_file('https://raw.githubusercontent.com/fschutt/proj5/master/examples/proj5.wasm');
load_wasm_file('examples/proj5.wasm')

.then((result) => {
    proj5Wasm = result;
    document.getElementById("convert").addEventListener("click", convert_coordinates)
});

function convert_coordinates() {
    alert("convert!");
}
</script>

</html>