volt-google_maps 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/README.md +45 -0
- data/Rakefile +1 -0
- data/VERSION +1 -0
- data/app/google_maps/assets/css/google-map.css +4 -0
- data/app/google_maps/config/dependencies.rb +2 -0
- data/app/google_maps/config/routes.rb +1 -0
- data/app/google_maps/controllers/main_controller.rb +187 -0
- data/app/google_maps/views/main/index.html +3 -0
- data/app/google_maps/views/main/main.html +2 -0
- data/lib/volt/google/maps.rb +9 -0
- data/volt-google-maps.gemspec +24 -0
- metadata +85 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 0ac8298a4831f6f6451523018de6206b82ca08f8
|
4
|
+
data.tar.gz: 072425f76c0802864d59fe8128b4280d07b7c1d4
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 07dcdd8c4156003671510de4b9f75fe95f98a18e5901098cf63a3e06e86889d69c26aab0d167d83b74c68fca343686fff497cb50262520889a7b5e8d2bd4eb82
|
7
|
+
data.tar.gz: e4bba9443061b019f2127bc60c7ef75f63560b45029420deee8e4caa0413ac7a6226f09cb7a90c3bd351d321f0a503fee4ded686714c39875569fb494c647680
|
data/.gitignore
ADDED
data/Gemfile
ADDED
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.public.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.1.0
|
@@ -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 < Volt::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
|
+
end
|
24
|
+
|
25
|
+
|
26
|
+
def before_index_remove
|
27
|
+
%x{
|
28
|
+
delete this.map;
|
29
|
+
delete this.geocoder;
|
30
|
+
}
|
31
|
+
|
32
|
+
@add_listener.remove if @add_listener
|
33
|
+
@remove_listener.remove if @remove_listener
|
34
|
+
end
|
35
|
+
|
36
|
+
def set_markers
|
37
|
+
-> do
|
38
|
+
markers = attrs.markers
|
39
|
+
|
40
|
+
markers.each do |marker|
|
41
|
+
add_marker(marker) do |result|
|
42
|
+
@markers << result
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
@add_listener.remove if @add_listener
|
47
|
+
@remove_listener.remove if @remove_listener
|
48
|
+
|
49
|
+
if markers.respond_to?(:on)
|
50
|
+
@add_listener = markers.on('added') do |index|
|
51
|
+
marker = markers[index]
|
52
|
+
|
53
|
+
add_marker(marker) do |result|
|
54
|
+
@markers[index] = result
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
@remove_listener = markers.on('removed') do |index|
|
59
|
+
marker = @markers.delete_at(index)
|
60
|
+
remove_marker(marker.to_n)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
end.watch!
|
65
|
+
end
|
66
|
+
|
67
|
+
def setup_zoom
|
68
|
+
puts "SETUP ZOOM"
|
69
|
+
`google.maps.event.addListener(self.map, 'zoom_changed', function() {
|
70
|
+
var zoomLevel = self.map.getZoom();`
|
71
|
+
|
72
|
+
@changing_zoom = true
|
73
|
+
new_zoom = Native(`zoomLevel`)
|
74
|
+
if attrs.zoom != new_zoom && attrs.respond_to?(:zoom=)
|
75
|
+
attrs.zoom = new_zoom
|
76
|
+
end
|
77
|
+
|
78
|
+
# Setup listener again
|
79
|
+
set_zoom
|
80
|
+
|
81
|
+
@changing_zoom = false
|
82
|
+
|
83
|
+
`});`
|
84
|
+
|
85
|
+
end
|
86
|
+
|
87
|
+
def set_zoom
|
88
|
+
-> do
|
89
|
+
attrs.zoom
|
90
|
+
puts "SET ZOOM"
|
91
|
+
unless @changing_zoom
|
92
|
+
level = attrs.zoom
|
93
|
+
if level.blank?
|
94
|
+
level = 8
|
95
|
+
else
|
96
|
+
level = (level || 8).to_i
|
97
|
+
end
|
98
|
+
|
99
|
+
level_n = level.to_n
|
100
|
+
`if (self.map.getZoom() != level_n) {`
|
101
|
+
`self.map.setZoom(level_n);`
|
102
|
+
`}`
|
103
|
+
end
|
104
|
+
end.watch!
|
105
|
+
end
|
106
|
+
|
107
|
+
def setup_map(node, latlng)
|
108
|
+
%x{
|
109
|
+
var mapOptions = {
|
110
|
+
center: latlng,
|
111
|
+
zoom: 8
|
112
|
+
};
|
113
|
+
this.map = new google.maps.Map($(node).find('.google-map-instance').get(0), mapOptions);
|
114
|
+
console.log('map setup');
|
115
|
+
}
|
116
|
+
|
117
|
+
if attrs.respond_to?(:center)
|
118
|
+
@first = true
|
119
|
+
-> { set_center(attrs.center) }.watch!
|
120
|
+
end
|
121
|
+
|
122
|
+
|
123
|
+
set_zoom if attrs.respond_to?(:zoom)
|
124
|
+
|
125
|
+
set_markers if attrs.respond_to?(:markers)
|
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,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.9.2"
|
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.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Ryan Stout
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-05-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.9.2
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.9.2
|
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.4.6
|
82
|
+
signing_key:
|
83
|
+
specification_version: 4
|
84
|
+
summary: A google maps component for Volt
|
85
|
+
test_files: []
|