Google 地图信息窗口显示特定内容

Google Maps Infowindow Display Specific Content

我正在尝试在信息窗口中显示机场信息:

从 .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 ] } }

我想从信息窗口中删除一些项目,例如 wikipedia_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)显示在信息窗口中?

一种方法是将 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>");