У меня есть GEOJSON из набора маркеров, который имеет следующую структуру.Это просто пример
{
"type": "FeatureCollection",
"features": [
{`enter code here`
"type": "Feature",
"id": 1,
"geometry": {
"type": "Point",
"coordinates": [
-95.980577,
41.287989
]
},
"properties": {
"CommunityPartner": "Abide Omaha",
"Address": "3223 N 45th St",
"City": "Omaha",
"State": "NE",
"Zip": "68104",
"Location": "Omaha, NE",
"Latitude": 41.287989,
"Longitude": -95.980577,
"PhoneNumber": "402-455-7807",
"Website": "www.abideomaha.org",
"PrimaryMissionFocus": "Social Justice",
"SecondaryMissionFocus": "Economic Sufficiency",
"WeitzCECPartner": "No",
"Enteredby": "Service Learning Academy",
"Notes": "",
"semester": [
"Spring 2018"
],
"time": "Spring 2018"
}
}
]}
Файл GEOJSON называется communityDatas.
У меня есть еще один полигональный файл GEOJSON под названием districtData.Структура многоугольника:
{
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"id": 1,
"geometry": {
"type": "Polygon",
"coordinates": []
},
"properties": {}
}
]
}
Я хочу выяснить, к какому полигону относится маркер, создать новый ключ в разделе «свойства» под названием «район» и назначить значение «id» многоугольника.к этому.Например, если маркер находится в многоугольнике с идентификатором 1, ключ «района» маркера в свойствах будет 1. Вот как я это сделал, используя turf.js
for (var i = 0; i < communityDatas.length; i++) {
var pt = communityDatas.features[i].geometry.coordinates;
pt = turf.point(pt)
for (var j = 0; j < districtData.length; j++) {
var polyg = districtData.features[j].geometry.coordinates;
polyg = turf.polygon(polyg)
if (turf.booleanPointInPolygon(point, polyg)) {
communityDatas.features[i].properties['district'] = districtData.features[j]['id']
}
}
}
Здесь я показываю текст во всплывающем окне маркера
function parseDescription(message) {
var string = ""
for (var i in message) {
if (i == "CommunityPartner") {
string += '<span style="font-weight:bold">' + i + '</span>' + ": " + message[i] + "<br>"
}if (i == "K-12 Partner") {
string += '<span style="font-weight:bold">' + i + '</span>' + ": " + message[i] + "<br>"
} else if (i == "PhoneNumber") {
string += '<span style="font-weight:bold">' + i + '</span>' + ": " + message[i] + "<br>"
} else if (i == "Website"){
var website = message[i]
var base = "http://"
if (!website.includes("http")){
website = base.concat(website)
}
//string += '<span style="font-weight:bold">' + i + '</span>: <a target="_blank" href="' + message[i] + '">' + message[i] + '</a><br>';
string += `<span style="font-weight:bold">${i}</span>:<a target="_blank" href="${website}" class="popup">${website}</a><br>`;
} else if (i= "district"){
string += '<span style="font-weight:bold">' + i + '</span>' + ": " + message[i] + "<br>"
}
}
return string;
}
Но он не работает должным образом.Вот как это выглядит сейчас.
![enter image description here](https://i.stack.imgur.com/S6pD7.png)
Любые отзывы / советы приветствуются.Спасибо