1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
<head>
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.7.1/dist/leaflet.css"
integrity="sha512-xodZBNTC5n17Xt2atTPuE1HxjVMSvLVW9ocqUKLsCC5CXdbqCmblAshOMAS6/keqq/sMZMZ19scR4PsZChSR7A=="
crossorigin="">
</link>
</head>
<script src="https://unpkg.com/leaflet@1.7.1/dist/leaflet.js"
integrity="sha512-XQoYMqMTK8LvdxXYG3nZ448hOEQiglfqkJs1NOQV44cWnUrBc8PkAOcXy20w0vlaXaVUearIOBhiXZ5V3ynxwA=="
crossorigin="">
</script>
<h1>Bienvenue à l'atelier carto d'IN COMMON</h1>
<div id="mapid" style="height: 500px;">
</div>
<script>
<% @resources = Resource.order(:uuid).page params[:page] %>
<% res = @resources.first%>
var mymap = L.map('mapid').setView([50.8503396, 4.3517103],13);
L.tileLayer('https://api.mapbox.com/styles/v1/{id}/tiles/{z}/{x}/{y}?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-v11',
tileSize: 512,
zoomOffset: -1,
accessToken: 'pk.eyJ1IjoibmVtYWVsIiwiYSI6ImNrZzBrYjBudTB3bnMyenFmNWtrN3h3bmMifQ.Rkeyhm-9iIQOV7NAMA5LaA'
}).addTo(mymap);
var marker = L.marker(<%= [res.feature["geometry"]["coordinates"][1],res.feature["geometry"]["coordinates"][0]]%>).addTo(mymap);
var marker = L.marker([50.850, 4.351]).addTo(mymap);
//CONTINUER AVEC LES WHILE ET CONDITIONS, @resources ne contient que 25 elements (lié au nombre d'élément par page?)
//OU PLUTOT UTILISER POSTGRES POUR FAIRE DES REQUESTES SUR @resources
var count = 0
<% i = 0
while i < 25
if @resources[i] != nil%>
var marker = L.marker(<%= [@resources[i].feature["geometry"]["coordinates"][1],@resources[i].feature["geometry"]["coordinates"][0]]%>).addTo(mymap);
console.log('<%= @resources[i].feature["properties"]["name"] %>');
console.log('<%= @resources[i].feature["geometry"]["coordinates"] %>');
count += 1
<% end %>
<% i += 1
end %>
console.log(count)
</script>
<p>Premier élément de la liste:</p>
<p><%= res.feature["properties"]["name"] %></p>
<p><%= res.feature["geometry"]["coordinates"] %></p>
|