Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

google-map-marker content does not update in dom-repeat #263

Open
mchp opened this issue Feb 26, 2016 · 6 comments
Open

google-map-marker content does not update in dom-repeat #263

mchp opened this issue Feb 26, 2016 · 6 comments

Comments

@mchp
Copy link

mchp commented Feb 26, 2016

Create some google-map-marker with content (infowindow) via dom-repeat template bounded to a data array. When the bound data changes, the position of all the markers are updated, but the contents are not.

I think this is because dom-repeat efficiently reuses existing doms. When google-map calls _attachChildrenToMap, child.map could already be set to the current map. Since the value is not updated, google-map-marker's _mapChanged and indirectly _contentChanged method is never called.

The MutationObserver attached in _contentChanged is also never fired because of this.

Example

      <template is="dom-repeat" items="[[data]]">
        <google-map-marker latitude="[[item.latitude]]" longitude="[[item.longitude]]">
          [[item.details]]
        </google-map-marker>
    </google-map>
  Polymer({
    properties: {
       data: {
         type: Array,
         value: [{
           latitude: 10.0,
           longitude: 10.0,
           details: "OLD VALUE",
         }]
       }
    },
    ready: function() {
      this.data = [{
        latitude: 20.0,
        longitude: 20.0,
        details: "CURRENT VALUE"
      }];
    }
  })
@ebidel
Copy link
Contributor

ebidel commented Feb 26, 2016

I believe this is related to #168. Namely, data binding does not work properly in the marker's info window. That's because, currently, the info window uses the imperative Maps API to create it. Changes after the first setup are not detected.

@framled
Copy link

framled commented Jun 2, 2016

I had the same issue... the info window doesn't render properly when use a filter on a dom-repeat
I just use a patch solution for fixit...

my solution:
every time when the user click on a google-map-marker element, create a new info window.

var marker = event.target.marker;
var item= event.model.item;
var contentString = "<span>" + item.location + "</span>;
var infowindow = new google.maps.InfoWindow({
    content: contentString
});
infowindow.open(this.$.googleMap.map, marker);
lastOpened = infowindow;

@thexs-dev
Copy link

this might be related with pull 294?
#294

I am using that patch and it's working fine, so far

@mabeing1
Copy link

mabeing1 commented Nov 2, 2016

I found the solution by simply adding the map = {{map}} property to the google-map and google-map-market elements
<google-map id="map" map={{map}}> <template is="dom-repeat" items="[[data]]"> <google-map-marker map={{map}} latitude="[[item.latitude]]" longitude="[[item.longitude]]"> [[item.details]] </google-map-marker> </template> </google-map>

@cbald24
Copy link

cbald24 commented Nov 7, 2016

I know this is unrelated but how did you guys make it so your map-marker locations would update. I currently have a polymer project where we want our map marker's to auto update their position every few seconds. we know it gets the new position correctly but doesn't visually update on the map. trying to use the marker's to track moving objects, and this has been our biggest hurdle

@framled
Copy link

framled commented Nov 7, 2016

@cbald24 you can do it with a
setTimeout(function(){updateMarkers()}, 3000);

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

No branches or pull requests

6 participants