如何在本地图形上使用Query或QueryTask? (GraphicsLayer)

时间:2017-07-20 14:27:25

标签: angular typescript arcgis-js-api

我正在使用Angular4处理ESRI地图的原型。我已成功使用Draw工具QueryFeatureLayer点上绘制ConvexHullBuffer等图片。

我的主要目标是在Buffer图形上实现干净的ConvexHull图形(我将其称为BufferOfPoints )。 现在,我有兴趣实现以前Buffer中2个或更多个的组合Buffers图形。

问题在于,对于BufferOfPoints,我可以在Query上使用包含我的观点的绘图工具实现FeatureLayer。 我的目标现在Query与缓冲图形相同,但它们不在FeatureLayer但在GraphicsLayer中,而不是&#34;可查询&#34;。< / p>

我发现不能做那么简单的事情真的很奇怪...... 有没有一个简单的解决方案呢?

这是我的工作简单案例的代码,以及我坚持的代码......

工作案例(简化)

    // Get the Toolbar instance
    this.drawToolbar.on('draw-complete', (RectangularSelectorGeometry) => {
      this.drawToolbar.deactivate();

      // Initialize the Query
      const query = new Query();
      query.geometry = RectangularSelectorGeometry.geometry;

      // Manage the actions for each configured layer
      featureLayersConcerned.forEach(featureLayer => {
        featureLayer.selectFeatures(query, FeatureLayer.SELECTION_NEW, (features) => {
          // Get the selected graphic points
          const points = features.map((feature) => {
            return feature.geometry;
          });

          ...

          // Calculate the convex Hull geometry
          // Create the BufferParameters
          // Apply the buffer on the ConvexHullResult
          // Show the buffer result
        });
      });
    });

不工作案例(简化)

    // Get the Toolbar instance
    this.drawToolbar2.on('draw-complete', (RectangularSelectorGeometry) => {
      this.drawToolbar2.deactivate();

      // Initialize the Query
      const query = new Query();
      query.geometry = RectangularSelectorGeometry.geometry;

      // Get the Graphic layer if it exists or create it otherwise
      let graphicLayer = this.map.getLayer('bufferGraphics');
      if (!graphicLayer) {
        graphicLayer = new GraphicsLayer({ id: 'bufferGraphics' });
        this.map.addLayer(graphicLayer);
      }

      graphicLayer.selectFeatures(query, GraphicsLayer.SELECTION_NEW, (features) => {  // <== Doesn't work :/

       ...

       // Calculate the convex Hull geometry
       // Create the BufferParameters
       // Apply the buffer on the ConvexHullResult
       // Show the buffer result
      });
    });

以下链接可帮助您了解:https://developers.arcgis.com/javascript/3/sandbox/sandbox.html?sample=exp_cors_buffer

在此链接中,选择一个简单的图形并缓冲它。这正是我所说的BufferOfPoints。我的新目标是查询其中2个红色区域,并用它们绘制一个新的缓冲区。

希望这很清楚

2 个答案:

答案 0 :(得分:0)

图形层没有selectFeatures()方法。

参考:https://developers.arcgis.com/javascript/3/jsapi/graphicslayer-amd.html#methods

您无法在图形图层中查询图形。仅限于功能层中的功能。两层之间的原因和主要区别在于,要素层是结构化层,所有要素具有相同的字段(以及关于它们的元数据)和相同的几何类型。对于图形图层,单个图形的字段/几何图形上没有此类元数据或限制/结构。

我不确定您正在尝试做什么,但您可能希望将FeatureCollections与FeatureLayer(而不是图形图层)一起使用: https://developers.arcgis.com/javascript/3/jsapi/featurelayer-amd.html#featurelayer2

答案 1 :(得分:0)

上述答案是正确的,因为几何图形无法像SelectionSet那样管理featureLayers。然而...

虽然它不是严格意义上运行在图形上的query函数,但您可以对缓冲结果图形执行graphicsUtils.getGeometries(),至少可以获得几何对象数组。如果您可以确定您感兴趣的几何形状,则可以实例化并缓冲缓冲区。