aboutsummaryrefslogtreecommitdiff
path: root/app/views/welcome/index.html.erb
blob: a07a034161cdb3fcaa7be4cab5074380f6534eb4 (plain)
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
<% content_for :head do %>
    <%= stylesheet_link_tag("https://unpkg.com/leaflet@1.7.1/dist/leaflet.css",
                            integrity: "sha512-xodZBNTC5n17Xt2atTPuE1HxjVMSvLVW9ocqUKLsCC5CXdbqCmblAshOMAS6/keqq/sMZMZ19scR4PsZChSR7A==",
                            crossorigin: '') %>
    <%= javascript_include_tag("https://unpkg.com/leaflet@1.7.1/dist/leaflet.js",
                               integrity: "sha512-XQoYMqMTK8LvdxXYG3nZ448hOEQiglfqkJs1NOQV44cWnUrBc8PkAOcXy20w0vlaXaVUearIOBhiXZ5V3ynxwA==",
                               crossorigin: '') %>
<% end %>
<script>

	function update_leaflet(points_list){
		console.log(points_list)
		console.log("EAFEAG")
		var marker = L.marker([50.900, 4.351]).addTo(mymap);
		var marker = L.marker([50.950, 4.351]).addTo(mymap);
		console.log(document.getElementsByName("categories")[0].value)
		<%= x = 2 %>
	}
	function get_selected_categories(){
		<%= def tt(v)
			puts v
		end %>
		cats = document.getElementsByName("cat_sel")
		checked = []
		for (i = 0; i < cats.length; i++){
			if (cats[i].checked){
				checked.push(cats[i].value)
			}
		}
		console.log(checked)
	}
</script>
<h1>Bienvenue à l'atelier carto d'IN COMMON</h1>

<%= tag.div(id: 'map') %>

<% content_for :debug do %>
	<%= def test_button
		list_points = Resource.where('feature @> ?', {"properties": {"categories": [87]}}.to_json)
		res_list = 0
		i = 0
		puts list_points
		return(list_points)
		end%>
    <p>Premier élément de la liste:</p>
    <% res = @resources.first %>
    <p><%= res.feature["properties"]["name"] %></p>
    <p><%= res.feature["geometry"]["coordinates"] %></p>
    <button onclick=<%= test_button() %>>Test</button>
	<% x = Resource.where('feature @> ?', {"properties": {"categories": [87]}}.to_json)%>
	<%= x[0].feature %>
	<%= @number_fiel = number_field_tag("categories")%>
	<%= "NUMBER FIELD:" + @number_fiel %>
	<p></p>
	<%= x1 = Resource.where('feature @> ?', {"properties": {"categories": [@number_fiel]}}.to_json) %>
	<%= "TEST" %>
	<%= link_to("test_button", "", :onclick=> "update_leaflet(" + "[50.900, 4.351]" + ")", data: "ABC", remote: true)%>
	<p></p>
	<%= categories = Category.order(:id)%>
	<%= check_box_tag(categories[0].id, value="1", :onchange=>'alert()') %>
	<p></p>
	<p></p>
	<% categories.each do |category| %>
		<%= x = check_box_tag("cat_sel", value=category.dewey_id, :onchange=> 'alert()') %>
		
		<%= puts x %>
		<%= label_tag(category.name) %>
	<% end %>
	<%= link_to("Update Leaflet", "", :onclick=> "test_button()", remote: true)%>

<% end %>

<% content_for :body_end do %>
<script>
	var mymap = L.map('map').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 &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-v11',
		tileSize: 512,
		zoomOffset: -1,
		accessToken: 'pk.eyJ1IjoibmVtYWVsIiwiYSI6ImNrZzBrYjBudTB3bnMyenFmNWtrN3h3bmMifQ.Rkeyhm-9iIQOV7NAMA5LaA'
	}).addTo(mymap);
	var marker = L.marker([50.850, 4.351]).addTo(mymap);
</script>
<% end %>