2016-02-19 54 views
1

我有下面的例子中我的電腦上工作:打開圖層3的鼠標位置檢測工作不

http://openlayers.org/en/v3.13.1/examples/mouse-position.html

但是當我改變使用EPSG代碼:27700,而不是無論是4326或3857 ,一個很簡單的變化:

var mousePositionControl = new ol.control.MousePosition({ 
    coordinateFormat: ol.coordinate.createStringXY(4), 
    // comment the following two lines to have the mouse position 
    // be placed within the map. 
    projection:'EPSG:27700', 
    className: 'custom-mouse-position', 
    target: document.getElementById('mouse-position'), 
    undefinedHTML: ' ' 
    }); 

...這似乎並沒有認識到EPSG:27700,默認爲3857

我曾嘗試通過包含在頂部下面添加proj4js庫:

<script src="http://cdnjs.cloudflare.com/ajax/libs/proj4js/2.3.6/proj4.js"></script> 

隨着我的身影OL3可能沒有這個投影在它的默認數據庫,但它仍然無法正常工作。

回答

0

它看起來像這些都是Proj4.js唯一的預定義的預測

instead of writing out the whole proj definition, by default proj4 has the following projections predefined: 

'EPSG:4326', which has the following alias 
'WGS84' 
'EPSG:4269' 
'EPSG:3857', which has the following aliases 
'EPSG:3785' 
'GOOGLE' 
'EPSG:900913' 
'EPSG:102113' 

一個小Googling建議您可以將其添加像這樣:

Proj4js.defs["EPSG:27700"] = "+proj=tmerc +lat_0=49 +lon_0=-2 +k=0.9996012717 +x_0=400000 +y_0=-100000 +ellps=airy +datum=OSGB36 +units=m +no_defs"; 
EPSG27700 = new OpenLayers.Projection("EPSG:27700");