Add "Center map on marker" option
authorJohn Firebaugh <john.firebaugh@gmail.com>
Sat, 27 Jul 2013 03:19:51 +0000 (20:19 -0700)
committerJohn Firebaugh <john.firebaugh@gmail.com>
Mon, 5 Aug 2013 15:31:46 +0000 (08:31 -0700)
app/assets/javascripts/leaflet.share.js
config/locales/en.yml

index 9388bde..4264e56 100644 (file)
@@ -61,7 +61,19 @@ L.OSM.share = function (options) {
               .bind('change', toggleMarker))
           .append(I18n.t('javascripts.share.include_marker')));
 
-    var $shortLink, $longLink;
+    $('<div>')
+      .attr('class', 'form-row')
+      .appendTo($form)
+      .append(
+        $('<label>')
+          .attr('for', 'center_marker')
+          .append(
+            $('<input>')
+              .attr('id', 'center_marker')
+              .attr('type', 'checkbox')
+              .prop('checked', true)
+              .bind('change', update))
+          .append(I18n.t('javascripts.share.center_marker')));
 
     $('<div>')
       .attr('class', 'form-row')
@@ -245,11 +257,18 @@ L.OSM.share = function (options) {
     }
 
     function update() {
+      if (map.hasLayer(marker) && $('#center_marker').is(':checked')) {
+        map.panTo(marker.getLatLng());
+      }
+
       var bounds = map.getBounds();
 
       $('#link_marker')
         .prop('checked', map.hasLayer(marker));
 
+      $('#center_marker')
+        .prop('disabled', !map.hasLayer(marker));
+
       $('#image_filter')
         .prop('checked', locationFilter.isEnabled());
 
index 8a11960..ae6f801 100644 (file)
@@ -2063,6 +2063,7 @@ en:
       download: "Download"
       short_url: "Short URL"
       include_marker: "Include marker"
+      center_marker: "Center map on marker"
       paste_html: "Paste HTML to embed in website"
     key:
       title: "Map Key"