使用CoffeeScript删除Gmaps4Rails中的标记阴影

时间:2014-11-13 01:40:41

标签: ruby-on-rails coffeescript gmaps4rails

我在gmap4rails中使用自定义标记选项,主要在CoffeeScript中实现。虽然标记的默认选项是添加阴影,但我希望将其删除但无法找到设置中的任何位置以从标记中删除阴影。

观点:

enter image description here

用于创建自定义标记的类:

class CustomMarkerBuilder extends Gmaps.Google.Builders.Marker
    create_marker: ->
      options = _.extend @marker_options(), @rich_marker_options()
      @serviceObject = new RichMarker options

    rich_marker_options: ->
      marker = document.createElement("div")
      marker.setAttribute('class', 'custom_marker_content')
      marker.innerHTML = this.args.custom_marker
      marker.shadow
      { content: marker }

用于显示所有标记的CoffeeScript操作:

allLocations = root.table.rows().data()
  $('#multi_markers').map ->
    handler = Gmaps.build("Google", builders: { Marker: CustomMarkerBuilder })
    handler.buildMap
      internal:
        id: "multi_markers"
    , ->
      for aLocation in allLocations
        markers = handler.addMarkers([
          {
            lat: aLocation[9]
            lng: aLocation[10]
            custom_marker:     "<img src='/assets/images/redDotMarker.png' width='40' height='40'>"
            custom_infowindow: "Store Number: #{aLocation[1]}; Address: #{aLocation[2]}, #{aLocation[3]}; Major Bidding City: #{aLocation[6]}"
          }
        ])
      handler.bounds.extendWith markers
      handler.fitMapToBounds()
      return

如何从CoffeeScript中的标记中删除阴影?

2 个答案:

答案 0 :(得分:2)

附加@serviceObject.setShadow("")以删除标记阴影。

class CustomMarkerBuilder extends Gmaps.Google.Builders.Marker
  create_marker: ->
    options = _.extend @marker_options(), @rich_marker_options()
    @serviceObject = new RichMarker options
    @serviceObject.setShadow("") # Added

答案 1 :(得分:0)

您需要设置RichMarker的选项。为此,请更改函数rich_marker_options中的返回值。

这是通过改变来完成的 { content: marker} - &gt; { content: marker, flat: true }

rich_marker_options的最终代码如下所示

rich_marker_options: ->
  marker = document.createElement 'div'
  marker.setAttribute 'class', 'custom_marker_content'
  marker.innerHTML = this.args.custom_marker
  marker.shadow
  {content: marker, flat: true}

通过查看RichMarker在此page

上的构建方式,我发现了这一点