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

Ways to import a library in JavaScript/TypeScript on a web browser?

I'm currently working on a project that involves a TypeScript file and an HTML page. Right now, I am loading the necessary libraries for the TypeScript file in the HTML Page using script tags like <script src="https://unpkg.com/<a href="/cd ...

How can you efficiently pass the index as a prop to a child component in React.js when dealing with arrays stored in

Just starting out with React, so bear with me if my terminology is a bit off. I'm working on a table that displays a list of people in a specific order. I want to be able to assign a this.props.tablePosition value based on the index of each person. t ...

React.js and Visual Studio Code have recently been causing unexpected and massive "Module not found" errors

Everything was going smoothly with my project until I uploaded it to Github and then cloned it. Suddenly, I started encountering various "Module not found: Can't resolve..." import errors. For example: Module not found: Can't resolve './co ...

"Encountered a 'NextAuth expression cannot be called' error

Recently, I delved into learning about authentication in Next.js using next-auth. Following the documentation diligently, I ended up with my app/api/auth/[...nextauth]/route.ts code snippet below: import NextAuth, { type NextAuthOptions } from "next-a ...

The functionality of the JQuery $.post method may be compatible with Firefox but may encounter issues when

I've encountered an issue with my website where certain functions that update the database using $.post work perfectly in Firefox, but fail to function properly in Internet Explorer. I'm struggling to identify the root cause of this problem. Here ...

The efficiency of XSL Template is significantly impacting loading time

Hello there, I am facing a challenge with my webpage's loading speed due to the code provided below. Can you assist me in optimizing it? <xsl:template match="Category" mode="CategorySelectorScript"> <xsl:variable name="ThisCateg ...

Error: Improper hook call detected with no hooks being used (material-ui v5)

I've created the following basic application: import Grid from '@material-ui/core/Grid'; function App() { return ( <div className="App"> <Grid container spacing={2}> <Grid item xs={8}> ...

vuejs props become null upon page refresh

MyComponent.vue template: <ResponsiveNavigation :nav-links="navLinks" /> script data: () => ({ navLinks: [] }), created: function() { this.getSocialMediaLinks(); }, methods: { getSocialMediaLinks() { var self = this; ...

What are the steps for implementing custom edit components in material-react-table?

I am currently using the official material-react-table documentation to implement a CRUD table. You can find more information at this link: . However, I encountered an issue while trying to utilize my own custom modal components for the "create new" featur ...

Transform the MUI Typescript Autocomplete component to output singular values of a specific property rather than a complete object

When utilizing MUI Autocomplete, the generic value specified in onChange / value is determined by the interface of the object set in the options property. For instance, consider an autocomplete with the following setup: <Autocomplete options={top ...

Create a compressed package of a Vue project that can easily be inserted into a Blogger blog post as a single HTML file

Is there a way to package all the files related to a Vue.js project (HTML, JavaScript, CSS) into one single HTML file for easy deployment on a Blogger Blogspot post? In the past, a question similar to this was asked regarding bundling files into a single ...

Creating a consistent base URL for both Vue and Apache reverse proxy configurations

Currently, I am experimenting with a Vue app and testing it using pm2 in conjunction with Apache. After starting the app with pm2 and running it on port 3000, I then utilize an Apache reverse proxy to access the app through a domain and HTTPS. However, I e ...

Tips for assigning data from an AJAX response to a variable

Using jQuery and the code provided, there seems to be an issue with variable scope when some_condition is false. The error "items is not defined" indicates this problem. The goal is to set the result variable to the AJAX response data in order to use it o ...

Including input within a component causes the input to capture all click events

I've been working on a project where I need to create a color picker component. When you click on the .swatch element, a popover opens up with a .cover div that covers the whole screen. Clicking on the cover closes the popover, following standard beha ...

Using the onKeyUp and onKeyDown functions to detect when the spacebar key is pressed

Is there a way for my function to be triggered by either clicking a button or pressing the spacebar? I have managed to make it work partially, but it's not quite right. This is the function in question: const showText = () => { const x = Toug ...

The AWS lambda function is experiencing difficulties with the AWS.HttpClient handleRequest operation

In my Node.Js lambda function, I am utilizing AWS HttpClient's handleRequest to search an ElasticSearch URL using the AWS SDK. I am following the guidelines provided in the AWS Documentation. Click here for more information on ES request signing. Pl ...

When the user clicks on the iframe, they will be redirected to the

My goal is to create a scenario where clicking on an iframe opens the same URL in a new browser tab, while ensuring that scroll and other mouse events within the iframe are not affected. I have experimented with various approaches but none have been succe ...

Adjust width based on value dynamically

I currently have a div that is sized at 250px, housing 3 child divs within it. My goal is for each of these 3 divs to dynamically scale based on their respective values, eventually reaching 100% width. This is the code snippet I am working with: <di ...

Strange issue with Firefox when utilizing disabled attribute as "disabled"

I found a curious bug in Firefox: Check out (unfortunately not reproducible in jsfiddle) <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html> <head> < ...

Activating a link click inside a table with jquery

I have been attempting to trigger a click on an anchor within the table compareTable with the code below, however it does not appear to be working as expected. Would anyone be able to provide insight into a possible solution? $('#compareTable a' ...