我是ReactJS的初學者,我使用反應傳單進行地圖渲染, 在這張地圖上,我在座標點上放了一些標記。Reactjs從(地理)json獲取座標
短篇小說,我試圖從JSON文件的一些對象,包含由面積值,並協調對多邊形點在地圖上呈現,它看起來像這樣:
{
"type": "FeatureCollection",
"crs": {
"type": "name",
"properties": {
"name": "urn:ogc:def:crs:OGC:1.3:CRS84"
}
},
"features": [
{
"type": "Feature",
"id": 656,
"properties": {
"DCOMIRIS": "940180101",
"DEPCOM": "94018",
"NOM_COM": "Charenton-le-Pont",
"IRIS": "0101",
"TYP_IRIS": "H",
"DEP": "94",
"aire": 0.2069,
"population": 3974
},
"geometry": {
"type": "MultiPolygon",
"coordinates": [
[
[
[2.4197, 48.8214],
[2.4196, 48.8205],
[2.4196, 48.8199],
[2.4196, 48.819],
[2.4196, 48.8181],
[2.4196, 48.8172],
[2.4196, 48.8169],
[2.4183, 48.8167],
[2.418, 48.8166],
[2.4166, 48.8164],
[2.4159, 48.8163],
[2.4159, 48.8163],
[2.4159, 48.8163],
[2.4155, 48.817],
[2.4152, 48.8175],
[2.4149, 48.8178],
[2.4148, 48.8181]
]
]
]
}
},
{
"type": "Feature",
"id": 657,
"properties": {
"DCOMIRIS": "940180109",
"DEPCOM": "94018",
"NOM_COM": "Charenton-le-Pont",
"IRIS": "0109",
"TYP_IRIS": "H",
"DEP": "94",
"aire": 0.4146,
"population": 3906
},
"geometry": {
"type": "MultiPolygon",
"coordinates": [
[
[
[2.4055, 48.8245],
[2.4053, 48.8244],
[2.4042, 48.8235],
[2.4032, 48.8226],
[2.4024, 48.8219],
[2.4014, 48.8211],
[2.4013, 48.821],
[2.4011, 48.8209],
[2.401, 48.8207],
[2.4009, 48.8207],
[2.4009, 48.8206],
[2.4007, 48.8207],
[2.3996, 48.8212]
]
]
]
}
}
以下劃線我試圖讓一些物體座標值,像這樣:
var find = _.findWhere(this.state.data, {coordinates: [2.4055, 48.8245]});
,但我什麼也沒得到,我不知道如何在我的JSON搜索「更深」。 如果我嘗試:
var find = _.findWhere(this.state.data, {id: 656});
下劃線讓我的對象......
有什麼建議?
是的,我想知道這是否可能是問題,但我不能改變de json誰是巨大的, 因此,循環檢查項目是一個接一個的解決方案? – vmazet
沒有看到這個:http:// stackoverflow。com/questions/237104/how-do-i-check-if-an-array-includes-an-object-in-javascript TL; DR循環遍歷所有的「座標」元素並檢查對象的indexOf試圖找到 – otorrillas
感謝您的幫助! – vmazet