【问题标题】:Gmaps4Rails integration with Stamen MapsGmaps4Rails 与 Stamen Maps 的集成
【发布时间】:2012-07-13 00:14:12
【问题描述】:

有人知道如何将 Stamen 瓦片与 Gmaps4rails 集成吗?这有点令人困惑,因为 google.maps 没有在 Gmaps4Rails gem 中明确调用。希望获得有关如何获取所需信息的任何建议。

【问题讨论】:

    标签: ruby-on-rails google-maps gmaps4rails stamen-maps


    【解决方案1】:

    我找到了一种(粗略的)方法来使用 gmaps4rails 创建一个带有 OSM 瓦片的滑动地图。从外观上看,雄蕊图应该更容易。您可能会在此处查看我的解决方案,找到一些提示如何与 gem 一起使用:Slippy maps for gmaps4rails

    我以前没有遇到过雄蕊图。他们看起来很棒。遗憾的是,地形图在欧洲不可用。我明天会玩它,看看我是否能找到更多。

    编辑:

    gmaps4rails.base.js.coffee添加这个方法:

     #creates a Stamen Map layer with the mapTypeId "toner"
     createStamenMap : ->
      StamenMapTypeOptions = new google.maps.ImageMapType(
        getTileUrl: (coord, zoom) ->
          "http://tile.stamen.com/toner/" + zoom + "/" + coord.x + "/" + coord.y + ".png"
        tileSize: new google.maps.Size(256, 256)
        name: "toner"
        maxZoom: 18
      )
      @serviceObject.mapTypes.set("toner", StamenMapTypeOptions)
      @serviceObject.setMapTypeId("toner")
    

    如果你想要水彩或地形,你需要在上面写着toner 的地方换成你喜欢的东西(包括在 TileUrl 中!)。

    js_builder.rb 中像这样添加对您的方法的调用

    @js << "#{gmap_id}.createStamenMap();"

    就在@js << "#{gmap_id}.initialize();"之后。

    如果你像我一样使用 rvm,js_builder.rb 不会在你的应用目录中,对我来说它在 /Users/<username>/.rvm/gems/ruby-1.9.3-p194/gems/gmaps4rails-1.5.2

    最后,像这样改变你的视图代码:

     <%= gmaps("markers" => {"data" => @json},
                    "map_options" => {"type" => "TERRAIN", :raw => '{mapTypeControlOptions: {mapTypeIds: ["toner", google.maps.MapTypeId.ROADMAP, google.maps.MapTypeId.TERRAIN], style: google.maps.MapTypeControlStyle.DROPDOWN_MENU}}'}) %>
    

    我确信有一种更漂亮的方法可以做到这一点,但它似乎有效。

    【讨论】:

    • 感谢您的回答。实际上,我最终删除了 gmaps4rails,只是手动写出了 js,这似乎更简单一些。你认为这颗宝石甚至值得吗?我没有完全看到使用它的任何好处..
    猜你喜欢
    • 2012-06-15
    • 1970-01-01
    • 2017-02-24
    • 1970-01-01
    • 1970-01-01
    • 2015-12-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多