我正在使用传单将http://esri.github.io/esri-leaflet/examples/geocoding-control.html上的代码用于HTML文件上的嵌入式地图。我想在地图上的标记上添加一个删除按钮。基本上是右上角的X
。我尝试添加
L.marker.bindPopup('<button id = "closeX" onclick="closeMarker()"> X</button>')
像这样:
searchControl.on('results',function (data) {
results.clearLayers();
for (var i = data.results.length - 1; i >= 0; i--) {
results.addLayer(L.marker(data.results[i].latlng));
}
L.marker.bindPopup('<button id = "closeX" onclick="closeMarker()"> X</button>')
});
发现,您不能将bindPopup
函数与L.marker
一起使用,因为它会给该函数带来未捕获的类型错误。还有另一种方法吗?