qvarforth / trackdirect

APRS Track Direct is a collection of tools that can be used to run an APRS website.
GNU General Public License v3.0
72 stars 40 forks source link

Google Maps Broken #49

Open shackrat opened 1 month ago

shackrat commented 1 month ago

Google made an API change over the summer, possibly as a response to the polyfill.io hack. This has had the effect of breaking the InfoWindow class such that it's not compatible with the call() method. The error generated is "TypeError: Cannot call a class constructor without |new|." The error is thrown from within the google library code so it cannot be fixed by the user.

The fix isn't complicated, but I don't have the ability to generate a PR anymore as my repo is archived and aprs.to only uses parts of the original code now.

A few small modifications are required to InfoWindow.js. They center around calling the InfoWindow constructor with the "new" keyword and storing the value in this._iw

Here are the code fragments that require changes..

$t.models.InfoWindow = function (marker, map, disableAutoPan) {
  this._iw = null;
  // Call the parent constructor
  if (typeof google === "object" && typeof google.maps === "object") {
    this._iw = new google.maps.InfoWindow({
      disableAutoPan: disableAutoPan,
    });
$t.models.InfoWindow.prototype.isInfoWindowOpen = function () {
  if (typeof google === "object" && typeof google.maps === "object") {
    if (this._iw.getMap() !== null) {
      return true;
    }
$t.models.InfoWindow.prototype.show = function (
  compactVersion,
  position
) {
  compactVersion =
    typeof compactVersion !== "undefined" ? compactVersion : false;
  position = typeof position !== "undefined" ? position : null;
  this._create(compactVersion);

  if (typeof google === "object" && typeof google.maps === "object") {
    if (position !== null) {
      this.setPosition(position);
      this._iw.open(this._defaultMap);
    } else {
      this._iw.open(this._defaultMap, this._marker);
    }
$t.models.InfoWindow.prototype.hide = function () {
  if (typeof google === "object" && typeof google.maps === "object") {
    this._iw.close();
    if (this._iw.getMap() !== null) {
      this._iw.setMap(null);
    }
$t.models.InfoWindow.prototype._create = function (compactVersion) {
  if (compactVersion) {
    var mainDiv = this._getCompactMainDiv();
    var menuwrapper = this._getMenuDiv(false);

    this._polyline = this._defaultMap.markerCollection.getMarkerPolyline(
      this._marker.markerIdKey
    );
  } else {
    var mainDiv = this._getMainDiv();
    if (!$t.isMobile) {
      mainDiv.append(this._getIconDiv());
    }

    mainDiv.append(this._getCompletePacketDiv());
    var menuwrapper = this._getMenuDiv(true);
  }

  mainDiv.append(menuwrapper);
  var wrapperDiv = $(document.createElement("div"));
  wrapperDiv.append(mainDiv);
  if (typeof google === "object" && typeof google.maps === "object") {
    this._iw.setContent(wrapperDiv.html());
  } else if (typeof L === "object") {

Good luck!

Steve White aprs.to