我的计算机上有以下示例:
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在其默认数据库中可能没有此投影,但是它仍然无法正常工作。
最佳答案
看来这些是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" );