rails-google-maps 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +18 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +29 -0
- data/Rakefile +1 -0
- data/lib/rails_google_maps.rb +8 -0
- data/lib/rails_google_maps/version.rb +3 -0
- data/rails_google_maps.gemspec +23 -0
- data/vendor/assets/javascripts/autocomplete.js.coffee +59 -0
- data/vendor/assets/javascripts/gmaps.js.coffee +133 -0
- data/vendor/assets/javascripts/test.js +0 -0
- metadata +103 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Yuri Ratanov
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# RailsGoogleMaps
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'rails_google_maps'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install rails_google_maps
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'rails_google_maps/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "rails-google-maps"
|
8
|
+
gem.version = RailsGoogleMaps::VERSION
|
9
|
+
gem.authors = ["Yuri Ratanov"]
|
10
|
+
gem.email = ["yratanov@gmail.com"]
|
11
|
+
gem.description = 'Provides simple way to add google maps to your app'
|
12
|
+
gem.summary = 'Provides simple way to add google maps to your app'
|
13
|
+
gem.homepage = 'http://github.com/yratanov/rails_google_maps'
|
14
|
+
|
15
|
+
gem.files = `git ls-files`.split("\n")
|
16
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
17
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
|
+
gem.require_paths = 'lib'
|
19
|
+
|
20
|
+
gem.add_dependency 'rails', '~>3.0'
|
21
|
+
gem.add_dependency 'jquery-rails'
|
22
|
+
gem.add_dependency 'railties', '~> 3.1'
|
23
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
root = exports ? this
|
2
|
+
|
3
|
+
class root.Autocomplete
|
4
|
+
source: ()->
|
5
|
+
[]
|
6
|
+
select: ()->
|
7
|
+
()->
|
8
|
+
change: ()->
|
9
|
+
()->
|
10
|
+
minChars: 2
|
11
|
+
|
12
|
+
constructor: (@selector)->
|
13
|
+
@$el = $(@selector)
|
14
|
+
|
15
|
+
apply: ()->
|
16
|
+
self = this
|
17
|
+
$(@selector).autocomplete
|
18
|
+
source: self.source(self)
|
19
|
+
select: self.select(self)
|
20
|
+
change: self.change(self)
|
21
|
+
this.afterApply()
|
22
|
+
|
23
|
+
afterApply: ()->
|
24
|
+
|
25
|
+
# Auto complete attached to the GoogleMap object
|
26
|
+
# Example:
|
27
|
+
# gmap = new GoogleMap()
|
28
|
+
# gmap.apply()
|
29
|
+
# autoComplete = new GmapAutocomplete('#gmaps-input-address', gmap)
|
30
|
+
# autoComplete.apply()
|
31
|
+
class root.GmapAutocomplete extends Autocomplete
|
32
|
+
|
33
|
+
constructor: (@selector, @gmap)->
|
34
|
+
|
35
|
+
source: (self)->
|
36
|
+
(request, response)->
|
37
|
+
self.gmap.geocoder.geocode {'address': request.term }, (results, status)->
|
38
|
+
response $.map results, (item) ->
|
39
|
+
label: item.formatted_address
|
40
|
+
value: item.formatted_address
|
41
|
+
geocode: item
|
42
|
+
|
43
|
+
select: (self)->
|
44
|
+
(event, ui) ->
|
45
|
+
self.gmap.updateUi ui.item.value, ui.item.geocode.geometry.location
|
46
|
+
self.gmap.updateMap ui.item.geocode.geometry
|
47
|
+
|
48
|
+
afterApply: ()->
|
49
|
+
this._addKeyDownHandlers()
|
50
|
+
|
51
|
+
_addKeyDownHandlers: ()->
|
52
|
+
self = this
|
53
|
+
$(@selector).bind 'keydown', (event)->
|
54
|
+
if event.keyCode == 13
|
55
|
+
self.gmap.geocodeLookup 'address', $(self.selector).val(), true
|
56
|
+
$(self.selector).autocomplete "disable"
|
57
|
+
else
|
58
|
+
$(self.selector).autocomplete "enable"
|
59
|
+
|
@@ -0,0 +1,133 @@
|
|
1
|
+
root = exports ? this
|
2
|
+
return unless google?
|
3
|
+
|
4
|
+
# Google map class
|
5
|
+
# Example:
|
6
|
+
# gmap = new GoogleMap
|
7
|
+
# gmap.apply()
|
8
|
+
class root.GoogleMap
|
9
|
+
|
10
|
+
inputField: '#gmaps-input-address'
|
11
|
+
|
12
|
+
#defines whether user can change map pin or not
|
13
|
+
immutable = false
|
14
|
+
|
15
|
+
_applied: false
|
16
|
+
|
17
|
+
@defaultGmapOptions: {
|
18
|
+
zoom: 2
|
19
|
+
mapTypeId: google.maps.MapTypeId.ROADMAP
|
20
|
+
center: new google.maps.LatLng(51.751724,-1.255284)
|
21
|
+
}
|
22
|
+
|
23
|
+
# options: object options
|
24
|
+
# gmapOptions: google map api options
|
25
|
+
constructor: (options = {}, gmapOptions = {}, @mapSelector = "#gmaps-canvas", @errorField = '#gmaps-error')->
|
26
|
+
@gmapOptions = $.extend {}, GoogleMap.defaultGmapOptions, gmapOptions
|
27
|
+
@immutable = true if options['immutable']
|
28
|
+
if options['saveLatLang']
|
29
|
+
@saveLangLat = true
|
30
|
+
@longitudeInput = options['longitudeInput']
|
31
|
+
@latitudeInput = options['latitudeInput']
|
32
|
+
|
33
|
+
apply: ()->
|
34
|
+
@map = new google.maps.Map $(@mapSelector)[0], @gmapOptions
|
35
|
+
@geocoder = new google.maps.Geocoder()
|
36
|
+
@marker = new google.maps.Marker {map: @map, draggable: true}
|
37
|
+
@gmapErrors = new GmapErrors @errorField
|
38
|
+
this._addListeners()
|
39
|
+
@_applied = true
|
40
|
+
|
41
|
+
updateMap: (geometry)->
|
42
|
+
@map.fitBounds( geometry.viewport )
|
43
|
+
@marker.setPosition( geometry.location )
|
44
|
+
|
45
|
+
updateUi: (address, latLng)->
|
46
|
+
$(@inputField).val(address)
|
47
|
+
|
48
|
+
applied: ()->
|
49
|
+
@_applied
|
50
|
+
|
51
|
+
geocodeLookup: (type, value, update = false)->
|
52
|
+
request = {}
|
53
|
+
request[type] = value
|
54
|
+
self = this
|
55
|
+
@geocoder.geocode request, (results, status)->
|
56
|
+
self.gmapErrors.cleanErrors()
|
57
|
+
if status is google.maps.GeocoderStatus.OK
|
58
|
+
self._succeed(results, update)
|
59
|
+
else
|
60
|
+
self._failed(update, type, value)
|
61
|
+
|
62
|
+
_addListeners: ()->
|
63
|
+
self = this
|
64
|
+
return if @immutable
|
65
|
+
google.maps.event.addListener @marker, 'dragend', () ->
|
66
|
+
self.geocodeLookup 'latLng', self.marker.getPosition()
|
67
|
+
google.maps.event.addListener @map, 'click', (event) ->
|
68
|
+
self.marker.setPosition event.latLng
|
69
|
+
self.geocodeLookup 'latLng', event.latLng
|
70
|
+
|
71
|
+
_succeed: (results, update)->
|
72
|
+
if results[0]
|
73
|
+
this.updateUi results[0].formatted_address, results[0].geometry.location
|
74
|
+
this.updateMap(results[0].geometry) if update
|
75
|
+
this._saveLatLang(results[0].geometry.location.lat(), results[0].geometry.location.lng()) if @saveLangLat
|
76
|
+
else
|
77
|
+
@gmapErrors.wrongInputError()
|
78
|
+
|
79
|
+
_failed: (update, type, value)->
|
80
|
+
this._saveLatLang('', '') if @saveLangLat
|
81
|
+
if type is 'address'
|
82
|
+
@gmapErrors.incorrectAddress(value)
|
83
|
+
else
|
84
|
+
@gmapErrors.incorrectLatlng()
|
85
|
+
this.updateUi('', value)
|
86
|
+
|
87
|
+
_saveLatLang: (lat, long)->
|
88
|
+
$(@latitudeInput).val(lat)
|
89
|
+
$(@longitudeInput).val(long)
|
90
|
+
|
91
|
+
# Class for displaying Gmap Errors.
|
92
|
+
# All the errors can be customised
|
93
|
+
# There are several type of errors:
|
94
|
+
# GmapErrors.wrongInputText
|
95
|
+
# GmapErrors.incorrectLatLngText
|
96
|
+
# GmapErrors.incorrectAddressText(value) - callback, incorrect address can be used inside
|
97
|
+
class root.GmapErrors
|
98
|
+
|
99
|
+
@wrongInputText: "Sorry, something went wrong. Try again!"
|
100
|
+
@incorrectLatLngText: "Woah... that's pretty remote! You're going to have to manually enter a place name."
|
101
|
+
|
102
|
+
constructor: (@errorField)->
|
103
|
+
|
104
|
+
incorrectAddress: (value)->
|
105
|
+
this.setError(GmapErrors.incorrectAddressText(value))
|
106
|
+
this.show()
|
107
|
+
|
108
|
+
incorrectLatlng: ()->
|
109
|
+
this.setError(@incorrectLatLngText)
|
110
|
+
this.show()
|
111
|
+
|
112
|
+
@incorrectAddressText: (value)->
|
113
|
+
"Sorry! We couldn't find #{value}. Try a different search term, or click the map."
|
114
|
+
|
115
|
+
wrongInputError: ()->
|
116
|
+
this.setError(@wrongInputText)
|
117
|
+
this.show()
|
118
|
+
|
119
|
+
cleanErrors: ()->
|
120
|
+
this.setError('')
|
121
|
+
this.hide()
|
122
|
+
|
123
|
+
show: ()->
|
124
|
+
$(@errorField).show()
|
125
|
+
|
126
|
+
hide: ()->
|
127
|
+
$(@errorField).hide()
|
128
|
+
|
129
|
+
setError: (text)->
|
130
|
+
$(@errorField).html(text)
|
131
|
+
|
132
|
+
|
133
|
+
|
File without changes
|
metadata
ADDED
@@ -0,0 +1,103 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rails-google-maps
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Yuri Ratanov
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-04-04 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.0'
|
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.0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: jquery-rails
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :runtime
|
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
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: railties
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ~>
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '3.1'
|
54
|
+
type: :runtime
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3.1'
|
62
|
+
description: Provides simple way to add google maps to your app
|
63
|
+
email:
|
64
|
+
- yratanov@gmail.com
|
65
|
+
executables: []
|
66
|
+
extensions: []
|
67
|
+
extra_rdoc_files: []
|
68
|
+
files:
|
69
|
+
- .gitignore
|
70
|
+
- Gemfile
|
71
|
+
- LICENSE.txt
|
72
|
+
- README.md
|
73
|
+
- Rakefile
|
74
|
+
- lib/rails_google_maps.rb
|
75
|
+
- lib/rails_google_maps/version.rb
|
76
|
+
- rails_google_maps.gemspec
|
77
|
+
- vendor/assets/javascripts/autocomplete.js.coffee
|
78
|
+
- vendor/assets/javascripts/gmaps.js.coffee
|
79
|
+
- vendor/assets/javascripts/test.js
|
80
|
+
homepage: http://github.com/yratanov/rails_google_maps
|
81
|
+
licenses: []
|
82
|
+
post_install_message:
|
83
|
+
rdoc_options: []
|
84
|
+
require_paths: lib
|
85
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
86
|
+
none: false
|
87
|
+
requirements:
|
88
|
+
- - ! '>='
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: '0'
|
91
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
92
|
+
none: false
|
93
|
+
requirements:
|
94
|
+
- - ! '>='
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
requirements: []
|
98
|
+
rubyforge_project:
|
99
|
+
rubygems_version: 1.8.24
|
100
|
+
signing_key:
|
101
|
+
specification_version: 3
|
102
|
+
summary: Provides simple way to add google maps to your app
|
103
|
+
test_files: []
|