Guide on transferring map-marker from mapclick event to a function within the google-map component

I am currently encountering some difficulties when attempting to open a map-info-window within the Google Map component in an Angular 14 project using the guidelines provided here. For this task, I am utilizing the Google Maps package for Angular available at this link.

Here is a snippet of my HTML code:

<google-map #GoogleMap height="500px" width="100%" [zoom]="zoom" [center]="center" [options]="options">
<map-marker-clusterer [imagePath]="'./assets/images/mappa/m'">
    <map-marker #markerElem *ngFor="let s of strutture; let i = index;" 
        (mapClick)="openInfo(markerElem, s.Nome)"
        [position]="{lat: toNumber(s.Latitudine), lng: toNumber(s.Longitudine)}"
        [label]="getLabel(s.Prezzo.toString())" [icon]="getIcon()">
    </map-marker>
    <map-info-window>{{ infoContent }}</map-info-window>
</map-marker-clusterer>

And here is a glimpse of my TypeScript file where I retrieve data and define functions:

export class MappaRisultatiComponent implements OnInit {
@Input() strutture: Struttura[];
toNumber = toNumber;
center!: google.maps.LatLngLiteral;
icon: google.maps.Icon;
zoom: 8;
options: google.maps.MapOptions = {
    ...
}
@ViewChild(GoogleMap, { static: false }) map: GoogleMap
@ViewChild(MapInfoWindow, { static: false }) info: MapInfoWindow
infoContent = ''
openInfo(marker: MapMarker, content) {
    this.infoContent = content
    this.info.open(marker)
}

ngOnInit() {
    this.center = {
        lat: toNumber(this.strutture[0].Latitudine),
        lng: toNumber(this.strutture[0].Longitudine),
    }

    this.icon = {
        url: './assets/images/mappa/priceLabel.png'
    }
}

public getLabel(prezzo: string): google.maps.MarkerLabel {
    let ret: google.maps.MarkerLabel = {
        fontWeight: 'bold',
        text: prezzo + '€'
    }
    return ret;
}

public getIcon(): google.maps.Icon {
    let ret: google.maps.Icon = {
        url: './assets/images/mappa/priceLabel.png'
    }
    return ret;
}

The issue I am facing is related to a compiling error that states: "error TS2345: Argument of type 'HTMLElement' is not assignable to parameter of type 'MapMarker'." from (mapClick)="openInfo(markerElem, s.Nome)"

I am currently working on resolving this issue. It seems like the function is receiving an HTML component instead of a marker, but I am unsure of how to address it. I have only been using Angular for a week, so I hope this is just a beginner mistake.

As a reference, here is a link to my package file:

package.json

Answer №1

It appears that changing the type can be done simply by using

from the .ts file.

import { GoogleMap, MapInfoWindow, MapMarker } from '@angular/google-maps';

in the HTML file.

<map-marker #markerElem="mapMarker" *ngF...

This method successfully resolved the issue.

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

Iterate through the Ionic3/Angular4 object using a loop

I've been attempting to cycle through some content. While I tried a few solutions from StackOverflow, none seem to be effective in my case. Here is the JSON data I am working with: { "-KmdNgomUUnfV8fkzne_":{ "name":"Abastecimento" }, ...

Sharing information between different pages in NEXT.js version 14

After performing a fetch and receiving a successful response containing data as an object, I use router.push to redirect the page to another one where I want to display the fetched data. const handleSubmit = async (event: any) => { event.preventDefa ...

What should be the datatype of props in a TypeScript functional HOC?

My expertise lies in creating functional HOCs to seamlessly integrate queries into components, catering to both functional and class-based components. Here is the code snippet I recently developed: const LISTS_QUERY = gql` query List { list { ...

Verify the data types of components received as props in a Typescript React application

I have a question regarding type checking in React components passed as props: What is the method for ensuring that only allowed components are passed as props? Allow me to demonstrate. We have the component we wish to pass around: type CustomProps = { ...

How to Set Up TypeScript in Laravel 5.6

I've been encountering errors while trying to set up TypeScript in Laravel 5.6 and running 'npm run dev'. Below is my configuration - can someone help me identify what's wrong? webpack.mix.js let mix = require('laravel-mix' ...

Google's reCAPTCHA issue: systemjs not found

Currently, I am attempting to integrate Google's reCAPTCHA into an Angular application by following a helpful tutorial found here. However, I have encountered a problem as the systemjs.config.js file seems to be missing from my Angular CLI project. An ...

When initializing an object, TypeScript automatically converts numbers to strings

I am working on a function that generates a POST request from class properties, but I have encountered an issue with data types. Here's the code snippet: public state: number; updateField(field: string | number, name: string, team: boolean = true) ...

Unique custom data type for an array of objects

My collection consists of objects that share a common structure: type Option = { label: string value: string | number | null } type ElementObject = { id: string options: Option[] } type ElementArray = ElementObject[] const array: Element ...

Issue with Node.js: Promise not completing execution

My current project involves retrieving data from multiple collections in MongoDB using Node.js and promises. Below is a snippet of the basic code I am using: await Promise.all( ["a", "b", "c"].map(async (collection) =& ...

BrowserSync initiates without any access URLs specified

Recently, I set up a scaffolding project using Yeoman (ng-fullstack) and opted for the client side options only. The installation went smoothly, but when I try to run "gulp", all tasks are executed without any errors and it launches http://localhost:3000. ...

Unlocking the potential of NextAuth.js by enhancing the user session with additional database information on authentication

Currently, I am in the process of creating a straightforward credentials sign flow using next-auth ^4.24.5 with a nextjs 14 app. Within my user model, there is a boolean property named 'isAdmin' that I wish to make accessible in my session using ...

The TypeError encountered in an Ionic pipe states that the property 'toString' cannot be read as it is undefined

I have a news application built in Ionic 4. The pubDate property of the UutinenPage class is being asynchronously assigned a value of data.items[this.id].pubDate in the uutinen.page.ts file. The expected format of this value is something like 2019-02-19 04 ...

Facing numerous "error TS1005" messages when performing a gulp build due to node_modules/@types/ [prop types] and [react] index.d.ts with SPFx Webpart

I am currently in the process of developing a custom spfx webpart that includes a feature to display link previews. In order to achieve this functionality, I integrated this specific library. However, I encountered some challenges during the implementation ...

Guide on creating several TypeScript interfaces that share identical type structures

export interface UserFailureResponse { statusCode: number statusMessage: string } export interface UserCreateResponse { statusCode: number statusMessage: string } export interface AuthCheckResponse { statusCode: number statusMessa ...

Executing numerous $http calls in Ionic2

I am curious about the possibility of making multiple requests in Angular: Suppose I start $http request 1, and when it finishes, attempt to call $http request 2. How can I achieve this? For instance, initiating $http request 1 followed by $http request ...

"Encountering an issue with ngx-loading: Unable to set this.loading to

Currently, I have implemented ngx-loading in my HTML. The issue I am facing is that the loader does not disappear after the success message is displayed when using the sendMail() function. It seems like the loader is not recognizing this.loading = false. A ...

Is there a way to resolve the issue of retrieving the processed value directly in NestJS's @OnEvent function?

Due to excessive logic in the API and its slow performance, I have resorted to handling some of the logic with @OnEvent. The problem arises when the frontend runs the @GET API immediately after this API, potentially without waiting for @OnEvent to update. ...

Unit test does not show the PrimeNG menubar start directive

Currently, I am in the process of writing Jasmine tests for my component which includes PrimeNG's menubar. Within this component, I am utilizing the start template directive in the following manner: <p-menubar id='menubar' [model]='i ...

I am interested in forming an object using an array and then looping through the keys of that object

I have a custom object with multiple attributes stored in an array. class Test { a1; a2; a3; a4; a5; } In my project, I have an array that always follows the same order as the attributes of the Test object. arrayWithValues = [a1,a2,a3,a4,a5]; To s ...

Error message: An unhandled TypeError occurs when attempting to access properties of an undefined object (specifically, the 'then' property) while refreshing the token using axios

Is there a way to refresh tokens in axios without interrupting the flow? For example, when the server returns an access token expiration error, I want to queue the request and replay it after getting a new token. In React, I'm using promises as shown ...