我在地图上创建了两个不同的geojson数据。我想点击选定的geojson数据。我使用这个代码工作,但我得到两个geojson id没有点击id。我只是想点击geojson id。这里f1是一个已定义的属性。
map.data.addListener('click', function(event){
var id=event.feature.getProperty('f1');
alert(id);
infowindow2.setContent(sContent);
infowindow2.setPosition(event.latLng);
infowindow2.setOptions({pixelOffset: new google.maps.Size(0,-34)});
infowindow2.open(map);
}
İt是geojson数据的例子
{
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"geometry": {
"type": "Polygon",
"coordinates": [
[
[
28.9707230069957,
41.0143811020089
],
[
28.9707162564384,
41.0143424956501
],
[
28.9707099456323,
41.0143003832993
],
[
28.9707027979273,
41.0142558268809
],
[
28.970696368278,
41.0142152406152
],
[
28.9706905696604,
41.0141716903304
],
[
28.9706439363613,
41.0141812741487
],
[
28.9706538187623,
41.0142586346452
],
[
28.9706604147999,
41.0143007495466
],
[
28.9706724204532,
41.0143865085056
],
[
28.9707230069957,
41.0143811020089
]
]
]
},
"properties": {
"f1": 110013011,
"f2": "FATİH",
"f3": "SURURİ",
"f4": "F21C25D2C",
"f5": "P29",
"f6": "337",
"f7": "34",
"f8": "1. Derece Koruma Bolgeleri",
"f9": null,
"f10": "Ş",
"f11": 55,
"f12": 96,
"f13": 1121229337,
"f14": 12,
"f15": 28.9706822916352,
"f16": 41.0142812568067,
"f17": 12,
"f18": 12,
"f19": 227,
"f20": "SURURİ",
"f21": "e17c8db4-bec3-11e5-b590-00a0d1e9ad00",
"f22": 10598737,
"f23": 20598781,
"f24": "e17c66a4-bec3-11e5-8eec-00a0d1e9ad00"
}
}
]
}