2014-01-17 1 views
0

다음은 왼쪽 하단에 표시된 나의 좌표 그림입니다. 그것은 내 마우스 위치의 좌표를 제공합니다.다른 좌표 시스템 전단지

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

문제는 글로벌 좌표계 (ESPG 4326)로되어 있지만 I는 (에스토니아어 로컬 좌표계)가 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); 
}; 

감사합니다, 크리스티안

답변

0

당신은 well described하지만 구현하기가 다소 긴 인 램버트 원뿔 곡선 (이차 곡선) 등각 (2P) 방법을 사용하여 변환해야하지만, 그 날을 멈추지 않았다. 여기에만 EPSG에 위도와 경도로 변환하는 예를 구현하지 그 반대의 경우도 마찬가지입니다 :

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 

참고 :

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]; 
    } 
} 

이제 당신은 그 deg2epsg 방법을 data for EPSG 3301EPSG의 인스턴스를 생성하고 실행할 수 있습니다 대부분의 데이터는 한 번만 초기화되므로 deg2epsg은 상당히 빠릅니다.

+0

답장을 보내 주셔서 감사합니다. 답장을 보내 주셔서 죄송합니다. 전체적으로 상당히 복잡해 보이고이 코드를 사용하는 데 문제가 있습니다. 기본적으로이 코드는 좌표를 수동으로 계산합니까? 왼쪽 하단에 어떻게 표시 할 수 있습니까? 감사합니다. – Ajudoonor

+0

EPSG 프로젝터를 한 번 만들어야합니다. 이것은 아마도 객체의 속성이어야합니다. '_OnMouse_Move' 메쏘드에서 위와 같이 easting과 northing을 계산합니다. 2 요소 배열을 반환합니다. 이 값들을 사용하여 - 길이 좌표 - 문자열을 만들고, 그 문자열에'this._container.innerHTML'을 설정하십시오. –