_border(e) { 让 countryCode = e;
$.ajax({
url: "php/borderGeo.php",
type: "POST",
dataType: "json",
success: function (result) {
// console.log(JSON.stringify(result));
const filterData = result.data.features.filter(
(a) => a.properties.iso_a2 === countryCode
);
{
let coords = filterData[0]; THE DATA I NEED TO PASS INTO L.geoJSON
}
},
});
} //////////////////////////////////////////////// ///////////////////////////////
类应用{
_foundPosition(位置){
L.geoJSON(DATA PASSED IN FROM AJAX).addTo(this.#map);
// Passes coordinates to methods
this.#map.on("click", this._weatherCall.bind(this));
this.#map.on("click", this._phpApiCall.bind(this));
//layer controller
L.Control.geocoder().addTo(this.#map);
L.control.layers(mapCollection).addTo(this.#map);
L.easyButton('<img src="img/icons8-country-50.png">', function () {
var myModal = new bootstrap.Modal(document.getElementById("modalOne"), {
keyboard: false,
});
var modalToggle = document.getElementById("modal"); // relatedTarget
myModal.show(modalToggle);
}).addTo(this.#map);
/////////////////////////////////////////////// //////////////
_border(e) { 让 countryCode = e;
$.ajax({
url: "php/borderGeo.php",
type: "POST",
dataType: "json",
success: function (result) {
// console.log(JSON.stringify(result));
const filterData = result.data.features.filter(
(a) => a.properties.iso_a2 === countryCode
);
{
let coords = filterData[0]; THE DATA I NEED TO PASS INTO L.geoJSON
}
},
});
}
}
const app = new App();
为了将过滤后的 JSON 数据从 AJAX 调用传递到 App 类的 _foundPosition 方法中,您可以进行以下修改:
$.ajax({
url: "php/borderGeo.php",
type: "POST",
dataType: "json",
success: function (result) {
const filterData = result.data.features.filter(
(a) => a.properties.iso_a2 === countryCode
);
let coords = filterData[0]; // THE DATA I NEED TO PASS INTO L.geoJSON
app._foundPosition(coords); // Call the _foundPosition method with coords as an argument
},
});
} //////////////////////////////////////////////////////////////////////////////////
class App {
_foundPosition(coords) { // Add a parameter to accept the coords
L.geoJSON(coords).addTo(this.#map); // Use the passed coords
// Passes coordinates to methods
this.#map.on("click", this._weatherCall.bind(this));
this.#map.on("click", this._phpApiCall.bind(this));
//layer controller
L.Control.geocoder().addTo(this.#map);
L.control.layers(mapCollection).addTo(this.#map);
L.easyButton('<img src="img/icons8-country-50.png">', function () {
var myModal = new bootstrap.Modal(document.getElementById("modalOne"), {
keyboard: false,
});
var modalToggle = document.getElementById("modal"); // relatedTarget
myModal.show(modalToggle);
}).addTo(this.#map);
///////////////////////////////////////////////////////////////
_border(e) { let countryCode = e;
$.ajax({
url: "php/borderGeo.php",
type: "POST",
dataType: "json",
success: function (result) {
const filterData = result.data.features.filter(
(a) => a.properties.iso_a2 === countryCode
);
let coords = filterData[0]; // THE DATA I NEED TO PASS INTO L.geoJSON
app._foundPosition(coords); // Call the _foundPosition method with coords as an argument
},
});
}
}
const app = new App();
如果你遇到任何问题,请告诉我?试图模仿你的电话,这可能会导致问题。