【问题标题】:Different coordinate system leaflet不同坐标系传单
【发布时间】:2014-01-17 12:01:56
【问题描述】:

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

http://i.stack.imgur.com/AT3tO.png

问题是它在全球坐标系(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);
};

谢谢, 克里斯蒂安

【问题讨论】:

    标签: javascript gis leaflet


    【解决方案1】:

    您必须使用 Lambert Conic Conformal (2P) 方法转换它们,该方法为 well described,但实施起来有些冗长,但这并没有阻止我。这是一个示例实现,它只将经度和纬度转换为 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];
        }
    }
    

    现在您可以使用data for EPSG 3301 创建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 投影仪;这可能应该是您的对象的属性。在您的 _OnMouse_Move 方法中,您计算​​东移和北移,如上所示。这将返回一个二元素数组。使用这些值 - 它们是长度坐标 - 创建一个字符串,然后将 this._container.innerHTML 设置为该字符串。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-04-19
    • 2014-09-03
    • 1970-01-01
    • 2014-08-29
    • 2016-08-09
    • 2018-04-25
    相关资源
    最近更新 更多