Google Maps is great, but some hacks are needed

I’m currently working on an AJAX-driven site also using Google Maps’ externally accessible API. But I have as several others been frustrated about the fact, that the GMarkerManager-class does not contain a clearMarkers method. So I combined the open-sourced source with the latest closed-source release, and mashed stuff up like this:

JAVASCRIPT:
  1. // hack GMarkerManager to contain a method for clearing all markers
  2. GMarkerManager.prototype.clearMarkers = function() {
  3.     var me = this;
  4.     //
  5.     // clear currently shown
  6.     if (me.Wd > 0) {
  7.         me.Id(me.K, me.Kd);
  8.     }
  9.     //
  10.     // reset arrays
  11.     var maxZoom = me.df;
  12.     var maxWidth = 256;
  13.     for (var zoom = 0; zoom < maxZoom; ++zoom){
  14.         me.ed[zoom] = [];
  15.         me.oc[zoom] = 0;
  16.         me.gc[zoom] = Math.ceil(maxWidth/me.Ec);
  17.         maxWidth <<= 1;
  18.      }
  19.     me.refresh();
  20. }

It is “hardcoded” to version 2.76 and will need to be changed for later versions of the API, but for now it must do :)

Feel free to use under the given license.

Leave a comment

Name: (Required)

eMail: (Required)

Website:

Comment: