rails-google-maps 0.0.15 → 0.0.16
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/README.md +5 -0
- data/app/inputs/google_maps_autocomplete_input.rb +4 -2
- data/lib/rails-google-maps/version.rb +1 -1
- data/vendor/assets/javascripts/rails-google-maps/autocomplete.js.coffee +30 -38
- data/vendor/assets/javascripts/rails-google-maps/google_maps.js.coffee +58 -58
- data/vendor/assets/stylesheets/rails_google_maps.css +11 -0
- metadata +20 -13
data/README.md
CHANGED
@@ -31,6 +31,11 @@ And include it in your ```application.js``` file after jquery:
|
|
31
31
|
//= require rails-google-maps/google_maps
|
32
32
|
```
|
33
33
|
|
34
|
+
Optionally you can use default styles for the map object:
|
35
|
+
```
|
36
|
+
// application.css
|
37
|
+
*= require rails_google_maps
|
38
|
+
```
|
34
39
|
|
35
40
|
## Usage
|
36
41
|
####SimpleForm usage:
|
@@ -1,4 +1,5 @@
|
|
1
1
|
class GoogleMapsAutocompleteInput < SimpleForm::Inputs::StringInput
|
2
|
+
include ActionView::Helpers::JavaScriptHelper
|
2
3
|
include ActionView::Helpers::TagHelper
|
3
4
|
def input
|
4
5
|
gmap_id = input_html_options.delete(:gmap_id)
|
@@ -6,7 +7,7 @@ class GoogleMapsAutocompleteInput < SimpleForm::Inputs::StringInput
|
|
6
7
|
lat_id = input_html_options.key?(:lat_id) ? input_html_options.delete(:lat_id) : nil
|
7
8
|
lng_id = input_html_options.key?(:lng_id) ? input_html_options.delete(:lng_id) : nil
|
8
9
|
input = @builder.text_field(attribute_name, input_html_options)
|
9
|
-
(input +
|
10
|
+
(input + javascript_tag(script_text(gmap_id, input, apply, lat_id, lng_id))).html_safe
|
10
11
|
end
|
11
12
|
|
12
13
|
private
|
@@ -30,7 +31,8 @@ class GoogleMapsAutocompleteInput < SimpleForm::Inputs::StringInput
|
|
30
31
|
}
|
31
32
|
var latId = '#{lat_id.to_s}', lngId = '#{lng_id.to_s}';
|
32
33
|
if(latId && lngId){
|
33
|
-
gmap.setOptions({longitudeInput: lngId, latitudeInput: latId});
|
34
|
+
gmap.setOptions({longitudeInput: '#' + lngId, latitudeInput: '#' + latId});
|
35
|
+
gmap.setFromLatLng()
|
34
36
|
}
|
35
37
|
})"
|
36
38
|
end
|
@@ -1,23 +1,18 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
class root.Autocomplete
|
4
|
-
source: ()->
|
1
|
+
class @Autocomplete
|
2
|
+
source: ()=>
|
5
3
|
[]
|
6
|
-
select: ()
|
7
|
-
|
8
|
-
change: ()->
|
9
|
-
()->
|
4
|
+
select: ()=>
|
5
|
+
change: ()=>
|
10
6
|
minChars: 2
|
11
7
|
|
12
|
-
constructor: (
|
13
|
-
@$el = $(
|
8
|
+
constructor: (selector)->
|
9
|
+
@$el = $(selector)
|
14
10
|
|
15
11
|
apply: ()->
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
change: self.change(self)
|
12
|
+
@$el.autocomplete
|
13
|
+
source: @source
|
14
|
+
select: @select
|
15
|
+
change: @change
|
21
16
|
this.afterApply()
|
22
17
|
|
23
18
|
afterApply: ()->
|
@@ -28,38 +23,35 @@ class root.Autocomplete
|
|
28
23
|
# gmap.apply()
|
29
24
|
# autoComplete = new GmapAutocomplete('#gmaps-input-address', gmap)
|
30
25
|
# autoComplete.apply()
|
31
|
-
class
|
26
|
+
class @GmapAutocomplete extends Autocomplete
|
32
27
|
|
33
|
-
constructor: (
|
34
|
-
|
35
|
-
@gmap.onSucceed.push (address)
|
36
|
-
|
28
|
+
constructor: (selector, @gmap)->
|
29
|
+
super selector
|
30
|
+
@gmap.onSucceed.push (address)=>
|
31
|
+
@$el.val address
|
37
32
|
|
38
|
-
source: (
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
geocode: item
|
33
|
+
source: (request, response) =>
|
34
|
+
@gmap.searchGeocodes request.term, (results)->
|
35
|
+
response $.map results, (item) ->
|
36
|
+
label: item.formatted_address
|
37
|
+
value: item.formatted_address
|
38
|
+
geocode: item
|
45
39
|
|
46
|
-
select: (
|
47
|
-
|
48
|
-
self.gmap.update ui.item.geocode
|
40
|
+
select: (event, ui) =>
|
41
|
+
@gmap.update ui.item.geocode
|
49
42
|
|
50
43
|
afterApply: ()->
|
51
|
-
|
52
|
-
|
44
|
+
@syncWithMap()
|
45
|
+
@_addKeyDownHandlers()
|
53
46
|
|
54
47
|
syncWithMap: ()->
|
55
|
-
@gmap.setMarker('address',
|
48
|
+
@gmap.setMarker('address', @$el.val()) if @$el.val()
|
56
49
|
|
57
50
|
_addKeyDownHandlers: ()->
|
58
|
-
|
59
|
-
$(@selector).bind 'keydown', (event)->
|
51
|
+
@$el.bind 'keydown', (event)=>
|
60
52
|
if event.keyCode == 13
|
61
|
-
|
62
|
-
|
53
|
+
@gmap.setMarker 'address', @$el.val()
|
54
|
+
@$el.autocomplete "disable"
|
63
55
|
else
|
64
|
-
|
56
|
+
@$el.autocomplete "enable"
|
65
57
|
|
@@ -1,11 +1,8 @@
|
|
1
|
-
root = exports ? this
|
2
|
-
return unless google?
|
3
|
-
|
4
1
|
# Google map class
|
5
2
|
# Example:
|
6
3
|
# gmap = new GoogleMap
|
7
4
|
# gmap.apply()
|
8
|
-
class
|
5
|
+
class @GoogleMap
|
9
6
|
|
10
7
|
#defines whether user can change map pin or not
|
11
8
|
immutable: false
|
@@ -33,112 +30,92 @@ class root.GoogleMap
|
|
33
30
|
@errorField = options['errorField'] if options['errorField']
|
34
31
|
if options['longitudeInput'] and options['latitudeInput']
|
35
32
|
@saveLangLat = true
|
36
|
-
@
|
37
|
-
@latitudeInput = options['latitudeInput']
|
38
|
-
|
33
|
+
@latLng = new LatLngContainer(options['latitudeInput'], options['longitudeInput'])
|
39
34
|
|
40
35
|
apply: ()->
|
41
36
|
if($(@mapSelector).length > 0)
|
42
37
|
@map = new google.maps.Map $(@mapSelector)[0], @gmapOptions
|
43
|
-
@marker = new google.maps.Marker {map: @map, draggable:
|
38
|
+
@marker = new google.maps.Marker {map: @map, draggable: !@immutable}
|
44
39
|
else
|
45
40
|
@mapless = true
|
46
41
|
@geocoder = new google.maps.Geocoder()
|
47
42
|
@gmapErrors = new GmapErrors @errorField
|
48
|
-
|
43
|
+
@_addListeners() unless @immutable or @mapless
|
49
44
|
@_applied = true
|
50
45
|
|
51
46
|
applied: ()->
|
52
47
|
@_applied
|
53
48
|
|
54
|
-
setMarker: (type, value,
|
49
|
+
setMarker: (type, value, focusOnMarker = true, afterCallback = ()->)->
|
55
50
|
request = {}
|
56
51
|
request[type] = value
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
if status is google.maps.GeocoderStatus.OK
|
61
|
-
self._succeed(results, update)
|
52
|
+
@geocoder.geocode request, (results, status)=>
|
53
|
+
if status is google.maps.GeocoderStatus.OK and results[0]
|
54
|
+
@_succeed results, focusOnMarker
|
62
55
|
else
|
63
|
-
|
56
|
+
@_failed(type, value)
|
64
57
|
afterCallback()
|
65
58
|
|
66
59
|
searchGeocodes: (term, callback)->
|
67
60
|
@geocoder.geocode {'address': term }, (results, status)->
|
68
61
|
callback(results, status)
|
69
62
|
|
70
|
-
|
71
63
|
update: (geocode)->
|
72
64
|
unless @mapless
|
73
65
|
@map.fitBounds geocode.geometry.viewport
|
74
66
|
@marker.setPosition geocode.geometry.location
|
75
|
-
|
67
|
+
@latLng.store(geocode.geometry) if @saveLangLat
|
76
68
|
|
77
|
-
|
78
|
-
|
79
|
-
return if @immutable
|
80
|
-
unless @mapless
|
81
|
-
google.maps.event.addListener @marker, 'dragend', () ->
|
82
|
-
self.setMarker 'latLng', self.marker.getPosition(), false
|
83
|
-
google.maps.event.addListener @map, 'click', (event) ->
|
84
|
-
self.marker.setPosition event.latLng
|
85
|
-
self.setMarker 'latLng', event.latLng, false
|
86
|
-
|
87
|
-
_succeed: (results, update)->
|
88
|
-
if results[0]
|
89
|
-
this.update(results[0]) if update
|
90
|
-
$.map @onSucceed, (callback)->
|
91
|
-
callback(results[0].formatted_address)
|
92
|
-
this.saveLatLang(results[0].geometry) if @saveLangLat
|
93
|
-
else
|
94
|
-
@gmapErrors.wrongInputError()
|
69
|
+
setFromLatLng: ()->
|
70
|
+
@setMarker('latLng', new google.maps.LatLng(@latLng.lat(), @latLng.lng()))
|
95
71
|
|
96
|
-
|
97
|
-
|
72
|
+
_addListeners: ()->
|
73
|
+
google.maps.event.addListener @marker, 'dragend', () =>
|
74
|
+
@setMarker 'latLng', @marker.getPosition(), false
|
75
|
+
google.maps.event.addListener @map, 'click', (event) =>
|
76
|
+
@marker.setPosition event.latLng
|
77
|
+
@setMarker 'latLng', event.latLng, false
|
78
|
+
|
79
|
+
_succeed: (results, focusOnMarker)->
|
80
|
+
@update(results[0]) if focusOnMarker
|
81
|
+
$.map @onSucceed, (callback)->
|
82
|
+
callback(results[0].formatted_address)
|
83
|
+
@latLng.store(results[0].geometry) if @saveLangLat
|
84
|
+
|
85
|
+
_failed: (type, value)->
|
98
86
|
if type is 'address'
|
99
87
|
@gmapErrors.incorrectAddress(value)
|
100
88
|
else
|
101
89
|
@gmapErrors.incorrectLatlng()
|
102
90
|
|
103
|
-
saveLatLang: (geometry)->
|
104
|
-
$(@latitudeInput).val(geometry.location.lat())
|
105
|
-
$(@longitudeInput).val(geometry.location.lng())
|
106
|
-
|
107
|
-
clearLatLng: ()->
|
108
|
-
$(@latitudeInput).val('')
|
109
|
-
$(@longitudeInput).val('')
|
110
|
-
|
111
91
|
# Class for displaying Gmap Errors.
|
112
92
|
# All the errors can be customised
|
113
93
|
# There are several type of errors:
|
114
94
|
# GmapErrors.wrongInputText
|
115
95
|
# GmapErrors.incorrectLatLngText
|
116
96
|
# GmapErrors.incorrectAddressText(value) - callback, incorrect address can be used inside
|
117
|
-
class
|
97
|
+
class @GmapErrors
|
118
98
|
|
119
|
-
@wrongInputText: "Sorry, something went wrong. Try again!"
|
120
99
|
@incorrectLatLngText: "Woah... that's pretty remote! You're going to have to manually enter a place name."
|
121
100
|
|
122
101
|
constructor: (@errorField)->
|
123
102
|
|
124
103
|
incorrectAddress: (value)->
|
125
|
-
|
126
|
-
|
104
|
+
@cleanErrors()
|
105
|
+
@setError(GmapErrors.incorrectAddressText(value))
|
106
|
+
@show()
|
127
107
|
|
128
108
|
incorrectLatlng: ()->
|
129
|
-
|
130
|
-
|
109
|
+
@cleanErrors()
|
110
|
+
@setError(@incorrectLatLngText)
|
111
|
+
@show()
|
131
112
|
|
132
113
|
@incorrectAddressText: (value)->
|
133
114
|
"Sorry! We couldn't find #{value}. Try a different search term, or click the map."
|
134
115
|
|
135
|
-
wrongInputError: ()->
|
136
|
-
this.setError(@wrongInputText)
|
137
|
-
this.show()
|
138
|
-
|
139
116
|
cleanErrors: ()->
|
140
|
-
|
141
|
-
|
117
|
+
@setError('')
|
118
|
+
@hide()
|
142
119
|
|
143
120
|
show: ()->
|
144
121
|
$(@errorField).show()
|
@@ -149,5 +126,28 @@ class root.GmapErrors
|
|
149
126
|
setError: (text)->
|
150
127
|
$(@errorField).html(text)
|
151
128
|
|
129
|
+
class LatLngContainer
|
130
|
+
constructor: (latitudeInput, longitudeInput)->
|
131
|
+
@latitudeInput = $(latitudeInput)
|
132
|
+
@longitudeInput = $(longitudeInput)
|
133
|
+
|
134
|
+
lat: ()->
|
135
|
+
@latitudeInput.val()
|
136
|
+
|
137
|
+
lng: ()->
|
138
|
+
@longitudeInput.val()
|
139
|
+
|
140
|
+
googleLatLng: ()->
|
141
|
+
new google.maps.LatLng(@lat, @lng)
|
142
|
+
|
143
|
+
store: (geometry)->
|
144
|
+
@latitudeInput.val(geometry.location.lat())
|
145
|
+
@longitudeInput.val(geometry.location.lng())
|
146
|
+
|
147
|
+
clear: ()->
|
148
|
+
@latitudeInput.val('')
|
149
|
+
@longitudeInput.val('')
|
150
|
+
|
151
|
+
|
152
152
|
|
153
153
|
|
@@ -0,0 +1,11 @@
|
|
1
|
+
#gmap_canvas {
|
2
|
+
padding: 6px;
|
3
|
+
border-width: 1px;
|
4
|
+
border-style: solid;
|
5
|
+
border-color: #ccc #ccc #999 #ccc;
|
6
|
+
-webkit-box-shadow: rgba(64, 64, 64, 0.5) 0 2px 5px;
|
7
|
+
-moz-box-shadow: rgba(64, 64, 64, 0.5) 0 2px 5px;
|
8
|
+
box-shadow: rgba(64, 64, 64, 0.1) 0 2px 5px;
|
9
|
+
width: 800px;
|
10
|
+
height: 400px;
|
11
|
+
}
|
metadata
CHANGED
@@ -1,48 +1,48 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails-google-maps
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.15
|
5
4
|
prerelease:
|
5
|
+
version: 0.0.16
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Yuri Ratanov
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-07-21 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
16
|
+
type: :runtime
|
16
17
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
20
20
|
- !ruby/object:Gem::Version
|
21
21
|
version: '3.0'
|
22
|
-
type: :runtime
|
23
|
-
prerelease: false
|
24
|
-
version_requirements: !ruby/object:Gem::Requirement
|
25
22
|
none: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
24
|
requirements:
|
27
25
|
- - ~>
|
28
26
|
- !ruby/object:Gem::Version
|
29
27
|
version: '3.0'
|
28
|
+
none: false
|
29
|
+
prerelease: false
|
30
30
|
- !ruby/object:Gem::Dependency
|
31
31
|
name: jquery-rails
|
32
|
+
type: :runtime
|
32
33
|
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
34
|
requirements:
|
35
35
|
- - ! '>='
|
36
36
|
- !ruby/object:Gem::Version
|
37
37
|
version: '0'
|
38
|
-
type: :runtime
|
39
|
-
prerelease: false
|
40
|
-
version_requirements: !ruby/object:Gem::Requirement
|
41
38
|
none: false
|
39
|
+
version_requirements: !ruby/object:Gem::Requirement
|
42
40
|
requirements:
|
43
41
|
- - ! '>='
|
44
42
|
- !ruby/object:Gem::Version
|
45
43
|
version: '0'
|
44
|
+
none: false
|
45
|
+
prerelease: false
|
46
46
|
description: Provides simple way to add google maps to your app
|
47
47
|
email:
|
48
48
|
- yratanov@gmail.com
|
@@ -62,6 +62,7 @@ files:
|
|
62
62
|
- rails-google-maps.gemspec
|
63
63
|
- vendor/assets/javascripts/rails-google-maps/autocomplete.js.coffee
|
64
64
|
- vendor/assets/javascripts/rails-google-maps/google_maps.js.coffee
|
65
|
+
- vendor/assets/stylesheets/rails_google_maps.css
|
65
66
|
homepage: http://github.com/yratanov/rails_google_maps
|
66
67
|
licenses: []
|
67
68
|
post_install_message:
|
@@ -69,20 +70,26 @@ rdoc_options: []
|
|
69
70
|
require_paths:
|
70
71
|
- lib
|
71
72
|
required_ruby_version: !ruby/object:Gem::Requirement
|
72
|
-
none: false
|
73
73
|
requirements:
|
74
74
|
- - ! '>='
|
75
75
|
- !ruby/object:Gem::Version
|
76
|
+
segments:
|
77
|
+
- 0
|
78
|
+
hash: 1853501962189102729
|
76
79
|
version: '0'
|
77
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
78
80
|
none: false
|
81
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
79
82
|
requirements:
|
80
83
|
- - ! '>='
|
81
84
|
- !ruby/object:Gem::Version
|
85
|
+
segments:
|
86
|
+
- 0
|
87
|
+
hash: 1853501962189102729
|
82
88
|
version: '0'
|
89
|
+
none: false
|
83
90
|
requirements: []
|
84
91
|
rubyforge_project:
|
85
|
-
rubygems_version: 1.8.
|
92
|
+
rubygems_version: 1.8.25
|
86
93
|
signing_key:
|
87
94
|
specification_version: 3
|
88
95
|
summary: Provides simple way to add google maps to your app
|