1
試行聚合物,想知道如何標記元素添加到聚合物元件。我知道如何將標記添加到標準的谷歌地圖。我應該只在Google地圖元素標記數組中插入一個標記對象嗎?如果是這樣的簽名是什麼,有沒有例子?在我這樣做之後,是否需要調用某種映射init或刷新,還是自動更新?你如何編程添加標記到聚合物谷歌地圖元素
(function() {
Polymer({
is: 'users-map',
created: function(){
this.loadMap(this.data[0]);
},
loadMap: function(row) {
var map = document.querySelector('#users-location-map');
row.users.forEach(function (user) {
var location = user.location;
var markerOptions = {
position: {lat: location[1], lng: location[0]},
//map: map //can't set this otherwise it throws an error on finding the google library
};
if (!user.online) {
markerOptions.icon = 'http://chart.apis.google.com/chart?chst=d_map_pin_letter&chld=%E2%80%A2|666666';
}
map.markers.push(something); //how should I instanstiate this something
// new google.maps.Marker(markerOptions); //normally I would just do this
});
},
下面的答案如果我註釋掉地圖的assingment的作品。
我還注意到,我的地圖變量顯示爲空,在我的模板我使用<谷歌地圖ID =「用戶定位地圖」> ...我在正確與我的查詢選擇選擇呢? – MonkeyBonkey
如果我選擇它的聚合物構造或準備功能之外,作爲模板文件本身的腳本,它找到的參考。 – MonkeyBonkey
好吧,所以通過將它改爲ready事件來修復dom引用。但是,我仍然遇到無法在google-map-marker元素中引用google地圖的問題。我是否必須硬編碼對google maps api腳本的引用,即使它位於Web組件中? – MonkeyBonkey