Dragging a Google Maps marker causes a border to appear around a nearby marker

Recently, I added a main draggable marker to the map. However, an unusual issue arises when dragging this marker - a blue outline appears around one of the existing markers on the map. This behavior is puzzling as it seems to be triggered by a click event listener attached to each marker. Removing this code snippet eliminates the blue outline but commenting out inner function calls within the click handler does not resolve the problem.

The blue outline occurs across different browsers such as Safari and Chrome, ruling out browser-specific issues.

                    marker.addListener('click',
                            function() {
                                openCloseNav(true);
                                car_park_details(marker);
                            }); 

To see the blue outline example, click here: Blue Outline Example (Rightmost marker)

Below is most of the JavaScript code:

        var markers = [];
        var geocoder;
        var map;
        var mainMarker;

        function initMap() {
            geocoder = new google.maps.Geocoder();

            var defaultCoord = {
                lat : 51.600960,
                lng : -0.275770
            };

            map = new google.maps.Map(document.getElementById('map'), {
                zoom : 15,
                center : defaultCoord,
                minZoom : 14,
                streetViewControl : false,
                controlSize : 33,
                gestureHandling : 'greedy',
                mapTypeControlOptions : {
                    mapTypeIds : []
                },
                styles : [ {
                    "featureType" : "all",
                    "elementType" : "all",
                    "stylers" : [ {
                        "hue" : "#008eff"
                    } ]
                }, {
                    "featureType" : "road",
                    "elementType" : "all",
                    "stylers" : [ {
                        "saturation" : "0"
                    }, {
                        "lightness" : "0"
                    } ]
                }, {
                    "featureType" : "transit",
                    "elementType" : "all",
                    "stylers" : [ {
                        "visibility" : "off"
                    } ]
                }, {
                    "featureType" : "water",
                    "elementType" : "all",
                    "stylers" : [ {
                        "visibility" : "simplified"
                    }, {
                        "saturation" : "-60"
                    }, {
                        "lightness" : "-20"
                    } ]
                } ]

            });

            mainMarker = new google.maps.Marker({
                    map,
                 position: defaultCoord,
                 draggable: true,
                 icon : {
                        url : 'mainmarker.png',
                        scaledSize : new google.maps.Size(30, 30),
                        origin : new google.maps.Point(0, 0),
                    }  
                
             });
            
            google.maps.event.addListener(map, 'tilesloaded',
                    find_closest_markers);
            google.maps.event.addListener(mainMarker, 'dragend',
                    find_closest_markers);

        }


        function geocodeEncapsulation(i) {

            return (function(results, status) {

                if (status == 'OK') {
                
                    var marker = new MarkerWithLabel({
                        map : map,
                        position : results[0].geometry.location,
                        icon : {
                            url : 'pin.png',
                            scaledSize : new google.maps.Size(40, 30),
                            //origin : new google.maps.Point(0, 0),
                        },
                        clickable: true,

                        labelContent : '£' + i.price.toFixed(2),
                        labelAnchor : new google.maps.Point(30, 35),
                        labelClass : "markerdesign",
                        labelInBackground : false,
                        title : i.name
                    });
                    marker.set("carpark", i);
                    


                    marker.addListener('mouseover',
                            function() {
                                marker.set("labelClass",
                                        "markerdesignhover");
                            });
                    marker.addListener('mouseout',
                            function() {
                                marker.set("labelClass", "markerdesign");
                            }); 
                    marker.addListener('click',
                            function() {
                                openCloseNav(true);
                                car_park_details(marker);
                            }); 
                    markers.push(marker);

                } else {
                    //console.log(status);
                }

            });
        }

Simplified Version On Fiddle, Drag the centre marker Simplified Version

Answer №1

Have you considered using CSS to address the issue?

* { outline:none; }

If this solution proves effective, consider targeting a specific element (if possible) with a class or id:

#map div:focus { outline:none; }

Answer №2

Latest Update:

By adding a distinct click listener to the draggable marker, I have successfully resolved the issue at hand. Nevertheless, I am puzzled as to why this solution works and would greatly appreciate it if someone could provide an explanation.

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

Preserve the values of checkboxes throughout the entire website by utilizing localStorage

Example A functionality in the example allows users to add images to a container by clicking on checkboxes. However, there is an issue where when a checkbox is checked on one page to store an image, and then another checkbox is checked on a different page ...

How can I make the background of a button change when I move my cursor over it

Is it possible to change the background image of a button when hovering over it? Perhaps have the image transition from left to right for a fading effect? Can this be accomplished? ...

Forbidden access error in codeigniter with Ajax request 403

I'm struggling to send a value via Ajax to a Controller file in Codeigniter, but unfortunately I haven't been successful. Despite researching this issue and finding that it has been asked many times before, I still can't seem to find a solut ...

Is there a way to determine if JavaScript is responsible for triggering the update on my update panel?

To ensure that the update panel with a user control in it only fires after the page has fully loaded, I have implemented the following javascript code: <script type="text/javascript"> function pageLoad(objSender, args) { Sys.WebF ...

Attempting to reduce the width of the dig when it reaches 400

I have a square element with a click event that increases its size by 50 pixels on each click. However, once it reaches a size of 400 pixels, the size decreases by 50 pixels with every click instead. Additionally, when the size of the square reaches 100 p ...

Tips for incorporating validation/restrictions into react-datepicker

I've been working on implementing restriction and validation in a react-datepicker component. I'm utilizing redux-form for validation and normalization purposes. Issue: I've noticed that neither the normalizing function nor the validation f ...

Error compiling template due to custom component issue

Can you help me troubleshoot my custom component? I'm trying to create a setup with: label input Why am I seeing the error message "idfor is undefined"? And what's causing the issue with labeltext? An unexpected identifier was found in the ...

How do I pass input values when calling an AJAX function to submit a form in HTML?

Utilizing a modal to submit new data via AJAX API consumption. Although sending the data through the API is not an issue, my lack of HTML skills makes it confusing on how to pass form data values. This scenario involves displaying a modal for users to in ...

Encountering a type error when attempting to assign an interface to a property

In my Angular project, I am working with typescript and trying to assign the IInfoPage interface to some data. export interface IInfoPage { href: string; icon: string; routing: boolean; order: number; styleType: string; ...

It is not possible to trigger an input click programmatically on iOS versions older than 12

Encountering a challenge in triggering the opening of a file dialogue on older iOS devices, particularly those running iOS 12. The approach involves utilizing the React-Dropzone package to establish a dropzone for files with an added functionality to tap ...

Is there a way for me to utilize the imported data from one component in the context API using an arrow function?

I am trying to utilize placeInfo, reviews, detailsInfo, news from a data file. Instead of using value='hello', I am unsure if I can directly use it like this: value={placeInfo, reviews, detailsInfo, news}, as it is producing an error. Should I st ...

Verify whether a class or id is present in the HTML response obtained from an AJAX request

Is there a way to check the content of HTML returned by an AJAX call before rendering it to avoid any flickering effect? I am aware of using hasClass() to check for classes, but in this scenario, the AJAX response is returning HTML. I can append the HTML ...

The checkbox will be automatically checked whenever there is any modification in the textbox

I'm currently working on a Grid view with a checkbox and two textboxes. What I want is for the checkbox to be automatically checked whenever there is a change in one of the textbox values, for example switching from 0 to 1. This project is being devel ...

"Glowing orbs in the night: a dark mode spectacle with

I have implemented a night mode (or perhaps dark mode) toggle button located at the top-right corner of my webpage. Here is a link to a perfect example showcasing what I am aiming for However, unlike the provided link, I switch between night mode and lig ...

A Beginner's Guide to Duplicating Bootstrap Containers in Jade

I am working with JSON data that is being transmitted from an Express and Mongoose Stack to be displayed on the user interface created in Jade. I am wondering which Jade Construct I should use to loop through a Bootstrap Container of col-md-4 using Jade s ...

Animate the transition of the previous element moving downward while simultaneously introducing a new element at the top

I currently have a hidden element called "new element" that is controlled by v-if. My goal is to create a button labeled "display" that, upon clicking, will reveal the new element on top after sliding down an old element. How can I achieve this using CSS ...

Separate an array in TypeScript based on the sign of each number, and then replace the empty spaces with null objects

Hey, I'm facing a little issue, I have an Array of objects and my goal is to split them based on the sign of numbers. The objects should then be dynamically stored in different Arrays while retaining their index and getting padded with zeros at the b ...

Is it possible to utilize ag-grid's API to filter multiple checkbox values simultaneously?

I am currently utilizing angularjs and have implemented a series of checkboxes to filter my ag-grid. So far, I have successfully utilized radio buttons and the api.setQuickFilter method for filtering based on individual values. However, I am facing an iss ...

In Three JS, shader x, y, z coordinates are based on the orientation of the object rather than the scene itself

Animating the x,y,z coordinates of vertices in a sphere-like manner with horizontal rings around the center using attributes on a THREE.Points() object has been quite intriguing. Initially, with a MeshStandardMaterial(), tilting the Points object along the ...

What could be causing the context of 'this' in Javascript to remain unchanged in this particular scenario?

Currently, I am exploring the concept of 'this' in Javascript and have encountered a perplexing situation. After delving into how JavaScript functions operate as outlined here, I grasped that when a function is invoked on an object, the object i ...