Google Maps错误?显示的标记根据缩放级别而变化

时间:2015-03-06 03:07:34

标签: javascript google-maps coffeescript

我正在显示一张Google地图,其中包含我已存储在数组中的一组固定标记。显示的特定标记取决于用户选择的日期。选择日期后,我会显示相应的标记,并更新每个标记的信息窗口,以查看该位置的事件。

我遇到的问题如下。有两个标记相对靠近,称为M1和M2。我选择了一个应该显示M2的日期,一切都按预期工作。显示正确的标记,并在信息窗口中显示正确的信息。然后我选择一个应该显示M1的日期。

单步执行代码表示显示了适当的标记(M1)。但是,信息窗口仍显示上次显示的M2信息。

奇怪的是,如果我放大以聚焦标记所在的区域,然后单击标记以显示信息窗口,将显示M1的相应信息。如果我缩小,则会显示M2的信息。

如果我重复上面的初始步骤并且地图已经放大,则信息窗口始终会显示相应的信息。

没有向zoom事件注册处理程序,并且所有标记都已初始化,并且optimize属性设置为false。

我不知道为什么会发生这种情况。有什么想法吗?

class ottb.Map
  constructor: () ->   

    @map = new google.maps.Map(document.getElementById("schedule-map"), gMapOptions)
    @gameMarkers = {}
    @displayedGames = {}
    @lastInfoWindow = null

  # Updates the map to show the games for the currently selected date.
  displayGames: (newGames) ->

    @lastInfoWindow.close() if @lastInfoWindow isnt null

    # Fade out currently displayed games if they are not in the new list of
    # games to display
    for own teamAbbr, displayedGame of @displayedGames
      hasIt = newGames.some( (newGame) -> newGame.home_team_abbr == displayedGame.home_team_abbr)
      if not hasIt
        @fadeOutMarker(@gameMarkers[displayedGame.home_team_abbr])
        delete @displayedGames[displayedGame.home_team_abbr]

    for newGame in newGames
      do (newGame) =>
        marker = @gameMarkers[newGame.home_team_abbr]
        if not marker?
          marker = new google.maps.Marker
            position: new google.maps.LatLng(parseFloat(newGame.lat), parseFloat(newGame.lon))
            map: @map
            opacity: 0
            opacities: []

        marker.setTitle(newGame.away_team_name + ' @ ' + newGame.home_team_name)

        hasIt = @displayedGames[newGame.home_team_abbr]?
        @fadeInMarker(marker, 0) if not hasIt

        source = $("#info-window").html()
        template = Handlebars.compile(source)
        context =
         game_id: newGame.id,
         away_team: newGame.away_team_abbr, 
         home_team: newGame.home_team_abbr, 
         game_time: newGame.game_time
         displaySelectGameLink: true

        google.maps.event.addListener(marker, 'click', =>
          @lastInfoWindow.close() if @lastInfoWindow isnt null
          @lastInfoWindow = new google.maps.InfoWindow()
          @lastInfoWindow.setContent(template(context))
          @lastInfoWindow.open(that.map, marker)
          return false)   

        @gameMarkers[newGame.home_team_abbr] = marker
        @displayedGames[newGame.home_team_abbr] = newGame

1 个答案:

答案 0 :(得分:1)

在原帖中我的第3次评论后,我头上的灯泡熄灭了。我正在淡入/淡出地图中的标记,并且从未将它们从地图中取出。 M2的不透明度为0,但其z-index必须高于M1,所以我仍然点击它。当我放大时,它们相距足够远,以至于它们不再重叠。

其中一天......(实际上是两天)。对不起,当我把头撞到墙上时。

相关问题