<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:" "
});
map.addControl(mousePositionControl);
</script>
</body>
疑问:不知道为什么直接通过设置controls参数加载鼠标位置控件就有错,但是调用map.addControl方法加载就对了;layer也是这样