huafu / ember-google-map

An Ember addon to include a google-map Ember friendly component in your apps.
http://huafu.github.io/#/ember?name=ember-google-map
MIT License
87 stars 34 forks source link

Issue in Safari? #63

Closed brandonparsons closed 9 years ago

brandonparsons commented 9 years ago

Hi again,

My map is working perfectly in Google & Firefox. In Safari, I'm getting the following error:

[Error] TypeError: undefined is not an object (evaluating 'val.lat')

Following the stack trace:


    /**
     * Initialize the map
     */
    initGoogleMap: on('didInsertElement', function () {
      var canvas;
      this.destroyGoogleMap();
      if (helpers['default'].hasGoogleLib()) {
        canvas = this.$('div.map-canvas')[0];
        this.createGoogleObject(canvas, null); // <<----------
        this._scheduleAutoFitBounds();
      }
    }),

/////////

    /**
     * Creates the google object
     *
     * @method createGoogleObject
     * @param {*} [firstArg]
     * @param {Object} [optionsOverrides]
     * @return {google.maps.MVCObject}
     */
    createGoogleObject: function (optionsOverrides) {
      var opt = this.serializeGoogleOptions(), object, firstArg, Class;
      if (arguments.length === 2) {
        firstArg = optionsOverrides;
        optionsOverrides = arguments[1];
      }
      opt = Ember['default'].merge(opt, optionsOverrides);
      Ember['default'].debug(fmt(
        '[google-maps] creating new %@: %@', this.get('googleName'), opt
      ));
      Class = this.get('googleClass');
      if (firstArg) {
        object = new Class(firstArg, opt);
      }
      else {
        object = new Class(opt);
      }
      this.set('googleObject', object);
      this.synchronizeEmberObject(); // <<<<------------
      return object;
    },

////////

    /**
     * Synchronize this Ember object by reading all values of the properties from google object
     */
    synchronizeEmberObject: function () {
      var def = this.get('_compiledProperties'),
        go = this.get('googleObject');
      if (!go) {
        return;
      }
      this.beginPropertyChanges();
      for (var i = 0; i < def.length; i++) {
        if (!def[i]._cfg.readOnly) {
          this.setProperties(def[i].readGoogle(go));  // <<<<-------
        }
      }
      this.endPropertyChanges();
    },

////////

  /**
   * Reads the value from the given google object
   *
   * @method readGoogle
   * @param {google.maps.MVCObject} googleObject
   * @returns {Object}
   */
  GoogleObjectProperty.prototype.readGoogle = function (googleObject) {
    var val;
    if (this._cfg.read) {
      val = this._cfg.read.call(this, googleObject);
    }
    else if (this._cfg.optionOnly) {
      return Object.create(null);
    }
    else {
      val = googleObject['get' + this._cfg.name.capitalize()]();
    }
    return this.fromGoogleValue(val);  // <<<<-------- //// VAL IS UNDEFINED HERE!
  };

 /////////////

  /**
   * Convert the value from google to Ember
   *
   * @method fromGoogleValue
   * @param {*} value
   * @returns {Object}
   */
  GoogleObjectProperty.prototype.fromGoogleValue = function (value) {
    var val;
    if (this._cfg.fromGoogle) {
      val = this._cfg.fromGoogle.call(this, value);   // <<<----- 
    }
    else {
      val = helpers['default'].makeObj(this._cfg.key, value);
    }
    return val;
  };

 ////////////

    _latLngFromGoogle: function (latKey, lngKey, val) {
      if (arguments.length === 1) {
        val = latKey;
        latKey = null;
      }
      return helpers.makeObj(latKey || 'lat', val.lat(), lngKey || 'lng', val.lng());  // <<<-----
    },

////////

Any ideas?

brandonparsons commented 9 years ago

I now know why the value was not defined, but still have no idea why it was only affecting Safari.