First of all let me say I absolutely love the concept of web components. I think it's the future of web development and I am really excited about it.
Now to the issue ... I have problems with google-map inside core-animated-pages. I am able to fix all of them, just wanted to post here for others and maybe to find a better solution.
<link rel="import" href="../../bower_components/polymer/polymer.html">
<link rel="import" href="../cb-home/cb-home.html">
<link rel="import" href="../cb-locations/cb-locations.html">
<link rel="import" href="../cb-paper/cb-paper.html">
<link rel="import" href="../cb-map/cb-map.html">
<polymer-element name="cb-app" attributes="route locations">
<template>
<link rel="stylesheet" href="cb-app.css">
<flatiron-director route="{{route}}" autoHash></flatiron-director>
<core-scaffold id="scaffold">
<core-header-panel navigation mode="seamed" flex>
<core-toolbar>
<span>Climbuddy</span>
</core-toolbar>
<core-menu selected="{{route}}" valueattr="hash">
<paper-item hash="home" noink><a href="/#home">Home</a></paper-item>
<paper-item hash="map" noink><a href="/#map">Map</a></paper-item>
<paper-item hash="locations" noink><a href="/#locations">Locations</a></paper-item>
</core-menu>
</core-header-panel>
<core-toolbar tool flex>
<span flex>Page</span>
<core-icon-button icon="perm-identity"></core-icon-button>
</core-toolbar>
<core-animated-pages id="pages" selected="{{route}}" valueattr="id" transitions="slide-from-right" layout fit>
<!-- home -->
<cb-home id="home"></cb-home>
<!-- map -->
<cb-map id="map" locations="{{locations}}" fit></cb-map>
<!-- locations -->
<cb-locations id="locations" locations="{{locations}}"></cb-locations>
<!-- location -->
<cb-location id="location"></cb-location>
</core-animated-pages>
</core-scaffold>
</template>
<script>
(function () {
Polymer('cb-app', {
ready: function() {
var pages = this.$.pages;
var map = this.$.map;
if (pages.selected !== 'map') {
// fix map size because of core-animated-pages on first
pages.addEventListener('core-animated-pages-transition-prepare', function() {
setTimeout(function() {
map.fixMap();
},0);
});
}
}
});
})();
</script>
</polymer-element>
<polymer-element name="cb-map" attributes="locations">
<template>
<google-map fit id="map" zoom="4" latitude="45.63" longitude="16.16">
<template repeat="{{loc in locations}}">
<google-map-marker title="{{loc.name}}" latitude="{{loc.lat}}" longitude="{{loc.lng}}" icon="/images/markers/marker.png"></google-map-marker>
</template>
</google-map>
</template>
<script>
(function () {
Polymer('cb-map', {
// just a helper function
fixMap: function() {
var map = this.$.map; // google map web component
var gmap = map.map; // google.maps.Map instance
var lat = gmap.getCenter().lat();
var lng = gmap.getCenter().lng();
// at this point, everything is ok
// before resize latitude 45.63 longitude 16.159999999999968
console.log('before resize', 'latitude', lat, 'longitude', lng);
// fix size for core-animated-pages
map.resize();
// at this point latitude and longitude ar wrong
// after resize latitude 19.16672805677583 longitude 42.878749999999954
console.log('after resize', 'latitude', gmap.getCenter().lat(), 'longitude', gmap.getCenter().lng());
// fix center because of resize
map.latitude = lat;
map.longitude = lng;
setTimeout(function(){
// after fixing center is ok again of course
// after fix latitude 45.62999999999999 longitude 16.15999999999995
console.log('after fix', 'latitude', gmap.getCenter().lat(), 'longitude', gmap.getCenter().lng());
},10);
}
});
})();
</script>
</polymer-element>
As you can see, map center is off after map.resize(), so I have to manually reset it, which causes a slight flicker in animation. I'm not sure if this is a bug or I'm doing something wrong. It appears as if latitude and longitude values are switched after resize.