volt-google-maps 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: e10c77d992b5dbf71902d06f66d890810aabaefc
4
+ data.tar.gz: d5cc43187191d9a2813369985b0722d629a3a720
5
+ SHA512:
6
+ metadata.gz: 5c37a3c7aa2dc4504592661ef7339e645f35698c03ba14bbeeead53e7e7b02c65cfd665569f0896e56cb11eef8a94c977cdd3e0474eb548d0cffea3f9c8ec322
7
+ data.tar.gz: bf4b5bb9e717f55ee3c57096a3120f9751964f99ab4d1d0c4f198face9ee4205e673852cd97535d705bd105dae1e5f9bc468f79f93598fd059e6f513febb4772
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in volt-google-maps.gemspec
4
+ gemspec
data/README.md ADDED
@@ -0,0 +1,45 @@
1
+ # Google Maps Volt Component
2
+
3
+ (still a work in progress)
4
+
5
+ Provides a simple google maps integration.
6
+
7
+ First signup for a google maps api key here:
8
+
9
+ https://developers.google.com/maps/documentation/javascript/tutorial
10
+
11
+ Next put it in your config/app.rb file:
12
+
13
+ config.google_maps_api_key = '....'
14
+
15
+ Add this line to your application's Gemfile:
16
+
17
+ gem 'volt-google-maps'
18
+
19
+ And then execute:
20
+
21
+ bundle
22
+
23
+ Then install the component in the config/dependencies.rb file of any components you want google maps in:
24
+
25
+ component 'google-maps'
26
+
27
+ Lastly, use the google-maps tag:
28
+
29
+ <style>
30
+ .google-map {
31
+ height: 400px;
32
+ width: 600px;
33
+ }
34
+ </style>
35
+ <div class="google-map">
36
+ <:google-maps />
37
+ </div>
38
+
39
+ The map will take up the width of the div, so we add the style tag.
40
+
41
+ The google-map tag can be passed many attributes:
42
+
43
+ - zoom - integer for different zoom levels
44
+ - center - the address to center the map on
45
+ - markers - an array of marker Models (with _address and _content)
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.2
@@ -0,0 +1,4 @@
1
+ .google-map-instance {
2
+ height: 100%;
3
+ width: 100%;
4
+ }
@@ -0,0 +1,2 @@
1
+ # Component dependencies
2
+ javascript_file "https://maps.googleapis.com/maps/api/js?key=" + Volt.config.google_maps_api_key
@@ -0,0 +1 @@
1
+ # Component routes
@@ -0,0 +1,187 @@
1
+ if RUBY_PLATFORM == 'opal'
2
+ require 'native'
3
+ end
4
+
5
+ module GoogleMaps
6
+ class MainController < ModelController
7
+ attr_accessor :section
8
+
9
+ def index_ready
10
+ @markers = []
11
+
12
+ `this.geocoder = new google.maps.Geocoder();`
13
+
14
+ node = section.container_node
15
+
16
+ if attrs.respond_to?(:center)
17
+ geocode(attrs.center) do |latlng|
18
+ setup_map(node, latlng.to_n)
19
+ end
20
+ else
21
+ setup_map(node, {lat: -34.397, lng: 150.644}.to_n)
22
+ end
23
+
24
+ if attrs.respond_to?(:zoom)
25
+ set_zoom
26
+ end
27
+
28
+ if attrs.respond_to?(:markers)
29
+ set_markers
30
+ end
31
+
32
+ end
33
+
34
+
35
+ def index_removed
36
+ %x{
37
+ delete this.map;
38
+ delete this.geocoder;
39
+ }
40
+
41
+ @add_listener.remove if @add_listener
42
+ @remove_listener.remove if @remove_listener
43
+ end
44
+
45
+ def set_markers
46
+ -> do
47
+ markers = attrs.markers
48
+
49
+ markers.each do |marker|
50
+ add_marker(marker) do |result|
51
+ @markers << result
52
+ end
53
+ end
54
+
55
+ @add_listener = markers.on('added') do |index|
56
+ marker = markers[index]
57
+
58
+ puts "ADD MARKER AT: #{index}"
59
+ add_marker(marker) do |result|
60
+ @markers[index] = result
61
+ end
62
+ end
63
+
64
+ @remove_listener = markers.on('removed') do |index|
65
+ puts "DELETE AT INDEX: #{index}"
66
+ marker = @markers.delete_at(index)
67
+ `console.log('marker: ', marker);`
68
+ remove_marker(marker.to_n)
69
+ end
70
+
71
+ end.watch!
72
+ end
73
+
74
+ def setup_zoom
75
+ `google.maps.event.addListener(self.map, 'zoom_changed', function() {
76
+ var zoomLevel = self.map.getZoom();`
77
+
78
+ new_zoom = Native(`zoomLevel`)
79
+ if attrs.zoom != new_zoom
80
+ attrs.zoom = new_zoom
81
+ end
82
+
83
+ # Setup listener again
84
+ set_zoom
85
+ `});`
86
+
87
+ end
88
+
89
+ def set_zoom
90
+ @first_zoom = true
91
+ -> do
92
+ if @first_zoom
93
+ @first_zoom = false
94
+
95
+ # Track
96
+ attrs.zoom
97
+ else
98
+ level = attrs.zoom
99
+ if level.blank?
100
+ level = 8
101
+ else
102
+ level = (level || 8).to_i
103
+ end
104
+
105
+ level_n = level.to_n
106
+ `if (self.map.getZoom() != level_n) {`
107
+ `self.map.setZoom(level_n);`
108
+ `}`
109
+ end
110
+ end.watch!
111
+ end
112
+
113
+ def setup_map(node, latlng)
114
+ %x{
115
+ var mapOptions = {
116
+ center: latlng,
117
+ zoom: 8
118
+ };
119
+ this.map = new google.maps.Map($(node).find('.google-map-instance').get(0), mapOptions);
120
+ }
121
+
122
+ if attrs.respond_to?(:center)
123
+ @first = true
124
+ -> { set_center(attrs.center) }.watch!
125
+ end
126
+
127
+ setup_zoom if attrs.respond_to?(:zoom)
128
+ end
129
+
130
+ def set_center(address)
131
+ if @first
132
+ @first = false
133
+ else
134
+ geocode(address) do |latlng|
135
+ latlng_n = latlng.to_n
136
+ `self.map.setCenter(latlng_n);`
137
+ end
138
+ end
139
+ end
140
+
141
+ def geocode(address)
142
+ unless address.is_a?(String)
143
+ yield({lat: -34.397, lng: 150.644})
144
+ return
145
+ end
146
+
147
+ `this.geocoder.geocode( { 'address': address}, function(results, status) {`
148
+ `if (status == google.maps.GeocoderStatus.OK) {`
149
+ `var latlng = results[0].geometry.location;`
150
+ yield(Native(`latlng`))
151
+ `} else {`
152
+ yield({lat: -34.397, lng: 150.644})
153
+ `}`
154
+ `}.bind(this));`
155
+
156
+ end
157
+
158
+ def add_marker(marker_data)
159
+ if marker_data.is_a?(String)
160
+ address = marker_data
161
+ content = marker_data
162
+ else
163
+ address = marker_data._address.or('').to_n
164
+ content = marker_data._content.or(address).or('').to_n
165
+ end
166
+
167
+ geocode(address) do |latlng|
168
+ latlng_n = latlng.to_n
169
+ marker = nil
170
+
171
+ %x{
172
+ marker = new google.maps.Marker({
173
+ position: latlng_n,
174
+ map: self.map,
175
+ title: content
176
+ });
177
+ }
178
+
179
+ yield Native(marker)
180
+ end
181
+ end
182
+
183
+ def remove_marker(marker)
184
+ `marker.setMap(null);`
185
+ end
186
+ end
187
+ end
@@ -0,0 +1,3 @@
1
+ <:Body>
2
+ <div class="google-map-instance"></div>
3
+
@@ -0,0 +1,2 @@
1
+ <:Body>
2
+ <h1>Google Maps</h1>
@@ -0,0 +1,9 @@
1
+ require "volt/google/maps/version"
2
+
3
+ class Volt
4
+ class Google
5
+ class Maps
6
+ # Your code goes here...
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+
5
+ version = File.read(File.expand_path('../VERSION', __FILE__)).strip
6
+
7
+
8
+ Gem::Specification.new do |spec|
9
+ spec.name = "volt-google-maps"
10
+ spec.version = version
11
+ spec.authors = ["Ryan Stout"]
12
+ spec.email = ["ryan@agileproductions.com"]
13
+ spec.summary = %q{A google maps component for Volt}
14
+ spec.homepage = ""
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0")
18
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
19
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_development_dependency "volt", "~> 0.8.0"
23
+ spec.add_development_dependency "rake"
24
+ end
metadata ADDED
@@ -0,0 +1,85 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: volt-google-maps
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Ryan Stout
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-10-14 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: volt
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.8.0
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.8.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description:
42
+ email:
43
+ - ryan@agileproductions.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - ".gitignore"
49
+ - Gemfile
50
+ - README.md
51
+ - Rakefile
52
+ - VERSION
53
+ - app/google-maps/assets/css/google-map.css
54
+ - app/google-maps/config/dependencies.rb
55
+ - app/google-maps/config/routes.rb
56
+ - app/google-maps/controllers/main_controller.rb
57
+ - app/google-maps/views/main/index.html
58
+ - app/google-maps/views/main/main.html
59
+ - lib/volt/google/maps.rb
60
+ - volt-google-maps.gemspec
61
+ homepage: ''
62
+ licenses:
63
+ - MIT
64
+ metadata: {}
65
+ post_install_message:
66
+ rdoc_options: []
67
+ require_paths:
68
+ - lib
69
+ required_ruby_version: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ version: '0'
74
+ required_rubygems_version: !ruby/object:Gem::Requirement
75
+ requirements:
76
+ - - ">="
77
+ - !ruby/object:Gem::Version
78
+ version: '0'
79
+ requirements: []
80
+ rubyforge_project:
81
+ rubygems_version: 2.2.2
82
+ signing_key:
83
+ specification_version: 4
84
+ summary: A google maps component for Volt
85
+ test_files: []