0
如何設置Google Map's feature'sid
來自geojson?如何從geojson設置Google地圖的功能ID?
id
是getId()
函數返回的結果。
雖然在性能存在id
屬性下面的代碼無法正常工作(打印undefined
):
var uluru = {lat: -25.363, lng: 131.044};
var map = new google.maps.Map(document.getElementById('map'), {
zoom: 4,
center: uluru
});
var data = {
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [131.044, -25.363]
},
"properties": {
"Id": 12
}
};
map.data.addGeoJson(data);
map.data.forEach(function(feature){
console.log("Id from Google's feature: " + feature.getId());
});
小提琴:https://jsfiddle.net/dimskraft/hj2t5je3/5/
UDPATE
我可以寫
var data = {
"type": "Feature",
"id": 13,
"geometry": {
"type": "Point",
"coordinates": [131.044, -25.363]
},
但是這不會是不正確的Geojson?
谷歌關於這方面的文檔並不是非常清晰,但您也可以在使用.loadGeoJson方法時添加選項 – Mackija