rails-google-maps 0.0.13 → 0.0.14
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
CHANGED
@@ -33,7 +33,15 @@ And include it in your ```application.js``` file after jquery:
|
|
33
33
|
|
34
34
|
|
35
35
|
## Usage
|
36
|
-
|
36
|
+
####SimpleForm usage:
|
37
|
+
```erb
|
38
|
+
/*NOTE: gmap-canvas - default value and can be ommited*/
|
39
|
+
<%= f.input :address, as: :google_maps_autocomplete, input_html: { gmap_id: 'gmap_canvas' } %>
|
40
|
+
...
|
41
|
+
<div id="gmap_canvas"></div>
|
42
|
+
```
|
43
|
+
Additionally on edit address point will be marked on the map.
|
44
|
+
####Javascript usage:
|
37
45
|
1) Apply google map to div element where map should appear:
|
38
46
|
```js
|
39
47
|
(new GoogleMap()).apply()
|
@@ -0,0 +1,31 @@
|
|
1
|
+
class GoogleMapsAutocompleteInput < SimpleForm::Inputs::StringInput
|
2
|
+
include ActionView::Helpers::TagHelper
|
3
|
+
def input
|
4
|
+
gmap_id = input_html_options.delete(:gmap_id)
|
5
|
+
input = @builder.text_field(attribute_name, input_html_options)
|
6
|
+
(input + content_tag('script', script_text(gmap_id, input).html_safe)).html_safe
|
7
|
+
end
|
8
|
+
|
9
|
+
private
|
10
|
+
|
11
|
+
def script_text(gmap_id, tag)
|
12
|
+
"$(document).ready(function(){
|
13
|
+
if(typeof google == 'undefined')
|
14
|
+
return;
|
15
|
+
var selector = '#{gmap_id}';
|
16
|
+
if(selector.length > 0){
|
17
|
+
selector = '#' + selector;
|
18
|
+
}
|
19
|
+
window.gmap = new GoogleMap({selector: selector});
|
20
|
+
input = $('#{tag}');
|
21
|
+
var id = input.attr('id');
|
22
|
+
var location = input.val();
|
23
|
+
window.googleAutocomplete = new GmapAutocomplete('#' + id, gmap);
|
24
|
+
gmap.apply();
|
25
|
+
googleAutocomplete.apply();
|
26
|
+
if(location.length > 0){
|
27
|
+
gmap.setMarker('address', location);
|
28
|
+
}
|
29
|
+
})"
|
30
|
+
end
|
31
|
+
end
|
@@ -31,19 +31,21 @@ class root.Autocomplete
|
|
31
31
|
class root.GmapAutocomplete extends Autocomplete
|
32
32
|
|
33
33
|
constructor: (@selector, @gmap)->
|
34
|
+
self = this
|
35
|
+
@gmap.onSucceed.push (address)->
|
36
|
+
$(self.selector).val address
|
34
37
|
|
35
38
|
source: (self)->
|
36
39
|
(request, response)->
|
37
|
-
self.gmap.
|
40
|
+
self.gmap.searchGeocodes request.term, (results)->
|
38
41
|
response $.map results, (item) ->
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
+
label: item.formatted_address
|
43
|
+
value: item.formatted_address
|
44
|
+
geocode: item
|
42
45
|
|
43
46
|
select: (self)->
|
44
47
|
(event, ui) ->
|
45
|
-
self.gmap.
|
46
|
-
self.gmap.updateMap ui.item.geocode.geometry
|
48
|
+
self.gmap.update ui.item.geocode
|
47
49
|
|
48
50
|
afterApply: ()->
|
49
51
|
this._addKeyDownHandlers()
|
@@ -52,7 +54,7 @@ class root.GmapAutocomplete extends Autocomplete
|
|
52
54
|
self = this
|
53
55
|
$(@selector).bind 'keydown', (event)->
|
54
56
|
if event.keyCode == 13
|
55
|
-
self.gmap.
|
57
|
+
self.gmap.setMarker 'address', $(self.selector).val()
|
56
58
|
$(self.selector).autocomplete "disable"
|
57
59
|
else
|
58
60
|
$(self.selector).autocomplete "enable"
|
@@ -7,12 +7,11 @@ return unless google?
|
|
7
7
|
# gmap.apply()
|
8
8
|
class root.GoogleMap
|
9
9
|
|
10
|
-
inputField: '#gmaps-input-address'
|
11
|
-
|
12
10
|
#defines whether user can change map pin or not
|
13
|
-
immutable
|
14
|
-
mapSelector
|
15
|
-
errorField
|
11
|
+
immutable: false
|
12
|
+
mapSelector: "#gmaps-canvas"
|
13
|
+
errorField: "#gmaps-error"
|
14
|
+
onSucceed: []
|
16
15
|
|
17
16
|
_applied: false
|
18
17
|
|
@@ -42,17 +41,10 @@ class root.GoogleMap
|
|
42
41
|
this._addListeners()
|
43
42
|
@_applied = true
|
44
43
|
|
45
|
-
updateMap: (geometry)->
|
46
|
-
@map.fitBounds( geometry.viewport )
|
47
|
-
@marker.setPosition( geometry.location )
|
48
|
-
|
49
|
-
updateUi: (address, latLng)->
|
50
|
-
$(@inputField).val(address)
|
51
|
-
|
52
44
|
applied: ()->
|
53
45
|
@_applied
|
54
46
|
|
55
|
-
|
47
|
+
setMarker: (type, value, update = true)->
|
56
48
|
request = {}
|
57
49
|
request[type] = value
|
58
50
|
self = this
|
@@ -63,19 +55,29 @@ class root.GoogleMap
|
|
63
55
|
else
|
64
56
|
self._failed(update, type, value)
|
65
57
|
|
58
|
+
searchGeocodes: (term, callback)->
|
59
|
+
@geocoder.geocode {'address': term }, (results, status)->
|
60
|
+
callback(results, status)
|
61
|
+
|
62
|
+
|
63
|
+
update: (geocode)->
|
64
|
+
@map.fitBounds geocode.geometry.viewport
|
65
|
+
@marker.setPosition geocode.geometry.location
|
66
|
+
|
66
67
|
_addListeners: ()->
|
67
68
|
self = this
|
68
69
|
return if @immutable
|
69
70
|
google.maps.event.addListener @marker, 'dragend', () ->
|
70
|
-
self.
|
71
|
+
self.setMarker 'latLng', self.marker.getPosition(), false
|
71
72
|
google.maps.event.addListener @map, 'click', (event) ->
|
72
73
|
self.marker.setPosition event.latLng
|
73
|
-
self.
|
74
|
+
self.setMarker 'latLng', event.latLng, false
|
74
75
|
|
75
76
|
_succeed: (results, update)->
|
76
77
|
if results[0]
|
77
|
-
this.
|
78
|
-
|
78
|
+
this.update(results[0]) if update
|
79
|
+
$.map @onSucceed, (callback)->
|
80
|
+
callback(results[0].formatted_address)
|
79
81
|
this._saveLatLang(results[0].geometry.location.lat(), results[0].geometry.location.lng()) if @saveLangLat
|
80
82
|
else
|
81
83
|
@gmapErrors.wrongInputError()
|
@@ -86,7 +88,6 @@ class root.GoogleMap
|
|
86
88
|
@gmapErrors.incorrectAddress(value)
|
87
89
|
else
|
88
90
|
@gmapErrors.incorrectLatlng()
|
89
|
-
this.updateUi('', value)
|
90
91
|
|
91
92
|
_saveLatLang: (lat, long)->
|
92
93
|
$(@latitudeInput).val(lat)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails-google-maps
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.14
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -55,6 +55,7 @@ files:
|
|
55
55
|
- LICENSE.txt
|
56
56
|
- README.md
|
57
57
|
- Rakefile
|
58
|
+
- app/inputs/google_maps_autocomplete_input.rb
|
58
59
|
- lib/rails-google-maps.rb
|
59
60
|
- lib/rails-google-maps/rails.rb
|
60
61
|
- lib/rails-google-maps/version.rb
|