【问题标题】:Making some placemarks visible with Google Maps API V3使用 Google Maps API V3 使一些地标可见
【发布时间】:2013-05-21 13:57:13
【问题描述】:

我有一个包含多个地标的 KML 文件,示例如下:

   <Placemark>
   <name>00550M</name>
   <description></description>
   <styleUrl>#550M</styleUrl>
   <Polygon>
     <outerBoundaryIs>
       <LinearRing>
         <tessellate>1</tessellate>
         <coordinates>
          -019.2041,63.4130
          -013.2722,57.0138
          004.2309,52.4405
           001.1318,49.5607
          -021.0657,55.3650
          -019.2041,63.4130
          </coordinates>
        </LinearRing>
     </outerBoundaryIs>
   </Polygon>
</Placemark>

使用 Earth 插件,我可以使用地标填充数组:

if ('getFeatures' in top.mykml) {  
var firstChild = top.mykml.getFeatures().getFirstChild();
while(firstChild !== null){                                      
    top.myObjects.push(firstChild);
    firstChild = firstChild.getNextSibling();        
  }    
} 

让它们可见或不可见:

for (var i = 0; i <  aLen; i++){
  aName = top.myObjects[i].getName();          
  aFL = (aName.substring(2, 5));    
  if (aFL == '200'){
    top.myObjects[i].setVisibility(true);               
  } 
}

但是,getFeatures 在地图中不可用,并且

if ('featureData' in top.mykml) 

返回 false。

是否有可能实现我想做的事情,如果可以的话。如果不是,我猜每个地标都必须放在一个文件中。

谢谢。

【问题讨论】:

    标签: google-maps-api-3 kml


    【解决方案1】:

    KmlLayer 不允许您访问地图上的对象。

    你有两个我能想到的选择:

    1. 将您的 KML 导入 FusionTables 并使用查询来显示或隐藏地标
    2. 使用第三方 KML 解析器(如 geoxml3geoxml-v3)使用原生 Google Maps Javascript API v3 对象呈现 KML 并公开这些对象,以便您控制它们

    example using geoxml3

    【讨论】:

      猜你喜欢
      • 2013-02-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多