用于在Google地球插件地图中添加/删除地标的Javascript



有谁知道在创建地标并通过javascript将它们添加到Google地球地图时是否有办法为地标分配唯一的ID? 下面是我用于创建和添加地标的代码类型的示例:

    var icon = ge.createIcon('');
    icon.setHref('<url here>');
    var style = ge.createStyle('');
    style.getIconStyle().setIcon(icon);
    style.getIconStyle().setScale(0.65);
    var pm = ge.createPlacemark('');
    pm.setStyleSelector(style);
    pm.setName("Type1");  // <-- NEED ANOTHER METHOD (ex. pm.SetId('uniqueId'))
    var pmPoint = ge.createPoint('');
    pmPoint.setLatitude(35.859545);
    pmPoint.setLongitude(-92.388783);
    pm.setGeometry(pmPoint);
    ge.getFeatures().appendChild(pm);

-------------------------------------------------------------

我有多组 KmlPlacemark 想要添加到地图中,并且我不想为了能够删除它们而为每组分配唯一的名称(主要是因为我不希望该名称显示在地图上)。 我正在尝试使用以下(不完整的)代码块删除某些地标:

var children = ge.getFeatures().getChildNodes();
for(var i = 0; i < children.getLength(); i++) { 
    var child = children.item(i);
    if(child.getType() == 'KmlPlacemark') {
        if(... ??? ...) {  **// <-- don't want to use if(child.getName().indexOf('criteria') !== -1)**
            ge.getFeatures().removeChild(child);
        }
    }
}

-------------------------------------------------------------

有人知道另一种方法来实现这一点吗? 我尝试使用 child.getUrl(),但这并没有返回任何我可以用来识别我想从地图中删除哪些 KmlPlacemark 的东西......

或者也许有一种方法可以将地图上的名称可见性设置为 false?

提前谢谢。

布兰登

创建地标时

   var pm = ge.createPlacemark('');

使用它来设置它的"id"

   var pm = ge.createPlacemark('uniqueID');

然后当您希望删除它时

   if(child.getType() == 'KmlPlacemark') {
    if(... ??? ...) {  **// <-- don't want to use if(child.getName().indexOf('criteria') !== -1)**
        ge.getFeatures().removeChild(child);
    }
}

成为

   if(child.getType() == 'KmlPlacemark') {
    if(child.getId()=='uniqueID')
        ge.getFeatures().removeChild(child);
    }
}

最新更新