Content method in Esri Maps PopupTemplate is executed only once for each feature

I am integrating Esri maps into an Angular app and utilizing Angular components to render popups by passing data from the PopupTemplate's content method:

layer.popupTemplate = new PopupTemplate({
  content: (feature: { graphic: __esri.Graphic }) => {
    this.publishPopupData(layer, feature.graphic.attributes);
    return popupComponent.viewContainerRef.element.nativeElement;
  },
  // other properties... 
});

While this setup works effectively, a challenge arises when multiple features exist at a particular point. If a user cycles through features and revisits one that was previously displayed, the content method does not re-execute, leading to unprocessed popup data.

Although I can access the currently selected feature on the MapView's popup, determining its originating layer is essential for accurate data publication (each layer has distinct requirements for processing ArcGIS data into popup models).

mapView.popup.watch('selectedFeature', (graphic: __esri.Graphic) => {
  const layer = ???;
  this.publishPopupData(layer, graphic.attributes);
});

In theory, graphic.layer should provide the layer reference, but in my case, it consistently returns null.

Is there a way to enforce the call of the content method for every feature, regardless of previous execution? Alternatively, is there a method to determine a feature's layer from MapView.popup or explore other potential solutions?

For context, the popups are associated with sublayers of MapImageLayer.

Answer №1

It's a common occurrence that the content function isn't triggered again when revisiting a feature popup that was previously displayed. The issue likely stems from continually overwriting the popupComponent variable every time the content function is invoked. Instead, this.publishPopupData() should yield a value that can be incorporated into a fresh html element.

Here is a solution in JavaScript since I'm not very familiar with TypeScript:

layer.popupTemplate = new PopupTemplate({
  content: function(graphic) {
    var popupElement = document.createElement("div");
    // Utilize popupElement.innerHTML if this.publishPopupData() returns a string or use popupElement.appendChild() if it's an html element
    popupElement.innerHTML = this.publishPopupData(layer, graphic.attributes); 
    return popupElement;
  },
  // other properties... 
});

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

Running RXJS Functions in a Sequence Maintained by an Array

I am trying to run a series of functions in sequence by storing them in an array (specifically for an Angular APP_INITIALIZER function). Here is the array in question: const obsArray = [ myService1.init(), myService2.init(), ... myServiceN ...

Having trouble typing computed values in Vue Composition API with TypeScript?

I'm attempting to obtain a computed value using the composition API in vue, and here is the code I am working with: setup() { const store = useStore(); const spaUrls = inject<SpaUrls>('spaUrls'); const azureAd = inject<AzureAd ...

React: Issue with passing arguments to redux action hooks

In my React application, I have implemented Redux-Toolkit to manage reducers and actions with slices. I am currently working on creating actions that can update and delete values from the store, requiring arguments for their usage. To achieve this, I have ...

Disabling dates in Kendo Date Time Picker (Angular): An easy guide

<input id="startDate" kendo-date-time-picker k-ng-model="vm.startDate" k-on-change="vm.updateStartDate()" required /> Can someone please explain how to incorporate disabled dates into this date picker without utilizi ...

When null is assigned to a type in Typescript, it does not result in an error being triggered

Could someone enlighten me on why this code is not causing an error? import { Injectable } from '@angular/core'; interface Animal{ name: string; } @Injectable() export class AnimalService { lion: Animal = null; constructor() {} get(){ ...

Issue in Typescript: The method `clear` or `send` is not recognized in type `unknown` within Protractor framework

Having trouble using clear and sendKeys in Protractor with TypeScript. Could it be that I am missing certain dependencies, as even the click function is giving errors? I have attempted various solutions from Protractor clear() not working, but unfortunate ...

What could be the reason for my Angular 2 app initializing twice?

Can someone help me figure out why my app is running the AppComponent code twice? I have a total of 5 files: main.ts: import { bootstrap } from '@angular/platform-browser-dynamic'; import { enableProdMode } from '@angular/core'; impor ...

I am struggling to comprehend the data organization illustrated by the typescript type declaration

type DocumentData = { [field: string]: any }; let data1: DocumentData = {4:3}; console.log(data1); //{4:3} It appears that the DocumentData type in the code above defines an object type where the key is of string type and the value can be of any type. Th ...

Troubleshooting: Why the OnPush change detection strategy may not be

Parent.component.html <app-child [activeUser]="activeUser" *ngIf="eceConfirm && activeUser"></app-child> Parent.component.ts During the initialization of the component, the getAllEmployees method is called to fetch ...

Issue with Cross-Origin Resource Sharing (CORS) in Angular 16 and

I have two Angular applications using Angular 16 and module federation - one for the MFE app and the other for the shell app. Everything works fine on localhost, but when I deployed the apps to different domains: for the MFE and for the shell app, I enco ...

Sequelize v5 & Typescript Model Loader

Having previous experience with Sequelize for projects (v4), I am now venturing into starting a new project using Sequelize v5 & Typescript. I have been following Sequelize's documentation on how to define Models at: https://sequelize.org/master/ ...

Angular local storage override problem

For system authentication purposes, I am storing the access token in the local storage. When User-A logs in, their access token is saved in the local storage without any issues. However, if User-B opens another tab of the same project and logs in, their ...

A Javascript promise that perpetually stays in a pending state

Utilizing the rotateByDegrees function from a library called node-poweredup within a typescript project: motor.rotateByDegrees(20,10).then(function(value) {console.log("test");}, function(value) {console.log("error");}); Expecting to s ...

Scope Error in VueJS Project with TypeScript

I'm facing an issue in my VueJS project with TypeScript where my vue files are divided into HTML, CSS, TS, and vue. The error message I'm getting is: Property '$router' does not exist on type '{ validate(): void; }' Here is ...

What is the equivalent of Buffer.from(<string>, 'hex') in Python?

I am currently facing the challenge of translating a Typescript library into Python. The specific library I am working with is bs58 in Typescript and its counterpart base58 in Python. My issue arises when attempting to replicate the following code: const ...

Generating a font file using webpack in the monaco-editor package

We are currently in the process of integrating a new package into our project that has a dependency on the monaco-editor module. Let me provide you with some details about our project: We have ejected from the create-react-app project Our project is writ ...

The function service.foo is not recognized in Angular

My service function is not being recognized by my component import { Injectable } from '@angular/core'; import { ToastController } from '@ionic/angular'; @Injectable({ providedIn: 'root' }) export class LocationService { ...

What is the best way to retrieve a member from a union type?

Here is a simple example to illustrate the problem: // library.d.ts import type { Bar } from './bar.d.ts'; export interface Foo { bar?: string | Bar | boolean; // and many other properties } // bar.d.ts export interface Bar { baz?: number ...

Issue with updating @input within ngFor loop's binding circuit

I am dealing with a component that has two binded inputs, which are a large array and two markers indicating positions within the array. This is how the component looks: export class listSequence { @Input() info: Data; @Input() position: Markers; .. .. ...

Difficulty Converting Array of Objects to Proper Type with Q.Promise and KO.mapping

I have encountered an issue while trying to filter an observable array. It seems that the ko.utils.arrayFilter method is converting all my model's field names to lowercase, causing unexpected behavior. I should mention that this project involves Types ...