Sha256: 84cd99d2e614ab04110db2b42903459d3cd5fc34993b42fb6ce72c677351a397

Contents?: true

Size: 1.65 KB

Versions: 1

Compression:

Stored size: 1.65 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,
      zoom: %d,

      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: yandexMapObject.zoom
        });

        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

1 entries across 1 versions & 1 rubygems

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