Snippets

Piotr Szrajber Geospatial Portal - Modify formatting of the coordinates for EPSG:4326

Created by Piotr Szrajber
/**
 * Modify coordinates formatting for EPSG:4326 to decimal minutes
 * 2018-01-25 Piotr Szrajber <piotr.szrajber@hexagongeospatial.com>
 */
Sys.Application.add_init(function() {
    // not sure about the computations, this is just an example :)
    function format(deg) {
        var seconds = Math.round(Math.abs(deg) * 360000),
            degrees = Math.floor(seconds / 360000),
            minutes = (seconds - degrees * 360000) / 6000;

        return String.format("{0}{1}\u00B0{2}", deg < 0 ? "-" : "", degrees, minutes.toFixed(4));
    }

    var orig = Intergraph.WebSolutions.Core.WebClient.Controls.Map.MapControl.prototype._updateCoords;
    Intergraph.WebSolutions.Core.WebClient.Controls.Map.MapControl.prototype._updateCoords = function(x, y) {
        // x and y are in units of the CRS
        if ($crs.getCurrent().get_id() === "EPSG:4326") {
            $(this._coordsDiv).html("LON:" + format(x) + ", " + "LAT" + format(y));
        } else {
            orig.call(this, x, y);
        }
    };
});

Comments (0)