Javascript 如何从带有传单的地图上删除标记?

Javascript 如何从带有传单的地图上删除标记?,javascript,leaflet,Javascript,Leaflet,如何从带有传单的地图上删除标记?我想在单击我创建的按钮后不单击地图就可以完成。我已经得到了要删除的标记的坐标 _deleteWorkout(e){ // check if the clicked target is delete button if(e.path[0].className === 'delete-workout'){ // determine the list of cilcked button

如何从带有传单的地图上删除标记?我想在单击我创建的按钮后不单击地图就可以完成。我已经得到了要删除的标记的坐标

_deleteWorkout(e){ 
        // check if the clicked target is delete button 
        if(e.path[0].className === 'delete-workout'){
            // determine the list of cilcked button
            const workEl = e.target.closest('.workout');
            const workElId = workEl.dataset.id;
            // find the index of of workout that clicked from the workouts array
            const deletedWorkoutIndx = this.#workouts.findIndex(el => el.id === workElId);
            const workout = this.#workouts[deletedWorkoutIndx];
            const coords = workout.coords;
            // delete the workout object  from workouts array 
            this.#workouts.splice(deletedWorkoutIndx, 1);
            // delete workout from the user interface 
            workEl.parentNode.removeChild(workEl);
            // remove workout from the map 
```}
}

一个简单而经典的解决方案是维护标记的字典,以便以后可以轻松检索与数据ID关联的标记

//全局字典
常量myMarkers={};
//从数据创建标记时
myMarkers[myDataId]=L.marker(myDataCoords).addTo(map);
//当您要从地图中删除标记时
myMarkers[workElId]。删除();

非常感谢您,我花了更多的时间和时间试图解决这个问题。谢谢您的帮助