0
基本上,我在我的Leaflet地图上有几个标记。我正在使用jQuery。目前,如果我想填补一个标志与AJAX弹出,我要使用此代码:宣传单:如何影响地图上的所有标记?
var marker = L.marker([51.5, -0.09]).addTo(map);
var marker2 = L.marker([51.49, -0.09]).addTo(map);
marker.on("click", function()
{
$.ajax({
type: "GET",
url: "Home/transactionForm",
dataType: "html",
success: function(ajaxresult)
{
marker.setPopupContent(ajaxresult);
},
error: function (ajaxresult) {
alert("Filling the popup failed!");
}
});
});
marker2.on("click", function()
{
$.ajax({
type: "GET",
url: "Home/transactionForm",
dataType: "html",
success: function(ajaxresult)
{
marker2.setPopupContent(ajaxresult);
},
error: function (ajaxresult) {
alert("Filling the popup failed!");
}
});
});
显然,这是很不理想。在jQuery中,这将是简单的:
$("#map").on("click", "#marker", function() {
$.ajax({
type: "GET",
url: "Home/transactionForm",
dataType: "html",
success: function(ajaxresult)
{
$(this).setPopupContent(ajaxresult);
},
error: function (ajaxresult) {
alert("Filling the popup failed!");
}
});
我该怎么做?我知道我的地图ID,但无法弄清楚ID Leaflet分配给它的标记,弹出窗口和其他元素。