What is the method for modifying the appearance of markers based on their status within the spider cluster on Azure Maps?

I am currently utilizing the Azure map Spider Cluster feature, but I am facing an issue with changing the style of markers displayed upon clicking on a cluster bubble. While I have succeeded in customizing the style of individual markers outside the cluster bubble using the HtmlMarkerLayer class, I am unable to modify the style of markers within the cluster bubble. Below is my code snippet:

<html lang="en">
<head>
    <!-- Include references to Azure Maps Map control JavaScript and CSS files. -->
    <link href="https://atlas.microsoft.com/sdk/javascript/mapcontrol/2/atlas.min.css" rel="stylesheet" />
    <script src="https://atlas.microsoft.com/sdk/javascript/mapcontrol/2/atlas.min.js"></script>
    <script src="https://raw.githubusercontent.com/Azure-Samples/azure-maps-html-marker-layer/main/dist/azure-maps-html-marker-layer.min.js"></script>
    <script src="https://raw.githubusercontent.com/Azure-Samples/azure-maps-spider-clusters/main/dist/azure-maps-spider-clusters.min.js"></script>
    <style>
        .customInfobox { max-width: 240px; padding: 10px; font-size: 12px; margin-right: 20px; white-space: normal }
        .customInfobox .name { font-size: 14px; font-weight: bold; margin-bottom: 5px }
        .popup-content-container .popup-close { top: 12px !important; right: 6px !important; color: #ffffff !important; font-size: 16px !important; line-height: 18px !important; height: 15px !important; background: #000000 !important; width: 15px !important; border-radius: 50px !important; display: flex !important; justify-content: center !important; align-items: center !important; }
        .atlas-map-canvas { width: 100% !important }
    </style>
</head>
<body onload="GetMap()">
    <div id="myMap" style="position:relative;width:100%;min-width:290px;height:600px;"></div>
    <script>
        var map, datasource, popup, spiderManager;
        function GetMap() {
            //Initialize a map instance.
            map = new atlas.Map('myMap', {
                center: [-110, 50],
                zoom: 2,
                view: 'Auto',
                //Add authentication details for connecting to Azure Maps.
                authOptions: {
                    //Use Azure Active Directory authentication.
                    authType: 'subscriptionKey',
                    subscriptionKey: 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
                }
            });

            // Additional code here...

        }

        var popupTemplate = '<div class="customInfobox"><div class="name">{name} ({status})</div></div>';
        showPopup = function (position, properties, pixelOffset) {
            var content = popupTemplate.replace(/{name}/g, properties.Name).replace(/{status}/g, properties.Status);
            popup.setOptions({
                //Update the content of the popup.
                content: content,
                //Update the position of the popup with the symbols coordinate.
                position: position,
                //Offset the popups position for better alignment with the layer.
                pixelOffset: pixelOffset
            });

            //Open the popup.
            popup.open(map);
        }

        hidePopup = function () {
            popup.close();
        }
    </script>
</body>
</html>

For further clarification, refer to this image: https://i.sstatic.net/8SyoM.png

I would appreciate any assistance in resolving this issue. Thank you.

Answer №1

If you want to style your markers using HTML DOM elements or CSS, it's best to avoid the HtmlMarker layer and go for SymbolLayer instead because it offers better performance.

When customizing the shapeLayer (Symbol layer) in your application to render points, the spider manager will automatically align with the same style when displaying expanded points.

It seems like you may be using the HtmlMarker layer to specify custom colors for your markers and to have pie charts for clusters. For symbol layers, icons are used, but there is a tool available that can generate these icons from built-in templates (samples).

Below is an updated version of your code that hides the HtmlMarker for individual points, creates green and grey marker icons, and utilizes the symbol layer to customize how points appear on the map.

<html lang="en">
<head>
    <!-- Include Azure Maps Map control JavaScript and CSS files -->
    <link href="https://atlas.microsoft.com/sdk/javascript/mapcontrol/2/atlas.min.css" rel="stylesheet" />
    <script src="https://atlas.microsoft.com/sdk/javascript/mapcontrol/2/atlas.min.js"></script>
    <script src="https://raw.githubusercontent.com/Azure-Samples/azure-maps-html-marker-layer/main/dist/azure-maps-html-marker-layer.min.js"></script>
    <script src="https://raw.githubusercontent.com/Azure-Samples/azure-maps-spider-clusters/main/dist/azure-maps-spider-clusters.min.js"></script>
    <style>
        .customInfobox { max-width: 240px; padding: 10px; font-size: 12px; margin-right: 20px; white-space: normal }
        .customInfobox .name { font-size: 14px; font-weight: bold; margin-bottom: 5px }
        .popup-content-container .popup-close { top: 12px !important; right: 6px !important; color: #ffffff !important; font-size: 16px !important; line-height: 18px !important; height: 15px !important; background: #000000 !important; width: 15px !important; border-radius: 50px !important; display: flex !important; justify-content: center !important; align-items: center !important; }
        .atlas-map-canvas { width: 100% !important }
    </style>
</head>
<body onload="GetMap()">
    <div id="myMap" style="position:relative;width:100%;min-width:290px;height:600px;"></div>
    <script>
        // Your map initialization script here
    </script>
</body>
</html>

Additionally, I've provided an example on the GitHub repository for the spider cluster manager implementation.

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

Encountering an error while trying to install an npm package

$ npm install sillyname npm WARN tar TAR_ENTRY_ERROR UNKNOWN: unknown error, write npm WARN tar TAR_ENTRY_ERROR UNKNOWN: unknown error, write npm WARN tar TAR_ENTRY_ERROR UNKNOWN: unknown error, write npm WARN tar TAR_ENTRY_ERROR UNKNOWN: unknown error, wr ...

What is the process for including a scope in an Angular.js HTTP controller?

I am looking to access a $scope variable within this controller in order to utilize Angular functions like ng-click and ng-change in my HTML. Currently, I am only able to use the $http function but unable to execute any Angular methods on it. I am struggli ...

Json file directory path

Here is a display of paths: var paths = [ "ubx/ubx-producao/Editora Abril/Exame 1106/FINANCAS_INOCAVAO_STARTUP_BANCOES.mp3", "ubx/ubx-producao/Editora Alto Astral/Previsoes signos Fevereiro 2016/aquario-fevereiro.mp3", "ubx/ubx-producao/Editor ...

Can anyone assist me in figuring out how to make a <div> refresh when a form is submitted?

I've scoured through Stack Overflow and Google extensively, but I keep finding only bits and pieces of code without the complete solution. How can I make a div reload upon form submission? Here is the specific div that I want to refresh: <div id= ...

DiscordJS | Duplicate embed message in a different conversation

Recently, I set up a synchronization between a form and a Discord webhook. Within the webhook, there are three reactions automatically generated by an external BOT. My goal is to configure it so that when a reaction is selected, a confirmation prompt appea ...

Why does JSON.parse need to be run twice - once for a string and once for an object?

When I send a JSON string via websocket (Socket.io) from a Node.js server to a client's browser, I find that I have to execute the JSON.parse function twice in order to extract an object from the received JSON string. This behavior is confusing to me. ...

Tips for including a button or text in the slides of a slideshow created using react-gesture-gallery

I recently created a slideshow using react-gesture-gallery and react-gesture-responder. Take a look at the code below: import React, { Component, useState } from "react"; import ReactDOM from "react-dom"; import { Gallery, GalleryImage } from ...

Error: The function res.getHeader is not recognized within the Next.js API environment

I am currently working on a web application using NextJS 13, TypeScript, Next Auth v4, Prisma (using SQLite for development), and OpenAI. While accessing the API endpoint, I encountered an error in the console with the following message: error - TypeError ...

Vue.js is displaying the error message "Expected Object, got Array" when the length appears as undefined

I have an app where users input style codes into a field. I want to create a popup confirmation modal that displays a message with the number of style codes provided. The code I currently have is: <template> <h4>Style Number</h4> <For ...

Execute local server's unit tests using a Gulp task

I am currently faced with the challenge of running automated unit tests in the terminal for a library application that utilizes the History API internally. To achieve this, I am utilizing Babel to transpile and consolidate my Mocha/Chai/Sinon unit tests in ...

CSS - tackling the issue of menu items overlapping

My menu has two items, and when the user clicks on each item, a sub-menu is displayed. The issue is that both menus are displaying at the same spot - under the first item. I've tried tweaking it for a while but can't seem to fix the problem. Ad ...

Develop a regular expression control specifically designed to validate URLs

I encountered a issue with my current web application. When I access the link: https://localhost:44311/#shop, the page loads perfectly as expected. Here is a screenshot: https://i.sstatic.net/6G6CJ.png However, when I try to change the URL to: https://loc ...

Implementing text assignment to a textbox field using React Redux

element: MainInput: ); } After successfully fetching student data from the database, I encountered an issue while trying to display the information in a textbox React Field. Even though this.props.firstname displayed the correct value on th ...

Creating Dynamic Lists with React Native

<Search ref="search_box" onSearch={this.onSearch} backgroundColor="white" cancelButtonTextStyle={{ color: "red" }} placeholder="Search Food..." ...

"Implementing a drop-down feature for various div elements based on their unique ids

What is the best way to implement dropdown menus in multiple divs with different IDs? I have a user stream where adding a dropdown menu for actions like delete and edit on each post only opens the dropdown in the first post. I know this needs to be handle ...

Adjusting the height of content in Angular Material 2 md-tab

I've recently started working with angular material and I'm facing an issue while trying to implement md-tab into my application. The problem is that I can't seem to style my tab content to take up the remaining height of the screen. Could s ...

End the sessions of all users sharing the identical JWT token

Currently, I am utilizing React and Nodejs while incorporating JWT for user authentication. An issue has arisen where multiple users are simultaneously logged in with the same email address such as "[email protected]". Our objective now is ...

Looking to Move the Image Up?

I've been experimenting with creating a grid layout where the bottom image will move up until it is 10px away from the image directly above it. However, no matter what I attempt, the spacing seems to be based on the tallest image rather than the one a ...

"Incorporating a hyperlink into a newly added table row with the help

When utilizing jQuery, I am able to dynamically add rows to a table with each row containing an anchor tag. However, when attempting to populate the anchor tags with links using jQuery, the links do not appear as expected. Strangely enough, the other data ...

unable to retrieve value from JSON object

It appears that I'm having trouble accessing my object variables, most likely due to a silly mistake on my part. When I console.log my array of objects (pResult), they all look very similar with the first object expanded: [Object, Object, Object, Obj ...