Advertisement
rodolpheg

Untitled

Feb 16th, 2021
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.85 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <title>Un titre</title>
  5. <meta charset="UTF-8">
  6. <!-- Téléchargement de la bibliothèque Leaflet.js -->
  7. <script src="https://unpkg.com/leaflet@1.6.0/dist/leaflet.js"></script>
  8. <!-- Importation du plugin Leaflet.ajax-->
  9. <script src='plugins/leaflet.ajax.min.js'></script>
  10. <!-- Téléchargement des instructions CSS de Leaflet, qui serviront à styliser les éléments de l'interface de la carte -->
  11. <link rel="stylesheet" href="https://unpkg.com/leaflet@1.6.0/dist/leaflet.css" />
  12.  
  13. <!-- Ajout d'information de style pour la page entière et le DIV ID='Carte'-->
  14. <style>
  15. html, body {height: 100%; margin: 0;}
  16. #Carte {width: 100%; height: 100%;}
  17. </style>
  18. </head>
  19. <body>
  20. <!-- Création d'un <div> qui contiendra notre carte-->
  21. <div id='Carte'></div>
  22.  
  23. <!-- Début du script JavaScript-->
  24. <script>
  25. // Création d'une variable "maCarte" qui contiendra... ma carte.
  26. maCarte = L.map('Carte')
  27. // On donne une position lat lng et un niveau de zoom par défaut
  28. maCarte.setView([45.5,-73.5], 10)
  29. // On définit notre fond de carte qui téléchargera les tuiles avec l'API Mapbox, vous devez d'abord aller chercher "VOTRE_CLÉ" sur https://account.mapbox.com
  30. fondDeCarte = L.tileLayer('https://api.mapbox.com/styles/v1/mapbox/light-v10/tiles/{z}/{x}/{y}?access_token=VOTRE_TOKEN')
  31. // J'attache ce fond de plan à ma carte
  32. fondDeCarte.addTo(maCarte)
  33.  
  34. // Utilisation du plugin Leaflet.ajax pour importer un fichier json externe de manière asynchrone
  35. couche = new L.GeoJSON.AJAX('data/Montreal_v0743.geojson')
  36. couche.addTo(maCarte)
  37.  
  38. // Ajout de la référence pour les données
  39. maCarte.attributionControl.addAttribution('Fond de plan OSM & MapBox. Données &copy; <a href="http://statisticscanada.ca/">Statistiques Canada</a>');
  40. </script>
  41. </body>
  42. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement