The overlappingmarkerspidifier is throwing an error because it is unable to access the property '__e3_' of an undefined variable

I am attempting to implement the overlapping marker spidifier feature in my code. I followed the instructions provided in this link: functioning code of oms

However, upon creating the OverlappingMarkerSpiderfier object, I encounter the error: Uncaught TypeError: Cannot read property '__e3_' of undefined. The line causing this error is:

oms = new OverlappingMarkerSpiderfier(map);

I am combining the example code from the linked source with my existing code but seem to be stuck on this error.

The segment of code I modified can be found between //----spyderfy---->> and everything else remains unchanged:

    'use strict'

window.onload = function() {
  var map;
  var oms;

  if ("geolocation" in navigator){
    navigator.geolocation.getCurrentPosition(onLocation, onError);
  }

  function onLocation(position){

    var myPosition = {
      lat: position.coords.latitude,
      lng: position.coords.longitude
    };

    createMap(myPosition);
    setupAutocomplete();
  }

  //----------------------------------spyderfy-------------------------------->>
  debugger;
  oms = new OverlappingMarkerSpiderfier(map);

    // listeners need to be registered only once
    oms.addListener('click', function(marker, event) {
      infowindow.setContent(marker.description);
      infowindow.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);
      } 
      infowindow.close();
    });

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

    function handleSucess(data){
      data.forEach(function(position_hash) {
        handleItem(position_hash);
      });
    };

    function handleItem(position_hash){


      debugger;
      //Info window content 
      var contentString = '<div id="content">'+
                          '<div id="siteNotice">'+
                          '</div>'+
                          '<h1 id="firstHeading" class="firstHeading">'+position_hash.title+'</h1>'+
                          '<div id="bodyContent">'+
                          '<p>'+position_hash.description+'</p>'+
                          '<p>'+ position_hash.date +'</p>'+
                          '<p>'+ position_hash.formatted_addres +'</p>'
                          '</div>'+
                          '</div>';

      var img = 'http://www.google.com/mapfiles/marker.png';
      var myLatLng = new google.maps.LatLng(position_hash.latitude, position_hash.longitude);
      var marker = new google.maps.Marker({
          position: myLatLng,
          map: map,
          icon: "https://cdn1.iconfinder.com/data/icons/Map-Markers-Icons-Demo-PNG/48/Map-Marker-Marker-Inside-Azure.png"
          });

      // to be possible in "click" show specific content
      marker.description = contentString;

      oms.addMarker(marker);

    };

//---------------------------------------spyderfy----------------------------->>


  function onError(err){
    console.log("What browser are you using? IE 7??", err);
  }

  function createMap(position){
    map = new google.maps.Map($('#map')[0], {
      center: position,
      zoom: 15,
    });
    yourPosition(position);

    $( document ).ready(function() {
      $.ajax({
        url:"http://localhost:3000/events.json",
        dataType: "json",
        success: handleSucess,
        error: handleError
      });
    });
  }

  function yourPosition(position){

    var marker = new google.maps.Marker({
      position: position,
      animation: google.maps.Animation.DROP,
      map: map,
      icon: {
      url: 'assets/your_pos.png',
      scaledSize: new google.maps.Size(60, 60), // scaled size
      origin: new google.maps.Point(0,0), // origin
      anchor: new google.maps.Point(0, 0) // anchor
      },          
      title: "You are here",
    });
  };

  function createMarker(position, position_hash) {};

    function handleError(jqXHR, status, errorThrown){
      alert("Something bad happened: "
        + status + ', ' + errorThrown);
    }
};

I have included a snippet below to simplify the identification of the error:

'use strict'

window.onload = function() {
  var map;
  var oms;

  //----------------------------------start-spyderfy-------------------------------->>
  oms = new OverlappingMarkerSpiderfier(map);

  // listeners need to be registered only once
  oms.addListener('click', function(marker, event) {
    infowindow.setContent(marker.description);
    infowindow.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);
    }
    infowindow.close();
  });

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

  function handleSucess(data) {
    data.forEach(function(position_hash) {
      handleItem(position_hash);
    });
  };

  function handleItem(position_hash) {
    //Info window content 
    var contentString = position_hash.title;

    var img = 'http://www.google.com/mapfiles/marker.png';
    var myLatLng = new google.maps.LatLng(position_hash.latitude, position_hash.longitude);
    var marker = new google.maps.Marker({
      position: myLatLng,
      map: map,
      icon: "https://cdn1.iconfinder.com/data/icons/Map-Markers-Icons-Demo-PNG/48/Map-Marker-Marker-Inside-Azure.png"
    });

    // to be possible in "click" show specific content
    marker.description = contentString;

    oms.addMarker(marker);

  };

  //---------------------------------------end-spyderfy----------------------------->>
function createMap(position) {
    map = new google.maps.Map($('#map')[0], {
      center: {
      lat: 41.4064557,
      lng: 2.1920477
    },
      zoom: 15,
    });

  function onError(err) {
    console.log("What browser are you using? IE 7??", err);
  }

    $(document).ready(function() {
      data=[{
    "id": 26,
    "title": "Fancy event",
    "latitude": 41.4064557,
    "longitude": 2.1920477
     },
     {
    "id": 27,
    "title": "betaBeers",
    "latitude": 41.391829,
    "longitude": 2.177191,
     }]
       handleSucess(data);
  });
  }


  function handleError(jqXHR, status, errorThrown) {
    alert("Something bad happened: " + status + ', ' + errorThrown);
  }

};
<html>

<head>
  <style>
    #map {
      height: 300px;
      margin: 0px;
      padding: 300px;
    }
  </style>
  <script src="https://maps.googleapis.com/maps/api/js?v=3.exp"></script>
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
  <script src="http://jawj.github.io/OverlappingMarkerSpiderfier/bin/oms.min.js"></script>
</head>

<body>
  <div id="map"></div>
</body>

</html>

Answer №1

Here is the complete code snippet that is currently operational. It might come in handy for someone in need of assistance down the line. The code is not minified and is as it appears in my project.

The following part actually works smoothly:

    'use strict'
  var map;
  var oms;

  //Create info window (only one needed)   
  var infowindow = new google.maps.InfoWindow(); 

  if ("geolocation" in navigator){
    navigator.geolocation.getCurrentPosition(onLocation, onError);
  }

  function onLocation(position){

    var myPosition = {
      lat: position.coords.latitude,
      lng: position.coords.longitude
    };

    createMap(myPosition);
    oms = new OverlappingMarkerSpiderfier(map);
    // listeners need to be registered only once
    oms.addListener('click', function(marker, event) {
      infowindow.setContent(marker.description);
      infowindow.open(map, marker);
    });

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

    setupAutocomplete();
  }

  function createMap(position){
    map = new google.maps.Map($('#map')[0], {
      center: position,
      zoom: 15,
    });
    yourPosition(position);

    $( document ).ready(function() {
        $.ajax({
          url:"http://localhost:3000/events.json",
          dataType: "json",
          success: handleSucess,
          error: handleError
        });
    });
  }

    function handleSucess(data){
      data.forEach(function(position_hash) {
        if (moment(position_hash.date).isAfter(moment())) {
          handleItem(position_hash);
        };
      });
    };

    function handleItem(position_hash){
      //Info window content 
      var contentString = '<div id="content">'+
                          '<div id="siteNotice">'+
                          '</div>'+
                          '<h1 id="firstHeading" class="firstHeading">'+position_hash.title+'</h1>'+
                          '<div id="bodyContent">'+
                          '<p>'+position_hash.description+'</p>'+
                          '<p>'+ position_hash.date +'</p>'+
                          '<p>'+ position_hash.formatted_addres +'</p>'
                          '</div>'+
                          '</div>';

      var img = 'http://www.google.com/mapfiles/marker.png';
      var myLatLng = new google.maps.LatLng(position_hash.latitude, position_hash.longitude);
      var marker = new google.maps.Marker({
          position: myLatLng,
          map: map,
          icon: "https://cdn1.iconfinder.com/data/icons/Map-Markers-Icons-Demo-PNG/48/Map-Marker-Marker-Inside-Azure.png"
          });

      marker.description = contentString;

      oms.addMarker(marker);

    };


  function onError(err){
    console.log("What browser are you using? IE 7??", err);
  }

  function createMap(position){
    map = new google.maps.Map($('#map')[0], {
      center: position,
      zoom: 15,
    });
    yourPosition(position);

    $( document ).ready(function() {
        $.ajax({
          url:"http://localhost:3000/events.json",
          dataType: "json",
          success: handleSucess,
          error: handleError
        });
    });
  }

  function yourPosition(position){

    var marker = new google.maps.Marker({
      position: position,
      animation: google.maps.Animation.DROP,
      map: map,
      icon: {
      url: 'assets/your_pos.png',
      scaledSize: new google.maps.Size(60, 60), // scaled size
      origin: new google.maps.Point(0,0), // origin
      anchor: new google.maps.Point(0, 0) // anchor
      },          
      title: "You are here",
    });
  };

    function handleError(jqXHR, status, errorThrown){
      alert("Something bad happened: "
        + status + ', ' + errorThrown);
    }


  function setupAutocomplete(){
    var input = $('#location-placheholder')[0];
    var autocomplete = new google.maps.places.Autocomplete(input);
    autocomplete.addListener('place_changed', function(){
      var place = autocomplete.getPlace();
      if (place.geometry.location) {
        $("#location-longitude").val(place.geometry.location.lng().toFixed(7));
        $("#location-longitude").trigger('input');
        $("#location-latitude").val(place.geometry.location.lat().toFixed(7));
        $("#location-latitude").trigger('input');
        $(".filling").val(place.formatted_address);
        $(".filling").trigger('input');
        map.setCenter(place.geometry.location);
        //createMarker(place.geometry.location, place.formatted_address);
      } else {
        alert("The place has no location...?")
      }
    });
  };

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

Utilizing a variety of textures across various surfaces of a single geometry

I'm new to working with Three.js and I have a question about displaying multiple images over a plane geometry. Here is the scenario: Imagine a simplified case where we have a plane divided into tiles like this: +---+---+---+ | 1 | 2 | 3 | +---+- ...

Achieving a dynamic "Picture Presentation" feature with JavaScript/jQuery

Currently, I am in the process of developing a website that will serve as a presentation. My plan is to create a slideshow effect using JavaScript. While I have implemented some functions, I must admit that it is not very organized at the moment. The main ...

What are the best methods for creating JavaScript charts that efficiently handle massive amounts of data?

After conducting a thorough search, I couldn't find any article similar to what I'm working on for my ASP.Net MVC4 project. The main challenge we're facing is drawing charts with AJAX and JavaScript for extremely large amounts of data. For ...

Transferring data from SocketIO to Vue.js

Is there a way to effectively transfer data results received from socketIO to the Vue instance? Below is my current code implementation: let socket = io(); let users; socket.on('user-connected', (data) => { users = data.count; }); socket ...

Transforming a circular data structure into JSON format within Firebase

The data returned from firebase is causing an issue when I try to stringify it: JSON.stringify(data) // where data represents the returned object This results in the error: TypeError: Converting circular structure to JSON What is the correct way to hand ...

Symfony along with React router have encountered an error: route not found

In my current project, I am working with Symfony3 and integrating React.js along with react-router to create a bundle. One issue I have encountered is that when using the routing in React, if I refresh the page, the Symfony routing module displays 'N ...

The method element.focus() is ineffective on a contentEditable div element that has been rerendered

https://example.com import React, { useEffect, useState } from "react"; import "./styles.css"; const MyCustomComponent = () => { const [text, setText] = useState(""); useEffect(() => { const textarea = documen ...

Showing data retrieved from nested JSON arrays in React Native

Recently, I delved into the world of React Native and encountered a challenge in displaying nested elements from fetched JSON data. Despite utilizing react hooks in the fetch API, I couldn't quite crack the code. export default function MedProfilScre ...

Clearly defined form field even with the inclusion of value=" "

I have a database that I am using to display data in an HTML form for user editing. <input type="text" id="name" placeholder="Name" required = "true" value = <?php if(isset($_SESSION['name'])) echo $_SESSION['name'] ;?>> ...

Utilize jQuery function within an HTML form

I am trying to integrate my jQuery function with an HTML tag for my login form that connects to an Azure database. I want a modal pop-up to appear when the client presses the Login button, displaying a specific message based on whether the user is in the d ...

How to display a name in an iframe using React

When I retrieve the movie name in React, it appears correctly as {movie.name} / {movie.enname} ({years}) . However, when I try to display this name within an iframe window at https://example.com/movie/{movie.name}, it does not show up properly. Here is th ...

JavaScript - Deleting the last element of an array

I have currently integrated a third-party API to visualize data using Highcharts. This external API provides data specific to the current month, such as March, April, May, and so on. graphArrOne contains an array with 251 elements. graphArrTwo contains ...

Exploring techniques to compare two objects in JavaScript and then dynamically generate a new object with distinct values

var person1={ name:"Sarah", age:"35", jobTitle:"Manager" } var person2={ name:"Sarah Sanders", age:"35", jobTitle:"Manager" } //the name value has been updated in the above object, s ...

I have been working on incorporating a menu item in React, but I keep encountering an error

I am using the MenuItem component to create a dropdown menu in my React project. Despite importing the necessary package, I am encountering an error when running the server. I have searched for solutions but haven't found a definitive me ...

JavaScript middleware not detected

Currently, I have begun self-learning and encountered a roadblock that I can't seem to overcome. I am attempting to design a login page and delving into middleware for the first time. The error message I'm facing is: throw new TypeError('a ...

Is it secure to store the access token within the NextAuth session?

Utilizing a custom API built with Node.js and Express.js, I have implemented nextAuth to authenticate users in my Next.js application. Upon a successful login, the date is stored in the nextAuth session and can be accessed using the useSession hook. To acc ...

Whenever I press a button, my card holder gradually slides downwards

I'm facing an issue with my code and I'm unsure whether it's related to CSS or JavaScript. Whenever I click the button on my page, my card-container2 moves downward unexpectedly. Here is the snippet of my code: HTML: <div class="car ...

The call function in Tween.js fails to execute after adding an EventListener

I encountered an issue while using tween.0.6.2. The following code snippet (borrowed from the tween.js Getting Started page and slightly simplified) works perfectly: createjs.Tween.get(circle) .to({x: 400}, 1000, createjs.Ease.getPowInOut ...

AngularJS property sorting: organize your list by name

I have a complicated structure that resembles: { 'street35':[ {'address154': 'name14'}, {'address244': 'name2'} ], 'street2':[ {'address15& ...

Tips for aligning an element in the center in relation to its sibling above

Help Needed with Centering Form Button https://i.sstatic.net/QhWqi.png I am struggling to center the "Send" button below the textarea in the form shown in the image. Despite trying various methods like using position absolute, relative, and custom margin ...