在下面发布的代码中,我根据鼠标指针在地图上移动的位置获得坐标。换句话说,当鼠标在地图上移动时,下面的代码根据鼠标指针的位置获得经度和纬度。
坐标分别显示在“鼠标位置”中,例如6.6920092、51.1328600、经度和纬度。
target: document.getElementById('mouse-position')如何将读取坐标的值拆分,以便将经度保存在变量中,将纬度保存在其他变量中,问题是在
new MousePosition({...})我怎么能把它们放在变量中?
是否有任何可以订阅事件鼠标或悬停的侦听器??
码
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
});
this.map = new Map({
controls: defaultControls().extend([mousePositionControl]),
target: 'map',
layers: [],
view: new View({
center: [properties.centerX, properties.centerY],
zoom: properties.zoom
})
});发布于 2021-04-14 12:36:32
您可以使用pointermove事件而不需要MousePosition控件。
var lonlat;
map.on('pointermove', function(e) {
lonlat = toLonLat(e.coordinate);
});https://stackoverflow.com/questions/67091534
复制相似问题