在下面发布的代码中,我有一个属性为coordinateFormat的MousePosition方法。
createStringXY()返回一个字符串,其中封装了经度和延迟,它们用逗号分隔。后一个函数在鼠标移动时保持提供long和LAT值。
我想要实现的是将createStringXY()生成的值赋给一个变量,然后拆分字符串。
ngOnInit() {
var mousePositionControl = new MousePosition({
className: 'custom-mouse-position',
coordinateFormat: createStringXY(7),
projection: 'EPSG:4326',
// comment the following two lines to have the mouse position
// be placed within the map.
target: document.getElementById('mouse-position'),
undefinedHTML: '', //for what to be rendered when the mouse leaves map scope: values https://openlayers.org/en/latest/apidoc/module-ol_control_MousePosition-MousePosition.html
});
}发布于 2021-03-26 18:50:08
如果我没理解错你的问题,你可以创建一个新的变量。使用split()拆分字符串。
var result = createStringXY(7)
var [long, lat] = result.split(",")
// Or doing it in one line
// var [long, lat] = createStringXY(7).split(",")希望它能回答你的问题。
https://stackoverflow.com/questions/66815078
复制相似问题