leaflet-rails 0 travis-ci ruby Rubygems

This gem provides the leaflet.js map display library for your Rails 4 application.

2 years after BSD-2-Clause

Build Status Gem Version

Quickstart Guide

To start using the leaflet-rails gem, follow the steps below (assuming you use the default asset pipeline):

First, add the following code to your Gemfile.

gem 'leaflet-rails'

Then, run bundle install from within your project to download the necessary files. Following that, open your application-wide CSS file (app/assets/stylesheets/application.css) and add the following line as a comment:

= require leaflet

After that, open your application-wide Javascript file (typically app/assets/javascripts/application.js) and add the following line before requiring files which depend on Leaflet:

= require leaflet

At this point, you may skip the first two steps of the Leaflet Quick Start guide and start at the third step (adding the map div to a view).

Version Parity

leaflet-rails tries to keep version parity with leaflet.js. However, this isn't possible in all cases. Discrepancies have been noted below.

leaflet-rails leaflet.js Reason
0.7.4 0.7.3 Requested in #33 because of large gap between master and rubygems.org.
0.7.5 0.7.5 leaflet.js 0.7.4 was reverted.
0.7.6 ---- Skipped to sync with upstream.
0.7.7 0.7.7 Sync version numbers with upstream.

Helpers

To get you up and running quickly, you can also use the gem's helper. To get started, add the following lines to a file called leaflet.rb in config/initializers:

Leaflet.tile_layer = "http://{s}.tile.cloudmade.com/YOUR-CLOUDMADE-API-KEY/997/256/{z}/{x}/{y}.png"
# You can also use any other tile layer here if you don't want to use Cloudmade - see http://leafletjs.com/reference.html#tilelayer for more
Leaflet.attribution = "Your attribution statement"
Leaflet.max_zoom = 18

If you are using a tile layer which requires non-default subdomains such as MapQuest-OSM Tiles, you can set the subdomains like this:

Leaflet.tile_layer = "http://{s}.mqcdn.com/tiles/1.0.0/map/{z}/{x}/{y}.png"
Leaflet.subdomains = ['otile1', 'otile2', 'otile3', 'otile4']

You will then be able to call the #map helper method in a view, and make sure that the helper method is inside an erb tag like so:

<%= map(:center => {
  :latlng => [51.52238797921441, -0.08366235665359283],
  :zoom => 18
}) %>

You can also add any number of markers like so:

map(:center => {
    :latlng => [51.52238797921441, -0.08366235665359283],
    :zoom => 18
  },
  :markers => [
    {
       :latlng => [51.52238797921441, -0.08366235665359283],
    }
  ]
)

Adding a :popup element to a marker hash will also generate a popup for a maker:

map(:center => {
    :latlng => [51.52238797921441, -0.08366235665359283],
    :zoom => 18
  },
  :markers => [
     {
       :latlng => [51.52238797921441, -0.08366235665359283],
       :popup => "Hello!"
     }
  ]
)

If you want to override the map settings you have set in the initializer, you can also add them to the helper method:

map(:center => {
    :latlng => [51.52238797921441, -0.08366235665359283],
    :zoom => 18
  },
  :tile_layer => "http://{s}.somedomain.com/somepath/{z}/{x}/{y}.png",
  :attribution => "Some other attribution text",
  :max_zoom => 4
)

If you want to have multiple maps on same page , you should add unique container_id in helper method for each map:

map(:container_id => "first_map", :center => {
    :latlng => [51.52238797921441, -0.08366235665359283],
    :zoom => 18
})

map(:container_id => "second_map", :center => {
    :latlng => [51.52238797921441, -0.08366235665359283],
    :zoom => 18
})

Related Repositories

mapknitter

mapknitter

Upload your own aerial images, position (rubbersheet) them in a web interface ov ...

mapplz-ruby

mapplz-ruby

Ruby gem to store, query, and visualize map data without all the complexity ...

leaflet-js

leaflet-js

Ruby Gem to wrap leaflet library ...

leaflet-markercluster-rails

leaflet-markercluster-rails

Rails engine for the Leaflet.markercluster project ...

angular-leaflet-rails

angular-leaflet-rails

angular-leaflet-directive packaged for Rails assets pipeline ...


Top Contributors

mourner axyjo JasonSanford dravnic mortenbekditlevsen pezholio TheMetalCode itsgreggreg anru mehmeta TSiege k4 msaspence ErshKUS neno-giscloud anbublacky asmaloney carljm pedantic-git florianf reignmaker CodeJosch jgraichen jderrough jgerigmeyer antonj smadeja tmcw samatjain bitdeli-chef

Releases

-   v1.0.0.pre.rc1 zip tar
-   v0.7.7 zip tar
-   v0.7.5 zip tar
-   v0.7.4 zip tar
-   v0.7.3 zip tar
-   v0.7.2 zip tar
-   v0.7.1 zip tar
-   v0.7.0 zip tar
-   v0.6.4 zip tar
-   v0.6.3 zip tar
-   v0.6.2 zip tar
-   v0.6.1 zip tar
-   v0.6.0 zip tar
-   v0.5.1 zip tar
-   v0.5.0 zip tar
-   v0.5.0.beta1 zip tar
-   v0.4.5 zip tar
-   v0.4.4 zip tar
-   v0.4.2.beta1 zip tar
-   v0.4.0.alpha6 zip tar
-   v0.4.0.alpha5 zip tar
-   v0.4.0.alpha4 zip tar
-   v0.4.0alpha3 zip tar
-   v0.4.0.alpha2 zip tar
-   v0.4.0.alpha1 zip tar
-   v0.3.1 zip tar
-   v0.3 zip tar
-   v0.2.1 zip tar
-   v0.2 zip tar
-   v0.1 zip tar