Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/376.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 从ArcGIS Online中的KML层获取范围_Javascript_Kml_Arcgis_Arcgis Js Api - Fatal编程技术网

Javascript 从ArcGIS Online中的KML层获取范围

Javascript 从ArcGIS Online中的KML层获取范围,javascript,kml,arcgis,arcgis-js-api,Javascript,Kml,Arcgis,Arcgis Js Api,有没有办法在ArcGIS Online中使用KMLayer({url:“my file”})方法计算从web加载的KML层的范围?从AGOL加载的KML具有有效的fullExtent属性,但从其他源加载的KML似乎默认为整个世界,这是没有用的 以下是一个例子: app.kml=new KMLLayer({ url: "my file" });

有没有办法在ArcGIS Online中使用KMLayer({url:“my file”})方法计算从web加载的KML层的范围?从AGOL加载的KML具有有效的fullExtent属性,但从其他源加载的KML似乎默认为整个世界,这是没有用的

以下是一个例子:

app.kml=new KMLLayer({ url: "my file" });                                                                                    
app.map.add(app.kml);                                                                                                    
app.kml.load().then(function() { app.mapView.extent=app.kml.fullExtent; console.log(app.kml) });
现场直播:


控制台打印出KMLLayer对象,而fullExtent字段似乎没有设置正确

我同意,似乎
fullExtent
属性不是您所期望的。我认为有两种解决办法:

编写一些代码来查询layerView以获取范围:

view.whenLayerView(kmlLayer).then(function(layerView) {
  watchUtils.whenFalseOnce(layerView, "updating", function() {
    var kmlFullExtent = queryExtent(layerView);
    view.goTo(kmlFullExtent);
  });
});

function queryExtent(layerView) {
  var polygons = layerView.allVisiblePolygons;
  var lines = layerView.allVisiblePolylines;
  var points = layerView.allVisiblePoints;
  var images = layerView.allVisibleMapImages;

  var kmlFullExtent = polygons
    .concat(lines)
    .concat(points)
    .concat(images)
    .map(
      graphic => (graphic.extent ? graphic.extent : graphic.geometry.extent)
    )
    .reduce((previous, current) => previous.union(current));
  return kmlFullExtent;
}
例如

--或者--

再次调用实用程序服务并使用“lookAtExtent”属性:

view.whenLayerView(kmlLayer).then(function(layerView) {
  watchUtils.whenFalseOnce(layerView, "updating", function() {
    // Query the arcgis utility and use the "lookAtExtent" property -
    esriRequest('https://utility.arcgis.com/sharing/kml?url=' + kmlLayer.url).then((response) => {
      console.log('response', response.data.lookAtExtent);
      view.goTo(new Extent(response.data.lookAtExtent));
    });

  });
});

示例。

Bill,你能发布一个代码示例,显示它正在加载KML文件,并且默认为整个世界吗?好的。我编辑了这篇文章。谢天谢地像个冠军!