Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
  app
  lib
  vendor
  MIT-LICENSE
  README.md
  Rakefile
Size: Mime:
  README.md

Mappyland

A superlight, standalone library to build Google maps with a set of markers.

Usage

Add a container to the page where you'd like the map. Mappyland uses data attributes to build the map.

Data Attributes

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

Rails Helper

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

Initialize it!

my_map = new Mappyland(document.getElementById('map-canvas'));

You're done! But, if you need to fiddle further:

Working with Mappyland Objects

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.

Serializing Records

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.

Installation

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

License

The gem is available as open source under the terms of the MIT License.