@@ -19,135 +19,5 @@ def latlng **args
1919 end
2020 end
2121 end
22-
23- class LatlngProxy < FormtasticProxy
24- def build ( _ , *args , &_block )
25- @lang , @id_lat , @id_lng , @height , @loading_map , @api_key = *args
26- end
27- end
28-
29- class GoogleMapProxy < LatlngProxy
30- def key
31- @api_key ? "&key=#{ @api_key } " : ""
32- end
33-
34- def loading_map_code
35- @loading_map ? "<script src=\" https://maps.googleapis.com/maps/api/js?language=#{ @lang } #{ key } &callback=googleMapObject.init\" async defer></script>" : ''
36- end
37-
38- def to_s
39- "<li>" \
40- "#{ loading_map_code } " \
41- "<div id=\" google_map\" style=\" height: #{ @height } px\" ></div>" \
42- "<script>
43- var googleMapObject = {
44- coords: null,
45- map: null,
46- marker: null,
47-
48- getCoordinates: function() {
49- return {
50- lat: parseFloat($(\" ##{ @id_lat } \" ).val()) || 55.7522200,
51- lng: parseFloat($(\" ##{ @id_lng } \" ).val()) || 37.6155600,
52- };
53- },
54-
55- saveCoordinates: function() {
56- $(\" ##{ @id_lat } \" ).val( googleMapObject.coords.lat.toFixed(10) );
57- $(\" ##{ @id_lng } \" ).val( googleMapObject.coords.lng.toFixed(10) );
58- },
59-
60- init: function() {
61- googleMapObject.coords = googleMapObject.getCoordinates();
62- googleMapObject.saveCoordinates();
63-
64- googleMapObject.map = new google.maps.Map(document.getElementById('google_map'), {
65- center: googleMapObject.coords,
66- zoom: 12
67- });
68-
69- var latLngCoord = new google.maps.LatLng(googleMapObject.coords.lat, googleMapObject.coords.lng);
70- googleMapObject.marker = new google.maps.Marker({
71- position: latLngCoord,
72- map: googleMapObject.map,
73- draggable: true
74- });
75- googleMapObject.map.addListener('click', function(e) {
76- googleMapObject.coords = { lat: e.latLng.lat(), lng: e.latLng.lng() };
77- googleMapObject.saveCoordinates();
78- googleMapObject.marker.setPosition(googleMapObject.coords);
79- });
80- googleMapObject.marker.addListener('drag', function(e) {
81- googleMapObject.coords = { lat: e.latLng.lat(), lng: e.latLng.lng() };
82- googleMapObject.saveCoordinates();
83- });
84- }
85- }
86- </script>" \
87- "</li>"
88- end
89- end
90-
91- class YandexMapProxy < LatlngProxy
92- def key
93- @api_key ? "&apikey=#{ @api_key } " : ""
94- end
95-
96- def loading_map_code
97- @loading_map ? "<script src=\" https://api-maps.yandex.ru/2.1/?lang=#{ @lang } #{ key } &load=Map,Placemark\" type=\" text/javascript\" ></script>" : ''
98- end
99-
100- def to_s
101- "<li>" \
102- "#{ loading_map_code } " \
103- "<div id=\" yandex_map\" style=\" height: #{ @height } px\" ></div>" \
104- "<script type=\" text/javascript\" >
105- var yandexMapObject = {
106- coords: null,
107- map: null,
108- placemark: null,
109-
110- getCoordinates: function() {
111- return [
112- parseFloat($(\" ##{ @id_lat } \" ).val()) || 55.7522200,
113- parseFloat($(\" ##{ @id_lng } \" ).val()) || 37.6155600,
114- ];
115- },
116-
117- saveCoordinates: function() {
118- $(\" ##{ @id_lat } \" ).val( yandexMapObject.coords[0].toFixed(10) );
119- $(\" ##{ @id_lng } \" ).val( yandexMapObject.coords[1].toFixed(10) );
120- },
121-
122- init: function() {
123- yandexMapObject.coords = yandexMapObject.getCoordinates();
124- yandexMapObject.saveCoordinates();
125-
126- yandexMapObject.map = new ymaps.Map(\" yandex_map\" , {
127- center: yandexMapObject.coords,
128- zoom: 12
129- });
130-
131- yandexMapObject.placemark = new ymaps.Placemark( yandexMapObject.coords, {}, { preset: \" twirl#redIcon\" , draggable: true } );
132- yandexMapObject.map.geoObjects.add(yandexMapObject.placemark);
133-
134- yandexMapObject.placemark.events.add(\" dragend\" , function (e) {
135- yandexMapObject.coords = this.geometry.getCoordinates();
136- yandexMapObject.saveCoordinates();
137- }, yandexMapObject.placemark);
138-
139- yandexMapObject.map.events.add(\" click\" , function (e) {
140- yandexMapObject.coords = e.get(\" coords\" );
141- yandexMapObject.saveCoordinates();
142- yandexMapObject.placemark.geometry.setCoordinates(yandexMapObject.coords);
143- });
144- }
145- }
146-
147- ymaps.ready(yandexMapObject.init);
148- </script>" \
149- "</li>"
150- end
151- end
15222 end
153- end
23+ end
0 commit comments