2016-11-12 130 views
-1

我想在信息窗口中顯示的機場信息:谷歌地圖信息窗口顯示特定內容

enter image description here

爲機場的信息是從.GEOjson文件中檢索:

{ "type": "Feature", "properties": { "Name": "Epps Airpark", "Description": "description: id: 6525 
 
<br>ident: 00AL 
 
<br>type: small_airport 
 
<br>latitude_deg: 34.86479949951172 
 
<br>longitude_deg: -86.77030181884766 
 
<br>elevation_ft: 820 
 
<br>continent: NA 
 
<br>iso_country: US 
 
<br>iso_region: US-AL 
 
<br>municipality: Harvest 
 
<br>scheduled_service: no 
 
<br>gps_code: 00AL 
 
<br>iata_code: 
 
<br>local_code: 00AL 
 
<br>home_link: 
 
<br>wikipedia_link: 
 
<br>keywords: 
 
<br>id: 6525.0 
 
<br>ident: 00AL 
 
<br>type: small_airport 
 
<br>latitude_deg: 34.86479949951172 
 
<br>longitude_deg: -86.77030181884766 
 
<br>elevation_ft: 820.0 
 
<br>continent: NA 
 
<br>iso_country: US 
 
<br>iso_region: US-AL 
 
<br>municipality: Harvest 
 
<br>scheduled_service: no 
 
<br>gps_code: 00AL 
 
<br>iata_code: 
 
<br>local_code: 00AL 
 
<br>home_link: 
 
<br>wikipedia_link: 
 
<br>keywords: " }, "geometry": { "type": "Point", "coordinates": [ -86.770302, 34.864799, 0.0 ] } }

我想刪除一些項目,如wikipe來自Infowindow的dia_link,local_code和id。

信息窗口代碼是這樣的:

var infowindow = new google.maps.InfoWindow(); 
 

 
function gotoFeature(featureNum) { 
 
    var feature = map.data.getFeatureById(features[featureNum].getId()); 
 
    if (!!feature) google.maps.event.trigger(feature, 'changeto', { 
 
    feature: feature 
 
    }); 
 
    else alert('feature not found!'); 
 
} 
 

 
map.data.addListener('click', function(event) { 
 
    var myHTML = event.feature.getProperty("Description"); 
 
    infowindow.setContent("<div style='width:250px; text-align: center; '>" + myHTML + "</div>"); 
 
    infowindow.setPosition(event.feature.getGeometry().get()); 
 
    infowindow.setOptions({ 
 
    pixelOffset: new google.maps.Size(0, -30) 
 
    }); 
 
    infowindow.open(map); 
 
});

你怎麼會去阻止某些項目(如wikipedia_link,local_code和id)被顯示在信息窗口?

回答

0

一種方式來做到這一點是通過拆分HTML描述成一個數組,並篩選出的項目,你不想顯示

var myHTML = event.feature.getProperty("Description"); 

var categories = ["wikipedia_link", "local_code", "id"]; // the categories to exclude 

function excludeCat(d) { 
    if (categories.indexOf(d.split(":")[0]) < 0) { 
    return d 
    }; 
}; 

myHTML = myHTML.split("<br>").filter(excludeCat).join("<br>"); 
相關問題