标记API用于gmaps4rails

时间:2014-02-10 16:44:51

标签: ruby-on-rails google-maps coffeescript gmaps4rails2

赦免我,我问这个问题可能是因为,咖啡脚本不太舒服。 在最新的gmaps4rails中,在构建地图和标记之后,我们是否有任何直接的api来修改标记,而不是使用您在https://github.com/apneadiving/Google-Maps-for-Rails/wiki/Change-handler-behavior

中的咖啡脚本中指定的功能

我的意思是,如果我们想要动态更改标记,例如将标记更改为显示接近度的透明圆圈。

以下代码是否有任何问题。缩进是否重要?

class RichMarkerBuilder extends Gmaps.Google.Builders.Marker #inherit from builtin builder
  #override create_marker method
  create_marker: ->
    options = _.extend @marker_options(), @rich_marker_options()
    @serviceObject = new RichMarker options #assign marker to @serviceObject

  rich_marker_options: ->
    boxText = document.createElement("p")
    boxText.setAttribute("class", 'heat-map-eclipse')
    _.extend(@marker_options(), { content: boxText, flat: true })

@buldMap= (markers)->

 handler = Gmaps.build 'Google', { builders: { Marker: RichMarkerBuilder} } #dependency injection

 #then standard use
 handler.buildMap { provider: {}, internal: {id: 'map'} }, ->
   markers = handler.addMarkers(markers)
   handler.bounds.extendWith(markers)
   handler.fitMapToBounds()

1 个答案:

答案 0 :(得分:0)

我刚试过:

class MarkerBuilder extends Gmaps.Google.Builders.Marker

  create_marker: ->
    options = _.extend @marker_options(), @rich_marker_options()
    @serviceObject = new RichMarker options

  rich_marker_options: ->
    boxText = document.createElement("p")
    boxText.setAttribute("class", 'heat-map-eclipse')
    _.extend(@marker_options(), { content: boxText, flat: true })

它给了我:

enter image description here

所以我猜它开箱即用,对吧?

但是你有一个错误的方法:根据定义,标记始终保持相同的尺寸