activeadmin_latlng 1.1.0 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b86c5f48d53b93211c0ad478a7c86c54dd153f3e
4
- data.tar.gz: ffd07c42182fecd3bf03b137c3130824d9752103
3
+ metadata.gz: 38b4b42f8113d60b1e6f5e770abdef40a6564086
4
+ data.tar.gz: f76b470fd420f00e8a2ab21fe6feb92b21cdeb65
5
5
  SHA512:
6
- metadata.gz: c309eed4f718dff9303867296eb533c39bd2beb0a15b966a4391ea4d1dc6114b22c95be7db80d71682b7d809fe82972e0df4f215b3fa32c60c6e93213c48faeb
7
- data.tar.gz: 55c308f1458c49cae97f85b45685606b493f79072b1c00ad9ef990b7af3318ea0560f4ee321f4fc715d4904043dd9141c8cbe2b0d7f117503b0dfb0cc348e19a
6
+ metadata.gz: e60d582e509b317a53fc71ab7cd5119f88d9fbaea73e6e09dd9a257060ee17e4c7cf923461d30c0a61ac4be10915965d35975f3acf2b2386ac69f5ec317594f6
7
+ data.tar.gz: c98623b9763916d2661644b0e7fdce687c34ee69e7a36688a6b64ee9d5332a3a0facc453c604af8b6df467dd1347868460cb12978cf136ae17b69be5a4c4654d
data/README.md CHANGED
@@ -45,6 +45,12 @@ end
45
45
 
46
46
  * `api_key_env` - you can send name of ENV-variable where storing API key for map.
47
47
 
48
+ * `default_lat` - default latitude for placemark, Moscow latitude by default.
49
+
50
+ * `default_lng` - default longitude for placemark, Moscow longitude by default.
51
+
52
+ * `map_zoom` - default zoom for map, `12` by default.
53
+
48
54
  ### Example
49
55
 
50
56
  ```ruby
@@ -6,11 +6,11 @@ module ActiveAdmin
6
6
  end
7
7
 
8
8
  def loading_map_code
9
- @loading_map ? "<script src=\"https://maps.googleapis.com/maps/api/js?language=#{@lang}#{key}&callback=googleMapObject.init\" async defer></script>" : ''
9
+ @loading_map ? "<script src=\"https://maps.googleapis.com/maps/api/js?language=#{@lang}#{key}&libraries=places&callback=googleMapObject.init\" async defer></script>" : ''
10
10
  end
11
11
 
12
12
  def to_s
13
- File.open(File.expand_path('../templates/google.html', __FILE__)).read % [loading_map_code, @height, @id_lat, @id_lng, @default_lat, @default_lng, @map_zoom]
13
+ File.open(File.expand_path('../templates/google.html', __FILE__)).read % [loading_map_code, @height, @id_lat, @id_lng, @map_zoom, @default_lat, @default_lng]
14
14
  end
15
15
  end
16
16
  end
@@ -8,6 +8,7 @@
8
8
  coords: null,
9
9
  map: null,
10
10
  marker: null,
11
+ zoom: %d,
11
12
 
12
13
  getCoordinates: function() {
13
14
  return {
@@ -27,25 +28,51 @@
27
28
 
28
29
  googleMapObject.map = new google.maps.Map(document.getElementById('google_map'), {
29
30
  center: googleMapObject.coords,
30
- zoom: %d
31
+ zoom: googleMapObject.zoom
31
32
  });
32
-
33
+
33
34
  var latLngCoord = new google.maps.LatLng(googleMapObject.coords.lat, googleMapObject.coords.lng);
34
35
  googleMapObject.marker = new google.maps.Marker({
35
36
  position: latLngCoord,
36
37
  map: googleMapObject.map,
37
38
  draggable: true
38
39
  });
40
+
39
41
  googleMapObject.map.addListener('click', function(e) {
40
42
  googleMapObject.coords = { lat: e.latLng.lat(), lng: e.latLng.lng() };
41
43
  googleMapObject.saveCoordinates();
42
44
  googleMapObject.marker.setPosition(googleMapObject.coords);
43
45
  });
46
+
44
47
  googleMapObject.marker.addListener('drag', function(e) {
45
48
  googleMapObject.coords = { lat: e.latLng.lat(), lng: e.latLng.lng() };
46
49
  googleMapObject.saveCoordinates();
47
50
  });
51
+
52
+ var searchBox = new google.maps.places.SearchBox(document.getElementById('latlng-search-box'));
53
+
54
+ googleMapObject.map.controls[google.maps.ControlPosition.TOP_CENTER].push(document.getElementById('latlng-search-box'));
55
+
56
+ google.maps.event.addListener(searchBox, 'places_changed', function() {
57
+ searchBox.set('map', null);
58
+
59
+ var bounds = new google.maps.LatLngBounds();
60
+
61
+ var place = searchBox.getPlaces()[0];
62
+ var location = place.geometry.location;
63
+
64
+ googleMapObject.coords = { lat: location.lat(), lng: location.lng() };
65
+ googleMapObject.saveCoordinates();
66
+
67
+ googleMapObject.marker.setPosition(location);
68
+ bounds.extend(location);
69
+
70
+ googleMapObject.map.fitBounds(bounds);
71
+ searchBox.set('map', googleMapObject.map);
72
+ googleMapObject.map.setZoom(googleMapObject.zoom);
73
+ });
48
74
  }
49
75
  }
50
76
  </script>
51
- </li>
77
+ <input id="latlng-search-box" type="text" style="margin-top: 10px; height: 18px;" placeholder="Search Google Maps...">
78
+ </li>
@@ -1,3 +1,3 @@
1
1
  module ActiveadminLatlng
2
- VERSION = "1.1.0"
2
+ VERSION = "1.2.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activeadmin_latlng
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexey Krylov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-09-27 00:00:00.000000000 Z
11
+ date: 2017-10-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activeadmin