Commit 5a4805b0 authored by PJ Janse van Rensburg's avatar PJ Janse van Rensburg

Avoid using 'ip-api.com' by specifying default coords in config.

parent 4c7e6b62
......@@ -7,4 +7,8 @@ SQLALCHEMY_ECHO = True
# credentials for loading map tiles from mapbox
MAPBOX_MAP_ID = '...'
MAPBOX_ACCESS_TOKEN = '...'
\ No newline at end of file
MAPBOX_ACCESS_TOKEN = '...'
# when the creating new shapes, use this default map center
DEFAULT_CENTER_LAT = -33.918861
DEFAULT_CENTER_LONG = 18.423300
......@@ -77,6 +77,10 @@
console.error("You must set MAPBOX_MAP_ID in your Flask settings to use the map widget");
return false;
}
if (!window.DEFAULT_CENTER_LAT || !window.DEFAULT_CENTER_LONG) {
console.error("You must set DEFAULT_CENTER_LAT and DEFAULT_CENTER_LONG in your Flask settings to use the map widget");
return false;
}
var geometryType = $el.data("geometry-type")
if (geometryType) {
......@@ -148,12 +152,8 @@
map.fitBounds(bounds);
}
} else {
// look up user's location by IP address
$.getJSON("//ip-api.com/json/?callback=?", function(data) {
map.setView([data["lat"], data["lon"]], 12);
}).fail(function() {
map.setView([0, 0], 1)
});
// use the default map center
map.setView([window.DEFAULT_CENTER_LAT, window.DEFAULT_CENTER_LONG], 12);
}
// set up tiles
......
......@@ -234,6 +234,10 @@
{% if config.MAPBOX_ACCESS_TOKEN %}
window.MAPBOX_ACCESS_TOKEN = "{{ config.MAPBOX_ACCESS_TOKEN }}";
{% endif %}
{% if config.DEFAULT_CENTER_LAT and config.DEFAULT_CENTER_LONG %}
window.DEFAULT_CENTER_LAT = "{{ config.DEFAULT_CENTER_LAT }}";
window.DEFAULT_CENTER_LONG = "{{ config.DEFAULT_CENTER_LONG }}";
{% endif %}
</script>
<script src="{{ admin_static.url(filename='vendor/leaflet/leaflet.js', v='1.0.2') }}"></script>
<script src="{{ admin_static.url(filename='vendor/leaflet/leaflet.draw.js', v='0.4.6') }}"></script>
......
......@@ -225,6 +225,10 @@
{% if config.MAPBOX_ACCESS_TOKEN %}
window.MAPBOX_ACCESS_TOKEN = "{{ config.MAPBOX_ACCESS_TOKEN }}";
{% endif %}
{% if config.DEFAULT_CENTER_LAT and config.DEFAULT_CENTER_LONG %}
window.DEFAULT_CENTER_LAT = "{{ config.DEFAULT_CENTER_LAT }}";
window.DEFAULT_CENTER_LONG = "{{ config.DEFAULT_CENTER_LONG }}";
{% endif %}
</script>
<script src="{{ admin_static.url(filename='vendor/leaflet/leaflet.js', v='1.0.2') }}"></script>
<script src="{{ admin_static.url(filename='vendor/leaflet/leaflet.draw.js', v='0.4.6') }}"></script>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment