ArcGIS交互式KML图层

时间:2016-10-31 18:34:29

标签: javascript kml arcgis

我正在处理ArcGIS地图。我需要能够与KML图层进行交互。

以下是我当前代码的最小版本:

map = new Map("map", {
  basemap: "topo",
  center: [-108.663, 42.68],
  zoom: 6
});
parser.parse();

var kmlUrl = "https://dl.dropboxusercontent.com/u/2142726/esrijs-samples/Wyoming.kml";
var kml = new KMLLayer(kmlUrl);
map.addLayer(kml);
kml.on("load", function() {
  console.log("done");
});

Here is a fiddle

我希望获得更像this map的内容,它会在悬停时概述图层。 (此示例来自FeatureLayer类,但我的KML是动态生成的。是否可以从KML数据动态创建功能层?)

如何在KML形状上监听鼠标悬停?

1 个答案:

答案 0 :(得分:0)

我明白了......

var kmlUrl = "https://dl.dropboxusercontent.com/u/2142726/esrijs-samples/Wyoming.kml";
var kml = new KMLLayer(kmlUrl);
map.addLayer(kml);
kml.on("load", function() {
  var layers = kml.getLayers()  
  layers[0].on("mouse-over", function () {
            alert("test");
        });
});

原来KML图层实际上是由FeatureLayers组成的。解决方案是使用getLayers()方法从KMLLayer获取要素图层。