如何删除传单地图中的传单标记窗格?

How to remove leaflet-marker-pane in leaflet map?

我在我的传单地图中实现了针脚指针。

function showLeaflet() {
  var map = L.map("map", {minZoom:1, maxZoom: 1}).setView([66, 384], 1);
  var imageUrl = detailResult.deck[deckFloor].deckplanLarge;
  var imageBounds = [[0, -200], [768, 1024]];
  var cord = (detailResult.deck[deckFloor].markerCordinates).split(',');
  L.imageOverlay(imageUrl, imageBounds).addTo(map);
  L.marker([cord[0], cord[1]]).addTo(map).bindPopup(detailResult.title).openPopup();
  map.setMaxBounds(imageBounds);
}

如何在以下事件中删除该引脚指针。

map.on('click', function(){
  //remove pointer
});

请帮帮我。谢谢..

您需要将您的标记分配给变量,以便您可以通过 L.MapremoveLayer 方法将其从地图中移除:

var marker = L.marker([0, 0]).addTo(map);

map.on('click', function () {
  map.removeLayer(marker);
});

Plunker 上的工作示例:http://plnkr.co/edit/lTXtnX?p=preview and here is the reference for L.Map's layer methods: http://leafletjs.com/reference.html#map-stuff-methods

您需要将创建的标记存储在某处,然后用它调用 map.removeLayer。我在下面编辑了您的代码。

function showLeaflet() {
  var map = L.map("map", {minZoom:1, maxZoom: 1}).setView([66, 384], 1);
  var imageUrl = detailResult.deck[deckFloor].deckplanLarge;
  var imageBounds = [[0, -200], [768, 1024]];
  var cord = (detailResult.deck[deckFloor].markerCordinates).split(',');
  L.imageOverlay(imageUrl, imageBounds).addTo(map);
  var mark = L.marker([cord[0], cord[1]]).addTo(map).bindPopup(detailResult.title).openPopup();
  map.setMaxBounds(imageBounds);

  map.on('click', function(){
      //remove pointer
      map.removeLayer(mark);
  });
}