angular - 单击Angular Mapbox获取坐标
问题描述
当我在 Angular 中单击我的地图时,我试图获取坐标,但事件返回 undefined。这是我的代码
HTML
<div id="map" (click)="getCoords($event)"></div>
TS
getCoords(e){
console.log(e.lngLat); // undefined
}
解决方案
Mapbox 鼠标指针坐标是每个MapMouseEvent
事件的参数参数的一部分。您只需通过Evented
sintax 声明事件侦听器。在这里,您可以捕获最简单的代码段:
// The `click` event is an example of a `MapMouseEvent`.
// Set up an event listener on the map.
map.on('click', function(e) {
// The event object (e) contains information like the
// coordinates of the point on the map that was clicked.
console.log('A click event has occurred at ' + e.lngLat);
});
推荐阅读
- javascript - 使用 Expresss JS 的错误处理程序中间件时应用程序崩溃
- angular - 使用 *ngFor 迭代时检查值是否存在 - Angular 10
- fluent-bit - 在输出中包含来自文件名(标签)的信息
- javascript - Javascript 总和和总和
- go-gorm - gorm v2:如何处理 v1 中的 gorm.Scope?
- javascript - 如何使用 javascript Map() 函数创建对象
- android - java.net.SocketTimeoutException:10000 毫秒后无法从 /192.168.2.5(端口 46198)连接到 /172.18.0.1(端口 8008)
- javascript - Angular Universal 不会接管客户端的渲染
- python - Discord tasks.loop,任务不循环
- python - `return +self` 有什么作用?