在BNG中打开图层3鼠标位置检测不起作用

时间:2016-02-19 13:43:09

标签: javascript openlayers-3 map-projections

我的计算机上有以下示例:

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可能没有在默认数据库中进行此投影,但它仍然无法正常工作。

1 个答案:

答案 0 :(得分: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'

有点谷歌搜索表明你可以像这样添加它:

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" );