Commit 55c690d5 authored by Nitish Rathi's avatar Nitish Rathi

use mapbox v4 only if MAPBOX_ACCESS_TOKEN present

parent b8de0532
......@@ -28,6 +28,10 @@ settings::
app = Flask(__name__)
app.config['MAPBOX_MAP_ID'] = "example.abc123"
To use the v4 of their API (the default is v3):::
app.config['MAPBOX_ACCESS_TOKEN'] = "pk.def456"
.. note::
Leaflet supports loading map tiles from any arbitrary map tile provider, but
at the moment, Flask-Admin only supports Mapbox. If you want to use other
......
......@@ -78,6 +78,10 @@
return false;
}
if (!window.MAPBOX_ACCESS_TOKEN) {
console.warn("You must set MAPBOX_ACCESS_TOKEN in your Flask settings to use the map widget with mapbox v4 API");
}
var geometryType = $el.data("geometry-type")
if (geometryType) {
geometryType = geometryType.toUpperCase();
......@@ -155,7 +159,8 @@
}
// set up tiles
L.tileLayer('http://{s}.tiles.mapbox.com/v3/'+MAPBOX_MAP_ID+'/{z}/{x}/{y}.png', {
mapboxVersion = window.MAPBOX_ACCESS_TOKEN ? 4 : 3
L.tileLayer('http://{s}.tiles.mapbox.com/v'+mapboxVersion+'/'+MAPBOX_MAP_ID+'/{z}/{x}/{y}.png?access_token='+window.MAPBOX_ACCESS_TOKEN, {
attribution: 'Map data &copy; <a href="http://openstreetmap.org">OpenStreetMap</a> contributors, <a href="http://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>, Imagery © <a href="http://mapbox.com">Mapbox</a>',
maxZoom: 18
}).addTo(map);
......
......@@ -187,6 +187,9 @@
{% if config.MAPBOX_MAP_ID %}
<script>
window.MAPBOX_MAP_ID = "{{ config.MAPBOX_MAP_ID }}";
{% if config.MAPBOX_ACCESS_TOKEN %}
window.MAPBOX_ACCESS_TOKEN = "{{ config.MAPBOX_MAP_ID }}";
{% endif %}
</script>
<script src="{{ admin_static.url(filename='vendor/leaflet/leaflet.js') }}"></script>
<script src="{{ admin_static.url(filename='vendor/leaflet/leaflet.draw.js') }}"></script>
......
......@@ -182,6 +182,9 @@
{% if config.MAPBOX_MAP_ID %}
<script>
window.MAPBOX_MAP_ID = "{{ config.MAPBOX_MAP_ID }}";
{% if config.MAPBOX_ACCESS_TOKEN %}
window.MAPBOX_ACCESS_TOKEN = "{{ config.MAPBOX_MAP_ID }}";
{% endif %}
</script>
<script src="{{ admin_static.url(filename='vendor/leaflet/leaflet.js') }}"></script>
<script src="{{ admin_static.url(filename='vendor/leaflet/leaflet.draw.js') }}"></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