Tips for effectively utilizing a Query or QueryTask with local graphics (GraphicsLayer)

Working on developing an ESRI map prototype using Angular4, I have successfully utilized the Draw tool to initiate a Query on a FeatureLayer to draw various graphics such as ConvexHull and Buffer.

The primary goal was to create a clear Buffer graphic over a ConvexHull graphic (referred to as BufferOfPoints). Now, my focus shifts towards generating a Buffer graphic by combining two or more of the previous Buffers.

The challenge lies in querying the Buffer graphics from a non-"Queryable" GraphicsLayer, unlike the points' FeatureLayer which is queryable.

Frustrated by this limitation, I seek a straightforward solution. Is there one available?


Below is code for the functioning simple scenario as well as the one posing difficulty:

Functioning Scenario (simplified)

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

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

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

      ...

      // Calculate Convex Hull geometry
      // Create BufferParameters
      // Apply buffer on ConvexHullResult
      // Display buffer result
    });
  });
});

Challenging Scenario (simplified)

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

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

  // Check Graphic layer's existence or create it
  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 Convex Hull geometry
   // Create BufferParameters
   // Apply buffer on ConvexHullResult
   // Display buffer result
  });
});

Refer to this link for better understanding:

In this link, choose a simple graphic and buffer it - resembling the BufferOfPoints mentioned earlier. My current objective is to query two of those red areas and generate a new Buffer with them.

Hoping this explanation is sufficiently clear.

Answer №1

It is important to note that geometries do not handle a SelectionSet in the same way as featureLayers. However, there are alternative methods...

Even though it doesn't directly act as a query function on graphics, utilizing graphicsUtils.getGeometries() on the buffered result graphics can provide an array of geometry objects. From there, you can identify the specific geometries you need, create features, and buffer accordingly.

Answer №2

The graphicslayer lacks a selectFeatures() method.

For more information, please visit:

You're unable to query graphics within a graphicslayer; only features within a featurelayer can be queried. The key distinction between the two layers is that a featurelayer is structured with consistent fields and geometry types for all features, while a graphicslayer lacks such standardized metadata or constraints on fields/geometry for individual graphics.

If you're unsure about what you're trying to achieve, consider utilizing FeatureCollections with the FeatureLayer instead of a graphicslayer:

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Angular 11 Working with template-driven model within a directive

My currency directive in Angular 8.2 formats currency fields for users by using the following code: <input [(ngModel)]="currentEmployment.monthlyIncome" currency> @Directive({ selector: '[ngModel][currency]', providers: [Curr ...

What is the best way to display suggested words from a given list of options?

Looking for a way to provide suggestions to users based on a list of words they enter in TypeScript while maintaining performance. How can this be achieved efficiently? ...

Is it acceptable to include a @types library as a regular dependency in the package.json file of a Typescript library?

Should the library also be compatible with Typescript projects? I am developing a Typescript library that utilizes node-fetch and @types/node-fetch, which will be shared through an internal NPM registry within the company. If I only include @types/node-f ...

Ways to rename a sequelize property following a join operation

I am encountering a problem with sequelize ORM. The data returned after joining has a nested object: { "id": 1, "username": "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="4125342e2f26252e282220 ...

Failed to set the reference: The first argument includes an undefined property. This error occurred within the context of

My journey with Firebase began just 4 days ago, although I've been a bit inconsistent. My goal was to create a user in the database, and while the user was successfully created, I encountered an issue when trying to return to the profile picture page. ...

Updating the countdown label in NativeScript and Angular

I am currently working on a timer countdown component and have the following code: @Component({ moduleId: module.id, selector: 'time-countdown', template: `<StackLayout> <Label text="{{timeRemaining}}" ></La ...

Creating React Context Providers with Value props using Typescript

I'd prefer to sidestep the challenge of nesting numerous providers around my app component, leading to a hierarchy of provider components that resembles a sideways mountain. I aim to utilize composition for combining those providers. Typically, my pro ...

"Null value is no longer associated with the object property once it has

What causes the type of y to change to string only after the destruction of the object? const obj: { x: string; y: string | null } = {} as any const { x, y } = obj // y is string now ...

Warning: Unhandled promise rejection detected

I'm encountering an issue with Promise.reject A warning message pops up: Unhandled promise rejection warning - version 1.1 is not released How should I go about resolving this warning? Your assistance is greatly appreciated public async retrieveVe ...

Searching within an Angular component's DOM using JQuery is restricted

Want to incorporate JQuery for DOM manipulation within Angular components, but only want it to target the specific markup within each component. Trying to implement Shadow DOM with this component: import { Component, OnInit, ViewEncapsulation } from &apo ...

Troubleshoot: Angular5 Service call not functioning properly when called in ngOnInit

Every time I go to the results component, the service inside ngOnInit behaves as expected. However, when I open the side menu, navigate to another page, and then return to the results page, the page fails to render the results. Instead, the ng-template is ...

What is the best way to assign the result of a promise to a variable?

My code includes an async function that retrieves a value async fetchUserName(environment: string, itemName: string, authToken: string): Promise<any> { let result = await this.obtainDeviceName(environment, itemName, authToken); return ...

Updating Angular 2 components using BaobabWould you like to learn how to

Exploring Baobab as a potential solution for developing Flux applications with Angular 2 has piqued my interest, but I have yet to come across any examples. My primary query revolves around the process of 'subscribing' an Angular Component to Ba ...

How to verify user authorization in Angular and PHP

After setting up authentication with Angular and PHP, I noticed that when the page is reloaded, users are required to re-enter their login credentials. This happens because upon reloading, Angular's "IsLoggedIn" variable gets reset to false. Is there ...

How to dynamically assign tab indices in Angular's mat-tab-group using ngFor

In my angular web application, I have a tab group that requires a mandatory tab (for posting a new object) and dynamic tabs (for editing existing objects). I am looking to set specific tabindex values for the dynamic tabs in order to have one of them disp ...

Bringing in a module that enhances a class

While scouring for a method to rotate markers using leaflet.js, I stumbled upon the module leaflet-rotatedmarker. After installing it via npm, I find myself at a loss on how to actually implement it. According to the readme, it simply extends the existing ...

Error in Angular SSR: Build failed due to project reference without "composite" setting set to true

Currently facing an issue while developing an Angular App with SSR. When using npm run build:ssr, the following errors are displayed: ERROR in [...]/tsconfig.json [tsl] ERROR TS6306: Referenced project '[...]/tsconfig.app.json' must have se ...

Encountering a 500 error in Angular while utilizing forkJoin for calling API services

In my Angular 7 project, I have implemented a call in the ngOnInit method to two different API routes to fetch some data using forkJoin. Here is how I have set it up: ngOnInit() { debugger this.route.params.pipe( switchMap(params => for ...

Understanding the infer keyword in Typescript when working with generic type constraints

Exploring a scenario where I have a generic interface that requires a type argument extending another generic type. export interface IPoint<TX, TY> { x: TX; y: TY; } export interface ISeries<TPoint extends IPoint> { points: Array& ...

Improper application of Angular bindings in Chrome when navigating to a page using the browser's back button

Have you encountered this issue before? I have a few textboxes generated within an ngFor loop: <tr *ngFor="let tableRow of lineItems; trackBy:trackByIndex; let rowIndex = index; "> <td class="psavingsSmallerGridCell"><input c ...