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