In the code posted below I have the method MousePosition which has coordinateFormat as an attribute.
The createStringXY() returns a string encapsulates the longitude and latuitude, and they are comma separated. The latter function keeps providing the long and lat values as the mouse moves.
What I want to achieve is to assign the values generated from createStringXY() to a variable and then split the string.
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
});
}
If I understand your question correctly, you can create a new variable. Use split()
to split the string.
var result = createStringXY(7)
var [long, lat] = result.split(",")
// Or doing it in one line
// var [long, lat] = createStringXY(7).split(",")
Hope it answers your question.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.