Sha256: f5f16ba61dfa8a2e14b428caed3665053e4f21342c62ac80bcfae80d0db8d8eb

Contents?: true

Size: 1.62 KB

Versions: 2

Compression:

Stored size: 1.62 KB

Contents

<li>
  %s
  <div id="yandex_map" style="height: %spx"></div>
  <script>
    var yandexMapObject = {
      idLat: '%s',
      idLng: '%s',
      coords: null,
      map: null,
      placemark: null,

      getCoordinates: function() {
        return [
          parseFloat($("#" + yandexMapObject.idLat).val()) || %f,
          parseFloat($("#" + yandexMapObject.idLng).val()) || %f,
        ];
      },

      saveCoordinates: function() {
        $("#" + yandexMapObject.idLat).val( yandexMapObject.coords[0].toFixed(10) );
        $("#" + yandexMapObject.idLng).val( yandexMapObject.coords[1].toFixed(10) );
      },

      init: function() {
        yandexMapObject.coords = yandexMapObject.getCoordinates();
        yandexMapObject.saveCoordinates();

        yandexMapObject.map = new ymaps.Map("yandex_map", {
          center: yandexMapObject.coords,
          zoom: %d
        });

        yandexMapObject.placemark = new ymaps.Placemark( yandexMapObject.coords, {}, { preset: "twirl#redIcon", draggable: true } );
        yandexMapObject.map.geoObjects.add(yandexMapObject.placemark);

        yandexMapObject.placemark.events.add("dragend", function (e) {      
          yandexMapObject.coords = this.geometry.getCoordinates();
          yandexMapObject.saveCoordinates();
        }, yandexMapObject.placemark);

        yandexMapObject.map.events.add("click", function (e) {        
          yandexMapObject.coords = e.get("coords");
          yandexMapObject.saveCoordinates();
          yandexMapObject.placemark.geometry.setCoordinates(yandexMapObject.coords);
        });
      }
    }

    ymaps.ready(yandexMapObject.init);
  </script>
</li>

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
activeadmin_latlng-1.2.0 lib/activeadmin/views/templates/yandex.html
activeadmin_latlng-1.1.0 lib/activeadmin/views/templates/yandex.html