rails_admin_map_field 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +10 -39
- data/app/assets/javascript/map.coffee +24 -23
- data/rails_admin_map_field.gemspec +1 -1
- metadata +2 -2
data/README.md
CHANGED
@@ -11,65 +11,36 @@ Usage
|
|
11
11
|
rails_admin_map_field expects that the model will have two attributes, one for latitude and one for longitude of the point represented. To enable rails_admin_map_field, add the following to your `Gemfile`:
|
12
12
|
|
13
13
|
```ruby
|
14
|
-
gem 'rails_admin_map_field'
|
14
|
+
gem 'rails_admin_map_field'
|
15
15
|
```
|
16
16
|
|
17
|
-
|
17
|
+
or directly from Github repo:
|
18
18
|
|
19
19
|
```ruby
|
20
|
-
|
21
|
-
config.model User do
|
22
|
-
edit do
|
23
|
-
field :latitude, :map
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
20
|
+
gem 'rails_admin_map_field', git: 'git://github.com/keitoaino/rails_admin_map_field.git'
|
27
21
|
```
|
28
22
|
|
29
|
-
|
30
|
-
|
31
|
-
Configuration
|
32
|
-
=============
|
33
|
-
|
34
|
-
For different configurations, rails_admin_map_field can be configured with the following:
|
35
|
-
|
36
|
-
- `longitude_field` - the name of the longitude field that forms the the co-ordinate with the latitude field specified. Defaults to "longitude"
|
37
|
-
- `google_api_key` - if you use a Google Maps API Key, it can be specified here.
|
38
|
-
- `default_latitude` - the latitude to center the map shown on if the latitude field is blank. Defaults to 51.5, the latitude of London, UK.
|
39
|
-
- `default_longitude` - the longitude used if the longitude field is blank. Defaults to -0.126, the longitude of London, UK.
|
40
|
-
|
41
|
-
A more complicated configuration example:
|
23
|
+
Then, add in your `config/initializers/rails_admin.rb` initializer:
|
42
24
|
|
43
25
|
```ruby
|
44
26
|
RailsAdmin.config do |config|
|
45
|
-
config.model
|
27
|
+
config.model User do
|
46
28
|
edit do
|
47
|
-
field :
|
48
|
-
longitude_field :lon
|
49
|
-
google_api_key "a1b2c3d4e5f6deadbeef"
|
50
|
-
default_latitude -34.0 # Sydney, Australia
|
51
|
-
default_longitude 151.0
|
52
|
-
end
|
29
|
+
field :address, :map
|
53
30
|
end
|
54
31
|
end
|
55
32
|
end
|
56
33
|
```
|
57
34
|
|
35
|
+
**Note**: The field which is set as a map-type field must be the address field.
|
36
|
+
|
58
37
|
LICENSE
|
59
38
|
=======
|
60
|
-
rails_admin_map_field is licensed under the
|
39
|
+
rails_admin_map_field is licensed under the GPLv2 license.
|
61
40
|
|
62
41
|
Copyright (C) 2011 by Jason Langenauer
|
63
42
|
|
64
|
-
|
65
|
-
of this software and associated documentation files (the "Software"), to deal
|
66
|
-
in the Software without restriction, including without limitation the rights
|
67
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
68
|
-
copies of the Software, and to permit persons to whom the Software is
|
69
|
-
furnished to do so, subject to the following conditions:
|
70
|
-
|
71
|
-
The above copyright notice and this permission notice shall be included in
|
72
|
-
all copies or substantial portions of the Software.
|
43
|
+
Copyright (C) 2013 by Keito Aino
|
73
44
|
|
74
45
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
75
46
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
@@ -10,34 +10,35 @@ mapOptions = {
|
|
10
10
|
mapTypeId: google.maps.MapTypeId.ROADMAP
|
11
11
|
}
|
12
12
|
|
13
|
-
|
14
|
-
|
13
|
+
window.onload = ->
|
14
|
+
map_element = document.getElementById 'map'
|
15
|
+
map = new google.maps.Map map_element, mapOptions
|
15
16
|
|
16
|
-
google.maps.event.addListener map, 'click', (event) ->
|
17
|
-
|
17
|
+
google.maps.event.addListener map, 'click', (event) ->
|
18
|
+
updateLocation event.latLng
|
18
19
|
|
19
|
-
updateLocation = (location, center) ->
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
20
|
+
updateLocation = (location, center) ->
|
21
|
+
if marker
|
22
|
+
marker.setPosition location
|
23
|
+
else
|
24
|
+
marker = new google.maps.Marker
|
25
|
+
position: location,
|
26
|
+
map: map
|
26
27
|
|
27
|
-
|
28
|
-
|
28
|
+
lat.value = location.lat()
|
29
|
+
lng.value = location.lng()
|
29
30
|
|
30
|
-
|
31
|
-
|
31
|
+
if center
|
32
|
+
map.setCenter location
|
32
33
|
|
33
|
-
setInterval ->
|
34
|
-
|
35
|
-
|
34
|
+
setInterval ->
|
35
|
+
google.maps.event.trigger map, 'resize'
|
36
|
+
, 100
|
36
37
|
|
37
|
-
address.addEventListener 'keyup', ->
|
38
|
-
|
39
|
-
|
40
|
-
|
38
|
+
address.addEventListener 'keyup', ->
|
39
|
+
geocoder.geocode {address: this.value}, (results, status) ->
|
40
|
+
if status == google.maps.GeocoderStatus.OK
|
41
|
+
updateLocation results[0].geometry.location, true
|
41
42
|
|
42
43
|
|
43
|
-
updateLocation new google.maps.LatLng(lat.value, lng.value), true
|
44
|
+
updateLocation new google.maps.LatLng(lat.value, lng.value), true
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails_admin_map_field
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-08-02 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: devise
|