OpenLayer 3 鼠标位置坐标显示控件

<body>
<div id="map">
<div id="mouse-position"></div>
</div>
<script>
var map=new ol.Map({
target:"map",
layer:[],
view:new ol.View({
center:[0,0],
zoom:2
})
//control:ol.control.defaults().extend([mousePositionControl])
})
var tileLayer=new ol.layer.Tile({
source:new ol.source.OSM()
})
map.addLayer(tileLayer);
var mousePositionControl=new ol.control.MousePosition({
coordinateFormat:ol.coordinate.createStringXY(4),
projection:"EPSG:4326",
className:"custom-mouse-position",
target:document.getElementById("mouse-position"),
undefinedHTML:"&nbsp"
});
map.addControl(mousePositionControl);
</script>
</body>

疑问:不知道为什么直接通过设置controls参数加载鼠标位置控件就有错,但是调用map.addControl方法加载就对了;layer也是这样
posted @ 2016-10-27 15:18  米娜-火箭  阅读(4157)  评论(1编辑  收藏  举报