【问题标题】:Highlighting or Bolding the Borders of a kml Polygon突出显示或加粗 kml 多边形的边界
【发布时间】:2014-03-12 22:56:16
【问题描述】:

嘿,在将 kml 文件加载到谷歌地球后,当用户单击 kml 中的某个多边形时,我试图让该多边形突出显示。

到目前为止,我可以记录点击事件、获取事件类型 (KmlPlacemark) 并获取其 kml 标记。 我尝试做类似于example 的事情,他们在 kmlObject 的 getFeatures 中添加了一个地标,但目标和类型似乎都没有“getFeatures”。查看文档后,我想我可能想要 Kml Polystyle 类的 setOutline 或 KmlLineStyle 类的 setWidth(),但我不确定。此外,当我尝试类似 target.setOutline(true);它不起作用。

谁能告诉我我是否走在正确的轨道上,提示我做错了什么,以及是否有更好的方法来做到这一点?

function recordEvent(event) {
            var target = event.getTarget();
            var type = target.getType();


            if(type == "KmlPolygon") {
                alert("KMLPolygon ");
            }else if(type == "KmlPlacemark") {
                // // get the data you want from the target.
                var description = target.getDescription();
                var balloon = target.getBalloonHtml();
                var outputKml = target.getKml();

                if ('getFeatures' in event) {
                    console.log("test");
                    event.getFeatures().appendChild(placemark);
                }

                console.log("hello?")
                // target.setOutline(true);
                console.log(outputKml);
            }
        };

      google.earth.addEventListener(ge.getGlobe(), 'click', recordEvent);

谢谢!

【问题讨论】:

    标签: kml google-earth google-earth-plugin


    【解决方案1】:

    我发现按照您的要求做的最好方法是:

    1. 像现在一样检测点击事件

    2. 如果单击,创建一个新样式,然后将其分配给目标

      var newStyle = ge.createStyle('');
      // Assign your Style's attributes such as LabelStyle and IconStyle
      // eg to set the scale of your label
      newStyle.getLabelStyle().setScale(2.5);
      // Set the Style
      target.setStyleSelector(newStyle);
      

    编辑以添加 Google 示例的此链接,更深入地展示它 https://code.google.com/apis/ajax/playground/#styling_placemarks_using_style_maps

    【讨论】:

      猜你喜欢
      • 2013-01-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-01-07
      • 1970-01-01
      • 1970-01-01
      • 2020-06-17
      • 1970-01-01
      相关资源
      最近更新 更多