openlayers5-添加经纬度控件
2019-09-17 本文已影响0人
知足常乐晨
两种不同的经纬度显示方式,通过MousePosition
对象,设置coordinateFormat
参数
方式一
import {
createStringXY,
toStringHDMS
} from 'ol/coordinate.js';
...
addMousePositionAndScaleControl(map) {
// let map = this.map;
var mousePositionControl = new MousePosition({
// coordinateFormat: createStringXY(4),
coordinateFormat: function(coord){return toStringHDMS(coord)},
projection: 'EPSG:4326',
// comment the following two lines to have the mouse position
// be placed within the map.
className: 'custom-mouse-position',
target: document.getElementById('mouse-position'),
undefinedHTML: ' '
});
var scaleLineControl = new ScaleLine({
//设置度量单位为米
units: 'metric',
target: 'scalebar',
className: 'ol-scale-line'
});
map.addControl(mousePositionControl);
//将比例尺控件加入到map中
map.addControl(scaleLineControl);
},
效果如下:
image.png
方式二
import {
createStringXY,
toStringHDMS
} from 'ol/coordinate.js';
...
addMousePositionAndScaleControl(map) {
// let map = this.map;
var mousePositionControl = new MousePosition({
coordinateFormat: createStringXY(4),
projection: 'EPSG:4326',
// comment the following two lines to have the mouse position
// be placed within the map.
className: 'custom-mouse-position',
target: document.getElementById('mouse-position'),
undefinedHTML: ' '
});
var scaleLineControl = new ScaleLine({
//设置度量单位为米
units: 'metric',
target: 'scalebar',
className: 'ol-scale-line'
});
map.addControl(mousePositionControl);
//将比例尺控件加入到map中
map.addControl(scaleLineControl);
},
image.png