From 4d472a76b820b0e05bcebc9bc1c22a4d709d7e1c Mon Sep 17 00:00:00 2001 From: Dan Reeves Date: Wed, 9 Sep 2015 11:09:15 +0100 Subject: [PATCH 1/7] add latlng feature --- .../static/wagtailgmaps/js/map-field.js | 28 ++++++++++++++----- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/wagtailgmaps/static/wagtailgmaps/js/map-field.js b/wagtailgmaps/static/wagtailgmaps/js/map-field.js index 300ba2c..37a0ef0 100644 --- a/wagtailgmaps/static/wagtailgmaps/js/map-field.js +++ b/wagtailgmaps/static/wagtailgmaps/js/map-field.js @@ -1,7 +1,7 @@ $(document).ready(function() { - + google.maps.event.addDomListener(window, 'load', function() { - + // One geocoder var to rule them all var geocoder = new google.maps.Geocoder(); @@ -11,7 +11,14 @@ $(document).ready(function() { latLng: pos }, function(responses) { if (responses && responses.length > 0) { - $(input).val(responses[0].formatted_address); + $input = $(input); + if ($input.hasClass('gmap--latlng')) { + $input.val( + String(results[0].geometry.location.lat) + ', ' + String(results[0].geometry.location.lng) + ); + } else { + $input.val(results[0].formatted_address); + } } else { alert('Cannot determine address at this location.'); } @@ -23,7 +30,14 @@ $(document).ready(function() { geocoder.geocode({'address': address}, function(results, status) { if (status == google.maps.GeocoderStatus.OK) { marker.setPosition(results[0].geometry.location); - $(input).val(results[0].formatted_address); + $input = $(input); + if ($input.hasClass('gmap--latlng')) { + $input.val( + String(results[0].geometry.location.lat) + ', ' + String(results[0].geometry.location.lng) + ); + } else { + $input.val(results[0].formatted_address); + } map.setCenter(results[0].geometry.location); } else { alert("Geocode was not successful for the following reason: " + status); @@ -56,7 +70,7 @@ $(document).ready(function() { marker[map_key].setPosition(event.latLng); geocodePosition(marker[map_key].getPosition(), mapElem.input); }); - + // Event listeners to update map when press enter or tab $(mapElem.input).bind("enterKey",function(event) { geocodeAddress($(this).val(), this, marker[map_key], map[map_key]); @@ -73,7 +87,7 @@ $(document).ready(function() { // Method to initialize a map and all of its related components (usually address input and marker) window.initialize_map = function (params) { - + // Get latlong form address to initialize map geocoder.geocode( { "address": params.address}, function(results, status) { if (status == google.maps.GeocoderStatus.OK) { @@ -106,4 +120,4 @@ $(document).ready(function() { }); -}); +}); From ff17c6255eb863221588dabd9065d26f666e060e Mon Sep 17 00:00:00 2001 From: Dan Reeves Date: Wed, 9 Sep 2015 11:38:17 +0100 Subject: [PATCH 2/7] update admin_base template --- .../templates/wagtailadmin/admin_base.html | 32 +++++++++---------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/wagtailgmaps/templates/wagtailadmin/admin_base.html b/wagtailgmaps/templates/wagtailadmin/admin_base.html index d4d9b98..e88c94b 100644 --- a/wagtailgmaps/templates/wagtailadmin/admin_base.html +++ b/wagtailgmaps/templates/wagtailadmin/admin_base.html @@ -1,31 +1,31 @@ {% extends "wagtailadmin/skeleton.html" %} -{% load compress wagtailadmin_tags %} +{% load compress static wagtailadmin_tags %} {% load wagtailgmaps_tags %} {% block css %} {% compress css %} - - - + + {% endcompress %} + {% block extra_css %}{% endblock %} {% endblock %} {% block js %} - + {% compress js %} - - - - - - - - - + + + + + + + + + {% main_nav_js %} {% endcompress %} - + {% block extra_js %}{% endblock %} -{% endblock %} \ No newline at end of file +{% endblock %} From bbbd65ed372bc687cfe200c103fd5944d47a66a6 Mon Sep 17 00:00:00 2001 From: Dan Reeves Date: Wed, 9 Sep 2015 11:46:50 +0100 Subject: [PATCH 3/7] fix typo, results -> responses --- wagtailgmaps/static/wagtailgmaps/js/map-field.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/wagtailgmaps/static/wagtailgmaps/js/map-field.js b/wagtailgmaps/static/wagtailgmaps/js/map-field.js index 37a0ef0..2ba429d 100644 --- a/wagtailgmaps/static/wagtailgmaps/js/map-field.js +++ b/wagtailgmaps/static/wagtailgmaps/js/map-field.js @@ -14,10 +14,10 @@ $(document).ready(function() { $input = $(input); if ($input.hasClass('gmap--latlng')) { $input.val( - String(results[0].geometry.location.lat) + ', ' + String(results[0].geometry.location.lng) + String(responses[0].geometry.location.lat) + ', ' + String(responses[0].geometry.location.lng) ); } else { - $input.val(results[0].formatted_address); + $input.val(responses[0].formatted_address); } } else { alert('Cannot determine address at this location.'); From 8bdbf92fc303c87a5a49a6bb99532ae7b6035b25 Mon Sep 17 00:00:00 2001 From: Dan Reeves Date: Wed, 9 Sep 2015 11:58:55 +0100 Subject: [PATCH 4/7] allow template to work with new gmap--latlng class --- .../edit_handlers/multi_field_panel.html | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/wagtailgmaps/templates/wagtailadmin/edit_handlers/multi_field_panel.html b/wagtailgmaps/templates/wagtailadmin/edit_handlers/multi_field_panel.html index 693d184..a8c8140 100644 --- a/wagtailgmaps/templates/wagtailadmin/edit_handlers/multi_field_panel.html +++ b/wagtailgmaps/templates/wagtailadmin/edit_handlers/multi_field_panel.html @@ -11,13 +11,13 @@ {% for child in self.children %}
  • {{ child.render_as_field }} - {% for class in child.classes %} - {% ifequal class 'gmap' %} - {% load wagtailgmaps_tags %} - {% map_editor child.bound_field.value 100 "%" 300 "px" 8 %} - {% endifequal %} - {% endfor %} + + {% if 'gmap' in child.classes %} + {% load wagtailgmaps_tags %} + {% map_editor child.bound_field.value 100 "%" 300 "px" 8 %} + {% endifequal %} +
  • {% endfor %} - \ No newline at end of file + From 890430fe6f5b57682cda3ad4bc7b52c3114f944e Mon Sep 17 00:00:00 2001 From: Dan Reeves Date: Wed, 9 Sep 2015 12:03:00 +0100 Subject: [PATCH 5/7] fix incorrect closing tag (endequalif) --- .../templates/wagtailadmin/edit_handlers/multi_field_panel.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wagtailgmaps/templates/wagtailadmin/edit_handlers/multi_field_panel.html b/wagtailgmaps/templates/wagtailadmin/edit_handlers/multi_field_panel.html index a8c8140..92d99d1 100644 --- a/wagtailgmaps/templates/wagtailadmin/edit_handlers/multi_field_panel.html +++ b/wagtailgmaps/templates/wagtailadmin/edit_handlers/multi_field_panel.html @@ -15,7 +15,7 @@ {% if 'gmap' in child.classes %} {% load wagtailgmaps_tags %} {% map_editor child.bound_field.value 100 "%" 300 "px" 8 %} - {% endifequal %} + {% endif %} {% endfor %} From bd8d5a14e71250f3affbcf3695ce67f72be787e8 Mon Sep 17 00:00:00 2001 From: Dan Reeves Date: Wed, 9 Sep 2015 12:16:45 +0100 Subject: [PATCH 6/7] fix multi_field template to match classes properly, test .closest(gmap) in js --- wagtailgmaps/static/wagtailgmaps/js/map-field.js | 4 ++-- .../edit_handlers/multi_field_panel.html | 12 ++++++------ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/wagtailgmaps/static/wagtailgmaps/js/map-field.js b/wagtailgmaps/static/wagtailgmaps/js/map-field.js index 2ba429d..f2324d2 100644 --- a/wagtailgmaps/static/wagtailgmaps/js/map-field.js +++ b/wagtailgmaps/static/wagtailgmaps/js/map-field.js @@ -12,7 +12,7 @@ $(document).ready(function() { }, function(responses) { if (responses && responses.length > 0) { $input = $(input); - if ($input.hasClass('gmap--latlng')) { + if ($input.closest('gmap').hasClass('gmap--latlng')) { $input.val( String(responses[0].geometry.location.lat) + ', ' + String(responses[0].geometry.location.lng) ); @@ -31,7 +31,7 @@ $(document).ready(function() { if (status == google.maps.GeocoderStatus.OK) { marker.setPosition(results[0].geometry.location); $input = $(input); - if ($input.hasClass('gmap--latlng')) { + if ($input.closest('gmap').hasClass('gmap--latlng')) { $input.val( String(results[0].geometry.location.lat) + ', ' + String(results[0].geometry.location.lng) ); diff --git a/wagtailgmaps/templates/wagtailadmin/edit_handlers/multi_field_panel.html b/wagtailgmaps/templates/wagtailadmin/edit_handlers/multi_field_panel.html index 92d99d1..4c46bf1 100644 --- a/wagtailgmaps/templates/wagtailadmin/edit_handlers/multi_field_panel.html +++ b/wagtailgmaps/templates/wagtailadmin/edit_handlers/multi_field_panel.html @@ -11,12 +11,12 @@ {% for child in self.children %}
  • {{ child.render_as_field }} - - {% if 'gmap' in child.classes %} - {% load wagtailgmaps_tags %} - {% map_editor child.bound_field.value 100 "%" 300 "px" 8 %} - {% endif %} - + {% for class in child.classes %} + {% if 'gmap' in class %} + {% load wagtailgmaps_tags %} + {% map_editor child.bound_field.value 100 "%" 300 "px" 8 %} + {% endif %} + {% endfor %}
  • {% endfor %} From a2bf5e6236540511753b30d40ddd6184902bdf0c Mon Sep 17 00:00:00 2001 From: Dan Reeves Date: Wed, 9 Sep 2015 12:31:16 +0100 Subject: [PATCH 7/7] referenceing a class with jquery, use gmaps api correctly to get latlng --- wagtailgmaps/static/wagtailgmaps/js/map-field.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/wagtailgmaps/static/wagtailgmaps/js/map-field.js b/wagtailgmaps/static/wagtailgmaps/js/map-field.js index f2324d2..d7a170c 100644 --- a/wagtailgmaps/static/wagtailgmaps/js/map-field.js +++ b/wagtailgmaps/static/wagtailgmaps/js/map-field.js @@ -12,9 +12,9 @@ $(document).ready(function() { }, function(responses) { if (responses && responses.length > 0) { $input = $(input); - if ($input.closest('gmap').hasClass('gmap--latlng')) { + if ($input.closest('.gmap').hasClass('gmap--latlng')) { $input.val( - String(responses[0].geometry.location.lat) + ', ' + String(responses[0].geometry.location.lng) + String(responses[0].geometry.location.lat()) + ', ' + String(responses[0].geometry.location.lng()) ); } else { $input.val(responses[0].formatted_address); @@ -31,9 +31,9 @@ $(document).ready(function() { if (status == google.maps.GeocoderStatus.OK) { marker.setPosition(results[0].geometry.location); $input = $(input); - if ($input.closest('gmap').hasClass('gmap--latlng')) { + if ($input.closest('.gmap').hasClass('gmap--latlng')) { $input.val( - String(results[0].geometry.location.lat) + ', ' + String(results[0].geometry.location.lng) + String(results[0].geometry.location.lat()) + ', ' + String(results[0].geometry.location.lng()) ); } else { $input.val(results[0].formatted_address);