0

请原谅我,我问这个问题可能是因为,我对咖啡脚本不太满意。在最新的 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()
4

1 回答 1

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 })

它给了我:

在此处输入图像描述

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

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

于 2014-02-12T09:21:33.060 回答