rodolpheg

Untitled

Feb 5th, 2020
311
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.48 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <title>Carte matricielle</title>
  5. <meta charset="utf-8" />
  6. <!-- Chargement de la bibliothèque de programmation Leafletjs.com -->
  7. <link rel="stylesheet" href="https://unpkg.com/[email protected]/dist/leaflet.css"/>
  8. <script src="https://unpkg.com/[email protected]/dist/leaflet.js"></script>
  9. <style>
  10. html, body {height: 100%; margin: 0;}
  11. #map { width: 100%; height: 100%; }
  12. .titre <h1> {
  13. font: 250px Helvetica;
  14. float: center;
  15. }
  16. .info {
  17. padding: 16px 16px;
  18. font: 14px Helvetica;
  19. background: white;
  20. background: rgba(255,255,255,0.8);
  21. box-shadow: 0 0 15px rgba(0,0,0,0.2);
  22. border-radius: 5px;
  23. }
  24. .info h4 {
  25. margin: 0 0 5px; color: #777;
  26. }
  27. </style>
  28. </head>
  29. <body>
  30. <div id='map'></div>
  31. <script>
  32.  
  33. // Initialisation d'une carte avec plusieurs fonds de carte
  34. // Nous mettons l'adresse de l'API MapBox dans une variable 'mapboxUrl'. Nottez la variable {id} qui sera attribuée plus tard (ligne 39, 40, 41) pour chaque fond de carte. 'votre_clef' doit être remplacé par la clef que vous trouverez sur account.mapbox.com
  35. mapboxUrl = 'https://api.mapbox.com/styles/v1/{id}/tiles/{z}/{x}/{y}?access_token=votre_clef';
  36. // Création d'une variable dans laquelle nous mettons les informations d'attribution
  37. mapboxAttribution = 'Fond de carte &copy; <a href="https://www.openstreetmap.org/">OpenStreetMap</a> contributors, ' + '<a href="https://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>, ' + 'via © <a href="https://www.mapbox.com/">Mapbox</a>'
  38. // Création des trois fond de carte en réutilisant les variables précédemment céées
  39. var light = L.tileLayer(mapboxUrl, {id: 'mapbox/light-v10', attribution: mapboxAttribution});
  40. var streets = L.tileLayer(mapboxUrl, {id: 'mapbox/streets-v11', attribution: mapboxAttribution});
  41. var sat = L.tileLayer(mapboxUrl, {id: 'mapbox/satellite-v9', attribution: mapboxAttribution});
  42. // Création de l'objet cartographique nque l'on nomme 'map' et à qui l'on passe nos trois fonds de carte
  43. var map = L.map('map', {
  44. center: [45.52,-73.63],
  45. zoom: 13,
  46. layers: [sat, streets, light]
  47. });
  48. // création d'objet 'images géoréférencées'. L'image que nous utilisons, s'il s'agit d'une carte matricielle, doit être dans la projection que l'on utilise pour notre cartographie en ligne, c'est à dire Web Mercator (EPSG:3857) par défaut
  49. var c1 = 'data/mtRoyal.png',
  50. // Une liste contenant deux listes. La première contient la position du coin Sud-Ouest de notre carte matricielle à superposer, la seconde le coin Nord-Est
  51. limite_c1 = [[45.48956,-73.62192],[45.51921,-73.57408]];
  52. c1l = L.imageOverlay(c1, limite_c1)
  53.  
  54. var c2 = 'data/lafontaine.png',
  55. limite_c2 = [[45.521229,-73.575849],[45.530658,-73.562472]];
  56. c2l = L.imageOverlay(c2, limite_c2, {interactive: true}).bindPopup('<h1>Parc Lafontaine</h1>')
  57.  
  58. var c3 = 'data/laurier.png',
  59. limite_c3 = [[45.530143,-73.590992],[45.534140,-73.584588]];
  60. c3l = L.imageOverlay(c3, limite_c3, {interactive: true}).bindPopup('<h1>Parc Laurier</h1>')
  61.  
  62. var c4 = 'data/jeanne_mance.png',
  63. limite_c4 = [[45.511902,-73.589586],[45.518309,-73.576995]];
  64. c4l = L.imageOverlay(c4, limite_c4, {interactive: true}).bindPopup('<h1>Parc Jeanne Mance</h1>');
  65.  
  66. // Nous ajoutons nos cartes matricielles à notre carte générale
  67. c1l.addTo(map);
  68. c2l.addTo(map);
  69. c3l.addTo(map);
  70. c4l.addTo(map);
  71.  
  72. </script>
  73. </body>
  74. </html>
Advertisement
Add Comment
Please, Sign In to add comment