Coder Social home page Coder Social logo

cartographer-2's Introduction

Cartographer

Cartographer generates painless Google Maps for your Rails application. It supports Google Maps API v3 & comes with all the goodies (MarkerManager && MarkerClusterer) for managing large number of markers with least effort.

Features

  • Support for Google Maps v3 and v2
  • Drop-in-replacement for older version of cartographer (which only worked with google maps v2)
  • Support for MarkerManager v3
  • Support for MarkerClusterer v3
  • You can easily define custom icons for cluster
  • Works with Rails 3+ and also works on older rails versions to provide backward compatibility

How to use?

if you want to use google maps v3, set this constant as first line of environment.rb (this constant should be set before the plugins are loaded, its best to keep on first line)


 CARTOGRAPHER_GMAP_VERSION = 3

In your controller...


@map = Cartographer::Gmap.new( 'map' )
@map.zoom = :bound
@icon = Cartographer::Gicon.new()
@map.icons <<  @icon
marker1 = Cartographer::Gmarker.new(:name=> "taj_mahal", :marker_type => "Building",
           :position => [27.173006,78.042086],
           :info_window_url => "/url_for_info_content", :icon => @icon)
marker2 = Cartographer::Gmarker.new(:name=> "raj_bhawan", :marker_type => "Building",
           :position => [28.614309,77.201353],
           :info_window_url => "/url_for_info_content", :icon => @icon)

@map.markers << marker1
@map.markers << marker2

In your view...


  # for Rails 3+ you need to make use of 'raw'
  <%= raw Cartographer::Header.new.to_s %>
  <%= raw @map.to_html %>

Here is another example with custom icons + clustering


  #controller code
  @map = Cartographer::Gmap.new( 'map' )
  @map.zoom = :bound
  @map.marker_clusterer = true

  icon_building = Cartographer::Gicon.new(:name => "building_icon",
          :image_url => '/images/icon.gif',
          :width => 31,
          :height => 24,
          :anchor_x => 0,
          :anchor_y => 20,
          :info_anchor_x => 5,
          :info_anchor_x => 1)

  building_cluster_icon = Cartographer::ClusterIcon.new({:marker_type => "Building"})
  #Clustering requires various variant of icon for different grouping/zoom level
  #push first variant
  building_cluster_icon << {
                 :url => '/images/small_icon.gif',
                 :height => 33,
                 :width => 58,
                 :opt_anchor => [10, 0],
                 :opt_textColor => 'black'
               }
  #push second variant
  building_cluster_icon << {
                 :url => '/images/bigger_icon.gif',
                 :height => 63,
                  :width => 98,
                 :opt_anchor => [20, 0],
                 :opt_textColor => 'black'
               }

  #push third variant
  building_cluster_icon << {
                 :url => '/images/biggest_icon.gif',
                 :height => 73,
                 :width => 118,
                 :opt_anchor => [26, 0],
                 :opt_textColor => 'black'
               }

  @map.marker_clusterer_icons = [building_cluster_icon]


  marker1 = Cartographer::Gmarker.new(:name=> "taj_mahal", :marker_type => "Building",
              :position => [27.173006,78.042086],
              :info_window_url => "/url_for_info_content",
              :icon => icon_building)
  marker2 = Cartographer::Gmarker.new(:name=> "raj_bhawan", :marker_type => "Building",
              :position => [28.614309,77.201353],
              :info_window_url => "/url_for_info_content",
              :icon => icon_building)

  @map.markers << marker1
  @map.markers << marker2

Sample app

If you want a quickest way to get started, you can download a sample app here https://github.com/downloads/parolkar/cartographer/carto_test.tgz Its a rails 3 app, run the server and point your browser to http://localhost:3000/welcome/index

Install


  cd rails_app
  git clone git://github.com/parolkar/cartographer.git vendor/plugins/cartographer

History:

Announcement of Cartographer's new avatar on Ruby5 Podcast : http://bit.ly/fSWCfh

Original Rails blog announcement of 2005 is at http://download.rubyonrails.com/2005/8/30/cartographer-effortless-google-maps-in-rails

Copyright (c) 2011 Abhishek Parolkar & Joshua Miller, released under the MIT license

cartographer-2's People

Contributors

joshuamiller avatar parolkar 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.