简体   繁体   English

单击访问传单标记元属性

[英]Accessing Leaflet Marker Meta properties on click

In my leaflet map when a user clicks on a marker it populates a table elsewhere in the page with a table of attribute fields.在我的传单地图中,当用户单击标记时,它会在页面的其他地方填充一个带有属性字段表的表。 I want to also have a button that would allow the user to delete the marker from the map.我还想要一个按钮,允许用户从地图中删除标记。 To do this I am aiming to write the current feature id and layer name to global variables whenever a scheme is clicked.为此,我的目标是在单击方案时将当前要素 ID 和图层名称写入全局变量。 This will then be used by the button to remove the selected feature from the map.然后按钮将使用它从地图中删除选定的要素。

How do I retrieve these meta attributes from a marker click event?如何从标记单击事件中检索这些元属性 I can retrieve the attribute information easily as shown below:我可以轻松检索属性信息,如下所示:

layer.on('click', function (e) {
globalVariable  = e.feature.properties.name
}

Save the marker object on click:单击时保存标记对象:

layer.on('click', function(e) {
     clickedMarker = e.target;
});

Then you can simply use然后你可以简单地使用

clickedMarker.removeFrom(map);

or one if its variants after checking that clickedMarker is actually a marker and is currently on the map.或者在检查clickedMarker实际上是一个标记并且当前在地图上之后它的变体。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM