Passage à MapBox

This commit is contained in:
Evarin 2019-02-25 17:17:58 +01:00
parent 76c7b1c642
commit b443073921
11 changed files with 38 additions and 20 deletions

View file

@ -1,4 +1,4 @@
function initEditStage(STATIC_URL, API_URL) { function initEditStage(STATIC_URL, API_URL, MAPBOX_API_KEY) {
var has_changes = true; var has_changes = true;
var stage_object_id = $("#stage_object_id").val(); var stage_object_id = $("#stage_object_id").val();
$(window).on('beforeunload', $(window).on('beforeunload',
@ -39,7 +39,7 @@ function initEditStage(STATIC_URL, API_URL) {
var slts = $("select[multiple]").selectize(); var slts = $("select[multiple]").selectize();
// CHOIX DU LIEU // CHOIX DU LIEU
var lieu_select = new SelectLieuWidget(STATIC_URL, API_URL, var lieu_select = new SelectLieuWidget(STATIC_URL, API_URL, MAPBOX_API_KEY,
$("#lieu_widget"), lieuChoisi); $("#lieu_widget"), lieuChoisi);
var avis_lieu_template = $("#avis_lieu_vide").remove().html(); var avis_lieu_template = $("#avis_lieu_vide").remove().html();
var lieux_liste = $("#lieux-selector"); var lieux_liste = $("#lieux-selector");

View file

@ -1,4 +1,4 @@
function InterfaceRecherche(STATIC_ROOT, API_LIEU, ITEMS_URL, lieux) { function InterfaceRecherche(STATIC_ROOT, API_LIEU, MAPBOX_API_KEY, ITEMS_URL, lieux) {
var interface_mode, main_container; var interface_mode, main_container;
var lieux_map = {}, lieux_list = [], stages_map = {}, lieux_db = {}; var lieux_map = {}, lieux_list = [], stages_map = {}, lieux_db = {};
var stages_db = {}; var stages_db = {};
@ -83,7 +83,12 @@ function InterfaceRecherche(STATIC_ROOT, API_LIEU, ITEMS_URL, lieux) {
function initCarte() { function initCarte() {
if (map !== undefined) return; if (map !== undefined) return;
map = L.map("carte").panTo([30, 15]).setZoom(1); map = L.map("carte").panTo([30, 15]).setZoom(1);
var layer = new L.TileLayer("https://korona.geog.uni-heidelberg.de/tiles/roads/x={x}&y={y}&z={z}", {attribution: 'Map tiles by <a href="http://korona.geog.uni-heidelberg.de/">GIScience Heidelberg</a>'}); var layer = L.tileLayer('https://api.tiles.mapbox.com/v4/{id}/{z}/{x}/{y}.png?access_token={accessToken}', {
attribution: 'Map data &copy; <a href="https://www.openstreetmap.org/">OpenStreetMap</a> contributors, <a href="https://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>, Imagery © <a href="https://www.mapbox.com/">Mapbox</a>',
maxZoom: 18,
id: 'mapbox.streets',
accessToken: MAPBOX_API_KEY
});
map.addLayer(layer); map.addLayer(layer);
$.getJSON(API_LIEU + "set/"+lieux_list.join(';')+"/?format=json", onLoadLieux); $.getJSON(API_LIEU + "set/"+lieux_list.join(';')+"/?format=json", onLoadLieux);

View file

@ -1,4 +1,4 @@
function SelectLieuWidget(STATIC_ROOT, API_LIEU, target, callback) { function SelectLieuWidget(STATIC_ROOT, API_LIEU, MAPBOX_API_KEY, target, callback) {
// //
// INITIALISATION // INITIALISATION
@ -63,12 +63,12 @@ function SelectLieuWidget(STATIC_ROOT, API_LIEU, target, callback) {
// Affiche la carte // Affiche la carte
map = L.map(map_el[0]).setView([48.8422411,2.3430553], 15); map = L.map(map_el[0]).setView([48.8422411,2.3430553], 15);
var layer = new L.TileLayer( var layer = L.tileLayer('https://api.tiles.mapbox.com/v4/{id}/{z}/{x}/{y}.png?access_token={accessToken}', {
"https://korona.geog.uni-heidelberg.de/" attribution: 'Map data &copy; <a href="https://www.openstreetmap.org/">OpenStreetMap</a> contributors, <a href="https://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>, Imagery © <a href="https://www.mapbox.com/">Mapbox</a>',
+ "tiles/roads/x={x}&y={y}&z={z}", maxZoom: 18,
{attribution: 'Map tiles by ' + id: 'mapbox.streets',
'<a href="http://korona.geog.uni-heidelberg.de/">' + accessToken: MAPBOX_API_KEY
'GIScience Heidelberg</a>'}); });
map.addLayer(layer); map.addLayer(layer);
map.addLayer(marqueurs); map.addLayer(marqueurs);

View file

@ -13,7 +13,12 @@
var STATIC_ROOT = "{{ STATIC_URL|escapejs }}"; var STATIC_ROOT = "{{ STATIC_URL|escapejs }}";
function initStageMap(lieux) { function initStageMap(lieux) {
var map = L.map("stage-map"); var map = L.map("stage-map");
var layer = new L.TileLayer("https://korona.geog.uni-heidelberg.de/tiles/roads/x={x}&y={y}&z={z}", {attribution: 'Map tiles by <a href="http://korona.geog.uni-heidelberg.de/">GIScience Heidelberg</a>'}); var layer = L.tileLayer('https://api.tiles.mapbox.com/v4/{id}/{z}/{x}/{y}.png?access_token={accessToken}', {
attribution: 'Map data &copy; <a href="https://www.openstreetmap.org/">OpenStreetMap</a> contributors, <a href="https://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>, Imagery © <a href="https://www.mapbox.com/">Mapbox</a>',
maxZoom: 18,
id: 'mapbox.streets',
accessToken: "{{ MAPBOX_API_KEY|escapejs }}"
});
map.addLayer(layer); map.addLayer(layer);
function makeIcon(couleur){ function makeIcon(couleur){

View file

@ -4,7 +4,7 @@
{% block title %}{% if creation %}Nouvelle expérience{% else %}Modification d'une expérience{% endif %}{% endblock %} {% block title %}{% if creation %}Nouvelle expérience{% else %}Modification d'une expérience{% endif %}{% endblock %}
{% block extra_head %} {% block extra_head %}
<script type="text/javascript" src="//maps.googleapis.com/maps/api/js?libraries=places&key=AIzaSyDd4innPShfHcW8KDJB833vZHZSsqt-ACw"></script> <script type="text/javascript" src="//maps.googleapis.com/maps/api/js?libraries=places&key={{ GOOGLE_API_KEY }}"></script>
<script type="text/javascript" src="{% static "js/leaflet.js" %}"></script> <script type="text/javascript" src="{% static "js/leaflet.js" %}"></script>
<script type="text/javascript" src="{% static "js/leaflet-gplaces-autocomplete.js" %}"></script> <script type="text/javascript" src="{% static "js/leaflet-gplaces-autocomplete.js" %}"></script>
<script type="text/javascript" src="{% static "js/leaflet.markercluster.js" %}"></script> <script type="text/javascript" src="{% static "js/leaflet.markercluster.js" %}"></script>
@ -22,7 +22,8 @@
$(function(){ $(function(){
initEditStage( initEditStage(
"{{ STATIC_URL|escapejs }}", "{{ STATIC_URL|escapejs }}",
"{% url 'avisstage:api_dispatch_list' resource_name="lieu" api_name="v1" %}"); "{% url 'avisstage:api_dispatch_list' resource_name="lieu" api_name="v1" %}",
"{{ MAPBOX_API_KEY|escapejs }}");
}); });
var django = {}; var django = {};
django.jQuery = $; django.jQuery = $;

View file

@ -59,6 +59,7 @@
var interfaceRecherche = new InterfaceRecherche( var interfaceRecherche = new InterfaceRecherche(
"{{ STATIC_URL|escapejs }}", "{{ STATIC_URL|escapejs }}",
"{% url 'avisstage:api_dispatch_list' resource_name="lieu" api_name="v1" %}", "{% url 'avisstage:api_dispatch_list' resource_name="lieu" api_name="v1" %}",
"{{ MAPBOX_API_KEY }}",
"{% url 'avisstage:stage_items' %}", "{% url 'avisstage:stage_items' %}",
lieux); lieux);
</script> </script>

View file

@ -6,6 +6,7 @@ from django.views.generic import DetailView, ListView
from django.views.generic.edit import UpdateView, CreateView from django.views.generic.edit import UpdateView, CreateView
from django import forms from django import forms
from django.urls import reverse from django.urls import reverse
from django.conf import settings
from django.contrib.admin.views.decorators import staff_member_required from django.contrib.admin.views.decorators import staff_member_required
from django.contrib.auth.decorators import login_required from django.contrib.auth.decorators import login_required
from braces.views import LoginRequiredMixin from braces.views import LoginRequiredMixin
@ -75,6 +76,10 @@ class StageView(LoginRequiredMixin, DetailView):
return Stage.objects.filter(filtre) return Stage.objects.filter(filtre)
def get_context_data(self, *args, **kwargs):
context = super().get_context_data(*args, **kwargs)
context['MAPBOX_API_KEY'] = settings.MAPBOX_API_KEY
return context
# FAQ # FAQ
def faq(request): def faq(request):
@ -156,7 +161,9 @@ def manage_stage(request, pk=None):
return render(request, "avisstage/formulaires/stage.html", return render(request, "avisstage/formulaires/stage.html",
{'form': form, 'avis_stage_form': avis_stage_form, {'form': form, 'avis_stage_form': avis_stage_form,
'avis_lieu_formset': avis_lieu_formset, 'avis_lieu_formset': avis_lieu_formset,
'creation': pk is None, "last_maj": last_maj}) 'creation': pk is None, "last_maj": last_maj,
'GOOGLE_API_KEY': settings.GOOGLE_API_KEY,
'MAPBOX_API_KEY': settings.MAPBOX_API_KEY})
# Ajout d'un lieu de stage # Ajout d'un lieu de stage
#login_required #login_required

View file

@ -229,7 +229,8 @@ def recherche_resultats(request):
template_name = 'avisstage/recherche/stage_items.html' template_name = 'avisstage/recherche/stage_items.html'
return render(request, template_name, return render(request, template_name,
{"form": form, "stages": stages, "paginator": stageids, {"form": form, "stages": stages, "paginator": stageids,
"tri": tri, "vue": vue, "lieux": lieux}) "tri": tri, "vue": vue, "lieux": lieux,
"MAPBOX_API_KEY": settings.MAPBOX_API_KEY})
@login_required @login_required
@en_scolarite_required @en_scolarite_required

View file

@ -12,6 +12,8 @@ https://docs.djangoproject.com/en/1.7/ref/settings/
import os import os
from django.core.urlresolvers import reverse_lazy from django.core.urlresolvers import reverse_lazy
from .secrets import SECRET_KEY, GOOGLE_API_KEY, MAPBOX_API_KEY
BASE_DIR = os.path.dirname(os.path.dirname(__file__)) BASE_DIR = os.path.dirname(os.path.dirname(__file__))
# Quick-start development settings - unsuitable for production # Quick-start development settings - unsuitable for production

View file

@ -1,7 +1,5 @@
from .settings_base import * from .settings_base import *
from .secrets import SECRET_KEY
DEBUG = True DEBUG = True
DATABASES = { DATABASES = {

View file

@ -1,7 +1,5 @@
from .settings_base import * from .settings_base import *
from .secrets import SECRET_KEY
import os, sys import os, sys
from django.core.urlresolvers import reverse_lazy from django.core.urlresolvers import reverse_lazy