Code Monkey home page Code Monkey logo

voltron-map's Introduction

Coverage Status Build Status License: GPL v3

Voltron::Map

Trying to find an easier way to generate various Google Maps

Installation

Add this line to your application's Gemfile:

gem 'voltron-map', '~> 0.1.2'

And then execute:

$ bundle install

Or install it yourself as:

$ gem install voltron-map

Then run the following to create the voltron.rb initializer (if not exists already) and add the map config:

$ rails g voltron:map:install

Usage

To generate a static map image, you may simple call the map_tag method in your views.

<%= map_tag(+address+, +options+, +image_options+) %>

Where +address+ is a valid street address or location ('Denver, CO' for example) or and array of [lat, long], or a comma separate list of lat,long.

+options+ are any of the "Map Parameters" defined on this page: https://developers.google.com/maps/documentation/static-maps/intro

+image_options+ is any valid option accepted in image_tag

Optionally, you may pass a black which allows you to define any "Feature Parameters" on this page: https://developers.google.com/maps/documentation/static-maps/intro

<%= map_tag('Denver, CO', { size: 300, scale: 2, format: :png32, zoom: 12 }, { size: 300, alt: 'Home' }) do

  # marker(+address+, +options+)
  # Passed with no arguments places a standard marker on the maps initial address, in this case, "Denver, CO"
  marker

  # Or define an address to mark, again as either a string address, string of "lat,long", or array as [lat, long],
  # followed by any marker options defined under "Marker Styles" here: https://developers.google.com/maps/documentation/static-maps/intro#Markers
  marker '600 S Broadway, Denver CO', color: :blue

  # path(+location+, +location+, +location+, ..., +options+)
  # Define a path, between multiple locations (for example: a line that goes from Denver to Castle Rock to Nederland to Fort Collins and back to Denver (closing the loop))
  # followed by any path options defined under "Path Styles" here: https://developers.google.com/maps/documentation/static-maps/intro#Paths
  path 'Denver, CO', 'Castle Rock, CO', 'Nederland, CO', 'Fort Collins, CO', 'Denver, CO', color: '0x234051', fillcolor: '0x00000033'

  # visible(+location+, +location+, +location+, ...)
  # Define one or more locations that should remain visible on the map, in the event that the given +map_tag+ params would result in it being cut off
  visible 'Colorado Springs, CO', 'Boulder, CO'

  # style(feature=all, element=all, rules)
  # Style a given part of the map with the provided rules (for example, simplify and make all local roads white on the map)
  style 'road.local', 'geometry', color: '0xFFFFFFF', visibility: :simplified

end %>

To generate just a map url, not within an <img /> tag, you may use the map_url helper, which is identical to map_tag with the exception of the image_options argument. It still accepts a block to add markers/paths/styles/etc

<%= map_url('Denver, CO') %>

Options

You may define a set of default map parameters in the config.map.defaults hash within the voltron initializer. They will apply to all calls to map_tag or map_url, but be overridden if the same option is specified in the method argument itself.

Development

After checking out the repo, run bin/setup to install dependencies. Then, run rake spec to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/ehainer/voltron-map. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.

License

The gem is available as open source under the terms of the GNU General Public License.

voltron-map's People

Contributors

ehainer avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.