Javascript 不同坐标系说明书

Javascript 不同坐标系说明书,javascript,gis,leaflet,Javascript,Gis,Leaflet,这是我的坐标图,显示在左下角。它给了我鼠标位置的坐标 问题是它在全局坐标系(ESPG 4326)中,但我需要它在EPSG 3301(爱沙尼亚本地坐标系)中 这是给出坐标的代码 L.Control.MousePosition = L.Control.extend({ options: { position: 'bottomleft', separator: ' : ', emptyString: 'Unavailable', lngFirst: fal

这是我的坐标图,显示在左下角。它给了我鼠标位置的坐标

问题是它在全局坐标系(ESPG 4326)中,但我需要它在EPSG 3301(爱沙尼亚本地坐标系)中

这是给出坐标的代码

    L.Control.MousePosition = L.Control.extend({
  options: {
    position: 'bottomleft',
    separator: ' : ',
    emptyString: 'Unavailable',
    lngFirst: false,
    numDigits: 5,
    lngFormatter: undefined,
    latFormatter: undefined,
    prefix: ""
  },

  onAdd: function (map) {
    this._container = L.DomUtil.create('div', 'leaflet-control-mouseposition');
    L.DomEvent.disableClickPropagation(this._container);
    map.on('mousemove', this._onMouseMove, this);
    this._container.innerHTML=this.options.emptyString;
    return this._container;
  },

  onRemove: function (map) {
    map.off('mousemove', this._onMouseMove)
  },

  _onMouseMove: function (e) {
    var lng = this.options.lngFormatter ? this.options.lngFormatter(e.latlng.lng) : L.Util.formatNum(e.latlng.lng, this.options.numDigits);
    var lat = this.options.latFormatter ? this.options.latFormatter(e.latlng.lat) : L.Util.formatNum(e.latlng.lat, this.options.numDigits);
    var value = this.options.lngFirst ? lng + this.options.separator + lat : lat + this.options.separator + lng;
    var prefixAndValue = this.options.prefix + ' ' + value;
    this._container.innerHTML = prefixAndValue;
  }

});

L.Map.mergeOptions({
    positionControl: false
});

L.Map.addInitHook(function () {
    if (this.options.positionControl) {
        this.positionControl = new L.Control.MousePosition();
        this.addControl(this.positionControl);
    }
});

L.control.mousePosition = function (options) {
    return new L.Control.MousePosition(options);
};
谢谢,
Kristjan

您必须使用Lambert圆锥共形(2P)方法对其进行转换,该方法的实现有点冗长,但这并没有阻止我。下面是一个仅从经度和纬度转换为EPSG的示例实现,而不是从经度和纬度转换为EPSG:

function EPSG(lat1, lat2, latF, lonF, EF, NF) {

    this.sqr = function(x) {
        return x*x;
    }

    this.rad = function(x) {
        return Math.PI * x / 180.0;
    }

    lat1 = this.rad(lat1);
    lat2 = this.rad(lat2);
    latF = this.rad(latF);
    lonF = this.rad(lonF);

    this.a = 6378206.400;
    this.e = 0.08227185;
    this.lat1 = lat1;
    this.lat2 = lat2;
    this.latF = latF;
    this.lonF = lonF;
    this.EF = EF;
    this.NF = NF;

    var e = this.e;
    var a = this.a;

    var m1 = Math.cos(lat1) / Math.sqrt(1 - this.sqr(e * Math.sin(lat1)));
    var m2 = Math.cos(lat2) / Math.sqrt(1 - this.sqr(e * Math.sin(lat2)));
    var t1 = Math.tan(0.25 * Math.PI - 0.5 * lat1) /
        Math.pow((1 - e * Math.sin(lat1)) / 
            (1 + e * Math.sin(lat1)), 0.5*e);
    var t2 = Math.tan(0.25 * Math.PI - 0.5 * lat2) /
        Math.pow((1 - e * Math.sin(lat2)) / 
            (1 + e * Math.sin(lat2)), 0.5*e);
    var tF = Math.tan(0.25 * Math.PI - 0.5 * latF) /
        Math.pow((1 - e * Math.sin(latF)) / 
            (1 + e * Math.sin(latF)), 0.5*e);
    var n = (Math.log(m1) - Math.log(m2)) / 
        (Math.log(t1) - Math.log(t2));
    var F = m1 / (n * Math.pow(t1, n));
    var rF = a * F * Math.pow(tF, n);

    this.rF = rF;
    this.n = n;

    this.deg2epsg = function(lon, lat) {
        var e = this.e;
        var a = this.a;

        lon = this.rad(lon);
        lat = this.rad(lat);

        var t = Math.tan(0.25 * Math.PI - 0.5 * lat) /
            Math.pow((1 - e * Math.sin(lat)) /
                (1 + e * Math.sin(lat)), 0.5*e);

        var r = a * F * Math.pow(t, n);
        var theta = n * (lon - lonF);

        var E = this.EF + r * Math.sin(theta);
        var N = this.NF + this.rF - r * Math.cos(theta);

        return [E, N];
    }
}
现在,您可以使用创建
EPSG
的实例,并运行其
deg2epsg
方法:

var epsg3301 = new EPSG(59.33333333333334, 58, 
    57.51755393055556, 24, 500000, 6375000);

var tallinn = epsg3301.deg2epsg(24.7453, 59.4372);

// tallinn[0] == 542293.7844303187
// tallinn[1] == 6589057.033686307

请注意,大多数数据仅初始化一次,因此
deg2epsg
应该相当快。

感谢您的回答,抱歉回复太长。整个事情似乎相当复杂,我发现使用这段代码有困难。基本上这段代码是手动计算坐标的?我怎样才能让它显示在左下角谢谢,你必须创建一次EPSG投影仪;这可能是对象的属性。在您的
\u OnMouse\u Move
方法中,您可以如上所示计算东距和北距。这将返回一个两元素数组。使用这些值(它们是长度坐标)创建一个字符串,然后将
this.\u container.innerHTML
设置为该字符串。