如何在本地图形上使用 Query 或 QueryTask? (图形层)
How to use a Query or QueryTask on local graphics ? (GraphicsLayer)
我正在使用 Angular4 制作 ESRI 地图的原型。我已经成功地使用 Draw
工具在 FeatureLayer
一些点上 Query
绘制图形,例如 ConvexHull
和 Buffer
。
我的主要 objective 是在 ConvexHull
图形上实现一个干净的 Buffer
图形(我称之为 BufferOfPoints
).
现在,我有兴趣实现一个 Buffer
图形,该图形由 2 个或更多先前 Buffers
的 组合 组成。
问题是对于 BufferOfPoints
,我可以在 FeatureLayer
上使用绘图工具实现 Query
,其中包含我的观点。
我的 objective 现在是 Query
与 Buffer 图形相同的方式,但那些不在 FeatureLayer
中而是在 GraphicsLayer
中,而不是 "Queryable"。
我觉得不能做这么简单的事情真的很奇怪......
有没有简单的解决方案来做到这一点?
这是我的工作简单案例的代码,以及我坚持使用的代码...
工作案例(简化)
// 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
});
});
这里有一个link可以帮助你理解:https://developers.arcgis.com/javascript/3/sandbox/sandbox.html?sample=exp_cors_buffer
在此link,select一个简单的图形并对其进行缓冲。这正是我所说的 BufferOfPoints
。我的新 objective 是查询其中 2 个红色区域并用它们绘制一个新的 Buffer。
希望这足够清楚
图形层没有 selectFeatures() 方法。
参考:https://developers.arcgis.com/javascript/3/jsapi/graphicslayer-amd.html#methods
您不能查询图形层中的图形。仅适用于要素图层中的要素。原因和两个层之间的主要区别在于,要素层是一个结构化层,所有要素都具有相同的字段(以及关于它们的元数据)和相同的几何类型。对于 graphicslayer 没有这样的元数据,或者 restriction/structure on fields/geometry 对于单个图形。
我不确定你到底想做什么,但你可能想看看将 FeatureCollections 与 FeatureLayer(而不是图形层)结合使用:
https://developers.arcgis.com/javascript/3/jsapi/featurelayer-amd.html#featurelayer2
以上答案是正确的,因为几何体不像 featureLayers
那样管理 SelectionSet
。然而...
虽然它不是严格意义上的对图形进行操作的query
函数,但您可以对缓冲的结果图形执行graphicsUtils.getGeometries()
至少会得到一个几何对象数组。如果您可以确定您感兴趣的几何图形,则可以实例化要素并缓冲缓冲区。
我正在使用 Angular4 制作 ESRI 地图的原型。我已经成功地使用 Draw
工具在 FeatureLayer
一些点上 Query
绘制图形,例如 ConvexHull
和 Buffer
。
我的主要 objective 是在 ConvexHull
图形上实现一个干净的 Buffer
图形(我称之为 BufferOfPoints
).
现在,我有兴趣实现一个 Buffer
图形,该图形由 2 个或更多先前 Buffers
的 组合 组成。
问题是对于 BufferOfPoints
,我可以在 FeatureLayer
上使用绘图工具实现 Query
,其中包含我的观点。
我的 objective 现在是 Query
与 Buffer 图形相同的方式,但那些不在 FeatureLayer
中而是在 GraphicsLayer
中,而不是 "Queryable"。
我觉得不能做这么简单的事情真的很奇怪...... 有没有简单的解决方案来做到这一点?
这是我的工作简单案例的代码,以及我坚持使用的代码...
工作案例(简化)
// 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
});
});
这里有一个link可以帮助你理解:https://developers.arcgis.com/javascript/3/sandbox/sandbox.html?sample=exp_cors_buffer
在此link,select一个简单的图形并对其进行缓冲。这正是我所说的 BufferOfPoints
。我的新 objective 是查询其中 2 个红色区域并用它们绘制一个新的 Buffer。
希望这足够清楚
图形层没有 selectFeatures() 方法。
参考:https://developers.arcgis.com/javascript/3/jsapi/graphicslayer-amd.html#methods
您不能查询图形层中的图形。仅适用于要素图层中的要素。原因和两个层之间的主要区别在于,要素层是一个结构化层,所有要素都具有相同的字段(以及关于它们的元数据)和相同的几何类型。对于 graphicslayer 没有这样的元数据,或者 restriction/structure on fields/geometry 对于单个图形。
我不确定你到底想做什么,但你可能想看看将 FeatureCollections 与 FeatureLayer(而不是图形层)结合使用: https://developers.arcgis.com/javascript/3/jsapi/featurelayer-amd.html#featurelayer2
以上答案是正确的,因为几何体不像 featureLayers
那样管理 SelectionSet
。然而...
虽然它不是严格意义上的对图形进行操作的query
函数,但您可以对缓冲的结果图形执行graphicsUtils.getGeometries()
至少会得到一个几何对象数组。如果您可以确定您感兴趣的几何图形,则可以实例化要素并缓冲缓冲区。