Passage à MapBox
This commit is contained in:
parent
76c7b1c642
commit
b443073921
11 changed files with 38 additions and 20 deletions
|
@ -1,4 +1,4 @@
|
|||
function initEditStage(STATIC_URL, API_URL) {
|
||||
function initEditStage(STATIC_URL, API_URL, MAPBOX_API_KEY) {
|
||||
var has_changes = true;
|
||||
var stage_object_id = $("#stage_object_id").val();
|
||||
$(window).on('beforeunload',
|
||||
|
@ -39,7 +39,7 @@ function initEditStage(STATIC_URL, API_URL) {
|
|||
var slts = $("select[multiple]").selectize();
|
||||
|
||||
// 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);
|
||||
var avis_lieu_template = $("#avis_lieu_vide").remove().html();
|
||||
var lieux_liste = $("#lieux-selector");
|
||||
|
|
|
@ -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 lieux_map = {}, lieux_list = [], stages_map = {}, lieux_db = {};
|
||||
var stages_db = {};
|
||||
|
@ -83,7 +83,12 @@ function InterfaceRecherche(STATIC_ROOT, API_LIEU, ITEMS_URL, lieux) {
|
|||
function initCarte() {
|
||||
if (map !== undefined) return;
|
||||
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 © <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);
|
||||
|
||||
$.getJSON(API_LIEU + "set/"+lieux_list.join(';')+"/?format=json", onLoadLieux);
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
function SelectLieuWidget(STATIC_ROOT, API_LIEU, target, callback) {
|
||||
function SelectLieuWidget(STATIC_ROOT, API_LIEU, MAPBOX_API_KEY, target, callback) {
|
||||
|
||||
//
|
||||
// INITIALISATION
|
||||
|
@ -63,12 +63,12 @@ function SelectLieuWidget(STATIC_ROOT, API_LIEU, target, callback) {
|
|||
|
||||
// Affiche la carte
|
||||
map = L.map(map_el[0]).setView([48.8422411,2.3430553], 15);
|
||||
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 © <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(marqueurs);
|
||||
|
||||
|
|
|
@ -13,7 +13,12 @@
|
|||
var STATIC_ROOT = "{{ STATIC_URL|escapejs }}";
|
||||
function initStageMap(lieux) {
|
||||
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 © <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);
|
||||
|
||||
function makeIcon(couleur){
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
{% block title %}{% if creation %}Nouvelle expérience{% else %}Modification d'une expérience{% endif %}{% endblock %}
|
||||
|
||||
{% 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-gplaces-autocomplete.js" %}"></script>
|
||||
<script type="text/javascript" src="{% static "js/leaflet.markercluster.js" %}"></script>
|
||||
|
@ -22,7 +22,8 @@
|
|||
$(function(){
|
||||
initEditStage(
|
||||
"{{ 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 = {};
|
||||
django.jQuery = $;
|
||||
|
|
|
@ -59,6 +59,7 @@
|
|||
var interfaceRecherche = new InterfaceRecherche(
|
||||
"{{ STATIC_URL|escapejs }}",
|
||||
"{% url 'avisstage:api_dispatch_list' resource_name="lieu" api_name="v1" %}",
|
||||
"{{ MAPBOX_API_KEY }}",
|
||||
"{% url 'avisstage:stage_items' %}",
|
||||
lieux);
|
||||
</script>
|
||||
|
|
|
@ -6,6 +6,7 @@ from django.views.generic import DetailView, ListView
|
|||
from django.views.generic.edit import UpdateView, CreateView
|
||||
from django import forms
|
||||
from django.urls import reverse
|
||||
from django.conf import settings
|
||||
from django.contrib.admin.views.decorators import staff_member_required
|
||||
from django.contrib.auth.decorators import login_required
|
||||
from braces.views import LoginRequiredMixin
|
||||
|
@ -75,6 +76,10 @@ class StageView(LoginRequiredMixin, DetailView):
|
|||
|
||||
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
|
||||
def faq(request):
|
||||
|
@ -156,7 +161,9 @@ def manage_stage(request, pk=None):
|
|||
return render(request, "avisstage/formulaires/stage.html",
|
||||
{'form': form, 'avis_stage_form': avis_stage_form,
|
||||
'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
|
||||
#login_required
|
||||
|
|
|
@ -229,7 +229,8 @@ def recherche_resultats(request):
|
|||
template_name = 'avisstage/recherche/stage_items.html'
|
||||
return render(request, template_name,
|
||||
{"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
|
||||
@en_scolarite_required
|
||||
|
|
|
@ -12,6 +12,8 @@ https://docs.djangoproject.com/en/1.7/ref/settings/
|
|||
import os
|
||||
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__))
|
||||
|
||||
# Quick-start development settings - unsuitable for production
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
from .settings_base import *
|
||||
|
||||
from .secrets import SECRET_KEY
|
||||
|
||||
DEBUG = True
|
||||
|
||||
DATABASES = {
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
from .settings_base import *
|
||||
|
||||
from .secrets import SECRET_KEY
|
||||
|
||||
import os, sys
|
||||
from django.core.urlresolvers import reverse_lazy
|
||||
|
||||
|
|
Loading…
Reference in a new issue