Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/google-maps/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Google maps 通过使用数据绑定在数组上迭代生成Google地图标记,为什么我会丢失信息窗口和/或单击数据更新上的事件?_Google Maps_Polymer_Google Maps Markers_Web Component_Google Web Component - Fatal编程技术网

Google maps 通过使用数据绑定在数组上迭代生成Google地图标记,为什么我会丢失信息窗口和/或单击数据更新上的事件?

Google maps 通过使用数据绑定在数组上迭代生成Google地图标记,为什么我会丢失信息窗口和/或单击数据更新上的事件?,google-maps,polymer,google-maps-markers,web-component,google-web-component,Google Maps,Polymer,Google Maps Markers,Web Component,Google Web Component,使用谷歌地图v1.1.10对抗git://github.com/GoogleWebComponents/google-map.git#* 我像这样建立我的标记: <template> <site-data sites="{{sites}}"> </site-data> <google-map fit-to-markers > <template is="dom-repeat" items="{{sites}}">

使用谷歌地图v1.1.10对抗git://github.com/GoogleWebComponents/google-map.git#*

我像这样建立我的标记:

<template>
   <site-data sites="{{sites}}"> </site-data>
   <google-map fit-to-markers >
   <template is="dom-repeat" items="{{sites}}">
    <template is="dom-repeat" items="{{item}}">
      <google-map-marker latitude={{item.latitude}}
                         longitude={{item.longitude}}
                         title="{{item.project_name}}"
                         >
        <h1>{{item.project_name}}</h1>
        <p style="margin: 0;">Location: <b>{{item.town}}, {{item.country}}</b></p>
        <p style="margin: 0;">Tech Description: <b>{{item.tech_desc}}</b></p>
      </google-map-marker>
    </template>
  </template>
</google-map>

{{item.project_name}
位置:{{item.town},{{{item.country}

技术说明:{{item.Tech_desc}}

在最初加载webapp时,一切都非常顺利。我可以点击一个标记,信息窗口显示内容。但是,如果我更改了sites数组中的任何值,我似乎会丢失信息窗口和/或单击事件。我必须刷新浏览器以恢复初始状态(单击以显示信息窗口)

此外,如果我更改lat/long并悬停显示工具提示,标记位置将完全更新。标题,也是恰当的

我已经添加了一个click事件,它将调用console.log到click事件中。在{{sites}}绑定中的值被更改之前,它工作得很好,所以当google地图自身更新时,我似乎丢失了单击事件

此元素中没有脚本

如果我能提供更多的信息,请让我知道

提前感谢,,
斯科特

谷歌地图标记似乎存在一些问题。我有一些黑客,你可以尝试,但你应该做一张罚单,以便有人可以采取更深入的研究

一个问题是更新MapMarker的MutationObserver没有观察到
characterData
,因此当MapMarker的简单文本内容更改时,它不会触发

另一个问题是
attach
/
detach
实现似乎不是互补的。例如,
detach
删除MutationObserver,而
attach
从不将其放回原处

最后,在某些情况下,
info
窗口与地图标记器断开连接

这是一个JSBin,其中有三种GoogleMapMarker设置的突变,如您所述:

  • 添加一个新的地图标记似乎效果不错

  • 由于我描述的MutationObserver问题,修改现有标记的内容失败。我通过修补GoogleMapMarker的
    \u contentChanged
    方法修复了这个问题,如下所示:

例如:

marker._contentChanged = function() {
  if (this._contentObserver)
    this._contentObserver.disconnect();
    // Watch for future updates.
    this._contentObserver = new MutationObserver( this._contentChanged.bind(this));
    this._contentObserver.observe( this, {
      childList: true,
      subtree: true,
      ///----------------
      // monkey patch 
      characterData: true
      //-----------------
    });
 ...
  • 最后,我人为地制作了一个示例,从DOM中删除一个标记并将其放回原处。如上所述,此操作失败,因此我对附加的
    和分离的
    进行了修补,如下所示:
例如:

  marker.detached = function() {
    if (this.marker) {
      google.maps.event.clearInstanceListeners(this.marker);
      this._listeners = {};
      this.marker.setMap(null);
      ///----------------
      // monkey patch 
      this.info = null;
      //-----------------
    }
    if (this._contentObserver)
      this._contentObserver.disconnect();
  };
  marker.attached = function() {
    // If element is added back to DOM, put it back on the map.
    if (this.marker) {
      this.marker.setMap(this.map);
      ///----------------
      // monkey patch 
      this._contentChanged();
      //-----------------
    }
  };
您没有指定要触发的更改的性质。
单击不显示信息窗口
问题似乎是当标记和信息变得混乱时会发生什么,可能是发生了
附加/分离


引诱我调查这件事玩得很好。:)

谢谢你调查这件事。我在这里提交了一份报告:你介意我将你的反馈添加到这个问题上吗?在此期间我将利用您的工作,非常感谢!当然,把它链接到这篇文章上,这就是我的想法。