Commit 000eb4e0 authored by Serge S. Koval's avatar Serge S. Koval

Merge pull request #862 from nitishr/revert-860-ks-mapbox-v4

Revert 860 ks mapbox v4
parents ebf5d597 55c690d5
......@@ -28,10 +28,9 @@ settings::
app = Flask(__name__)
app.config['MAPBOX_MAP_ID'] = "example.abc123"
To use the v4 of their API: (Note that while 4 is parameterized here, only v3 and v4 are currently supported.)::
To use the v4 of their API (the default is v3):::
app.config['MAPBOX_ACCESS_TOKEN'] = "pk.def456"
app.config['MAPBOX_API_VERSION'] = 4
.. note::
Leaflet supports loading map tiles from any arbitrary map tile provider, but
......
......@@ -73,11 +73,15 @@
* Process Leaflet (map) widget
*/
function processLeafletWidget($el, name) {
if (!window.MAPBOX_MAP_ID || (window.MAPBOX_API_VERSION === 4 && !window.MAPBOX_ACCESS_TOKEN)) {
console.error("You must set MAPBOX_MAP_ID and MAPBOX_ACCESS_TOKEN in your Flask settings to use the map widget");
if (!window.MAPBOX_MAP_ID) {
console.error("You must set MAPBOX_MAP_ID in your Flask settings to use the map widget");
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,11 +159,8 @@
}
// set up tiles
var mapboxTemplateUrl = 'http://{s}.tiles.mapbox.com/v3/'+MAPBOX_MAP_ID+'/{z}/{x}/{y}.png';
if (MAPBOX_API_VERSION === 4) {
mapboxTemplateUrl = 'http://{s}.tiles.mapbox.com/v4/'+MAPBOX_MAP_ID+'/{z}/{x}/{y}.png?access_token='+MAPBOX_ACCESS_TOKEN;
}
L.tileLayer(mapboxTemplateUrl, {
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,9 +187,8 @@
{% if config.MAPBOX_MAP_ID %}
<script>
window.MAPBOX_MAP_ID = "{{ config.MAPBOX_MAP_ID }}";
{% if config.get(MAPBOX_API_VERSION) == 4 %}
window.MAPBOX_ACCESS_TOKEN = "{{ config.MAPBOX_ACCESS_TOKEN }}";
window.MAPBOX_API_VERSION = "{{ config.MAPBOX_API_VERSION }}";
{% 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>
......
......@@ -169,7 +169,7 @@
<link href="{{ admin_static.url(filename='vendor/select2/select2.css') }}" rel="stylesheet">
<link href="{{ admin_static.url(filename='vendor/select2/select2-bootstrap3.css') }}" rel="stylesheet">
<link href="{{ admin_static.url(filename='vendor/bootstrap-daterangepicker/daterangepicker-bs3.css') }}" rel="stylesheet">
{% if config.MAPBOX_MAP_ID and config.MAPBOX_ACCESS_TOKEN %}
{% if config.MAPBOX_MAP_ID %}
<link href="{{ admin_static.url(filename='vendor/leaflet/leaflet.css') }}" rel="stylesheet">
<link href="{{ admin_static.url(filename='vendor/leaflet/leaflet.draw.css') }}" rel="stylesheet">
{% endif %}
......@@ -179,12 +179,11 @@
{% endmacro %}
{% macro form_js() %}
{% if config.MAPBOX_MAP_ID and config.MAPBOX_ACCESS_TOKEN %}
{% if config.MAPBOX_MAP_ID %}
<script>
window.MAPBOX_MAP_ID = "{{ config.MAPBOX_MAP_ID }}";
{% if config.get('MAPBOX_API_VERSION') == 4 %}
window.MAPBOX_ACCESS_TOKEN = "{{ config.MAPBOX_ACCESS_TOKEN }}";
window.MAPBOX_API_VERSION = "{{ config.MAPBOX_API_VERSION }}";
{% 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>
......
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