Skip to content
This repository has been archived by the owner on Nov 30, 2018. It is now read-only.

Versions above 2.1.3 rerender map everytime for non primitive type in icon attribute #1785

Open
shikha-desai opened this issue Mar 29, 2016 · 5 comments

Comments

@shikha-desai
Copy link

I have used angular google map for displaying some geo information and used fit="true" attribute on my markers to display all markers in first view.
I had used icon specification as:

item.icon = {
                    url: "http://chart.apis.google.com/chart?chst=d_map_pin_letter&chld=%E2%80%A2|FFBF00", // url
                    origin: new google.maps.Point(0,0), // origin
                    anchor: new google.maps.Point(0, 32) // anchor
                 };

Due to my icon being a non-primitive datatype instead of the primitive specification as: item.icon="url_string", it raised a problem.

My problem was solved by using version 2.1.3

What I found out was that for non primitive data types, angular-google-maps version <=2.1.3 always created a reference to the original object, so whenever it checks that whether an object is changed or not, it got the same object so didn't rerender.
But in the versions above 2.1.3, instead of copying reference to the object, it copies the entire object so everytime it checks for icon, it assumes that the object is changed and tries to rerender entire map. So everytime i zoomed in to see a marker and clicked over it to see InfoWindow, it always zoomed out to the fitted position displaying all markers.

The lines from which I considered this to be a problem are:

version 2.1.3: this.clonedModel = _.extend({}, model); (in function MarkerChildModel.prototype.updateModel)
version 2.3.2: this.clonedModel = _.clone(this.model, true); (in function BasePolyChildModel(arg))

@nmccready
Copy link
Contributor

I believe the cloning code was removed. (thinking leaflet) So is this still an issue. Also it would help if you highlight the lines by copying the github url.

@dhaval-patel
Copy link

@nmccready Creating deep copy of any model is fine. but while doing dirty check.. need to take care of primitive and non-primitive type. Comparison should also be deep. Can not compare two value directly because value can be object also.

 WindowsParentModel.prototype.modelKeyComparison = function(model1, model2) {
          var isEqual, scope;
          scope = this.scope.coords != null ? this.scope : this.parentScope;
          if (scope == null) {
            throw 'No scope or parentScope set!';
          }
          isEqual = GmapUtil.equalCoords(this.evalModelHandle(model1, scope.coords), this.evalModelHandle(model2, scope.coords));
          if (!isEqual) {
            return isEqual;
          }
          isEqual = _.every(_.without(this["interface"].scopeKeys, 'coords'), (function(_this) {
            return function(k) {
              return _this.evalModelHandle(model1, scope[k]) === _this.evalModelHandle(model2, scope[k]);
            };
          })(this));
          return isEqual;
        };

@nmccready
Copy link
Contributor

Instead of copying and pasting code please use github URLS where the code lines are highlighted. It is way easier to get your point across.

@shikha-desai
Copy link
Author

The following line does a direct comparison instead of deep comparison due to which non-primitive types are not working:
https://github.com/angular-ui/angular-google-maps/blob/master/dist/angular-google-maps.js#L6026

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants