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

dom-repeat and google-map-marker problem #149

Closed
MeloJR opened this issue Jun 9, 2015 · 4 comments
Closed

dom-repeat and google-map-marker problem #149

MeloJR opened this issue Jun 9, 2015 · 4 comments

Comments

@MeloJR
Copy link

MeloJR commented Jun 9, 2015

I have the following snippet:

<google-map id="map" latitude="{{center.lat}}" longitude="{{center.lng}}" click-events on-google-map-click='handleMapClick'>
  <template is="dom-repeat" items="{{spots}}">
    <google-map-marker click-events latitude="{{item.lat}}" longitude="{{item.lng}}" on-google-map-marker-click='handleSpotTap'></google-map-marker>
  </template>
</google-map>

was trying to add a google-map-marker in my map when the user click in it so the handleMapClick function is as follows:

handleMapClick: function(event, detail) {
    var newSpot = {lat: detail.latLng.lat(), lng: detail.latLng.lng()};
    this.push('spots', newSpot);
    this.$.map.resize();  // I don't know if it is necessary
}

with this function the new google-map-marker are added to the DOM (although they are added doubled) but the map doesn't show them.

I try another approach that seems to work:

handleMapClick: function(event, detail) {
     var marker = document.createElement("google-map-marker");
     marker.latitude = detail.latLng.lat();
     marker.longitude = detail.latLng.lng();
     Polymer.dom(this.$.map).appendChild(marker);
}

I checked that the _updateMarkers method of google-map is executed with both approaches but only works with the first. What is the problem with the first approach?

Thank you.

@atotic
Copy link
Contributor

atotic commented Jun 9, 2015

You can't manually add an item to a dom-repeat template. It gets generated, and regenerated automatically from an array.

@atotic atotic closed this as completed Jun 9, 2015
@MeloJR
Copy link
Author

MeloJR commented Jun 9, 2015

I haven't added an item manually to the DOM template, I have used the Polymer API to modify arrays (in the first approach):
this.push('array', elementToPush)

P.S. I had a mistake in my last comment, the approach that works is the second one.

@atotic
Copy link
Contributor

atotic commented Jun 10, 2015

You are right, you did do the right thing. If the element was in dom, it should have been picked up by mutationobserver, and added to map. Who knows, if you'd like to pursue this, create a jsbin somewhere, and I can trace it through.

@ibhi
Copy link

ibhi commented Jul 31, 2016

@atotic
I am facing the same issue. Here is a jsbin(https://jsbin.com/qorowo/edit?html,output) where, I have reproduced the issue. The issue is, inside the dom-repeat, the property binding for latitude and longitude for the google-map-marker is not working, if the data for binding is async(populated, from database etc.,). However, the title property binding is working(its really weird). When I remove theshadow dom strategy, the same code works fine.
I think it is related to #299

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

3 participants