Dynamically update multilayer markers on X-map using angular-maps

Utilizing Bing Maps (x-map) for displaying data in multiple layers on the map. The markers' data will be updated through a REST API call to the backend.

I am facing an issue where the markers do not update on the map despite changing the data source. How can I troubleshoot this problem?

Below is the code snippet from the file component.ts:

import { Component, NgModule, VERSION, OnDestroy } from '@angular/core'
import { BrowserModule } from '@angular/platform-browser'
// other imports...

@Component({
    selector: 'my-app',
    templateUrl: './app.component.html',
    styleUrls: ['./app.component.css']
})

export class App implements OnDestroy {
    // component logic here...
}

This is the HTML snippet:

<div style="height: 600px">
    <x-map #xmap [Options]="_options" [Box]="_box">
        <x-map-layer *ngFor="let $l of _layers, let $layerIndex=index" [Visible]="$l.visible">
            <x-map-marker *ngFor="let $m of $l.markers; let $markerIndex=index" [Latitude]="$m.latitude"
                [Longitude]="$m.longitude" [Title]="'Marker ' + $markerIndex.toString() + ' in Layer ' + $layerIndex"
                [IconInfo]="{
                    markerType: _markerTypeId.FontMarker,
                    fontName: 'FontAwesome',
                    fontSize: 24,
                    color: $layerIndex == 0 ? 'red' : ( $layerIndex == 1 ? 'blue' : 'green') ,
                    markerOffsetRatio: { x: 0.5, y: 1 },
                    text: '\uF276'
                }">
                <x-info-box
                    [DisableAutoPan]="true"
                    [Title]="'My InfoBox ' + $layerIndex + '.' + $markerIndex.toString()"
                    [Description]="'Hi, this is the content of the <strong>info window</strong>.'"
                >
                    <x-info-box-action
                        [Label]="'Click Me'"
                        (ActionClicked)="_click($layerIndex, $markerIndex)"
                    >
                    </x-info-box-action>
                </x-info-box>
            </x-map-marker>
        </x-map-layer>
    </x-map>
</div>

Answer №1

To ensure proper functioning of the markers within layers, it is essential to make adjustments as outlined below.

this.dataSubscription = interval(5000).pipe(startWith(0)).subscribe(() => {
    let temp = [];
    for (let i: number = 0; i < 20; i++) {
        temp.push({ latitude: 26.714994 + Math.random() - Math.random(),
                    longitude: -94.46244 + Math.random() - Math.random() });
    }
    this._layers[0].markers = temp;
})

this.dataSubscription = interval(3000).pipe(startWith(0)).subscribe(() => {
    let temp1 = [];
    for (let i: number = 0; i < 20; i++) {
        temp1.push({ latitude: 24.714994 + Math.random() - Math.random(),
                     longitude: -92.46244 + Math.random() - Math.random() });
    }
    this._layers[1].markers = temp1;
})

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

Issue accessing object property in Handlebars template with ExpressJs

Personalized Routes: router.use(function(req, res, next) { res.locals.currentUser = req.user; next(); }); /* Accessing the home page. */ router.get('/', function(req, res, next) { console.log(res.locals.currentUser.username); ==>> t ...

The amazing magnific popup boasts a pair of close buttons

I recently started working on integrating a front-end HTML theme with a back-end Laravel app. Oddly enough, I noticed that the popup modal is displaying two close x buttons instead of just one. Despite my efforts, I have been unable to pinpoint what exactl ...

What is the best way to eliminate items from an array in a side-scrolling video game?

In my gaming project, I am creating a unique experience where the player needs to collect all the words from a given array. Currently, I am utilizing the shift() method to eliminate elements, as demonstrated in the code snippet below: if ( bX + bird.width ...

A guide to creating an HTTPS request using node.js

I am currently in the process of developing a web crawler. Previously, I utilized the following code for HTTP requests: var http=require('http'); var options={ host:'http://www.example.com', path:'/foo/example' }; ...

Ways to adjust the color of an angular mat-radio-button when it is in the unchecked state

Is there a way to change the color of a mat-radio-button when it is NOT checked without having to modify the entire theme? I've been searching for an answer for quite some time now and I'm starting to wonder if it's even possible. Using CSS ...

Tips for effectively managing dynamic xpaths

When conducting a search operation, I am required to select the text that is returned as a result. Each search will produce different xpaths. Below are examples of various xpaths returned during a search: .//*[@id='messageBoxForm']/div/div[1]/di ...

The dropdown menu is dynamically populated based on the selection from another dropdown menu, with options retrieved from

Apologies if this has been addressed previously, but the existing solutions do not seem to work for me. I have 5 dropdowns: Brand, Model, Color, Engine No., and Chassis No. My query pertains to how I can link the dropdown options for Model based on the sel ...

Using Node.js with Typescript and RedisJSON allows for a powerful and efficient

I've recently started delving into nodejs, typescript, and redis for programming. However, I've encountered an issue with redis: when defining a data interface to be stored in redis, the system throws errors as soon as I try to specify the data t ...

Is there a minimum height restriction for v-select in Vuetify.js?

Looking at the code snippet provided below, I am facing an issue while trying to decrease the height of a v-select element. It seems like there is a minimum limit set for the height, as reducing it beyond height = 40 doesn't have any effect. Is there ...

The seamless integration of NestJs, Angular, and Cognito for a streamlined user

Implementing the Authentication and Authorization flows can be tricky without concrete examples. While NestJs doc provides a good example for JWT tokens, I still struggle to establish the correct flow. Here is my current approach to solving the authorizat ...

Undefined jQuery was encountered on the object when using the appropriate selector

Having a jQuery issue with the following HTML code snippet: <div class="side-finder"> <div class="brand"><img src="/img/test.net-logo.png" /></div> <div class="finder-content"> <ul class="nav nav-pills nav-stacked" id= ...

Ways to fix the loading error in AngularJS version 1.3.5?

My HTML page includes AngularJS components. Below is the code snippet: <!DOCTYPE html> <html ng-app="MyApp"> <head> <base href="/"> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> &l ...

inject the HTML content into the <div> container

Snippet: https://jsfiddle.net/x9ghz1ko/ (Includes notes.) In my HTML file, there are two distinct sections: <section class="desktop_only"> and <section class="mobile_only">. The challenge lies in positioning a JavaScript sc ...

What are some ways to streamline inline styling without having to create numerous variables?

Currently, I am in the process of constructing a tab component and establishing inline variables for CSS styling. This particular project involves a streamlit app that allows me to modify settings on the Python side. At the moment, there are four elements ...

If someone installs our chat widget on their website using an <iframe> script, I would like the widget to be deactivated when our website is experiencing downtime

We utilize an iframe to create our Chat Widget. One issue we face is that when our main website is down, it causes errors on client websites where the widget is embedded. I am looking for a way to automatically disable the "Chat widget" when our website ...

Unable to access attributes of an undefined value (current state is undefined)

After completing a small project, I attempted to deploy it on Vercel. The project runs smoothly without any errors on my local machine. However, when I tried to run it on the server, I encountered the following error: "Cannot read properties of undefined ( ...

Using regular expressions to replace strings in JavaScript

I have a URL that resembles the following http://localhost:12472/auctions/auction-12/lots/sort/something/12 I am looking to switch it out with this new URL http://localhost:12472/auctions/auction-12/lots/sort/somethingelse/12 Here, somethingelse can be ...

Ensure redirection for unauthorized users using the AngularFire Auth Guard feature and then direct them back to the initial URL

Currently utilizing the guard utility redirectUnauthorizedTo(['login']) from @angular/fire/auth-guard. However, I now have a need to redirect users to the initial route they were attempting after successfully logging in. It appears that accessing ...

Incorporating database coordinates into Marker React Leaflet: A Step-by-Step Guide

When I retrieve coordinates from the database, they are structured as "lat" and "lon" fields. In my mapping application, I have multiple markers to display. How can I combine these two fields to pass coordinates (coord.lat and coord.lon) to the Marker comp ...