Skip to content

Commit

Permalink
Merge pull request #4 from danreeves/master
Browse files Browse the repository at this point in the history
Wagtail 1.0 update & latlng feature
  • Loading branch information
jordij committed Oct 2, 2015
2 parents 6606f49 + a2bf5e6 commit a6b1393
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 26 deletions.
28 changes: 21 additions & 7 deletions wagtailgmaps/static/wagtailgmaps/js/map-field.js
Original file line number Diff line number Diff line change
@@ -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();

Expand All @@ -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.closest('.gmap').hasClass('gmap--latlng')) {
$input.val(
String(responses[0].geometry.location.lat()) + ', ' + String(responses[0].geometry.location.lng())
);
} else {
$input.val(responses[0].formatted_address);
}
} else {
alert('Cannot determine address at this location.');
}
Expand All @@ -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.closest('.gmap').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);
Expand Down Expand Up @@ -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]);
Expand All @@ -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) {
Expand Down Expand Up @@ -106,4 +120,4 @@ $(document).ready(function() {

});

});
});
32 changes: 16 additions & 16 deletions wagtailgmaps/templates/wagtailadmin/admin_base.html
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
{% extends "wagtailadmin/skeleton.html" %}
{% load compress wagtailadmin_tags %}
{% load compress static wagtailadmin_tags %}
{% load wagtailgmaps_tags %}

{% block css %}
{% compress css %}
<link rel="stylesheet" href="{{ STATIC_URL }}wagtailadmin/{% wagtail_version %}/vendor/jquery-ui/jquery-ui-1.10.3.verdant.css" />
<link rel="stylesheet" href="{{ STATIC_URL }}wagtailadmin/{% wagtail_version %}/core.{% wagtail_version %}" type="text/{% wagtail_version %}" />
<link rel="stylesheet" href="{{ STATIC_URL }}wagtailgmaps/css/admin.css" type="text/css" />
<link rel="stylesheet" href="{% static 'wagtailadmin/css/vendor/jquery-ui/jquery-ui-1.10.3.verdant.css' %}" />
<link rel="stylesheet" href="{% static 'wagtailadmin/css/core.css' %}" type="text/css" />
{% endcompress %}
<link rel="stylesheet" href="{% static 'wagtailgmaps/css/admin.css' %}" type="text/css" />

{% block extra_css %}{% endblock %}
{% endblock %}

{% block js %}
<script src="https://maps.google.com/maps/api/js?sensor=false"></script>
<script src="https://maps.google.com/maps/api/js?sensor=false"></script>
{% compress js %}
<script src="{{ STATIC_URL }}wagtailadmin/js/vendor/jquery-1.10.3.js"></script>
<script src="{{ STATIC_URL }}wagtailadmin/js/vendor/jquery-ui-1.10.3.js"></script>
<script src="{{ STATIC_URL }}wagtailadmin/js/vendor/jquery.datetimepicker.js"></script>
<script src="{{ STATIC_URL }}wagtailadmin/js/vendor/jquery.autosize.js"></script>
<script src="{{ STATIC_URL }}wagtailadmin/js/vendor/bootstrap-transition.js"></script>
<script src="{{ STATIC_URL }}wagtailadmin/js/vendor/bootstrap-modal.js"></script>
<script src="{{ STATIC_URL }}wagtailadmin/js/vendor/bootstrap-tab.js"></script>
<script src="{{ STATIC_URL }}wagtailadmin/js/vendor/jquery.dlmenu.js"></script>
<script src="{{ STATIC_URL }}wagtailadmin/js/core.js"></script>
<script src="{% static 'wagtailadmin/js/vendor/jquery-1.10.3.js' %}"></script>
<script src="{% static 'wagtailadmin/js/vendor/jquery-ui-1.10.3.js' %}"></script>
<script src="{% static 'wagtailadmin/js/vendor/jquery.datetimepicker.js' %}"></script>
<script src="{% static 'wagtailadmin/js/vendor/jquery.autosize.js' %}"></script>
<script src="{% static 'wagtailadmin/js/vendor/bootstrap-transition.js' %}"></script>
<script src="{% static 'wagtailadmin/js/vendor/bootstrap-modal.js' %}"></script>
<script src="{% static 'wagtailadmin/js/vendor/bootstrap-tab.js' %}"></script>
<script src="{% static 'wagtailadmin/js/vendor/jquery.dlmenu.js' %}"></script>
<script src="{% static 'wagtailadmin/js/core.js' %}"></script>
{% main_nav_js %}
{% endcompress %}

{% block extra_js %}{% endblock %}
{% endblock %}
{% endblock %}
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@
<li class="{{ child.classes|join:" " }}">
{{ child.render_as_field }}
{% for class in child.classes %}
{% ifequal class 'gmap' %}
{% if 'gmap' in class %}
{% load wagtailgmaps_tags %}
{% map_editor child.bound_field.value 100 "%" 300 "px" 8 %}
{% endifequal %}
{% endif %}
{% endfor %}
</li>
{% endfor %}
</ul>
</fieldset>
</fieldset>

0 comments on commit a6b1393

Please sign in to comment.