Repository URL to install this package:
Version:
0.3.0 ▾
|
app |
lib |
vendor |
MIT-LICENSE |
README.md |
Rakefile |
A superlight, standalone library to build Google maps with a set of markers.
Add a container to the page where you'd like the map. Mappyland uses data attributes to build the map.
Mappyland expects two data attributes to build a map in your container
markers
Required. Your records as json. See Serializing Records
options
Optional options!
Option | Description |
---|---|
defaultIcon |
URL or attribute set for default icon |
autoFitToMarkers |
Default: true. Enable/disable fitBounds to markers |
gmap_options |
Directly passed to theGoogle Map initializer |
Mappyland includes a Rails helper to easily build the proper markup.
Example:
# mappyland(marker_data, options) <%= mappyland my_records_as_json, html_options: { tag: 'div', id: 'my-cool-map' }, defaultIcon: asset_path('cool-marker.png'), autoFitToMarkers: false, gmap_options: { minZoom: 3 } %>
becomes something like
<div id='my-cool-map' data-markers="##JSONIFIED MARKER DATA##" data-options="{defaultIcon: '/images/cool-marker.png', autoFitToMarkers: false, gmap_options:{minZoom: 3}"> </div>
For extra easiness there's some default html_options
; { tag: :div, id: 'map-canvas' }
my_map = new Mappyland(document.getElementById('map-canvas'));
You're done! But, if you need to fiddle further:
Attribute | Description |
---|---|
gmap |
The Google Map object |
markers |
ID-keyed object storing the refs to markers |
currentInfoWindow |
Currently open infowindow, if any |
markerBounds |
The boundaries of the loaded marker set |
Function | Description |
---|---|
fitToMarkers() |
fitBound the map to the markers boundaries |
findMarker(id) |
Finds a marker based on ID |
triggerMarkerClick(idOrMarker) |
Simulate a click on a marker given either an id or the marker itself. |
Mappyland expects a JSON array of objects with the following attributes
Attribute | Required? | Description |
---|---|---|
id |
Required | Unique identifier to refer to marker |
title |
Recommended | A title for the marker |
latitude |
Required | Latitude of marker |
longitude |
Required | Longitude of marker |
icon |
Optional | URL or attribute set for marker icon |
info_window |
Optional | HTML content string or attribute set for constructing infoWindow |
ActiveModel::Serializers is easy and clean way to generate these.
Add this line to your application's Gemfile:
gem 'mappyland'
And then execute:
$ bundle
Or install it yourself as:
$ gem install mappyland
Require mappyland in your application's javascript. This gem also includes libraries for clustering and spidering your markers. These features will automatically be enabled if their respective libraries are detected.
//= require mappyland //= require marker_clusterer //= require oms
The gem is available as open source under the terms of the MIT License.