Markers are not displaying after integrating overlapping marker spiderfier with Google Map v3

Currently, I am trying to incorporate the Overlapping Marker Spiderfier add-on into my Google Map configuration. The location data is retrieved from MongoDB and passed to a Jade Template.

Prior to implementing the add-on, I utilized a for loop to generate markers from an array of coordinates, which displayed correctly on the map.

However, after integrating the Spiderfier code, the markers are no longer being added to the map. Even though the map is still visible, the JavaScript console is showing an error message:

Uncaught Reference Error - OverlappingMarkerSpiderfier is not defined
. Does this suggest that there is an issue with how the add-on is being called? Despite my efforts, such as:

  • Reviewing existing examples of the add-on
  • Comparing my code to other solutions on Stack Overflow

Below is the code related to the Google Map:

script(src="http://maps.googleapis.com/maps/api/js?key=AIzaSyASXfB-y1pwF_S-qToDhYL7doiHrUFOx0Q&sensor=false")
script(src"http://jawj.github.io/OverlappingMarkerSpiderfier/bin/oms.min.js")

script.
    var locationArray = [];
each tweetlocations, i in locationlist
    script.
        var latitude = "#{tweetlocations.latitude}";
        var longitude = "#{tweetlocations.longitude}";

        var markerlocation = new google.maps.LatLng(latitude,longitude);
        locationArray.push(markerlocation);

<script>.
    function initialize()
    {

        var mapProp = {
            center:markerlocation,
            zoom:1,
            mapTypeId:google.maps.MapTypeId.ROADMAP
        };

        var map=new google.maps.Map(document.getElementById("googleMap"),mapProp);
        var iw = new google.maps.InfoWindow();
        var oms = new OverlappingMarkerSpiderfier(map,{markersWontMove: true, markersWontHide: true});

        var usualColor = 'eebb22';
        var spiderfiedColor = 'ffee22';
        var iconWithColor = function(color) {
            return 'http://chart.googleapis.com/chart?chst=d_map_xpin_letter&chld=pin|+|' + color + '|000000|ffff00';
        }
        var shadow = new google.maps.MarkerImage('https://www.google.com/intl/en_ALL/mapfiles/shadow50.png',
            new google.maps.Size(37, 34),
            new google.maps.Point(0, 0),
            new google.maps.Point(10, 34)
        );

        oms.addListener('click', function(marker, event) {
            iw.open(map, marker);
        });

        oms.addListener('spiderfy', function(markers) {
            for(var i = 0; i < markers.length; i ++) {
                markers[i].setIcon(iconWithColor(spiderfiedColor));
                markers[i].setShadow(null);
            } 
            iw.close();
        });

        oms.addListener('unspiderfy', function(markers) {
            for(var i = 0; i < markers.length; i ++) {
                markers[i].setIcon(iconWithColor(usualColor));
                markers[i].setShadow(shadow);
            }
        });

        var bounds = new google.maps.LatLngBounds();
        var coord;
        for (coord in locationArray) {
            bounds.extend(coord);
            var marker = new google.maps.Marker({
                position: locationArray[coord],
                map: map,
                icon: iconWithColor(usualColor),
                shadow: shadow
            });
            oms.addMarker(marker);
        }
    }

    google.maps.event.addDomListener(window, 'load', initialize);

Answer №1

It appears there was a minor error in the second script() function, as the = sign was missing between src and url. As a result, the external Spiderfier script failed to load, leading to the error message

OverlappingMarkerSpiderfier is not defined
.

To correct this issue, simply update

script(src"http://jawj.github.io/OverlappingMarkerSpiderfier/bin/oms.min.js")

to include the = sign like so:

script(src="http://jawj.github.io/OverlappingMarkerSpiderfier/bin/oms.min.js")

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

Passing data from React component to JavaScript page or function

I am trying to pass a variable called "pokemon" from Cell.js to Detail.js. Cell.js creates buttons, each representing a different pokemon. When clicked, it should navigate to a detailed page about the specific pokemon. Therefore, I need to send the pokemo ...

Error occurred due to an invalid element type with the imported React component

Using a component imported from an npm package in two different apps has resulted in unexpected behavior. In one app, the component functions perfectly as expected. However, in the other app, an error is raised: Element type is invalid: expected a string ...

Having difficulty controlling the movement of my object with an onscreen joystick (nipplejs) using three js and ammo js

Currently, I am working on an open-world project using three.js along with the ammo.js physics engine. After completing all the necessary setup and ensuring that collisions are functioning correctly, I encountered a particular issue. Despite my efforts, ...

Steps to retrieve the specific card ID when a button is clicked using REACT

Hey there, hope all is well! I've successfully retrieved experiences from the database and stored them in a state called 'experiences' as shown in the code snippet. Now, I'm trying to get the currently selected experience when clicking ...

The npm postinstall script is functional, however, it does not complete successfully and ends

I have encountered an issue while trying to solve a problem with my project. In my package.json file, I have included a postinstall script that connects to a database and calls a function to write data into it. The script seems to be working fine as the da ...

Having trouble connecting to socket.io

I have a question that I haven't been able to find the answer to despite reading tutorials and websites. After installing node.js and running npm install socket.io, I don't see any errors in the command line but I am unable to access socket.io as ...

Time-sensitive Meteor Collections that automatically expire

I was thinking of using a Collection for this. It's crucial that the data gets cleared after a certain period of time, though. Is there a way to set an expiration date for a Meteor Collection? I need to empty the collection 30 seconds after making m ...

Retrieve the information from all promises

Hey there, I hope you're having a great day! So, after successfully returning multiple images using multer and testing it out, I now want to access the result variable. Take a look at how I achieved this below: req.body.images = []; const images = ...

Choosing a unique identifier attribute using jQuery

Why does the 'In Stock' field get replaced by the last quantity entered instead of updating individually for each product? <form action="add_sales.php" method="POST"> <table class="table table-striped table-bordered table-hover res ...

The Google API Node.js client version 5.2.0 is facing difficulties in installing its dependencies

After updating to version 5.2.0, I encountered issues with npm failing to install dependencies. Launching my project resulted in a "dependency swig is missing" error message. Attempting to manually install it using the command (npm install swig), I then ...

What is the best way to incorporate user-provided values into a dynamic URL?

I am trying to create a feature where users can input a value and then click a button that will take them to a URL tailored to their entry. Here is my current code, but I am facing an issue - the user_input data does not seem to be passed to the URL when ...

Assigning a default value to an AngularJS service

Here is a sample configuration: var myApp = angular.module('myApp', []); myApp.factory('Data', function () { return { message: "I am data from a service" }; }); function FirstCtrl($scope, Data) { $scope.data = Data; } function ...

Unlocking the contents of an array from a separate file in Next.js

I am developing a Quiz App that consists of two main pages: takeQuiz.js and result.js. My goal is to transfer the data from the multiple-choice questions (mcqs) in takeQuiz.js to be accessible in result.js. Utilizing router.replace(), I ensure that once th ...

How can I categorize the message.author.id into different arrays according to numerical values?

There's a coding scenario that involves inserting the message.author.id into an array within a JSON file. The code snippet looks like this: if(message.content.startsWith (prefix + " craft")) { let editedmessage = message.content.slice(pr ...

What is the best way to shut down a browser using C#?

After clicking the Login button, I want to automatically close the browser if the login is successful. protected void btnLogin_Click(object sender, AuthenticateEventArgs e) { if (isAuthenticated) { // close the browser } } Since I am not using AJAX, thi ...

Change the term to its corresponding translation

I have developed an Ionic Multilingual App that includes a select feature. Within this select, choosing a specific option disables certain page elements. However, I am facing an issue where one of the elements needs to change its text based on the selected ...

After the element is re-rendered, the React ref becomes null

My task management system includes a to-do list where tasks can be either a single big textarea (referred to as dataArea) or a list of those textareas. The goal is for these textareas to dynamically grow in height as content is added, achieved by setting t ...

What is the best way to send URL encoded JSON data and receive a response?

I have been attempting to send URL-encoded data using the code snippet below: $.post( "url",{param:"value"},function(data){ alert("data==="+data); }); In this case, the URL is a restful API URL. Unfortunately, this approach was not successful. I the ...

Conceal confidential information in the response for users using NestJS and Mongoose

I recently delved into using nest in the past week and although I found it extremely useful, there are a few aspects that I am unable to replicate from a traditional Express/Mongoose application. One of these aspects is securely passing sensitive data such ...

Extracting responseXML data specifically for CSS styling purposes

I am working on a simple XMLHttpRequest setup that fetches data from an xml file and displays it in a div on my webpage within a ul element: var requestData; if (window.XMLHttpRequest){ requestData = new XMLHttpRequest(); }else{ requestData = new ...