gmap_coordinates_picker 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2013 Muntasim Ahmed
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,52 @@
1
+ Gmap Cordinates Picker
2
+ =====================
3
+
4
+ works to provide an easy to use Google Maps interface for displaying and setting geographic co-ordinates .
5
+
6
+ Where a latitude and longitude is set on the model, it is indicated by a marker shown on a Google map centered at the marker. The administrator can change the value of these fields by clicking on the desired new location on the map.
7
+
8
+ Usage
9
+ =====
10
+
11
+ add the following to your `Gemfile`:
12
+
13
+ ```ruby
14
+ gem " gmap_coordinates_picker"
15
+ ```
16
+
17
+ Then, add in your form:
18
+
19
+ ```ruby
20
+ <%= form.gmap_coordinate_picker :gmap_conf => {:lat_column => 'latitude', :lng_column => 'longitude', :zoom_level => 10 }, :default_coordinates => [lat,lng] %>
21
+ ```
22
+
23
+ Or, user is as form helper:
24
+
25
+ ```ruby
26
+ <%= render_gmap_coordinate_picker :gmap_conf => {:lat_column => 'latitude', :lng_column => 'longitude', :zoom_level => 10 }, :default_coordinates => [lat,lng] %>
27
+ ```
28
+
29
+
30
+ Configuration
31
+ =============
32
+
33
+ beside the option depicted on the example above it can be configured with the following:
34
+
35
+ - `map_container_class` - custom class for the map container
36
+ - `map_width` - default "600px
37
+ - `map_height` - default "400px"
38
+ - `api_key` - Google Map api key (optional)
39
+
40
+
41
+
42
+
43
+ LICENSE
44
+ =======
45
+ is licensed under the MIT license.
46
+
47
+ Copyright (C) 2013 by Muntasim Ahmed
48
+
49
+
50
+ Inspired from **rails_admin_map_field** (https://github.com/trademobile/rails_admin_map_field)
51
+
52
+
data/Rakefile ADDED
@@ -0,0 +1,38 @@
1
+ #!/usr/bin/env rake
2
+ begin
3
+ require 'bundler/setup'
4
+ rescue LoadError
5
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
6
+ end
7
+ begin
8
+ require 'rdoc/task'
9
+ rescue LoadError
10
+ require 'rdoc/rdoc'
11
+ require 'rake/rdoctask'
12
+ RDoc::Task = Rake::RDocTask
13
+ end
14
+
15
+ RDoc::Task.new(:rdoc) do |rdoc|
16
+ rdoc.rdoc_dir = 'rdoc'
17
+ rdoc.title = 'GmapCoordinatesPicker'
18
+ rdoc.options << '--line-numbers'
19
+ rdoc.rdoc_files.include('README.rdoc')
20
+ rdoc.rdoc_files.include('lib/**/*.rb')
21
+ end
22
+
23
+
24
+
25
+
26
+ Bundler::GemHelper.install_tasks
27
+
28
+ require 'rake/testtask'
29
+
30
+ Rake::TestTask.new(:test) do |t|
31
+ t.libs << 'lib'
32
+ t.libs << 'test'
33
+ t.pattern = 'test/**/*_test.rb'
34
+ t.verbose = false
35
+ end
36
+
37
+
38
+ task :default => :test
@@ -0,0 +1,50 @@
1
+ <%= javascript_include_tag ("http://maps.googleapis.com/maps/api/js?key=#{api_key}&sensor=false") %>
2
+ <script type="text/javascript">
3
+ var gMapObj = gMapObj || {};
4
+
5
+ jQuery(function () {
6
+ var marker = null;
7
+ var latlng = new google.maps.LatLng(<%= default_coordinates[0]%>, <%=default_coordinates[1] %>);
8
+
9
+ var myOptions = {
10
+ zoom: <%=zoom_level %>,
11
+ center:latlng,
12
+ mapTypeId:google.maps.MapTypeId.ROADMAP
13
+ };
14
+
15
+ var map = new google.maps.Map(document.getElementById("<%=map_container%>"), myOptions);
16
+ gMapObj = map;
17
+
18
+ <% if lat_column_value && lng_column_value%>
19
+ marker = new google.maps.Marker({
20
+ position:new google.maps.LatLng(<%= lat_column_value%>,<%=lng_column_value %>),
21
+ map:map
22
+ });
23
+ <% end%>
24
+
25
+ google.maps.event.addListener(map, 'click', function(e) {
26
+ updateLocation(e.latLng);
27
+ });
28
+
29
+ function updateLocation(location) {
30
+ if(marker) {
31
+ marker.setPosition(location);
32
+ } else {
33
+ marker = new google.maps.Marker({
34
+ position: location,
35
+ map: map
36
+ });
37
+ }
38
+
39
+ map.setCenter(location);
40
+ jQuery("#<%= lat_dom_id%>").val(location.lat());
41
+ jQuery("#<%=lng_dom_id %>").val(location.lng());
42
+ }
43
+
44
+ });
45
+ </script>
46
+ <div class="<%= map_container_class%>" id="<%=map_container%>" style="<%= "width:#{map_width};height:#{map_height}"%>">
47
+ </div>
48
+ <%= lat_field%>
49
+ <%= lng_field%>
50
+
@@ -0,0 +1,8 @@
1
+ module GmapCoordinatesPicker
2
+ autoload :ViewHelper, 'gmap_coordinates_picker/view_helper'
3
+ autoload :FormBuilder, 'gmap_coordinates_picker/form_builder'
4
+
5
+
6
+ end
7
+
8
+ require 'gmap_coordinates_picker/engine' if defined?(Rails)
@@ -0,0 +1,37 @@
1
+ # encoding: utf-8
2
+ require 'rails'
3
+ require 'gmap_coordinates_picker'
4
+
5
+ module GmapCoordinatesPicker
6
+ #class Engine < ::Rails::Engine
7
+ # config.before_initialize do
8
+ # ActiveSupport.on_load :active_record do
9
+ # ActiveRecord::Base.send(:include, SimpleCaptcha::ModelHelpers)
10
+ # end
11
+ # end
12
+ #
13
+ # config.after_initialize do
14
+ # ActionView::Base.send(:include, SimpleCaptcha::ViewHelper)
15
+ # ActionView::Helpers::FormBuilder.send(:include, SimpleCaptcha::FormBuilder)
16
+ #
17
+ # if Object.const_defined?("Formtastic")
18
+ # if Formtastic.const_defined?("Helpers")
19
+ # Formtastic::Helpers::FormHelper.builder = SimpleCaptcha::CustomFormBuilder
20
+ # else
21
+ # Formtastic::SemanticFormHelper.builder = SimpleCaptcha::CustomFormBuilder
22
+ # end
23
+ # end
24
+ # end
25
+ #
26
+ # config.app_middleware.use SimpleCaptcha::Middleware
27
+ #end
28
+
29
+ class Engine < ::Rails::Engine
30
+ config.after_initialize do
31
+ ActionView::Base.send(:include, GmapCoordinatesPicker::ViewHelper)
32
+ ActionView::Helpers::FormBuilder.send(:include, GmapCoordinatesPicker::FormBuilder)
33
+ end
34
+ end
35
+ end
36
+
37
+
@@ -0,0 +1,23 @@
1
+ module GmapCoordinatesPicker
2
+ module FormBuilder
3
+ def self.included(base)
4
+ base.send(:include, GmapCoordinatesPicker::ViewHelper)
5
+ base.send(:include, GmapCoordinatesPicker::FormBuilder::ClassMethods)
6
+ end
7
+
8
+ module ClassMethods
9
+ # Example:
10
+ # <% form_for :shop, :url => shops_path do |form| %>
11
+ # ...
12
+ # <%= form.gmap_coordinate_picker :gmap_conf => {:lat_column => 'latitude', :lng_column => 'longitude' }, :default_coordinates => some_default_coordinates %>
13
+ # <% end %>
14
+ #
15
+ def gmap_coordinate_picker(options = {})
16
+ options.update :object => @object_name
17
+ render_gmap_coordinate_picker(objectify_options(options))
18
+ end
19
+
20
+
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,3 @@
1
+ module GmapCoordinatesPicker
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,46 @@
1
+ module GmapCoordinatesPicker #:nodoc
2
+ module ViewHelper #:nodoc
3
+ def render_gmap_coordinate_picker(options={})
4
+ lat_column = options[:gmap_conf][:lat_column]
5
+ lng_column = options[:gmap_conf][:lng_column]
6
+ default_coordinates = options[:default_coordinates] || [0, 0]
7
+ lat_column_value = options[:object].present? ? options[:object].send(lat_column) : default_coordinates[0]
8
+ lng_column_value = options[:object].present? ? options[:object].send(lng_column) : default_coordinates[1]
9
+ prefix = options[:object].present? ? options[:object].class.name.downcase : "gmap_coordinate_picker"
10
+ lat_dom_id = "#{prefix}_#{lat_column}"
11
+ lng_dom_id = "#{prefix}_#{lng_column}"
12
+
13
+ locals = {
14
+ :api_key => options[:api_key],
15
+ :lat_column => options[:gmap_conf][:lat_column],
16
+ :lng_column => options[:gmap_conf][:lng_column],
17
+ :lat_column_value => lat_column_value,
18
+ :lng_column_value => lng_column_value,
19
+ :zoom_level => options[:gmap_conf][:zoom_level] || 10,
20
+ :map_container => "#{prefix}_#{lat_column}_#{lng_column}_container",
21
+ :map_container_class => options[:map_container_class],
22
+ :map_width => options[:map_width] || "600px",
23
+ :map_height => options[:map_height] ||"400px",
24
+ :default_coordinates => default_coordinates,
25
+ :lat_dom_id => lat_dom_id,
26
+ :lng_dom_id => lng_dom_id,
27
+ :lat_field => lat_lng_field(lat_column, lat_column_value,lat_dom_id, options),
28
+ :lng_field => lat_lng_field(lng_column, lng_column_value,lng_dom_id, options)
29
+ }
30
+
31
+
32
+ render :partial => 'gmap_coordinate_picker/gmap_coordinate_picker', :locals => locals
33
+ end
34
+
35
+ private
36
+ def lat_lng_field(column, value,dom_id, options={})
37
+ if options[:object]
38
+ hidden_field(column, {:value => value, :id =>dom_id})
39
+ else
40
+ hidden_field_tag(column, nil, {:id =>dom_id})
41
+ end
42
+ end
43
+
44
+
45
+ end
46
+ end
metadata ADDED
@@ -0,0 +1,87 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: gmap_coordinates_picker
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Muntasim Ahmed
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-02-19 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rails
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 3.2.11
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: 3.2.11
30
+ - !ruby/object:Gem::Dependency
31
+ name: sqlite3
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ description: It works without any dependency to any third party library
47
+ email:
48
+ - ahmed2tul@gmail.com
49
+ executables: []
50
+ extensions: []
51
+ extra_rdoc_files: []
52
+ files:
53
+ - app/views/gmap_coordinate_picker/_gmap_coordinate_picker.html.erb
54
+ - lib/gmap_coordinates_picker/engine.rb
55
+ - lib/gmap_coordinates_picker/form_builder.rb
56
+ - lib/gmap_coordinates_picker/version.rb
57
+ - lib/gmap_coordinates_picker/view_helper.rb
58
+ - lib/gmap_coordinates_picker.rb
59
+ - MIT-LICENSE
60
+ - Rakefile
61
+ - README.rdoc
62
+ homepage: ''
63
+ licenses: []
64
+ post_install_message:
65
+ rdoc_options: []
66
+ require_paths:
67
+ - lib
68
+ required_ruby_version: !ruby/object:Gem::Requirement
69
+ none: false
70
+ requirements:
71
+ - - ! '>='
72
+ - !ruby/object:Gem::Version
73
+ version: '0'
74
+ required_rubygems_version: !ruby/object:Gem::Requirement
75
+ none: false
76
+ requirements:
77
+ - - ! '>='
78
+ - !ruby/object:Gem::Version
79
+ version: '0'
80
+ requirements: []
81
+ rubyforge_project:
82
+ rubygems_version: 1.8.24
83
+ signing_key:
84
+ specification_version: 3
85
+ summary: works to provide an easy to use Google Maps interface for displaying and
86
+ setting geographic co-ordinates
87
+ test_files: []