2013-03-05 133 views
6

我在一個家庭項目中使用Leafletjs(這是它看起來,現在。 但我找不到必須設置投影,我發現它爲OpenLayers,看起來像這樣:Leafletjs上的設置投影

// Openlayers settings 
    //var defaultMaxExtent = new OpenLayers.Bounds(427304, 6032920, 927142, 6485144); 
    var defaultMaxExtent = new OpenLayers.Bounds(427304, 6032920, 927142, 6485144); 

    var defaultProjection = "EPSG:25832"; 
    var defaultUnits = "Meters"; 
    var defaultResolutions = new Array(1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024); 
    var defaultExtent = new OpenLayers.Bounds(215446, 2103547, 706886, 6203897); //this extent is used when the page is loaded. 
    //var defaultExtent = new OpenLayers.Bounds(705446, 6203547, 706886, 6203897); //this extent is used when the page is loaded. 
    map = new OpenLayers.Map('map', { projection: defaultProjection, units: defaultUnits, maxExtent: defaultMaxExtent, resolutions: defaultResolutions, controls: [ 

     // Hide controls by default 
    new OpenLayers.Control.Navigation({ wheelChange: HideInfoBox() }), 
    new OpenLayers.Control.ArgParser(), 
    new OpenLayers.Control.Attribution()] 
    }); 
    layer = new OpenLayers.Layer.WMS("kort", "http://serverAddress?", { nbr: '', username: 'admin', password: 'adminadmin', layers: 'Overlayer', format: 'image/png' }); 

任何人都可以幫助我

更新: 我試圖從單張採取標準投影和定製它,像這樣

L.CRS.EPSG25832 = L.extend({}, L.CRS, { 
    code: 'EPSG:25832', 
    projection: L.Projection.SphericalMercator, 
    transformation: new L.Transformation(0.5/Math.PI, 0.5, -0.5/Math.PI, 0.5), 

    project: function (latlng) { // (LatLng) -> Point 
     var projectedPoint = this.projection.project(latlng), 
       earthRadius = 6378137; 
     return projectedPoint.multiplyBy(earthRadius); 
    } 
}); 

現在投影是正確的。但現在的問題是座標是錯誤的,所以例如,如果我從Leaflet獲得座標,Kolding現在在法國中部而不是在丹麥。

+0

也許源的幫助:https://github.com/Leaflet/Leaflet/blob/master/src/map/Map.js#L10和https://github.com/單張/單張/樹/主/ src目錄/地理/ CRS。 – tbicr 2013-03-05 14:12:12

+0

怎麼回事? – flup 2013-03-05 17:26:41

+0

@flup應該更像這張圖片從源https://dl.dropbox.com/u/2230967/DKv2.PNG – mortenstarck 2013-03-06 06:32:24

回答

6

我自己找到了解決問題的辦法。 通過這樣做,而不是:

var crs = L.CRS.proj4js('EPSG:25832', '+proj=utm +zone=32 +ellps=GRS80 +units=m +no_defs', new L.Transformation(0.5/(Math.PI * L.Projection.Mercator.R_MAJOR), 0.5, -0.5/(Math.PI * L.Projection.Mercator.R_MINOR), 0.5)); 

    var map = new L.Map('Krak-Map', { center: new L.LatLng(latitude, longitude), zoom: 17, crs: crs }); 
+2

您好Morten,我在這裏與其他投影類似的問題:http:// stackoverflow。 com/questions/31070949/leaflet-map-with-wms-and-custom-projection問題:你在哪裏找到變換部分? – Steen 2015-06-26 11:50:41

+0

因此,EPSG:25832不被支持,但你通過添加utm +區域32等來糾正它的問題? – 2016-06-21 07:59:44