English 中文(简体)
点击器上的坐标
原标题:Coordinates on clickevent

I m new to @asymmetrik/ngx-pagelet and Angular in general, so this is maybe only a newbie-issue.

I have an Angular.io (v5) project using the @asymmetrik/ngx-leaflet-tutorial-ngcli

现在,我想得到我点击的坐标。 http://github.com/Asymmetrik/ngx-pagelet/issues/51”rel=“noreferer” 第51期在点击时获得坐标?。 我补充说:

map.on( click , () => { console.log(e.latlng); });

:

onMapReady(map: Map) {
    map.fitBounds(this.route.getBounds(), {
        padding: point(24, 24),
        maxZoom: 12,
        animate: true
    });
    map.on( click , () => { console.log(e.latlng); });
}

that gives me a runtime error: Cannot find name e .

Which kind of makes sense to me. So, I changed the code :

map.on(点击,(e) =>{ console.log(e.latlng);};

但这也给我留下了一个错误:Property latlng在LafletEvent 上不存在。

When I just put e to the console console.log(e) I can see the latlng-Property exists... Why can t I access the coordinates with e.latlng?

我的项目正在使用:

"@angular/cli": "1.4.7",
"@asymmetrik/ngx-leaflet": "^2.5.1",
"@types/leaflet": "^1.2.0",
"leaflet": "^1.2.0",

最佳回答

汇编者指出,活动类型是LeafletEvent, 而后者没有相应的次要财产。 因此,你重犯了这一错误。

Leaflet docs 指出,这一活动实际上为LeafletMouseEvent, 扩展了LafletEvent。 因此,你可以让大家了解莱夫莱特·莫塞特的特性(如下文所示):

map.on( click , (<LeafletMouseEvent>e) => {
    console.log(e.latlng);
});
问题回答

Try to “cast” it as a code>LeafletMouseE :

map.on( click , <LeafletMouseEvent>(e) => { console.log(e.latlng) });

拥有<代码>latlng财产,使用参数类别LeafletMouseEvent,而不是LeafletEvent





相关问题
Angular matSort not working on Date column by desc

Trying to sort the material table with date column , date format is MM/DD/YYYY ,h:mm A , order of date is not by latest date and time. Anything which i missed from the below stackblitz code. https:/...

热门标签