Trouble with mouseout listener in Wordpress causing Google Map to malfunction

Having trouble integrating a map into my WordPress site using the Google Maps API v3. The issue I am facing is that the listener assigned to the mouseout event is not functioning properly. I have copied and pasted the code from another website where it was working fine. The intended functionality is that when you hover over a marker, the info window should appear, and it should disappear when you move the mouse away. However, after hovering over a marker, I am unable to drag the map.

Refer to:

header.php

<script type="text/javascript" src="<?php bloginfo('template_url'); ?>/js/common.js"></script>
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false&language=en"></script>
<script type="text/javascript">
    locations = [<?php echo $locations; ?>];
    iwData = [<?php echo $iwData; ?>];
</script>

Page

<div id="city_canvas" style="margin-top:40px; width:500px; height:300px; border:solid 1px #000;"><script>window.onload = function() {sdgCityMap(<?php echo $cityCoord; ?>);}</script></div>

common.js

var map;  
var myIcon;  
var image;  
var infoWin;  
var markers = new Array();

function sdgCityMap(lat,lng) {
...
    map = new google.maps.Map(document.getElementById("city_canvas"), myOptions);

    function buildOverHandler(i) {
        return function() {showIW(i);};
    }

    function buildClickHandler(i) {
        return function() {lnkToStore(i);};
    }

    for (i in locations) {
        myIcon = (locations[i][0] == 1) ? "http://www.fashiontraveler.com/newsite/media/imgs/maps/mono_store.png" : "http://www.fashiontraveler.com/newsite/media/imgs/maps/multi_store.png";
        image = new google.maps.MarkerImage(myIcon, new google.maps.Size(45,22));
        coords[i] = new google.maps.LatLng(locations[i][2],locations[i][3]);
        markers[i] = new google.maps.Marker({position:coords[i], map:map, icon:image});
        google.maps.event.addListener(markers[i], 'mouseover', buildOverHandler(i));
        google.maps.event.addListener(markers[i], 'mouseout', function(event) {infoWin.close();});
        google.maps.event.addListener(markers[i], 'click', buildClickHandler(i));
    }
    centerZoomMap();
}

function showIW(i) {
    var contentString = '<div id="shopDataMap"><p><span class="VB11435E89">'+locations[i][1]+'</span></p>'+iwData[i]+'</div>';
    infoWin = new google.maps.InfoWindow({content:contentString});
    infoWin.open(map, markers[i]);
}
...
//var infoWin; var redefinition caused the problem!
}

Answer №1

The issue arose due to the duplication of the variable infoWin, with it being defined both at the start and end of the file, likely resulting from a copy/paste action

var map;  
var myIcon;  
var image;  
var infoWin;  
var markers = new Array();

function sdgCityMap(lat,lng) {
...
}

function showIW(i) {
    var contentString = '<div id="shopDataMap"><p><span class="VB11435E89">'+locations[i][1]+'</span></p>'+iwData[i]+'</div>';
    infoWin = new google.maps.InfoWindow({content:contentString});
    infoWin.open(map, markers[i]);
}
...
//var infoWin; var redefinition caused 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

Is it possible to change the text of a scrollspy dropdown to a default text when it is not actively tracking any items?

I am new to Vue and currently implementing Bootstrap Vue Scrollspy (view example here). My sticky dropdown is tracking all referenced content and updates with the current section in view. You can check out my code sample here. Is there a way to set the d ...

I am trying to update the content in ckeditor when a different option is selected, but for some reason it is not working

jquery issue: the jquery that I added and the content doesn't change even though the "alert(model);" works fine <script> $(document).ready(function() { $("select.modele").change(function() { var modele = $(this) ...

Customize your WooCommerce products with added, updated, or removed custom fields

I have a code snippet here that saves a Value to the database. My issue is that even when I delete the input, it still retains the data unless I add a space as input. Here's the code: $field_key_pills_1 = 'custom_text_field_category_pills'; ...

What is the best way to display values from a Localstorage array in a tabular format using a looping structure

I have set up a local storage key 'fsubs' to store form submissions as an array. Here is how I am doing it: var fsubs = JSON.parse(localStorage.getItem('fsubs') || "[]"); var fcodes = {"barcodeno" : this.form.value.barcode, "reelno" : ...

Connect various inputs in Vue.js so they can be updated simultaneously

I need to have multiple text inputs that are interconnected, so when I change the value of one input, the others should update with the same value. These inputs are being generated dynamically in a loop using v-for as shown below: <tbody> <varia ...

AngularJS uses two ng-repeat directives to manage and manipulate data in

I'm implementing a feature where I have two views in my HTML5 code that display the same list. <div class="list" data-ng-repeat="item in model.items"> <div class=list-item"> {{ item.name }} <a data-ng-click="addToLi ...

What techniques can I use to generate a 3D visual effect by shifting the background image layer as the user scrolls (creating a Parallax effect

I have combined two images in the heading; one on top of the other. My goal is to create a subtle vertical movement in the background image as the user scrolls, giving the illusion of depth. Both images share the same width, but the background image is tal ...

What is the method for including the "edit post" feature on a WordPress page where I am displaying a particular page ID using echoing?

Currently, I am in the process of customizing a theme from Elegant Themes called Aggregate. I have managed to customize the home page to feature editable content by pulling in information from a separate page ID and echoing it out. My main query is whether ...

`In Node.js, retry attempts resulted in an HTTP 504 status code.`

I have a scenario where my http server always returns a 504 status code: const express = require('express') const app = express() app.get('/', (req, res) => { console.log('I AM HERE'); res.status(504).send('N ...

What sets onEnter apart from onStart in ui-router?

I am transitioning to the latest version of ui-router (1.0.0-alpha.5) and I am exploring how to utilize the onEnter hook versus the onStart hook: $transitions.onStart() as well as $transitions.onEnter() In previous versions, we only had the event $sta ...

Emphasizing sections using a specific class for paragraph highlighting

Is it possible to dynamically change the style of paragraphs based on certain classes? Let's say we have a text with a list of p elements and we want to modify the styles of paragraphs that come after specific classes, such as 'alert' or &ap ...

Does anyone have insight on which JavaScript library is being utilized in this context?

While perusing an interesting article, I came across an image that caught my attention. Clicking on it revealed a unique way to view the full size. I am curious if anyone knows which JavaScript library was used for this effect. You can find the article her ...

The specified function is not recognized within the HTMLButtonElement's onclick event in Angular 4

Recently diving into Angular and facing a perplexing issue: "openClose is not defined at HTMLButtonElement.onclick (index:13)" Even after scouring through various resources, the error seems to be rooted in the index page rather than within any of the app ...

Is there a way to control the playback of a video, such as

Currently, I am involved in a project related to IPTV. One of my objectives is to be able to capture the moment at which a video is paused so that when clicking on another button, a small iframe opens with the same video continuing from where it was origin ...

Utilizing Three.js to apply a matrix transformation to a collection of objects and subsequently refreshing their positions

How can we ensure that objects added to a group in a scene (now Object3D()) correctly apply the group's matrix, updating their locations within the scene? ...

Searching for a different method in JavaScript that can add items without duplication, as the prependTo function tends to insert multiple items

Every time my code runs successfully, a success message is generated and displayed using prependTo within the HTML. However, the issue arises when the user performs the successful action twice, resulting in two success messages being shown on the screen. ...

While attempting an AJAX request with jQuery, I encountered the following error message: "Error: ER_SP_UNDECLARED_VAR: Undeclared variable: NaN"

I encountered an issue that says: ` throw err; // Rethrow non-MySQL errors ^ Error: ER_SP_UNDECLARED_VAR: Undeclared variable: NaN ` while attempting a jQuery AJAX get request, and I'm unsure of the cause. My backend is built using node.js a ...

What could be causing htmlparser2 in Node.js to add extra nodes during document parsing?

Seeking to extract the HTML content of a webpage using node so I can process its DOM to create something unrelated. It's crucial to accurately obtain the DOM representation from the HTML in order to properly process it. Utilizing htmlparser2 for this ...

Issue with Sequential Drop Down List Functionality in ASP.Net MVC View Page

I am currently in the process of migrating code from one project to another. Although the code works fine in the original project, it is not functioning properly in the new one. I’m uncertain if something was overlooked on my end. Within this code, ther ...

Finding the main directory in JavaScript: a step-by-step guide

My website uses mod_rewrite to reformat the URLs like this: The issue arises when making AJAX calls to a file: I want to access login.php from the root without specifying the full URL or using the "../" method due to varying folder levels. So, I need a ...