Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7610759
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T01:29:43+00:00 2026-05-31T01:29:43+00:00

Any change in zoom level causes all markers to appear on the map that

  • 0

Any change in zoom level causes all markers to appear on the map that have been on the map at any time since the last page load. This is true whether the zoom level change is due to a setZoom() call in my code or because I operate the zoom slider.

I have a map control widget with buttons to add markers that correspond to different categories. So you click the button for Groups and the map populates with markers that represent Groups. Then you click on the Individuals button and the Groups markers are cleared and deleted and the Individual markers appear on the map. And so on with other categories. But any change in zoom level brings back any markers that have been on the map since the page was last refreshed.

I’m using MarkerClustererPlus. I don’t know whether this would be a bug in MarkerClustererPlus, in Google’s code or in my code. Hopefully the latter. I’ll include my addMarkers function below. Since I both clear and delete the markers before adding new markers, I don’t know how it’s possible for the previous markers to come back, nevermind why a zoom change trigger their return:

function addMarkers(map,flag) { 

  clearOverlays();
  deleteOverlays();

  if ('event' == flag) {
    data = himaps_event_data;
  } else if ('story' == flag) {
    data = himaps_story_data;
  } else if ('group' == flag) {
    data = himaps_group_data;
  } else {
    data = himaps_user_data;
  }

  for (var k in data) {
    var item = data[k];
    var latLng = new google.maps.LatLng(item.lat, item.lng);
    var marker = new google.maps.Marker({'position': latLng});
    markersArray.push(marker); 
  } 

  var markerCluster = new MarkerClusterer(map, markersArray);  
}

Also, if I change zoom, then the markers don’t clear anymore. They just continue to accumulate on the map if I click the buttons to change category. That definitely doesn’t happen if I don’t change the zoom level.

By request, here’s more of the code:

function clearOverlays() {
  if (markersArray) { 
    for (var i = 0; i < markersArray.length; i++ ) {
      markersArray[i].setMap(null);
    }
  }
}

function deleteOverlays() {
  if (markersArray) {
    for (i in markersArray) {
      markersArray[i].setMap(null);
    }
    markersArray.length = 0;
  }
}

/* map controls */
(function($) {
  Drupal.behaviors.himaps = {
  attach: function(context, settings) {
    $('.map-controls button').click(function() {
      flag = this.id.replace('map-',''); 
      addMarkers(map,flag);
    });
  }
  }
})(jQuery);


/* homepage map */
function newMap(clat,clng) {
  if (!clat) {
    clat = 37.65;  
  }
  if (!clng) {
    clng = -97.43;  
  }
  var myOptions = {
    scrollwheel: false,
    mapTypeControl: false,
    mapTypeControlOptions: {
        style: google.maps.MapTypeControlStyle.HORIZONTAL_BAR,
        position: google.maps.ControlPosition.LEFT_CENTER
    },
    panControl: false,
    panControlOptions: {
        position: google.maps.ControlPosition.LEFT_CENTER
    },
    zoomControlOptions: {
        style: google.maps.ZoomControlStyle.LARGE,
        position: google.maps.ControlPosition.LEFT_CENTER
    },
    draggable: true,
    center: new google.maps.LatLng(clat, clng),
    zoom: 4,
    mapTypeId: google.maps.MapTypeId.ROADMAP
  };

  return new google.maps.Map(document.getElementById("map-canvas"), myOptions);

}

var map;
var markersArray = [];
var geocoder; 
var marker;
var listener;

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

function initmapping() { //aka initialize()
  map = newMap();
  addMarkers(map,'group');
  geocoder = new google.maps.Geocoder();
}

Last but not least, here is the MarkerClustererPlus library: http://google-maps-utility-library-v3.googlecode.com/svn/tags/markerclustererplus/2.0.9/src/

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T01:29:44+00:00Added an answer on May 31, 2026 at 1:29 am

    I don’t know much about MarkerClusterer but what appears to be happening is every time you call your addMarkers function you are creating a new MarkerClusterer but the old one is never destroyed/removed, hence on zoom change all instances you have created redraw the markers they have. Try the clearMarkers or removerMarkers method of MarkerClusterer and also only create one instance of MarkerClusterer and reuse it instead of creating a new one each time you cal addMarkers.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an OpenLayers map with a TMS layer. For each zoom change, my
I have imported a JSF/Facelets project from SVN into Netbeans. Any change which I
The strong exception safety guarantee says that an operation won't change any program state
I have a Google map and street view based on provided lat/lng coordinates, zoom,
I have a high-resolution image that I want to use as a tiled map
Is there any way i can implement a zoom listener that can trigger events
I have an Android app with a MapView, and zoom controls have been implemented.
How may I modify a XML file without any change like attributes ordering, tag
Upon serving a request for an ASPX page, if ASP.NET notices any change to
When I change any of the rest of the input boxes equal to the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.